~ubuntu-branches/ubuntu/vivid/ncbi-tools6/vivid-proposed

« back to all changes in this revision

Viewing changes to tools/toporg.c

  • Committer: Package Import Robot
  • Author(s): Aaron M. Ucko, Andreas Tille
  • Date: 2012-06-24 22:54:29 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20120624225429-y81u0gzrppi3fhyf
Tags: 6.1.20120620-2
[ Andreas Tille ]
debian/upstream: Strings containing ': ' need to be quoted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
static char const rcsid[] = "$Id: toporg.c,v 6.183 2011/07/07 21:24:49 kans Exp $";
 
1
static char const rcsid[] = "$Id: toporg.c,v 6.197 2012/05/10 21:20:48 kans Exp $";
2
2
 
3
3
#include <stdio.h>
4
4
#include <ncbi.h>
15
15
#include <subutil.h>
16
16
#include <tofasta.h>
17
17
#include <objfdef.h>
 
18
#include <valid.h>
18
19
 
19
20
static ValNodePtr GetDescrNoTitles (ValNodePtr PNTR descr);
20
21
 
5032
5033
  VisitBioseqsInSep (sep, NULL, StripBadTitleFromProteinProducts);
5033
5034
}
5034
5035
 
5035
 
/*
5036
 
  EC number replacement - copied from Sequin, with protection
5037
 
  multiple reads if no replacement file available
5038
 
*/
5039
 
 
5040
 
typedef struct ecrepdata {
5041
 
  CharPtr  before;
5042
 
  CharPtr  after;
5043
 
} EcRepData, PNTR EcRepPtr;
5044
 
 
5045
 
static ValNodePtr     ec_rep_list = NULL;
5046
 
static EcRepPtr PNTR  ec_rep_data = NULL;
5047
 
static Int4           ec_rep_len = 0;
5048
 
static Boolean        ec_rep_read = FALSE;
5049
 
 
5050
 
static int LIBCALLBACK SortVnpByEcBefore (VoidPtr ptr1, VoidPtr ptr2)
5051
 
 
5052
 
{
5053
 
  EcRepPtr    erp1, erp2;
5054
 
  CharPtr     str1, str2;
5055
 
  ValNodePtr  vnp1, vnp2;
5056
 
 
5057
 
  if (ptr1 == NULL || ptr2 == NULL) return 0;
5058
 
  vnp1 = *((ValNodePtr PNTR) ptr1);
5059
 
  vnp2 = *((ValNodePtr PNTR) ptr2);
5060
 
  if (vnp1 == NULL || vnp2 == NULL) return 0;
5061
 
  erp1 = (EcRepPtr) vnp1->data.ptrvalue;
5062
 
  erp2 = (EcRepPtr) vnp2->data.ptrvalue;
5063
 
  if (erp1 == NULL || erp2 == NULL) return 0;
5064
 
  str1 = erp1->before;
5065
 
  str2 = erp2->before;
5066
 
  if (str1 == NULL || str2 == NULL) return 0;
5067
 
  return StringCmp (str1, str2);
5068
 
}
5069
 
 
5070
 
static void SetupECReplacementTable (CharPtr file)
5071
 
 
5072
 
{
5073
 
  EcRepPtr    erp;
5074
 
  FileCache   fc;
5075
 
  FILE        *fp = NULL;
5076
 
  Int4        i;
5077
 
  ValNodePtr  last = NULL;
5078
 
  Char        line [512];
5079
 
  Char        path [PATH_MAX];
5080
 
  CharPtr     ptr;
5081
 
  ErrSev      sev;
5082
 
  CharPtr     str;
5083
 
  ValNodePtr  vnp;
5084
 
 
5085
 
  if (ec_rep_data != NULL) return;
5086
 
  if (ec_rep_read) return;
5087
 
 
5088
 
  if (FindPath ("ncbi", "ncbi", "data", path, sizeof (path))) {
5089
 
    FileBuildPath (path, NULL, file);
5090
 
    sev = ErrSetMessageLevel (SEV_ERROR);
5091
 
    fp = FileOpen (path, "r");
5092
 
    ErrSetMessageLevel (sev);
5093
 
    if (fp != NULL) {
5094
 
      FileCacheSetup (&fc, fp);
5095
 
  
5096
 
      str = FileCacheReadLine (&fc, line, sizeof (line), NULL);
5097
 
      while (str != NULL) {
5098
 
        if (StringDoesHaveText (str)) {
5099
 
          ptr = StringChr (str, '\t');
5100
 
          if (ptr != NULL) {
5101
 
            *ptr = '\0';
5102
 
            ptr++;
5103
 
            /* only replace if a single destination number, not a split from one to many */
5104
 
            if (StringChr (ptr, '\t') == NULL) {
5105
 
              erp = (EcRepPtr) MemNew (sizeof (EcRepData));
5106
 
              if (erp != NULL) {
5107
 
                erp->before = StringSave (str);
5108
 
                erp->after = StringSave (ptr);
5109
 
                vnp = ValNodeAddPointer (&last, 0, (Pointer) erp);
5110
 
                if (ec_rep_list == NULL) {
5111
 
                  ec_rep_list = vnp;
5112
 
                }
5113
 
                last = vnp;
5114
 
              }
5115
 
            }
5116
 
          }
5117
 
        }
5118
 
        str = FileCacheReadLine (&fc, line, sizeof (line), NULL);
5119
 
      }
5120
 
 
5121
 
      FileClose (fp);
5122
 
      ec_rep_len = ValNodeLen (ec_rep_list);
5123
 
      if (ec_rep_len > 0) {
5124
 
        ec_rep_list = ValNodeSort (ec_rep_list, SortVnpByEcBefore);
5125
 
        ec_rep_data = (EcRepPtr PNTR) MemNew (sizeof (EcRepPtr) * (ec_rep_len + 1));
5126
 
        if (ec_rep_data != NULL) {
5127
 
          for (vnp = ec_rep_list, i = 0; vnp != NULL; vnp = vnp->next, i++) {
5128
 
            erp = (EcRepPtr) vnp->data.ptrvalue;
5129
 
            ec_rep_data [i] = erp;
5130
 
          }
5131
 
        }
5132
 
      }
5133
 
    }
5134
 
  }
5135
 
 
5136
 
  ec_rep_read = TRUE;
5137
 
}
5138
 
 
5139
 
static CharPtr GetECReplacement (CharPtr str)
5140
 
 
5141
 
{
5142
 
  EcRepPtr  erp;
5143
 
  Int4      L, R, mid;
5144
 
 
5145
 
  if (StringHasNoText (str)) return NULL;
5146
 
 
5147
 
  L = 0;
5148
 
  R = ec_rep_len - 1;
5149
 
  while (L < R) {
5150
 
    mid = (L + R) / 2;
5151
 
    erp = ec_rep_data [(int) mid];
5152
 
    if (erp != NULL && StringCmp (erp->before, str) < 0) {
5153
 
      L = mid + 1;
5154
 
    } else {
5155
 
      R = mid;
5156
 
    }
5157
 
  }
5158
 
  erp = ec_rep_data [(int) R];
5159
 
  if (erp != NULL && StringCmp (erp->before, str) == 0 && StringChr (erp->after, '\t') == NULL) return erp->after;
5160
 
 
5161
 
  return NULL;
5162
 
}
5163
 
 
5164
 
static void UpdateProtEC (SeqFeatPtr sfp, Pointer userdata)
5165
 
 
5166
 
{
5167
 
  Int2        inf_loop_check;
5168
 
  CharPtr     nxt;
5169
 
  ProtRefPtr  prp;
5170
 
  CharPtr     rep;
5171
 
  CharPtr     str;
5172
 
  ValNodePtr  vnp;
5173
 
 
 
5036
static void RemoveOrgFromEndOfProtein (SeqFeatPtr sfp, Pointer userdata)
 
5037
 
 
5038
{
 
5039
  BioSourcePtr  biop;
 
5040
  BioseqPtr     bsp;
 
5041
  CharPtr       cp;
 
5042
  size_t        len;
 
5043
  OrgRefPtr     orp;
 
5044
  ProtRefPtr    prp;
 
5045
  SeqDescrPtr   sdp;
 
5046
  CharPtr       str;
 
5047
  ValNodePtr    vnp;
 
5048
 
5174
5049
  if (sfp == NULL || sfp->data.choice != SEQFEAT_PROT) return;
5175
5050
  prp = (ProtRefPtr) sfp->data.value.ptrvalue;
5176
 
  if (prp == NULL || prp->ec == NULL) return;
5177
 
  for (vnp = prp->ec; vnp != NULL; vnp = vnp->next) {
 
5051
  if (prp == NULL) return;
 
5052
 
 
5053
  for (vnp = prp->name; vnp != NULL; vnp = vnp->next) {
5178
5054
    str = (CharPtr) vnp->data.ptrvalue;
5179
5055
    if (StringHasNoText (str)) continue;
5180
 
    rep = GetECReplacement (str);
5181
 
    if (rep == NULL) continue;
5182
 
    nxt = rep;
5183
 
    inf_loop_check = 0;
5184
 
    while (nxt != NULL && inf_loop_check < 10) {
5185
 
      rep = nxt;
5186
 
      inf_loop_check++;
5187
 
      nxt = GetECReplacement (rep);
5188
 
    }
5189
 
    vnp->data.ptrvalue = MemFree (vnp->data.ptrvalue);
5190
 
    vnp->data.ptrvalue = StringSave (rep);
 
5056
    len = StringLen (str);
 
5057
    if (len < 5) continue;
 
5058
    if (str [len - 1] != ']') continue;
 
5059
    cp = StringRChr (str, '[');
 
5060
    if (cp == NULL) continue;
 
5061
    if (StringNCmp (cp, "[NAD", 4) == 0) continue;
 
5062
    bsp = BioseqFindFromSeqLoc (sfp->location);
 
5063
    if (bsp == NULL) continue;
 
5064
    sdp = GetNextDescriptorUnindexed (bsp, Seq_descr_source, NULL);
 
5065
    if (sdp == NULL) continue;
 
5066
    biop = (BioSourcePtr) sdp->data.ptrvalue;
 
5067
    if (biop == NULL) continue;
 
5068
    orp = biop->org;
 
5069
    if (orp == NULL) continue;
 
5070
    if (StringHasNoText (orp->taxname)) continue;
 
5071
    len = StringLen (orp->taxname);
 
5072
    if (StringLen (cp) != len + 2) continue;
 
5073
    if (StringNICmp (cp + 1, orp->taxname, len - 1) != 0) continue;
 
5074
    *cp = '\0';
 
5075
    TrimSpacesAroundString (orp->taxname);
5191
5076
  }
5192
5077
}
5193
5078
 
5215
5100
  AddIntegerToNcbiCleanupUserObject (uop, "day", dp->data [3]);
5216
5101
  AddIntegerToNcbiCleanupUserObject (uop, "year", dp->data [1] + 1900);
5217
5102
 
 
5103
  DateFree (dp);
 
5104
 
5218
5105
  sdp = NewDescrOnSeqEntry (sep, Seq_descr_user);
5219
5106
  if (sdp == NULL) return;
5220
5107
  sdp->data.ptrvalue = uop;
5247
5134
  /* clear indexes, since CleanupEmptyFeatCallback removes genes, etc. */
5248
5135
  SeqMgrClearFeatureIndexes (entityID, NULL);
5249
5136
  RemoveAllNcbiCleanupUserObjects (sep);
5250
 
  RemoveDuplicateNestedSetsForEntityID (entityID);
 
5137
  RemoveDuplicateNestedSetsForEntityIDNoUpdate (entityID);
5251
5138
  SeqMgrClearFeatureIndexes (entityID, NULL);
5252
5139
  if (IS_Bioseq_set (sep)) {
5253
5140
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
5316
5203
  move_cds_ex (sep, doPseudo);
5317
5204
  SeqEntryExplore (sep, NULL, MolInfoUpdate);
5318
5205
  DeleteMarkedObjects (0, OBJ_SEQENTRY, (Pointer) sep);
 
5206
  VisitFeaturesInSep (sep, NULL, RemoveOrgFromEndOfProtein);
5319
5207
  /* do these again, since SE2A3 can create full length source feature */
5320
5208
  SeqEntryExplore (sep, NULL, CleanupGenbankCallback);
5321
5209
  ConvertFullLenSourceFeatToDesc (sep);
5323
5211
  SeqEntryExplore (sep, NULL, CleanupEmptyFeatCallback);
5324
5212
  SeqEntryExplore (sep, NULL, MergeAdjacentAnnotsCallback);
5325
5213
  /* VisitBioseqsInSep (sep, NULL, BarCodeTechToKeyword); */
5326
 
  SetupECReplacementTable ("ecnum_replaced.txt");
5327
 
  if (ec_rep_data != NULL && ec_rep_len > 0) {
5328
 
    VisitFeaturesInSep (sep, NULL, UpdateProtEC);
 
5214
 
 
5215
  /* tbl2asn now calls processes EC numbers with reporting before SSEC */
 
5216
  UpdateReplacedECNumbersEx (sep, NULL, NULL, TRUE, FALSE);
 
5217
 
 
5218
  /*
 
5219
   if (GetAppProperty ("NcbiTbl2Asn") != NULL) {
 
5220
    DeleteBadECNumbers (sep);
5329
5221
  }
 
5222
  */
 
5223
 
5330
5224
  /* reindex, since CdEndCheck (from CdCheck) gets best overlapping gene */
5331
5225
  SeqMgrIndexFeatures (entityID, NULL);
5332
5226
  biop = NULL;
5364
5258
      VisitBioseqsInSep (sep, (Pointer) &isEmblOrDdbj, RemoveUnneededGeneXrefs);
5365
5259
    }
5366
5260
  }
 
5261
  ResynchCodingRegionPartials (sep);
 
5262
  ResynchMessengerRNAPartials (sep);
 
5263
  ResynchProteinPartials (sep);
5367
5264
  InstantiateProteinTitles (entityID, NULL);
5368
5265
  SeqMgrClearFeatureIndexes (entityID, NULL);
5369
5266
  MakeNcbiCleanupObject (sep, gpipeMode);
5422
5319
  AddIntegerToNcbiCleanupUserObject (uop, "day", dp->data [3]);
5423
5320
  AddIntegerToNcbiCleanupUserObject (uop, "year", dp->data [1] + 1900);
5424
5321
 
 
5322
  DateFree (dp);
 
5323
 
5425
5324
  adp = AnnotDescrNew (NULL);
5426
5325
  if (adp == NULL) return;
5427
5326
 
6022
5921
  hasNulls = LocationHasNullsBetween (sfp->location);
6023
5922
 
6024
5923
  if (sfp->data.choice == SEQFEAT_GENE) {
6025
 
    slp = SeqLocMergeExEx (bsp, sfp->location, NULL, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE);
 
5924
    slp = SeqLocMergeExEx (bsp, sfp->location, NULL, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE);
6026
5925
    hasNulls = FALSE;
6027
5926
    sfp->partial = FALSE;
6028
5927
  } else if (sfp->data.choice == SEQFEAT_CDREGION) {
6029
 
    slp = SeqLocMergeExEx (bsp, sfp->location, NULL, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE);
 
5928
    slp = SeqLocMergeExEx (bsp, sfp->location, NULL, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE);
6030
5929
  } else if (sfp->data.choice == SEQFEAT_RNA) {
6031
 
    slp = SeqLocMergeExEx (bsp, sfp->location, NULL, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE);
 
5930
    slp = SeqLocMergeExEx (bsp, sfp->location, NULL, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE);
6032
5931
  } else {
6033
 
    slp = SeqLocMergeExEx (bsp, sfp->location, NULL, FALSE, TRUE, FALSE, hasNulls, FALSE, FALSE);
 
5932
    slp = SeqLocMergeExEx (bsp, sfp->location, NULL, FALSE, TRUE, FALSE, hasNulls, FALSE, FALSE, FALSE);
6034
5933
  }
6035
5934
  if (slp == NULL) {
6036
5935
    ValNodeFree (partiallist);