~ubuntu-branches/debian/experimental/ncbi-tools6/experimental

« back to all changes in this revision

Viewing changes to api/sqnutil1.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2008-07-14 19:43:15 UTC
  • mfrom: (2.1.12 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080714194315-ed44u9ek7txva2rz
Tags: 6.1.20080302-3
tools/readdb.c: enable madvise()-based code on all glibc (hence all
Debian) systems, not just Linux.  (Closes: #490437.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*
30
30
* Version Creation Date:   9/2/97
31
31
*
32
 
* $Revision: 6.388 $
 
32
* $Revision: 6.433 $
33
33
*
34
34
* File Description: 
35
35
*
481
481
}
482
482
 
483
483
typedef struct tripletdata {
484
 
        Uint2      entityID;
485
 
        Uint4      itemID;
486
 
        Uint2      itemtype;
487
 
        Pointer    lookfor;
 
484
    Uint2      entityID;
 
485
    Uint4      itemID;
 
486
    Uint2      itemtype;
 
487
    Pointer    lookfor;
488
488
} TripletData, PNTR TripletDataPtr;
489
489
 
490
490
static Boolean FindIDsFromPointer (GatherContextPtr gcp)
587
587
NLM_EXTERN void SaveSeqEntryObjMgrData (SeqEntryPtr target, ObjMgrDataPtr PNTR omdptopptr, ObjMgrData PNTR omdataptr)
588
588
 
589
589
{
590
 
  ObjMgrPtr          omp;
 
590
  ObjMgrPtr         omp;
591
591
  ObjMgrDataPtr  omdp, omdptop = NULL;
592
592
 
593
593
  if (target == NULL || omdptopptr == NULL || omdataptr == NULL) return;
610
610
NLM_EXTERN void RestoreSeqEntryObjMgrData (SeqEntryPtr target, ObjMgrDataPtr omdptop, ObjMgrData PNTR omdataptr)
611
611
 
612
612
{
613
 
  ObjMgrPtr     omp;
 
613
  ObjMgrPtr    omp;
614
614
  ObjMgrDataPtr omdp, omdpnew = NULL;
615
615
 
616
616
  if (target == NULL || omdptop == NULL || omdataptr == NULL) return;
1151
1151
              bssp->_class != BioseqseqSet_class_eco_set &&
1152
1152
              bssp->_class != BioseqseqSet_class_wgs_set &&
1153
1153
              (bssp->_class != BioseqseqSet_class_gen_prod_set ||
1154
 
               (! tdp->skipGenProdSet))) {
 
1154
           (! tdp->skipGenProdSet))) {
1155
1155
            return FALSE;
1156
1156
          }
1157
1157
        } else if (gcp->gatherstack [i].itemtype == OBJ_BIOSEQ) {
1852
1852
  SeqFeatPtr           first;
1853
1853
  GBQualPtr            gbq;
1854
1854
  Int4                 i;
1855
 
  Char                 id [64];
 
1855
  Char                 id [128];
1856
1856
  SeqEntryPtr          last;
1857
 
  Char                 lcl [64];
 
1857
  Char                 lcl [128];
1858
1858
  BioseqPtr            mbsp;
1859
1859
  MolInfoPtr           mip;
1860
1860
  SeqEntryPtr          msep;
1976
1976
    sfp = first;
1977
1977
    while (sfp != NULL) {
1978
1978
      if (sfp->data.choice == SEQFEAT_RNA &&
1979
 
          sfp->idx.subtype != FEATDEF_tRNA &&
 
1979
          /* sfp->idx.subtype != FEATDEF_tRNA && */
1980
1980
          sfp->product == NULL && (! sfp->pseudo)) {
1981
1981
        gbq = sfp->qual;
1982
1982
        prevqual = (GBQualPtr PNTR) &(sfp->qual);
2041
2041
                mbsp->repr = Seq_repr_raw;
2042
2042
                mbsp->mol = Seq_mol_rna;
2043
2043
                mbsp->seq_data_type = Seq_code_iupacna;
2044
 
                mbsp->seq_data = bs;
 
2044
                mbsp->seq_data = (SeqDataPtr) bs;
2045
2045
                mbsp->length = BSLen (bs);
2046
2046
                BioseqPack (mbsp);
2047
2047
                bs = NULL;
2090
2090
                      case FEATDEF_snoRNA :
2091
2091
                        mip->biomol = MOLECULE_TYPE_SNORNA;
2092
2092
                        break;
 
2093
                      case FEATDEF_ncRNA :
 
2094
                        mip->biomol = MOLECULE_TYPE_NCRNA;
 
2095
                        break;
 
2096
                      case FEATDEF_tmRNA :
 
2097
                        mip->biomol = MOLECULE_TYPE_TMRNA;
 
2098
                        break;
2093
2099
                      default :
2094
2100
                        mip->biomol = 0;
2095
2101
                        break;
2182
2188
                pbsp->repr = Seq_repr_raw;
2183
2189
                pbsp->mol = Seq_mol_aa;
2184
2190
                pbsp->seq_data_type = Seq_code_ncbieaa;
2185
 
                pbsp->seq_data = bs;
 
2191
                pbsp->seq_data = (SeqDataPtr) bs;
2186
2192
                pbsp->length = BSLen (bs);
2187
2193
                bs = NULL;
2188
2194
                sep = NULL;
2394
2400
static Boolean HasNoText (CharPtr str)
2395
2401
 
2396
2402
{
2397
 
  Uchar  ch;    /* to use 8bit characters in multibyte languages */
 
2403
  Uchar  ch;    /* to use 8bit characters in multibyte languages */
2398
2404
 
2399
2405
  if (str != NULL) {
2400
2406
    ch = *str;
2413
2419
 
2414
2420
{
2415
2421
  CharPtr  amp;
2416
 
  Uchar    ch;  /* to use 8bit characters in multibyte languages */
 
2422
  Uchar    ch;    /* to use 8bit characters in multibyte languages */
2417
2423
  CharPtr  dst;
2418
2424
  CharPtr  ptr;
2419
2425
 
2470
2476
)
2471
2477
 
2472
2478
{
2473
 
  Uchar    ch;  /* to use 8bit characters in multibyte languages */
 
2479
  Uchar    ch;    /* to use 8bit characters in multibyte languages */
2474
2480
  CharPtr  dst;
2475
2481
  Boolean  isPeriod;
2476
2482
  CharPtr  ptr;
2525
2531
  return str;
2526
2532
}
2527
2533
 
 
2534
static CharPtr TrimSpacesSemicolonsAndCommas (CharPtr str)
 
2535
 
 
2536
{
 
2537
  CharPtr  amp;
 
2538
  Uchar    ch;    /* to use 8bit characters in multibyte languages */
 
2539
  CharPtr  dst;
 
2540
  CharPtr  ptr;
 
2541
 
 
2542
  if (str != NULL && str [0] != '\0') {
 
2543
    dst = str;
 
2544
    ptr = str;
 
2545
    ch = *ptr;
 
2546
    if (ch != '\0' && (ch <= ' ' || ch == ';' || ch == ',')) {
 
2547
      while (ch != '\0' && (ch <= ' ' || ch == ';' || ch == ',')) {
 
2548
        ptr++;
 
2549
        ch = *ptr;
 
2550
      }
 
2551
      while (ch != '\0') {
 
2552
        *dst = ch;
 
2553
        dst++;
 
2554
        ptr++;
 
2555
        ch = *ptr;
 
2556
      }
 
2557
      *dst = '\0';
 
2558
    }
 
2559
    amp = NULL;
 
2560
    dst = NULL;
 
2561
    ptr = str;
 
2562
    ch = *ptr;
 
2563
    while (ch != '\0') {
 
2564
      if (ch == '&') {
 
2565
        amp = ptr;
 
2566
        dst = NULL;
 
2567
      } else if (ch <= ' ') {
 
2568
        if (dst == NULL) {
 
2569
          dst = ptr;
 
2570
        }
 
2571
        amp = NULL;
 
2572
      } else if (ch == ';') {
 
2573
        if (dst == NULL && amp == NULL) {
 
2574
          dst = ptr;
 
2575
        }
 
2576
      } else if (ch == ',') {
 
2577
        if (dst == NULL) {
 
2578
          dst = ptr;
 
2579
        }
 
2580
        amp = NULL;
 
2581
      } else {
 
2582
        dst = NULL;
 
2583
      }
 
2584
      ptr++;
 
2585
      ch = *ptr;
 
2586
    }
 
2587
    if (dst != NULL) {
 
2588
      *dst = '\0';
 
2589
    }
 
2590
  }
 
2591
  return str;
 
2592
}
 
2593
 
2528
2594
static void CleanVisString (CharPtr PNTR strp)
2529
2595
 
2530
2596
{
2622
2688
  vnp = *vnpp;
2623
2689
  while (vnp != NULL) {
2624
2690
    next = vnp->next;
2625
 
    TrimSpacesAndSemicolons (vnp->data.ptrvalue);
 
2691
    TrimSpacesSemicolonsAndCommas (vnp->data.ptrvalue);
2626
2692
    if (HasNoText (vnp->data.ptrvalue) || AlreadyInVnpList (*vnpp, vnp)) {
2627
2693
      *prev = vnp->next;
2628
2694
      vnp->next = NULL;
2717
2783
        grp->locus_tag = StringSave (gbq->val);
2718
2784
        break;
2719
2785
      case 5 :
2720
 
        if (StringHasNoText (gbq->val)) return FALSE;
2721
 
        if (grp->locus_tag != NULL) {
2722
 
          if (StringICmp (gbq->val, grp->locus_tag) == 0) return TRUE;
2723
 
          return FALSE;
2724
 
        }
 
2786
/* removed by indexer request */
 
2787
/*        if (StringHasNoText (gbq->val)) return FALSE;
 
2788
 *       if (grp->locus_tag != NULL) {
 
2789
 *         if (StringICmp (gbq->val, grp->locus_tag) == 0) return TRUE;
 
2790
 *         return FALSE;
 
2791
 *       }
 
2792
 */
 
2793
        return FALSE;
2725
2794
        break;
2726
2795
      default :
2727
2796
        break;
2739
2808
   CharPtr  str, eptr, ptr;
2740
2809
   Uint1    aa;
2741
2810
 
2742
 
        str = StringStr(qval, "aa:");
2743
 
        if (str != NULL) {
2744
 
            str += 3;
2745
 
        } else {
 
2811
    str = StringStr(qval, "aa:");
 
2812
    if (str != NULL) {
 
2813
        str += 3;
 
2814
    } else {
2746
2815
        ErrPostEx (SEV_WARNING, ERR_QUALIFIER_InvalidDataFormat,
2747
2816
                   "bad transl_except %s", qval);
2748
 
        str = StringStr(qval, ",");
2749
 
        if (str != NULL) {
2750
 
            str = StringStr(str, ":");
2751
 
            if (str != NULL) {
 
2817
        str = StringStr(qval, ",");
 
2818
        if (str != NULL) {
 
2819
            str = StringStr(str, ":");
 
2820
            if (str != NULL) {
2752
2821
              str++;
2753
 
            }
2754
 
        }
2755
 
        }
 
2822
            }
 
2823
        }
 
2824
    }
2756
2825
 
2757
2826
    if (str == NULL) return (Uint1) 'X';
2758
2827
 
2759
 
        while (*str == ' ')
2760
 
        ++str;
2761
 
        for (eptr = str; *eptr != ')' && *eptr != ' ' && *eptr != '\0';  eptr++) continue;
 
2828
       while (*str == ' ')
 
2829
           ++str;
 
2830
       for (eptr = str; *eptr != ')' && *eptr != ' ' && *eptr != '\0';  eptr++) continue;
2762
2831
 
2763
2832
    ptr = TextSave(str, eptr-str);
2764
2833
    aa = ValidAminoAcid(ptr);
2773
2842
   CharPtr bptr, eptr;
2774
2843
 
2775
2844
   if ((bptr = StringStr(qval, "(pos:")) == NULL) {
2776
 
                return NULL;
 
2845
           return NULL;
2777
2846
   }
2778
2847
    
2779
2848
   bptr += 5;
3453
3522
  return FALSE;
3454
3523
}
3455
3524
 
 
3525
 
3456
3526
static Boolean HandledGBQualOnRNA (SeqFeatPtr sfp, GBQualPtr gbq, Boolean isEmblOrDdbj)
3457
3527
 
3458
3528
{
3537
3607
      }
3538
3608
    }
3539
3609
    if (rrp->ext.choice != 0 && rrp->ext.choice != 1) return FALSE;
3540
 
    if (! HasNoText ((CharPtr) rrp->ext.value.ptrvalue)) {
3541
 
      if (StringICmp ((CharPtr) rrp->ext.value.ptrvalue, gbq->val) == 0) {
 
3610
    name = (CharPtr) rrp->ext.value.ptrvalue;
 
3611
    if (! HasNoText (name)) {
 
3612
      if (StringICmp (name, gbq->val) == 0) {
3542
3613
        return TRUE;
3543
3614
      }
3544
3615
      str = StringStr (gbq->val, "rDNA");
3545
3616
      if (str != NULL) {
3546
3617
        str [1] = 'R';
3547
 
        if (StringICmp ((CharPtr) rrp->ext.value.ptrvalue, gbq->val) == 0) {
 
3618
        if (StringICmp (name, gbq->val) == 0) {
3548
3619
          return TRUE;
3549
3620
        }
3550
3621
      }
 
3622
      if (rrp->type == 255) {
 
3623
        /* new convention follows ASN.1 spec comments, allows new RNA types */
 
3624
        return FALSE;
 
3625
      }
3551
3626
      /* subsequent /product now added to comment */
3552
3627
      if (sfp->comment == NULL) {
3553
3628
        sfp->comment = gbq->val;
3682
3757
  } else if (StringICmp (gbq->qual, "label") == 0) {
3683
3758
    choice = 5;
3684
3759
  } else if (StringICmp (gbq->qual, "allele") == 0) {
3685
 
          choice = 6;
 
3760
      choice = 6;
3686
3761
  }
3687
3762
  if (choice == 1 || choice == 4) {
3688
3763
    vnp = prp->name;
3704
3779
  } else if (choice == 5) {
3705
3780
    return FALSE; /* keep label gbqual only */
3706
3781
  } else if (choice == 6) {
3707
 
          return FALSE;
 
3782
      return FALSE;
3708
3783
  }
3709
3784
 
3710
3785
  if (StringICmp (gbq->qual, "experiment") == 0 ||
3862
3937
  }
3863
3938
}
3864
3939
 
 
3940
static void CleanupRptUnitRange (GBQualPtr gbq)
 
3941
 
 
3942
{
 
3943
  Char     ch;
 
3944
  Int2     dashes = 0;
 
3945
  Int2     dots = 0;
 
3946
  size_t   len;
 
3947
  CharPtr  ptr;
 
3948
  CharPtr  str;
 
3949
  CharPtr  tmp;
 
3950
 
 
3951
  if (gbq == NULL) return;
 
3952
  if (StringHasNoText (gbq->val)) return;
 
3953
  ptr = gbq->val;
 
3954
  ch = *ptr;
 
3955
  while (ch != '\0') {
 
3956
    if (ch == '-') {
 
3957
      dashes++;
 
3958
    } else if (ch == '.') {
 
3959
      dots++;
 
3960
    } else if (IS_DIGIT (ch)) {
 
3961
      /* okay */
 
3962
    } else return;
 
3963
    ptr++;
 
3964
    ch = *ptr;
 
3965
  }
 
3966
 
 
3967
  if (dashes > 0 && dots == 0) {
 
3968
    len = StringLen (gbq->val + dashes);
 
3969
    str = (CharPtr) MemNew (sizeof (Char) * (len + 5));
 
3970
    tmp = str;
 
3971
    ptr = gbq->val;
 
3972
    ch = *ptr;
 
3973
    while (ch != '\0') {
 
3974
      if (ch == '-') {
 
3975
        *tmp = '.';
 
3976
        tmp++;
 
3977
        *tmp = '.';
 
3978
        tmp++;
 
3979
      } else {
 
3980
        *tmp = ch;
 
3981
        tmp++;
 
3982
      }
 
3983
      ptr++;
 
3984
      ch = *ptr;
 
3985
    }
 
3986
    gbq->val = MemFree (gbq->val);
 
3987
    gbq->val = str;
 
3988
  }
 
3989
}
 
3990
 
3865
3991
static void CleanupReplace (GBQualPtr gbq)
3866
3992
 
3867
3993
{
3945
4071
static Boolean StringIsJustQuotes (CharPtr str)
3946
4072
 
3947
4073
{
3948
 
  Nlm_Uchar  ch;        /* to use 8bit characters in multibyte languages */
 
4074
  Nlm_Uchar  ch;    /* to use 8bit characters in multibyte languages */
3949
4075
 
3950
4076
  if (str != NULL) {
3951
4077
    ch = *str;
4105
4231
{
4106
4232
  ValNodePtr      afterMe = NULL;
4107
4233
  Char            ch;
4108
 
  GBQualPtr       compare = NULL;
4109
4234
  DbtagPtr        db;
4110
4235
  GBQualPtr       gbq;
4111
4236
  GeneRefPtr      grp;
4113
4238
  size_t          len;
4114
4239
  GBQualPtr       nextqual;
4115
4240
  ObjectIdPtr     oip;
4116
 
  GBQualPtr       old_locus_tag = NULL;
4117
4241
  GBQualPtr PNTR  prevqual;
4118
4242
  CharPtr         ptr;
4119
 
  GBQualPtr       rpt_type = NULL;
4120
4243
  GBQualPtr       rpt_unit_range = NULL;
4121
4244
  GBQualPtr       rpt_unit_seq = NULL;
4122
4245
  CharPtr         str;
4123
4246
  CharPtr         tag;
4124
4247
  Boolean         unlink;
4125
 
  GBQualPtr       usedin = NULL;
4126
4248
  ValNodePtr      vnp;
4127
4249
  SeqFeatXrefPtr  xref;
4128
4250
 
4196
4318
        sfp->comment = str;
4197
4319
      }
4198
4320
    } else if (StringICmp (gbq->qual, "db_xref") == 0) {
4199
 
      vnp = ValNodeNew (NULL);
4200
 
      db = DbtagNew ();
4201
 
      vnp->data.ptrvalue = db;
4202
4321
      tag = gbq->val;
4203
4322
      ptr = StringChr (tag, ':');
4204
4323
      if (ptr != NULL) {
 
4324
        vnp = ValNodeNew (NULL);
 
4325
        db = DbtagNew ();
 
4326
        vnp->data.ptrvalue = db;
4205
4327
        *ptr = '\0';
4206
4328
        ptr++;
4207
4329
        db->db = StringSave (tag);
4240
4362
    } else if (StringICmp (gbq->qual, "rpt_unit_seq") == 0) {
4241
4363
      CleanupRptUnitSeq (gbq);
4242
4364
      unlink = FALSE;
 
4365
    } else if (StringICmp (gbq->qual, "rpt_unit_range") == 0) {
 
4366
      CleanupRptUnitRange (gbq);
 
4367
      unlink = FALSE;
4243
4368
    } else if (sfp->data.choice == SEQFEAT_GENE && HandledGBQualOnGene (sfp, gbq)) {
4244
4369
    } else if (sfp->data.choice == SEQFEAT_CDREGION && HandledGBQualOnCDS (sfp, gbq, &afterMe)) {
4245
4370
    } else if (sfp->data.choice == SEQFEAT_RNA && HandledGBQualOnRNA (sfp, gbq, isEmblOrDdbj)) {
4278
4403
        CleanupInference (gbq);
4279
4404
        unlink = FALSE;
4280
4405
      }
 
4406
    } else if (StringICmp (gbq->qual, "transposon") == 0) {
 
4407
      if (StringICmp (gbq->val, "class I integron") == 0 ||
 
4408
          StringICmp (gbq->val, "class II integron") == 0 ||
 
4409
          StringICmp (gbq->val, "class III integron") == 0 ||
 
4410
          StringICmp (gbq->val, "class 1 integron") == 0 ||
 
4411
          StringICmp (gbq->val, "class 2 integron") == 0 ||
 
4412
          StringICmp (gbq->val, "class 3 integron") == 0) {
 
4413
        len = StringLen ("integron") + StringLen (gbq->val) + 5;
 
4414
        str = MemNew (sizeof (Char) * len);
 
4415
        StringCpy (str, "integron");
 
4416
        StringCat (str, ":");
 
4417
        ptr = StringStr (gbq->val, " integron");
 
4418
        if (ptr != NULL) {
 
4419
          *ptr = '\0';
 
4420
        }
 
4421
        StringCat (str, gbq->val);
 
4422
        gbq->val = MemFree (gbq->val);
 
4423
        gbq->val = str;
 
4424
        gbq->qual = MemFree (gbq->qual);
 
4425
        gbq->qual = StringSave ("mobile_element");
 
4426
        unlink = FALSE;
 
4427
      } else {
 
4428
        len = StringLen ("transposon") + StringLen (gbq->val) + 5;
 
4429
        str = MemNew (sizeof (Char) * len);
 
4430
        StringCpy (str, "transposon");
 
4431
        StringCat (str, ":");
 
4432
        StringCat (str, gbq->val);
 
4433
        gbq->val = MemFree (gbq->val);
 
4434
        gbq->val = str;
 
4435
        gbq->qual = MemFree (gbq->qual);
 
4436
        gbq->qual = StringSave ("mobile_element");
 
4437
        unlink = FALSE;
 
4438
      }
 
4439
    } else if (StringICmp (gbq->qual, "insertion_seq") == 0) {
 
4440
      len = StringLen ("insertion sequence") + StringLen (gbq->val) + 5;
 
4441
      str = MemNew (sizeof (Char) * len);
 
4442
      StringCpy (str, "insertion sequence");
 
4443
      StringCat (str, ":");
 
4444
      StringCat (str, gbq->val);
 
4445
      gbq->val = MemFree (gbq->val);
 
4446
      gbq->val = str;
 
4447
      gbq->qual = MemFree (gbq->qual);
 
4448
      gbq->qual = StringSave ("mobile_element");
 
4449
      unlink = FALSE;
4281
4450
    } else {
4282
4451
      unlink = FALSE;
4283
4452
    }
 
4453
    if (StringICmp (gbq->qual, "mobile_element") == 0) {
 
4454
      if (StringStr (gbq->val, " :") == 0 || StringStr (gbq->val, ": ") == 0) {
 
4455
        len = StringLen (gbq->val) + 5;
 
4456
        ptr = StringChr (gbq->val, ':');
 
4457
        if (ptr != NULL) {
 
4458
          *ptr = '\0';
 
4459
          ptr++;
 
4460
          TrimSpacesAroundString (gbq->val);
 
4461
          TrimSpacesAroundString (ptr);
 
4462
          str = MemNew (sizeof (Char) * len);
 
4463
          StringCpy (str, gbq->val);
 
4464
          StringCat (str, ":");
 
4465
          StringCat (str, ptr);
 
4466
          gbq->val = MemFree (gbq->val);
 
4467
          gbq->val = str;
 
4468
        }
 
4469
      }
 
4470
    }
4284
4471
    if (rpt_unit_seq != NULL) {
4285
4472
      CleanupRptUnit (rpt_unit_seq);
4286
4473
    }
4577
4764
  return list;
4578
4765
}
4579
4766
 
4580
 
static void CleanOrgModList (OrgModPtr PNTR ompp)
4581
 
 
4582
 
{
 
4767
 
 
4768
static void RemoveSpaceBeforeAndAfterColon (CharPtr str)
 
4769
{
 
4770
  CharPtr pColon, cp, src, dst;
 
4771
 
 
4772
  if (StringHasNoText (str)) {
 
4773
    return;
 
4774
  }
 
4775
 
 
4776
  pColon = StringChr (str, ':');
 
4777
  while (pColon != NULL) {
 
4778
    cp = pColon - 1;
 
4779
    while (cp > str && isspace (*cp)) {
 
4780
      cp--;
 
4781
    }
 
4782
    if (cp < str || !isspace (*cp)) {
 
4783
      cp++;
 
4784
    }
 
4785
    *cp = ':';
 
4786
    dst = cp + 1;
 
4787
    cp = pColon + 1;
 
4788
    while (isspace (*cp)) {
 
4789
      cp++;
 
4790
    }
 
4791
    src = cp;
 
4792
    pColon = dst - 1;
 
4793
    if (src != dst) {
 
4794
      while (*src != 0) {
 
4795
        *dst = *src;
 
4796
        dst++; src++;
 
4797
      }
 
4798
      *dst = 0;
 
4799
    }
 
4800
    pColon = StringChr (pColon + 1, ':');
 
4801
  }
 
4802
}
 
4803
 
 
4804
 
 
4805
NLM_EXTERN void CleanOrgModList (OrgModPtr PNTR ompp)
 
4806
 
 
4807
{
 
4808
  Char            ch;
4583
4809
  OrgModPtr       last = NULL;
4584
4810
  OrgModPtr       next;
4585
4811
  OrgModPtr       omp;
4586
4812
  OrgModPtr PNTR  prev;
 
4813
  CharPtr         ptr;
 
4814
  CharPtr         tmp;
4587
4815
  Boolean         unlink;
4588
4816
 
4589
4817
  if (ompp == NULL) return;
4610
4838
        omp->subname = NULL;
4611
4839
        unlink = TRUE;
4612
4840
      }
 
4841
    } else if (HasNoText (omp->subname)) {
 
4842
      unlink = TRUE;
4613
4843
    } else {
4614
4844
      last = omp;
4615
4845
    }
4623
4853
    }
4624
4854
    omp = next;
4625
4855
  }
 
4856
 
 
4857
  for (omp = *ompp; omp != NULL; omp = omp->next) {
 
4858
    if (omp->subtype != ORGMOD_specimen_voucher &&
 
4859
        omp->subtype != ORGMOD_culture_collection &&
 
4860
        omp->subtype != ORGMOD_bio_material) continue;
 
4861
    if (StringHasNoText (omp->subname)) continue;
 
4862
    RemoveSpaceBeforeAndAfterColon (omp->subname);
 
4863
    ptr = StringStr (omp->subname, "::");
 
4864
    if (ptr == NULL) continue;
 
4865
    ptr++;
 
4866
    tmp = ptr;
 
4867
    tmp++;
 
4868
    ch = *tmp;
 
4869
    while (ch != '\0') {
 
4870
      *ptr = ch;
 
4871
      ptr++;
 
4872
      tmp++;
 
4873
      ch = *tmp;
 
4874
    }
 
4875
    *ptr = '\0';
 
4876
    
 
4877
  }
4626
4878
}
4627
4879
 
4628
4880
static int LIBCALLBACK SortBySubSourceSubtype (VoidPtr ptr1, VoidPtr ptr2)
4693
4945
static CharPtr TrimParenthesesAndCommasAroundString (CharPtr str)
4694
4946
 
4695
4947
{
4696
 
  Uchar    ch;  /* to use 8bit characters in multibyte languages */
 
4948
  Uchar    ch;    /* to use 8bit characters in multibyte languages */
4697
4949
  CharPtr  dst;
4698
4950
  CharPtr  ptr;
4699
4951
 
4753
5005
  return str;
4754
5006
}
4755
5007
 
4756
 
static void CleanSubSourceList (SubSourcePtr PNTR sspp)
 
5008
static Uint1 LocationForPlastidText (CharPtr plastid_name)
 
5009
{
 
5010
  if (StringICmp (plastid_name, "chloroplast") == 0) {
 
5011
    return GENOME_chloroplast;
 
5012
  } else if (StringICmp (plastid_name, "chromoplast") == 0) {
 
5013
    return GENOME_chromoplast;
 
5014
  } else if (StringICmp (plastid_name, "kinetoplast") == 0) {
 
5015
    return GENOME_kinetoplast;
 
5016
  } else if (StringICmp (plastid_name, "plastid") == 0) {
 
5017
    return GENOME_plastid;
 
5018
  } else if (StringICmp (plastid_name, "apicoplast") == 0) {
 
5019
    return GENOME_apicoplast;
 
5020
  } else if (StringICmp (plastid_name, "leucoplast") == 0) {
 
5021
    return GENOME_leucoplast;
 
5022
  } else if (StringICmp (plastid_name, "proplastid") == 0) {
 
5023
    return GENOME_proplastid;
 
5024
  } else {
 
5025
    return 0;
 
5026
  }
 
5027
}
 
5028
 
 
5029
 
 
5030
extern void CleanSubSourceList (SubSourcePtr PNTR sspp, Uint1 location)
4757
5031
 
4758
5032
{
4759
5033
  Char               ch;
4778
5052
    if (ssp->subtype != SUBSRC_germline &&
4779
5053
        ssp->subtype != SUBSRC_rearranged &&
4780
5054
        ssp->subtype != SUBSRC_transgenic &&
4781
 
        ssp->subtype != SUBSRC_environmental_sample) {
 
5055
        ssp->subtype != SUBSRC_environmental_sample &&
 
5056
        ssp->subtype != SUBSRC_metagenomic) {
4782
5057
      CleanVisString (&(ssp->name));
 
5058
    } else if (StringICmp (ssp->name, "TRUE") == 0) {
 
5059
      ssp->name = MemFree (ssp->name);
 
5060
      ssp->name = StringSave ("");
 
5061
    }
 
5062
    if (ssp->subtype == SUBSRC_country ||
 
5063
        ssp->subtype == SUBSRC_clone) {
 
5064
      CleanVisStringJunk (&(ssp->name));
4783
5065
    }
4784
5066
    if (ssp->subtype == SUBSRC_fwd_primer_seq ||
4785
5067
        ssp->subtype == SUBSRC_rev_primer_seq) {
4847
5129
          ssp->subtype != SUBSRC_germline &&
4848
5130
          ssp->subtype != SUBSRC_rearranged &&
4849
5131
          ssp->subtype != SUBSRC_transgenic &&
4850
 
          ssp->subtype != SUBSRC_environmental_sample) {
 
5132
          ssp->subtype != SUBSRC_environmental_sample &&
 
5133
          ssp->subtype != SUBSRC_metagenomic) {
4851
5134
        unlink = TRUE;
4852
5135
      } else if (last->subtype == ssp->subtype &&
4853
5136
                 (ssp->subtype == SUBSRC_germline ||
4854
5137
                  ssp->subtype == SUBSRC_rearranged ||
4855
5138
                  ssp->subtype == SUBSRC_transgenic ||
4856
5139
                  ssp->subtype == SUBSRC_environmental_sample ||
 
5140
                  ssp->subtype == SUBSRC_metagenomic ||
4857
5141
                  StringICmp (last->name, ssp->name) == 0 ||
4858
5142
                  (last->subtype == SUBSRC_other &&
4859
5143
                   StringStr (last->name, ssp->name) != NULL))) {
4866
5150
        ssp->name = NULL;
4867
5151
        unlink = TRUE;
4868
5152
      }
 
5153
    } else if (HasNoText (ssp->name) &&
 
5154
               ssp->subtype != SUBSRC_germline &&
 
5155
               ssp->subtype != SUBSRC_rearranged &&
 
5156
               ssp->subtype != SUBSRC_transgenic &&
 
5157
               ssp->subtype != SUBSRC_environmental_sample &&
 
5158
               ssp->subtype != SUBSRC_metagenomic) {
 
5159
      unlink = TRUE;
 
5160
    } else if (ssp->subtype == SUBSRC_plastid_name &&
 
5161
               location != 0
 
5162
               && location == LocationForPlastidText (ssp->name)) {
 
5163
      unlink = TRUE;
4869
5164
    } else {
4870
5165
      last = ssp;
4871
5166
    }
4995
5290
  return val;
4996
5291
}
4997
5292
 
4998
 
static CharPtr unstructured_orgmod_list [] = {
4999
 
  "?", "?", "strain", "substrain", "type", "subtype", "variety",
5000
 
  "serotype", "serogroup", "serovar", "cultivar", "pathovar", "chemovar",
5001
 
  "biovar", "biotype", "group", "subgroup", "isolate", "common name",
5002
 
  "acronym", "dosage", "natural host", "sub-species", "specimen-voucher",
5003
 
  "authority", "forma", "forma-specialis", "ecotype", "synonym",
5004
 
  "anamorph", "teleomorph", "breed", "gb-acronym", "gb-anamorph",
5005
 
  "gb-synonym", "old-lineage", "old-name", NULL
5006
 
};
 
5293
 
 
5294
Nlm_QualNameAssoc current_orgmod_subtype_alist[] = {
 
5295
  {" ",                 0},
 
5296
  {"Acronym",          ORGMOD_acronym},
 
5297
  {"Anamorph",         ORGMOD_anamorph},
 
5298
  {"Authority",        ORGMOD_authority},
 
5299
  {"Bio-material",     ORGMOD_bio_material},
 
5300
  {"Biotype",          ORGMOD_biotype},
 
5301
  {"Biovar",           ORGMOD_biovar},
 
5302
  {"Breed",            ORGMOD_breed},
 
5303
  {"Chemovar",         ORGMOD_chemovar},
 
5304
  {"Common",           ORGMOD_common},
 
5305
  {"Cultivar",         ORGMOD_cultivar},
 
5306
  {"Culture-collection", ORGMOD_culture_collection},
 
5307
  {"Ecotype",          ORGMOD_ecotype},
 
5308
  {"Forma",            ORGMOD_forma},
 
5309
  {"Forma-specialis",  ORGMOD_forma_specialis},
 
5310
  {"Group",            ORGMOD_group},
 
5311
  {"Isolate",          ORGMOD_isolate},
 
5312
  {"Metagenome-source",  ORGMOD_metagenome_source},
 
5313
  {"Pathovar",         ORGMOD_pathovar},
 
5314
  {"Serogroup",        ORGMOD_serogroup},
 
5315
  {"Serotype",         ORGMOD_serotype},
 
5316
  {"Serovar",          ORGMOD_serovar},
 
5317
  {"Specific-host",    ORGMOD_nat_host},
 
5318
  {"Specimen-voucher", ORGMOD_specimen_voucher},
 
5319
  {"Strain",           ORGMOD_strain},
 
5320
  {"Subgroup",         ORGMOD_subgroup},
 
5321
  {"Sub-species",      ORGMOD_sub_species},
 
5322
  {"Substrain",        ORGMOD_substrain},
 
5323
  {"Subtype",          ORGMOD_subtype},
 
5324
  {"Synonym",          ORGMOD_synonym},
 
5325
  {"Teleomorph",       ORGMOD_teleomorph},
 
5326
  {"Type",             ORGMOD_type},
 
5327
  {"Variety",          ORGMOD_variety},
 
5328
  { NULL, 0 } };
 
5329
 
 
5330
Nlm_QualNameAssoc discouraged_orgmod_subtype_alist[] = {
 
5331
  {"Old Lineage",      ORGMOD_old_lineage},
 
5332
  {"Old Name",         ORGMOD_old_name},
 
5333
  { NULL, 0 } };
 
5334
 
 
5335
Nlm_QualNameAssoc discontinued_orgmod_subtype_alist[] = {
 
5336
  {"Dosage",           ORGMOD_dosage},
 
5337
  { NULL, 0 } };
 
5338
 
 
5339
 
 
5340
Nlm_NameNameAssoc orgmod_aliases[] = {
 
5341
  {"Sub-species",   "subspecies", ORGMOD_sub_species},
 
5342
  {"Specific-host", "nat-host",   ORGMOD_nat_host},
 
5343
  { NULL, NULL, 0 } };
 
5344
 
 
5345
extern CharPtr GetOrgModQualName (Uint1 subtype)
 
5346
{
 
5347
  Int4 i;
 
5348
  
 
5349
  if (subtype == ORGMOD_other) {
 
5350
    return "Note";
 
5351
  }
 
5352
  for (i = 0; current_orgmod_subtype_alist[i].name != NULL; i++) {
 
5353
    if (current_orgmod_subtype_alist[i].value == subtype) {
 
5354
      return current_orgmod_subtype_alist[i].name;
 
5355
    }
 
5356
  }
 
5357
  for (i = 0; discouraged_orgmod_subtype_alist[i].name != NULL; i++) {
 
5358
    if (discouraged_orgmod_subtype_alist[i].value == subtype) {
 
5359
      return discouraged_orgmod_subtype_alist[i].name;
 
5360
    }
 
5361
  }
 
5362
 
 
5363
  for (i = 0; discontinued_orgmod_subtype_alist[i].name != NULL; i++) {
 
5364
    if (discontinued_orgmod_subtype_alist[i].value == subtype) {
 
5365
      return discontinued_orgmod_subtype_alist[i].name;
 
5366
    }
 
5367
  }
 
5368
 
 
5369
  return NULL;
 
5370
}
 
5371
 
 
5372
 
 
5373
extern void BioSourceHasOldOrgModQualifiers (BioSourcePtr biop, BoolPtr has_discouraged, BoolPtr has_discontinued)
 
5374
{
 
5375
  OrgModPtr mod;
 
5376
  Boolean   discouraged = FALSE, discontinued = FALSE;
 
5377
  Int4      i;
 
5378
 
 
5379
  if (biop != NULL && biop->org != NULL && biop->org->orgname != NULL) {
 
5380
    mod = biop->org->orgname->mod;
 
5381
    while (mod != NULL && (!discouraged || !discontinued)) {
 
5382
      for (i = 0; discouraged_orgmod_subtype_alist[i].name != NULL && !discouraged; i++) {
 
5383
        if (mod->subtype == discouraged_orgmod_subtype_alist[i].value) {
 
5384
          discouraged = TRUE;
 
5385
        }
 
5386
      }
 
5387
      for (i = 0; discontinued_orgmod_subtype_alist[i].name != NULL && !discontinued; i++) {
 
5388
        if (mod->subtype == discontinued_orgmod_subtype_alist[i].value) {
 
5389
          discontinued = TRUE;
 
5390
        }
 
5391
      }
 
5392
      mod = mod->next;
 
5393
    }
 
5394
  }
 
5395
 
 
5396
  if (has_discouraged != NULL) {
 
5397
    *has_discouraged = discouraged;
 
5398
  }
 
5399
  if (has_discontinued != NULL) {
 
5400
    *has_discontinued = discontinued;
 
5401
  }
 
5402
}
 
5403
 
 
5404
 
 
5405
static void StringHasOrgModPrefix (CharPtr str, CharPtr PNTR pval, Uint1Ptr p_subtypeval, Boolean skippref)
 
5406
{
 
5407
  Int2          i;
 
5408
  CharPtr       val = NULL;
 
5409
  Uint1         subtype_val = 0;
 
5410
  
 
5411
  for (i = 0; current_orgmod_subtype_alist[i].name != NULL && subtype_val == 0; i++) {
 
5412
    val = StringHasPrefix (str, current_orgmod_subtype_alist [i].name, FALSE, skippref);
 
5413
    if (val != NULL) {
 
5414
      subtype_val = current_orgmod_subtype_alist[i].value;
 
5415
    }
 
5416
  }  
 
5417
  if (subtype_val == 0) {
 
5418
    for (i = 0; orgmod_aliases[i].name != NULL && subtype_val == 0; i++) {
 
5419
      val = StringHasPrefix (str, orgmod_aliases [i].alias, FALSE, skippref);
 
5420
      if (val != NULL) {
 
5421
        subtype_val = orgmod_aliases[i].value;
 
5422
      }
 
5423
    }
 
5424
  }
 
5425
  if (pval != NULL) {
 
5426
    *pval = val;
 
5427
  }
 
5428
  if (p_subtypeval != NULL) {
 
5429
    *p_subtypeval = subtype_val;
 
5430
  }
 
5431
}
5007
5432
 
5008
5433
static void OrpModToOrgMod (ValNodePtr PNTR vnpp, OrgModPtr PNTR ompp)
5009
5434
 
5010
5435
{
5011
5436
  Char        ch;
5012
 
  Int2        i;
5013
5437
  ValNodePtr  next;
5014
5438
  Int2        numcommas;
5015
5439
  Int2        numspaces;
5018
5442
  CharPtr     str;
5019
5443
  CharPtr     val;
5020
5444
  ValNodePtr  vnp;
 
5445
  Uint1       subtype;
5021
5446
 
5022
5447
  if (vnpp == NULL || ompp == NULL) return;
5023
5448
  vnp = *vnpp;
5025
5450
    next = vnp->next;
5026
5451
    str = (CharPtr) vnp->data.ptrvalue;
5027
5452
    val = NULL;
5028
 
    for (i = 0; unstructured_orgmod_list [i] != NULL; i++) {
5029
 
      val = StringHasPrefix (str, unstructured_orgmod_list [i], FALSE, TRUE);
5030
 
      if (val != NULL) break;
5031
 
    }
 
5453
    subtype = 0;
 
5454
    StringHasOrgModPrefix (str, &val, &subtype, TRUE);
5032
5455
    if (val != NULL) {
5033
5456
      numspaces = 0;
5034
5457
      numcommas = 0;
5050
5473
    if (val != NULL) {
5051
5474
      omp = OrgModNew ();
5052
5475
      if (omp != NULL) {
5053
 
        omp->subtype = (Uint1) i;
 
5476
        omp->subtype = (Uint1) subtype;
5054
5477
        omp->subname = StringSave (val);
5055
5478
        omp->next = *ompp;
5056
5479
        *ompp = omp;
5065
5488
  }
5066
5489
}
5067
5490
 
5068
 
static CharPtr unstructured_subsource_list [] = {
5069
 
  "?", "chromosome", "map", "clone", "subclone", "haplotype",
5070
 
  "genotype", "sex", "cell-line", "cell-type", "tissue-type",
5071
 
  "clone-lib", "dev-stage", "frequency", "germline", "rearranged",
5072
 
  "lab-host", "pop-variant", "tissue-lib", "plasmid", "transposon",
5073
 
  "ins-seq", "plastid", "country", "segment", "endogenous-virus",
5074
 
  "transgenic", "environmental-sample", "isolation-source",
5075
 
  "lat-lon", "collection-date", "collected-by", "identified-by",
5076
 
  "fwd-primer-seq", "rev-primer-seq", "fwd-primer-name", "rev-primer-name",
5077
 
  NULL
5078
 
};
 
5491
Nlm_QualNameAssoc current_subsource_subtype_alist[] = {
 
5492
  {" ",                      0},
 
5493
  {"Cell-line",             SUBSRC_cell_line},
 
5494
  {"Cell-type",             SUBSRC_cell_type},
 
5495
  {"Chromosome",            SUBSRC_chromosome},
 
5496
  {"Clone",                 SUBSRC_clone},
 
5497
  {"Clone-lib",             SUBSRC_clone_lib},
 
5498
  {"Collected-by",          SUBSRC_collected_by},
 
5499
  {"Collection-date",       SUBSRC_collection_date},
 
5500
  {"Country",               SUBSRC_country},
 
5501
  {"Dev-stage",             SUBSRC_dev_stage},
 
5502
  {"Endogenous-virus-name", SUBSRC_endogenous_virus_name},
 
5503
  {"Environmental-sample",  SUBSRC_environmental_sample},
 
5504
  {"Frequency",             SUBSRC_frequency},
 
5505
  {"Fwd-PCR-primer-name",   SUBSRC_fwd_primer_name},
 
5506
  {"Fwd-PCR-primer-seq",    SUBSRC_fwd_primer_seq},
 
5507
  {"Genotype",              SUBSRC_genotype},
 
5508
  {"Germline",              SUBSRC_germline},
 
5509
  {"Haplotype",             SUBSRC_haplotype},
 
5510
  {"Identified-by",         SUBSRC_identified_by},
 
5511
  {"Isolation-source",      SUBSRC_isolation_source},
 
5512
  {"Lab-host",              SUBSRC_lab_host},
 
5513
  {"Lat-Lon",               SUBSRC_lat_lon},
 
5514
  {"Map",                   SUBSRC_map},
 
5515
  {"Metagenomic",           SUBSRC_metagenomic},
 
5516
  {"Plasmid-name",          SUBSRC_plasmid_name},
 
5517
  {"Pop-variant",           SUBSRC_pop_variant},
 
5518
  {"Rearranged",            SUBSRC_rearranged},
 
5519
  {"Rev-PCR-primer-name",   SUBSRC_rev_primer_name},
 
5520
  {"Rev-PCR-primer-seq",    SUBSRC_rev_primer_seq},
 
5521
  {"Segment",               SUBSRC_segment},
 
5522
  {"Sex",                   SUBSRC_sex},
 
5523
  {"Subclone",              SUBSRC_subclone},
 
5524
  {"Tissue-lib",            SUBSRC_tissue_lib},
 
5525
  {"Tissue-type",           SUBSRC_tissue_type},
 
5526
  {"Transgenic",            SUBSRC_transgenic},
 
5527
  { NULL, 0 } };
 
5528
 
 
5529
Nlm_QualNameAssoc discouraged_subsource_subtype_alist[] = {
 
5530
  {"Plastid-name",          SUBSRC_plastid_name},
 
5531
  { NULL, 0 } };
 
5532
 
 
5533
Nlm_QualNameAssoc discontinued_subsource_subtype_alist[] = {
 
5534
  {"Ins-seq-name",          SUBSRC_insertion_seq_name},
 
5535
  {"Transposon-name",       SUBSRC_transposon_name},
 
5536
  { NULL, 0 } };
 
5537
 
 
5538
Nlm_NameNameAssoc subsource_aliases[] = {
 
5539
  {"Fwd-PCR-primer-name", "fwd-primer-name",    SUBSRC_fwd_primer_name},
 
5540
  {"Fwd-PCR-primer-seq",  "fwd-primer-seq",     SUBSRC_fwd_primer_seq},
 
5541
  {"Rev-PCR-primer-name", "rev-primer-name",    SUBSRC_rev_primer_name},
 
5542
  {"Rev-PCR-primer-seq",  "rev-primer-seq",     SUBSRC_rev_primer_seq},
 
5543
  {"Subclone",            "sub-clone",          SUBSRC_subclone},
 
5544
  {"Lat-Lon",             "Lat-long",           SUBSRC_lat_lon},
 
5545
  {"Lat-Lon",             "Latitude-Longitude", SUBSRC_lat_lon },
 
5546
  { NULL, NULL, 0 } };
 
5547
 
 
5548
extern CharPtr GetSubsourceQualName (Uint1 subtype)
 
5549
{
 
5550
  Int4 i;
 
5551
  
 
5552
  if (subtype == SUBSRC_other) {
 
5553
    return "Note";
 
5554
  }
 
5555
  for (i = 0; current_subsource_subtype_alist[i].name != NULL; i++) {
 
5556
    if (current_subsource_subtype_alist[i].value == subtype) {
 
5557
      return current_subsource_subtype_alist[i].name;
 
5558
    }
 
5559
  }
 
5560
 
 
5561
  for (i = 0; discouraged_subsource_subtype_alist[i].name != NULL; i++) {
 
5562
    if (discouraged_subsource_subtype_alist[i].value == subtype) {
 
5563
      return discouraged_subsource_subtype_alist[i].name;
 
5564
    }
 
5565
  }
 
5566
 
 
5567
  for (i = 0; discontinued_subsource_subtype_alist[i].name != NULL; i++) {
 
5568
    if (discontinued_subsource_subtype_alist[i].value == subtype) {
 
5569
      return discontinued_subsource_subtype_alist[i].name;
 
5570
    }
 
5571
  }
 
5572
 
 
5573
  return NULL;
 
5574
}
 
5575
 
 
5576
 
 
5577
extern void BioSourceHasOldSubSourceQualifiers (BioSourcePtr biop, BoolPtr has_discouraged, BoolPtr has_discontinued)
 
5578
{
 
5579
  SubSourcePtr ssp;
 
5580
  Boolean   discouraged = FALSE, discontinued = FALSE;
 
5581
  Int4      i;
 
5582
 
 
5583
  if (biop != NULL) {
 
5584
    ssp = biop->subtype;
 
5585
    while (ssp != NULL && (!discouraged || !discontinued)) {
 
5586
      for (i = 0; discouraged_subsource_subtype_alist[i].name != NULL && !discouraged; i++) {
 
5587
        if (ssp->subtype == discouraged_subsource_subtype_alist[i].value) {
 
5588
          discouraged = TRUE;
 
5589
        }
 
5590
      }
 
5591
      for (i = 0; discontinued_subsource_subtype_alist[i].name != NULL && !discontinued; i++) {
 
5592
        if (ssp->subtype == discontinued_subsource_subtype_alist[i].value) {
 
5593
          discontinued = TRUE;
 
5594
        }
 
5595
      }
 
5596
      ssp = ssp->next;
 
5597
    }
 
5598
  }
 
5599
 
 
5600
  if (has_discouraged != NULL) {
 
5601
    *has_discouraged = discouraged;
 
5602
  }
 
5603
  if (has_discontinued != NULL) {
 
5604
    *has_discontinued = discontinued;
 
5605
  }
 
5606
}
 
5607
 
 
5608
 
 
5609
static void StringHasSubSourcePrefix (CharPtr str, CharPtr PNTR pval, Uint1Ptr p_subtypeval, Boolean skippref)
 
5610
{
 
5611
  Int2          i;
 
5612
  CharPtr       val = NULL;
 
5613
  Uint1         subtype_val = 0;
 
5614
  
 
5615
  for (i = 0; current_subsource_subtype_alist[i].name != NULL && subtype_val == 0; i++) {
 
5616
    val = StringHasPrefix (str, current_subsource_subtype_alist [i].name,
 
5617
                           (Boolean) (current_subsource_subtype_alist[i].value == SUBSRC_germline ||
 
5618
                                      current_subsource_subtype_alist[i].value == SUBSRC_rearranged ||
 
5619
                                      current_subsource_subtype_alist[i].value == SUBSRC_transgenic ||
 
5620
                                      current_subsource_subtype_alist[i].value == SUBSRC_environmental_sample ||
 
5621
                                      current_subsource_subtype_alist[i].value == SUBSRC_metagenomic),
 
5622
                           skippref);
 
5623
    if (val != NULL) {
 
5624
      subtype_val = current_subsource_subtype_alist[i].value;
 
5625
    }
 
5626
  }  
 
5627
  if (subtype_val == 0) {
 
5628
    for (i = 0; subsource_aliases[i].name != NULL && subtype_val == 0; i++) {
 
5629
      val = StringHasPrefix (str, subsource_aliases [i].alias,
 
5630
                             (Boolean) (subsource_aliases[i].value == SUBSRC_germline ||
 
5631
                                        subsource_aliases[i].value == SUBSRC_rearranged ||
 
5632
                                        subsource_aliases[i].value == SUBSRC_transgenic ||
 
5633
                                        subsource_aliases[i].value == SUBSRC_environmental_sample ||
 
5634
                                        subsource_aliases[i].value == SUBSRC_metagenomic),
 
5635
                             skippref);
 
5636
      if (val != NULL) {
 
5637
        subtype_val = subsource_aliases[i].value;
 
5638
      }
 
5639
    }
 
5640
  }
 
5641
  if (pval != NULL) {
 
5642
    *pval = val;
 
5643
  }
 
5644
  if (p_subtypeval != NULL) {
 
5645
    *p_subtypeval = subtype_val;
 
5646
  }
 
5647
}
5079
5648
 
5080
5649
static void OrpModToSubSource (ValNodePtr PNTR vnpp, SubSourcePtr PNTR sspp)
5081
5650
 
5082
5651
{
5083
5652
  Char          ch;
5084
 
  Int2          i;
5085
5653
  ValNodePtr    next;
5086
5654
  Int2          numcommas;
5087
5655
  Int2          numspaces;
5090
5658
  CharPtr       str;
5091
5659
  CharPtr       val;
5092
5660
  ValNodePtr    vnp;
 
5661
  Uint1         subtype_val = 0;
5093
5662
 
5094
5663
  if (vnpp == NULL || sspp == NULL) return;
5095
5664
  vnp = *vnpp;
5097
5666
    next = vnp->next;
5098
5667
    str = (CharPtr) vnp->data.ptrvalue;
5099
5668
    val = NULL;
5100
 
    for (i = 0; unstructured_subsource_list [i] != NULL; i++) {
5101
 
      val = StringHasPrefix (str, unstructured_subsource_list [i],
5102
 
                             (Boolean) (i == SUBSRC_germline ||
5103
 
                                        i == SUBSRC_rearranged ||
5104
 
                                        i == SUBSRC_transgenic ||
5105
 
                                        i == SUBSRC_environmental_sample),
5106
 
                             TRUE);
5107
 
      if (val != NULL) break;
5108
 
    }
 
5669
    subtype_val = 0;
 
5670
    StringHasSubSourcePrefix (str, &val, &subtype_val, TRUE);
 
5671
 
5109
5672
    if (val != NULL) {
5110
5673
      numspaces = 0;
5111
5674
      numcommas = 0;
5127
5690
    if (val != NULL) {
5128
5691
      ssp = SubSourceNew ();
5129
5692
      if (ssp != NULL) {
5130
 
        ssp->subtype = (Uint1) i;
 
5693
        ssp->subtype = subtype_val;
5131
5694
        ssp->name = StringSave (val);
5132
5695
        ssp->next = *sspp;
5133
5696
        *sspp = ssp;
5146
5709
 
5147
5710
{
5148
5711
  GBQualPtr  gbq;
5149
 
  Int2       i;
5150
5712
  size_t     len;
5151
5713
  GBQualPtr  next;
5152
5714
  CharPtr    str;
5153
5715
  Boolean    unlink;
5154
5716
  CharPtr    val;
 
5717
  Uint1      subtype_val;
5155
5718
 
5156
5719
  if (prevgbq == NULL) return;
5157
5720
  gbq = *prevgbq;
5161
5724
    str = gbq->qual;
5162
5725
    if (str != NULL) {
5163
5726
      val = NULL;
5164
 
      for (i = 0; unstructured_orgmod_list [i] != NULL; i++) {
5165
 
        val = StringHasPrefix (str, unstructured_orgmod_list [i], FALSE, FALSE);
5166
 
        if (val != NULL) break;
5167
 
      }
5168
 
      if (val == NULL) {
5169
 
        for (i = 0; unstructured_subsource_list [i] != NULL; i++) {
5170
 
          val = StringHasPrefix (str, unstructured_subsource_list [i],
5171
 
                                 (Boolean) (i == SUBSRC_germline ||
5172
 
                                            i == SUBSRC_rearranged ||
5173
 
                                            i == SUBSRC_transgenic ||
5174
 
                                            i == SUBSRC_environmental_sample),
5175
 
                                 FALSE);
5176
 
          if (val != NULL) break;
5177
 
        }
5178
 
      }
5179
 
      if (val == NULL) {
5180
 
        val = StringHasPrefix (str, "sub-clone", FALSE, FALSE);
5181
 
        if (val != NULL) {
5182
 
          val = "subclone";
5183
 
        }
 
5727
      subtype_val = 0;
 
5728
      StringHasOrgModPrefix (str, &val, &subtype_val, FALSE);
 
5729
      if (val == NULL) {
 
5730
        subtype_val = 0;
 
5731
        StringHasSubSourcePrefix (str, &val, &subtype_val, FALSE);
 
5732
 
5184
5733
      }
5185
5734
      if (val != NULL) {
5186
5735
        len = StringLen (gbq->val);
5343
5892
      if (StringICmp (dbt->db, "Genew") == 0) {
5344
5893
        dbt->db = MemFree (dbt->db);
5345
5894
        dbt->db = StringSave ("HGNC");
 
5895
      } else if (StringICmp (dbt->db, "IFO") == 0) {
 
5896
        dbt->db = MemFree (dbt->db);
 
5897
        dbt->db = StringSave ("NBRC");
5346
5898
      }
5347
5899
    }
5348
5900
    vnp = vnp->next;
5907
6459
 
5908
6460
{
5909
6461
  if (afp == NULL) return NULL;
5910
 
  CleanVisString (&(afp->affil));
5911
 
  CleanVisString (&(afp->div));
5912
 
  CleanVisString (&(afp->city));
5913
 
  CleanVisString (&(afp->sub));
5914
 
  CleanVisString (&(afp->country));
5915
 
  CleanVisString (&(afp->street));
5916
 
  CleanVisString (&(afp->email));
5917
 
  CleanVisString (&(afp->fax));
5918
 
  CleanVisString (&(afp->phone));
5919
 
  CleanVisString (&(afp->postal_code));
 
6462
  CleanVisStringJunk (&(afp->affil));
 
6463
  CleanVisStringJunk (&(afp->div));
 
6464
  CleanVisStringJunk (&(afp->city));
 
6465
  CleanVisStringJunk (&(afp->sub));
 
6466
  CleanVisStringJunk (&(afp->country));
 
6467
  CleanVisStringJunk (&(afp->street));
 
6468
  CleanVisStringJunk (&(afp->email));
 
6469
  CleanVisStringJunk (&(afp->fax));
 
6470
  CleanVisStringJunk (&(afp->phone));
 
6471
  CleanVisStringJunk (&(afp->postal_code));
 
6472
  if (afp->choice == 2) {
 
6473
    if (StringCmp (afp->country, "U.S.A.") == 0) {
 
6474
      afp->country = MemFree (afp->country);
 
6475
      afp->country = StringSave ("USA");
 
6476
    }
 
6477
  }
5920
6478
  if (afp->affil == NULL &&
5921
6479
      afp->div == NULL &&
5922
6480
      afp->city == NULL &&
6065
6623
/* from utilpub.c */
6066
6624
static Boolean empty_citgen(CitGenPtr  cit)
6067
6625
{
6068
 
        if (cit == NULL)
6069
 
                return TRUE;
6070
 
        if (cit->cit)
6071
 
                return FALSE;
6072
 
        if (cit->authors)
6073
 
                return FALSE;
6074
 
        if (cit->muid > 0)
6075
 
                return FALSE;
6076
 
        if (cit->journal)
6077
 
                return FALSE;
6078
 
        if (cit->volume)
6079
 
                return FALSE;
6080
 
        if (cit->issue)
6081
 
                return FALSE;
6082
 
        if (cit->pages)
6083
 
                return FALSE;
6084
 
        if (cit->date)
6085
 
                return FALSE;
6086
 
        if (cit->serial_number > 0)
6087
 
                return FALSE;
6088
 
        if (cit->title)
6089
 
                return FALSE;
6090
 
        if (cit->pmid > 0)
6091
 
                return FALSE;
6092
 
        return TRUE;
 
6626
    if (cit == NULL)
 
6627
        return TRUE;
 
6628
    if (cit->cit)
 
6629
        return FALSE;
 
6630
    if (cit->authors)
 
6631
        return FALSE;
 
6632
    if (cit->muid > 0)
 
6633
        return FALSE;
 
6634
    if (cit->journal)
 
6635
        return FALSE;
 
6636
    if (cit->volume)
 
6637
        return FALSE;
 
6638
    if (cit->issue)
 
6639
        return FALSE;
 
6640
    if (cit->pages)
 
6641
        return FALSE;
 
6642
    if (cit->date)
 
6643
        return FALSE;
 
6644
    if (cit->serial_number > 0)
 
6645
        return FALSE;
 
6646
    if (cit->title)
 
6647
        return FALSE;
 
6648
    if (cit->pmid > 0)
 
6649
        return FALSE;
 
6650
    return TRUE;
6093
6651
}
6094
6652
 
6095
6653
static void NormalizeAPub (ValNodePtr vnp, Boolean stripSerial, Boolean fixInitials)
6156
6714
              tmp = StringSaveNoNull (TrimSpacesAroundString (str));
6157
6715
              affil->affil = MemFree (affil->affil);
6158
6716
              affil->affil = tmp;
6159
 
              alp->affil = CleanAffil (alp->affil);
6160
6717
            }
6161
6718
          }
6162
6719
        }
 
6720
        alp->affil = CleanAffil (alp->affil);
6163
6721
      }
6164
6722
      break;
6165
6723
    case PUB_Article :
6217
6775
{
6218
6776
  Char             buf1 [121];
6219
6777
  Char             buf2 [121];
 
6778
  CitArtPtr        cap;
6220
6779
  CitGenPtr        cgp;
 
6780
  CitJourPtr       cjp;
6221
6781
  Boolean          fixInitials = TRUE;
6222
6782
  Boolean          hasArt = FALSE;
6223
6783
  Boolean          hasUid = FALSE;
 
6784
  ImprintPtr       imp;
6224
6785
  ValNodePtr       next;
6225
6786
  ValNodePtr PNTR  prev;
6226
6787
  ValNodePtr       vnp;
6279
6840
    buf1 [0] = '\0';
6280
6841
    PubLabelUnique (vnp, buf1, sizeof (buf1) - 1, OM_LABEL_CONTENT, TRUE);
6281
6842
    NormalizeAPub (vnp, stripSerial, fixInitials);
 
6843
    if (vnp->choice == PUB_Article) {
 
6844
      cap = (CitArtPtr) vnp->data.ptrvalue;
 
6845
      if (cap != NULL && cap->from == 1) {
 
6846
        cjp = (CitJourPtr) cap->fromptr;
 
6847
        if (cjp != NULL) {
 
6848
          imp = cjp->imp;
 
6849
          if (imp != NULL) {
 
6850
            if (imp->pubstatus == PUBSTATUS_aheadofprint && imp->prepub != 2) {
 
6851
              imp->prepub = 2;
 
6852
            }
 
6853
            if (imp->pubstatus == PUBSTATUS_epublish && imp->prepub == 2) {
 
6854
              imp->prepub = 0;
 
6855
            }
 
6856
          }
 
6857
        }
 
6858
      }
 
6859
    }
6282
6860
    if (vnp->choice == PUB_Gen && empty_citgen ((CitGenPtr) vnp->data.ptrvalue)) {
6283
6861
      *prev = vnp->next;
6284
6862
      vnp->next = NULL;
6760
7338
  Char          goid [32];
6761
7339
  CharPtr       evidence;
6762
7340
  Int4          pmid;
 
7341
  CharPtr       goref;
6763
7342
  UserFieldPtr  ufp;
6764
7343
} GosStruc, PNTR GosStrucPtr;
6765
7344
 
6768
7347
{
6769
7348
  int           compare;
6770
7349
  GosStrucPtr   gsp1, gsp2;
6771
 
  Int4          pmid1 = 0, pmid2 = 0;
6772
 
  CharPtr       str1 = NULL, str2 = NULL;
6773
7350
  ValNodePtr    vnp1, vnp2;
6774
7351
 
6775
7352
  if (ptr1 == NULL || ptr2 == NULL) return 0;
6817
7394
};
6818
7395
 
6819
7396
static CharPtr goFieldType [] = {
6820
 
  "", "text string", "go id", "pubmed id", "evidence", NULL
 
7397
  "", "text string", "go id", "pubmed id", "go ref", "evidence", NULL
6821
7398
};
6822
7399
 
6823
7400
static UserFieldPtr SortGoTerms (
6826
7403
 
6827
7404
{
6828
7405
  UserFieldPtr  entry, topufp, ufp, lastufp;
6829
 
  CharPtr       evidence, goid, textstr;
 
7406
  CharPtr       evidence, goid, goref, textstr;
6830
7407
  Char          gid [32];
6831
7408
  GosStrucPtr   gsp, lastgsp;
6832
7409
  ValNodePtr    head = NULL, vnp;
6844
7421
    textstr = NULL;
6845
7422
    evidence = NULL;
6846
7423
    goid = NULL;
 
7424
    goref = NULL;
6847
7425
    pmid = 0;
6848
7426
    for (ufp = topufp; ufp != NULL; ufp = ufp->next) {
6849
7427
      oip = ufp->label;
6873
7451
          break;
6874
7452
        case 4 :
6875
7453
          if (ufp->choice == 1) {
 
7454
            goref = (CharPtr) ufp->data.ptrvalue;
 
7455
          }
 
7456
          break;
 
7457
        case 5 :
 
7458
          if (ufp->choice == 1) {
6876
7459
            evidence = (CharPtr) ufp->data.ptrvalue;
6877
7460
          }
6878
7461
          break;
6888
7471
        StringNCpy_0 (gsp->goid, goid, sizeof (gsp->goid));
6889
7472
        gsp->evidence = evidence;
6890
7473
        gsp->pmid = pmid;
 
7474
        gsp->goref = goref;
6891
7475
        gsp->ufp = entry;
6892
7476
        ValNodeAddPointer (&head, 0, (Pointer) gsp);
6893
7477
      }
6905
7489
    if (gsp == NULL || gsp->ufp == NULL) continue;
6906
7490
    if (lastgsp != NULL &&
6907
7491
        (StringICmp (gsp->term, lastgsp->term) == 0 || StringICmp (gsp->goid, lastgsp->goid) == 0) &&
6908
 
        (gsp->pmid == lastgsp->pmid && StringICmp (gsp->evidence, lastgsp->evidence) == 0)) {
 
7492
         (gsp->pmid == lastgsp->pmid &&
 
7493
          StringICmp (gsp->goref, lastgsp->goref) == 0 &&
 
7494
          StringICmp (gsp->evidence, lastgsp->evidence) == 0)) {
6909
7495
      gsp->ufp->next = NULL;
6910
7496
      UserFieldFree (gsp->ufp);
6911
7497
    } else {
6965
7551
  }
6966
7552
}
6967
7553
 
 
7554
static void CleanupGoTerms (
 
7555
  UserFieldPtr entryhead
 
7556
)
 
7557
 
 
7558
{
 
7559
  UserFieldPtr  entry, topufp, ufp;
 
7560
  CharPtr       goid, goref, str;
 
7561
  Int2          j;
 
7562
  ObjectIdPtr   oip;
 
7563
 
 
7564
  if (entryhead == NULL) return;
 
7565
 
 
7566
  for (entry = entryhead; entry != NULL; entry = entry->next) {
 
7567
    if (entry == NULL || entry->choice != 11) break;
 
7568
    topufp = (UserFieldPtr)  entry->data.ptrvalue;
 
7569
    if (topufp == NULL) continue;
 
7570
 
 
7571
    goid = NULL;
 
7572
    goref = NULL;
 
7573
    for (ufp = topufp; ufp != NULL; ufp = ufp->next) {
 
7574
      oip = ufp->label;
 
7575
      if (oip == NULL) continue;
 
7576
      for (j = 0; goFieldType [j] != NULL; j++) {
 
7577
        if (StringICmp (oip->str, goFieldType [j]) == 0) break;
 
7578
      }
 
7579
      if (goFieldType [j] == NULL) continue;
 
7580
      switch (j) {
 
7581
        case 2 :
 
7582
          if (ufp->choice == 1) {
 
7583
            goid = (CharPtr) ufp->data.ptrvalue;
 
7584
            if (goid != NULL && *goid != '\0') {
 
7585
              if (StringNICmp (goid, "GO:", 3) == 0) {
 
7586
                str = StringSave (goid + 3);
 
7587
                ufp->data.ptrvalue = (Pointer) str;
 
7588
                MemFree (goid);
 
7589
              }
 
7590
            }
 
7591
          }
 
7592
          break;
 
7593
        case 4 :
 
7594
          if (ufp->choice == 1) {
 
7595
            goref = (CharPtr) ufp->data.ptrvalue;
 
7596
            if (goref != NULL && *goref != '\0') {
 
7597
              if (StringNICmp (goref, "GO_REF:", 7) == 0) {
 
7598
                str = StringSave (goref + 7);
 
7599
                ufp->data.ptrvalue = (Pointer) str;
 
7600
                MemFree (goref);
 
7601
              }
 
7602
            }
 
7603
          }
 
7604
          break;
 
7605
        default :
 
7606
          break;
 
7607
      }
 
7608
    }
 
7609
  }
 
7610
}
 
7611
 
 
7612
static void CleanupGoTermsUfp (
 
7613
  UserFieldPtr ufp,
 
7614
  Pointer userdata
 
7615
)
 
7616
 
 
7617
{
 
7618
  UserFieldPtr  entry;
 
7619
  Int2          i;
 
7620
  ObjectIdPtr   oip;
 
7621
 
 
7622
  if (ufp == NULL || ufp->choice != 11) return;
 
7623
  oip = ufp->label;
 
7624
  if (oip == NULL) return;
 
7625
  for (i = 0; goQualType [i] != NULL; i++) {
 
7626
    if (StringICmp (oip->str, goQualType [i]) == 0) break;
 
7627
  }
 
7628
  if (goQualType [i] == NULL) return;
 
7629
 
 
7630
  entry = ufp->data.ptrvalue;
 
7631
  if (entry == NULL || entry->choice != 11) return;
 
7632
 
 
7633
  CleanupGoTerms (entry);
 
7634
}
 
7635
 
 
7636
static void CleanupGoTermsSfp (
 
7637
  UserObjectPtr uop,
 
7638
  Pointer userdata
 
7639
)
 
7640
 
 
7641
{
 
7642
  ObjectIdPtr  oip;
 
7643
 
 
7644
  if (uop == NULL) return;
 
7645
  oip = uop->type;
 
7646
  if (oip == NULL) return;
 
7647
  if (StringCmp (oip->str, "GeneOntology") == 0) {
 
7648
    VisitUserFieldsInUop (uop, userdata, CleanupGoTermsUfp);
 
7649
  }
 
7650
}
 
7651
 
6968
7652
static void CleanupFeatureStrings (SeqFeatPtr sfp, Boolean stripSerial, ValNodePtr PNTR publist)
6969
7653
 
6970
7654
{
6972
7656
  BioSourcePtr  biop;
6973
7657
  Char          ch;
6974
7658
  Uint1         codon [6];
 
7659
  GBQualPtr     gbq;
6975
7660
  GeneRefPtr    grp;
6976
7661
  ImpFeatPtr    ifp;
6977
7662
  Boolean       is_fMet = FALSE;
6978
7663
  Int2          j;
6979
7664
  Boolean       justTrnaText;
 
7665
  GBQualPtr     last;
6980
7666
  size_t        len;
6981
7667
  CharPtr       name;
6982
7668
  OrgNamePtr    onp;
7010
7696
    VisitUserObjectsInUop (sfp->ext, NULL, SortGoTermsSfp);
7011
7697
  }
7012
7698
  */
 
7699
  if (sfp->ext != NULL) {
 
7700
    VisitUserObjectsInUop (sfp->ext, NULL, CleanupGoTermsSfp);
 
7701
  }
7013
7702
  switch (sfp->data.choice) {
7014
7703
    case SEQFEAT_BOND :
7015
7704
    case SEQFEAT_PSEC_STR :
7161
7850
      if ((prp->processed == 1 || prp->processed == 2) && prp->name == NULL) {
7162
7851
        ValNodeCopyStr (&(prp->name), 0, "unnamed");
7163
7852
      }
 
7853
      for (vnp = prp->name; vnp != NULL; vnp = vnp->next) {
 
7854
        str = (CharPtr) vnp->data.ptrvalue;
 
7855
        if (StringICmp (str, "RbcL") == 0) {
 
7856
          vnp->data.ptrvalue = StringSave ("ribulose-1,5-bisphosphate carboxylase/oxygenase large subunit");
 
7857
          MemFree (str);
 
7858
        } else if (StringICmp (str, "RbcS") == 0) {
 
7859
          vnp->data.ptrvalue = StringSave ("ribulose-1,5-bisphosphate carboxylase/oxygenase small subunit");
 
7860
          MemFree (str);
 
7861
        }
 
7862
      }
7164
7863
      break;
7165
7864
    case SEQFEAT_RNA :
7166
7865
      rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
7348
8047
            name++;
7349
8048
            ch = *name;
7350
8049
          }
 
8050
          /*
7351
8051
          if (ch == 's' && StringCmp (name, "s ribosomal RNA") == 0) {
7352
8052
            *name = 'S';
7353
8053
          }
 
8054
          */
 
8055
          if (ch == 's' && name [1] == ' ') {
 
8056
            *name = 'S';
 
8057
          }
7354
8058
        }
7355
8059
        StrStripSpaces ((CharPtr) rrp->ext.value.ptrvalue);
7356
8060
        name = (CharPtr) rrp->ext.value.ptrvalue;
7474
8178
          rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
7475
8179
          rrp->ext.value.ptrvalue = StringSave ("internal transcribed spacer 3");
7476
8180
        }
 
8181
 
 
8182
        name = (CharPtr) rrp->ext.value.ptrvalue;
 
8183
        if (StringNICmp (name, "internal transcribed spacer", 27) == 0) {
 
8184
          gbq = GBQualNew ();
 
8185
          if (gbq != NULL) {
 
8186
            rrp->ext.value.ptrvalue = StringSave ("misc_RNA");
 
8187
            gbq->qual = StringSave ("product");
 
8188
            gbq->val = name;
 
8189
            if (sfp->qual == NULL) {
 
8190
              sfp->qual = gbq;
 
8191
            } else {
 
8192
              last = sfp->qual;
 
8193
              while (last->next != NULL) {
 
8194
                last = last->next;
 
8195
              }
 
8196
              last->next = gbq;
 
8197
            }
 
8198
          }
 
8199
        }
 
8200
 
 
8201
        for (gbq = sfp->qual; gbq != NULL; gbq = gbq->next) {
 
8202
          if (StringCmp (gbq->qual, "product") != 0) continue;
 
8203
          name = gbq->val;
 
8204
          if (StringHasNoText (name)) continue;
 
8205
          if (StringICmp (name, "its1") == 0 || StringICmp (name, "its 1") == 0) {
 
8206
            gbq->val = MemFree (gbq->val);
 
8207
            gbq->val = StringSave ("internal transcribed spacer 1");
 
8208
          } else if (StringICmp (name, "its2") == 0 || StringICmp (name, "its 2") == 0) {
 
8209
            gbq->val = MemFree (gbq->val);
 
8210
            gbq->val = StringSave ("internal transcribed spacer 2");
 
8211
          } else if (StringICmp (name, "its3") == 0 || StringICmp (name, "its 3") == 0) {
 
8212
            gbq->val = MemFree (gbq->val);
 
8213
            gbq->val = StringSave ("internal transcribed spacer 3");
 
8214
          }
 
8215
        }
7477
8216
      }
7478
8217
      break;
7479
8218
    case SEQFEAT_PUB :
7524
8263
        CleanVisStringList (&(orp->mod));
7525
8264
        OrpModToSubSource (&(orp->mod), &(biop->subtype));
7526
8265
      }
7527
 
      CleanSubSourceList (&(biop->subtype));
7528
8266
      biop->subtype = SortSubSourceList (biop->subtype);
 
8267
      CleanSubSourceList (&(biop->subtype), biop->genome);
7529
8268
      break;
7530
8269
    default :
7531
8270
      break;
7670
8409
        CleanVisStringList (&(orp->mod));
7671
8410
        OrpModToSubSource (&(orp->mod), &(biop->subtype));
7672
8411
      }
7673
 
      CleanSubSourceList (&(biop->subtype));
7674
8412
      biop->subtype = SortSubSourceList (biop->subtype);
 
8413
      CleanSubSourceList (&(biop->subtype), biop->genome);
7675
8414
      break;
7676
8415
    case Seq_descr_molinfo :
7677
8416
      break;
8028
8767
    if (head [i].pos < pos) {
8029
8768
      out_of_order = TRUE;
8030
8769
    }
 
8770
    pos = head [i].pos;
8031
8771
  }
8032
8772
 
8033
8773
  if (out_of_order) {
8080
8820
  }
8081
8821
}
8082
8822
 
 
8823
 
 
8824
CharPtr ncrnaClassList[] = {
 
8825
"antisense_RNA",
 
8826
"autocatalytically_spliced_intron",
 
8827
"hammerhead_ribozyme",
 
8828
"RNase_P_RNA",
 
8829
"RNase_MRP_RNA",
 
8830
"telomerase_RNA",
 
8831
"guide_RNA",
 
8832
"rasiRNA",
 
8833
"scRNA",
 
8834
"siRNA",
 
8835
"miRNA",
 
8836
"piRNA",
 
8837
"snoRNA",
 
8838
"snRNA",
 
8839
"SRP_RNA",
 
8840
"vault_RNA",
 
8841
"Y_RNA",
 
8842
"other",
 
8843
NULL};
 
8844
 
 
8845
Int4 NcrnaOTHER = sizeof (ncrnaClassList) / sizeof (CharPtr) - 1;
 
8846
 
 
8847
 
 
8848
extern Boolean IsStringInNcRNAClassList (CharPtr str)
 
8849
{
 
8850
  CharPtr PNTR p;
 
8851
 
 
8852
  if (StringHasNoText (str)) return FALSE;
 
8853
  for (p = ncrnaClassList; *p != NULL; p++)
 
8854
  {
 
8855
    if (StringICmp (str, *p) == 0)
 
8856
    {
 
8857
      return TRUE;
 
8858
    }
 
8859
  }
 
8860
  return FALSE;
 
8861
}
 
8862
 
 
8863
 
 
8864
static void AddNonCopiedQual (SeqFeatPtr sfp, CharPtr qual, CharPtr class_val)
 
8865
{
 
8866
  GBQualPtr gbq;
 
8867
 
 
8868
  if (sfp == NULL || StringHasNoText (qual) || StringHasNoText (class_val)) 
 
8869
  {
 
8870
    return;
 
8871
  }
 
8872
  gbq = sfp->qual;
 
8873
  while (gbq != NULL 
 
8874
          && (StringCmp (gbq->qual, qual) != 0
 
8875
              || StringCmp (gbq->val, class_val) != 0))
 
8876
  {
 
8877
    gbq = gbq->next;
 
8878
  }
 
8879
  if (gbq == NULL)
 
8880
  {
 
8881
    gbq = GBQualNew ();
 
8882
    gbq->qual = StringSave (qual);
 
8883
    gbq->val = StringSave (class_val);
 
8884
    gbq->next = sfp->qual;
 
8885
    sfp->qual = gbq;
 
8886
  }
 
8887
 
 
8888
}
 
8889
 
 
8890
 
 
8891
static CharPtr GetMiRNAProduct (CharPtr str)
 
8892
{
 
8893
  Int4    len;
 
8894
  CharPtr product = NULL;
 
8895
 
 
8896
  if (StringHasNoText (str)) return NULL;
 
8897
  if (StringNCmp (str, "miRNA ", 6) == 0)
 
8898
  {
 
8899
    product = StringSave (str + 6);
 
8900
  }
 
8901
  else if (StringNCmp (str, "microRNA ", 9) == 0)
 
8902
  {
 
8903
    product = StringSave (str + 9);
 
8904
  }
 
8905
  else
 
8906
  {
 
8907
    len = StringLen (str);
 
8908
    if (len > 6 && StringCmp (str + len - 6, " miRNA") == 0
 
8909
        && (len < 15 || StringCmp (str - 15, "precursor miRNA") != 0))
 
8910
    {
 
8911
      product = (CharPtr) MemNew (sizeof (Char) * (len - 5));
 
8912
      StringNCpy (product, str, len - 6);
 
8913
      product[len - 6] = 0;
 
8914
    }
 
8915
    else if (len > 9 && StringCmp (str + len - 9, " microRNA") == 0
 
8916
             && (len < 21 || StringCmp (str - 21, "precursor microRNA") != 0))
 
8917
    {
 
8918
      product = (CharPtr) MemNew (sizeof (Char) * (len - 8));
 
8919
      StringNCpy (product, str, len - 9);
 
8920
      product[len - 9] = 0;
 
8921
    }
 
8922
  }
 
8923
  return product;
 
8924
}
 
8925
 
 
8926
 
 
8927
static Boolean ConvertToNcRNA (SeqFeatPtr sfp)
 
8928
{
 
8929
  GBQualPtr gbq;
 
8930
  RnaRefPtr rrp;
 
8931
  Boolean was_converted = FALSE;
 
8932
  CharPtr miRNAproduct = NULL;
 
8933
 
 
8934
  if (sfp == NULL || sfp->data.choice != SEQFEAT_RNA || sfp->data.value.ptrvalue == NULL)
 
8935
  {
 
8936
    return FALSE;
 
8937
  }
 
8938
  rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
8939
  if (rrp->type == 5 || rrp->type == 6 || rrp->type == 7)
 
8940
  {
 
8941
    if (rrp->type == 5)
 
8942
    {
 
8943
      AddNonCopiedQual (sfp, "ncRNA_class", "snRNA");
 
8944
    }
 
8945
    else if (rrp->type == 6)
 
8946
    {
 
8947
      AddNonCopiedQual (sfp, "ncRNA_class", "scRNA");
 
8948
    }
 
8949
    else if (rrp->type == 7)
 
8950
    {
 
8951
      AddNonCopiedQual (sfp, "ncRNA_class", "snoRNA");
 
8952
    }
 
8953
    if (rrp->ext.choice == 1)
 
8954
    {
 
8955
      AddNonCopiedQual (sfp, "product", rrp->ext.value.ptrvalue);
 
8956
      rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
8957
    }
 
8958
    rrp->ext.choice = 1;
 
8959
    rrp->ext.value.ptrvalue = StringSave ("ncRNA");
 
8960
    rrp->type = 255;
 
8961
    was_converted = TRUE;
 
8962
  }
 
8963
  else if (rrp->type == 255 && rrp->ext.choice == 1)
 
8964
  {
 
8965
    if (IsStringInNcRNAClassList (rrp->ext.value.ptrvalue)) 
 
8966
    {
 
8967
      AddNonCopiedQual (sfp, "ncRNA_class", rrp->ext.value.ptrvalue);
 
8968
      rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
8969
      rrp->ext.value.ptrvalue = StringSave ("ncRNA");
 
8970
      was_converted = TRUE;
 
8971
    }
 
8972
    else if ((miRNAproduct = GetMiRNAProduct (rrp->ext.value.ptrvalue)) != NULL)
 
8973
    {
 
8974
      AddNonCopiedQual (sfp, "ncRNA_class", "miRNA");
 
8975
      rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
8976
      rrp->ext.value.ptrvalue = StringSave ("ncRNA");
 
8977
      AddNonCopiedQual (sfp, "product", miRNAproduct);
 
8978
      miRNAproduct = MemFree (miRNAproduct);
 
8979
      was_converted = TRUE;
 
8980
    }
 
8981
    else if (StringCmp (rrp->ext.value.ptrvalue, "ncRNA") != 0
 
8982
             && StringCmp (rrp->ext.value.ptrvalue, "tmRNA") != 0
 
8983
             && StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") != 0)
 
8984
    {
 
8985
      AddNonCopiedQual (sfp, "product", rrp->ext.value.ptrvalue);
 
8986
      rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
8987
      rrp->ext.value.ptrvalue = StringSave ("misc_RNA");
 
8988
    }
 
8989
  }
 
8990
  if (rrp->type == 255 && rrp->ext.choice == 0) {
 
8991
    rrp->ext.choice = 1;
 
8992
    rrp->ext.value.ptrvalue = StringSave ("misc_RNA");
 
8993
  }
 
8994
  if (rrp->type == 255 && rrp->ext.choice == 1 &&
 
8995
      StringCmp (rrp->ext.value.ptrvalue, "misc_RNA") == 0) {
 
8996
    for (gbq = sfp->qual; gbq != NULL; gbq = gbq->next) {
 
8997
      if (StringCmp (gbq->qual, "ncRNA_class") == 0) {
 
8998
        rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
8999
        rrp->ext.value.ptrvalue = StringSave ("ncRNA");
 
9000
        was_converted = TRUE;
 
9001
      } else if (StringCmp (gbq->qual, "tag_peptide") == 0) {
 
9002
        rrp->ext.value.ptrvalue = MemFree (rrp->ext.value.ptrvalue);
 
9003
        rrp->ext.value.ptrvalue = StringSave ("tmRNA");
 
9004
        was_converted = TRUE;
 
9005
      }
 
9006
    }
 
9007
  }
 
9008
  return was_converted;
 
9009
}
 
9010
 
 
9011
 
8083
9012
NLM_EXTERN void CleanUpSeqFeat (
8084
9013
  SeqFeatPtr sfp,
8085
9014
  Boolean isEmblOrDdbj,
8113
9042
  if (sfp == NULL) return;
8114
9043
  crp = NULL;
8115
9044
  if (sfp->data.choice == SEQFEAT_IMP) {
8116
 
        ifp = (ImpFeatPtr) sfp->data.value.ptrvalue;
8117
 
        if (ifp != NULL) {
8118
 
          if (ifp->loc != NULL) {
8119
 
                str = StringStr (ifp->loc, "replace");
8120
 
                if (str != NULL) {
8121
 
                  AddReplaceQual (sfp, str);
8122
 
                  ifp->loc = MemFree (ifp->loc);
8123
 
                }
8124
 
          }
8125
 
          if (StringCmp (ifp->key, "CDS") == 0) {
8126
 
                if (! isEmblOrDdbj) {
8127
 
                  sfp->data.value.ptrvalue = ImpFeatFree (ifp);
8128
 
                  sfp->data.choice = SEQFEAT_CDREGION;
8129
 
                  crp = CdRegionNew ();
8130
 
                  sfp->data.value.ptrvalue = crp;
8131
 
                  sfp->idx.subtype = FEATDEF_CDS;
8132
 
                }
8133
 
          } else if (StringCmp (ifp->key, "allele") == 0 ||
8134
 
                                 StringCmp (ifp->key, "mutation") == 0) {
8135
 
                ifp->key = MemFree (ifp->key);
8136
 
                ifp->key = StringSave ("variation");
8137
 
                sfp->idx.subtype = FEATDEF_variation;
8138
 
          } else if (StringCmp (ifp->key, "Import") == 0 ||
8139
 
                                 StringCmp (ifp->key, "virion") == 0) {
8140
 
                ifp->key = MemFree (ifp->key);
8141
 
                ifp->key = StringSave ("misc_feature");
8142
 
                sfp->idx.subtype = FEATDEF_misc_feature;
8143
 
          } else if (StringHasNoText (ifp->loc)) {
8144
 
                rrptype = 0;
8145
 
                if (StringCmp (ifp->key, "precursor_RNA") == 0) {
8146
 
                  rrptype = 1;
8147
 
                } else if (StringCmp (ifp->key, "mRNA") == 0) {
8148
 
                  rrptype = 2;
8149
 
                } else if (StringCmp (ifp->key, "tRNA") == 0) {
8150
 
                  rrptype = 3;
8151
 
                } else if (StringCmp (ifp->key, "rRNA") == 0) {
8152
 
                  rrptype = 4;
8153
 
                } else if (StringCmp (ifp->key, "snRNA") == 0) {
8154
 
                  rrptype = 5;
8155
 
                } else if (StringCmp (ifp->key, "scRNA") == 0) {
8156
 
                  rrptype = 6;
8157
 
                } else if (StringCmp (ifp->key, "snoRNA") == 0) {
8158
 
                  rrptype = 7;
8159
 
                } else if (StringCmp (ifp->key, "misc_RNA") == 0) {
8160
 
                  rrptype = 255;
8161
 
                }
8162
 
                if (rrptype != 0) {
8163
 
                  sfp->data.value.ptrvalue = ImpFeatFree (ifp);
8164
 
                  sfp->data.choice = SEQFEAT_RNA;
8165
 
                  rrp = RnaRefNew ();
8166
 
                  sfp->data.value.ptrvalue = rrp;
8167
 
                  rrp->type = rrptype;
8168
 
                  sfp->idx.subtype = FindFeatDefType (sfp);
8169
 
                } else {
8170
 
                  processed = 0;
8171
 
                  if (StringCmp (ifp->key, "proprotein") == 0 || StringCmp (ifp->key, "preprotein") == 0) {
8172
 
                        processed = 1;
8173
 
                  } else if (StringCmp (ifp->key, "mat_peptide") == 0) {
8174
 
                        processed = 2;
8175
 
                  } else if (StringCmp (ifp->key, "sig_peptide") == 0) {
8176
 
                        processed = 3;
8177
 
                  } else if (StringCmp (ifp->key, "transit_peptide") == 0) {
8178
 
                        processed = 4;
8179
 
                  }
8180
 
                  if (processed != 0 || StringCmp (ifp->key, "Protein") == 0) {
8181
 
                        bsp = BioseqFind (SeqLocId (sfp->location));
8182
 
                        if (bsp != NULL && ISA_aa (bsp->mol)) {
8183
 
                          sfp->data.value.ptrvalue = ImpFeatFree (ifp);
8184
 
                          sfp->data.choice = SEQFEAT_PROT;
8185
 
                          prp = ProtRefNew ();
8186
 
                          sfp->data.value.ptrvalue = prp;
8187
 
                          prp->processed = processed;
8188
 
                          sfp->idx.subtype = FindFeatDefType (sfp);
8189
 
                        }
8190
 
                  }
8191
 
                }
8192
 
          }
8193
 
        }
 
9045
    ifp = (ImpFeatPtr) sfp->data.value.ptrvalue;
 
9046
    if (ifp != NULL) {
 
9047
      if (ifp->loc != NULL) {
 
9048
        str = StringStr (ifp->loc, "replace");
 
9049
        if (str != NULL) {
 
9050
          AddReplaceQual (sfp, str);
 
9051
          ifp->loc = MemFree (ifp->loc);
 
9052
        }
 
9053
      }
 
9054
      if (StringCmp (ifp->key, "CDS") == 0) {
 
9055
        if (! isEmblOrDdbj) {
 
9056
          sfp->data.value.ptrvalue = ImpFeatFree (ifp);
 
9057
          sfp->data.choice = SEQFEAT_CDREGION;
 
9058
          crp = CdRegionNew ();
 
9059
          sfp->data.value.ptrvalue = crp;
 
9060
          sfp->idx.subtype = FEATDEF_CDS;
 
9061
        }
 
9062
      } else if (StringCmp (ifp->key, "allele") == 0 ||
 
9063
                 StringCmp (ifp->key, "mutation") == 0) {
 
9064
        ifp->key = MemFree (ifp->key);
 
9065
        ifp->key = StringSave ("variation");
 
9066
        sfp->idx.subtype = FEATDEF_variation;
 
9067
      } else if (StringCmp (ifp->key, "Import") == 0 ||
 
9068
                 StringCmp (ifp->key, "virion") == 0) {
 
9069
        ifp->key = MemFree (ifp->key);
 
9070
        ifp->key = StringSave ("misc_feature");
 
9071
        sfp->idx.subtype = FEATDEF_misc_feature;
 
9072
      } else if (StringHasNoText (ifp->loc)) {
 
9073
        rrptype = 0;
 
9074
        if (StringCmp (ifp->key, "precursor_RNA") == 0) {
 
9075
          rrptype = 1;
 
9076
        } else if (StringCmp (ifp->key, "mRNA") == 0) {
 
9077
          rrptype = 2;
 
9078
        } else if (StringCmp (ifp->key, "tRNA") == 0) {
 
9079
          rrptype = 3;
 
9080
        } else if (StringCmp (ifp->key, "rRNA") == 0) {
 
9081
          rrptype = 4;
 
9082
        } else if (StringCmp (ifp->key, "snRNA") == 0) {
 
9083
          rrptype = 5;
 
9084
        } else if (StringCmp (ifp->key, "scRNA") == 0) {
 
9085
          rrptype = 6;
 
9086
        } else if (StringCmp (ifp->key, "snoRNA") == 0) {
 
9087
          rrptype = 7;
 
9088
        } else if (StringCmp (ifp->key, "misc_RNA") == 0) {
 
9089
          rrptype = 255;
 
9090
        }
 
9091
        if (rrptype != 0) {
 
9092
          sfp->data.value.ptrvalue = ImpFeatFree (ifp);
 
9093
          sfp->data.choice = SEQFEAT_RNA;
 
9094
          rrp = RnaRefNew ();
 
9095
          sfp->data.value.ptrvalue = rrp;
 
9096
          rrp->type = rrptype;
 
9097
          sfp->idx.subtype = FindFeatDefType (sfp);
 
9098
        } else {
 
9099
          processed = 0;
 
9100
          if (StringCmp (ifp->key, "proprotein") == 0 || StringCmp (ifp->key, "preprotein") == 0) {
 
9101
            processed = 1;
 
9102
          } else if (StringCmp (ifp->key, "mat_peptide") == 0) {
 
9103
            processed = 2;
 
9104
          } else if (StringCmp (ifp->key, "sig_peptide") == 0) {
 
9105
            processed = 3;
 
9106
          } else if (StringCmp (ifp->key, "transit_peptide") == 0) {
 
9107
            processed = 4;
 
9108
          }
 
9109
          if (processed != 0 || StringCmp (ifp->key, "Protein") == 0) {
 
9110
            bsp = BioseqFind (SeqLocId (sfp->location));
 
9111
            if (bsp != NULL && ISA_aa (bsp->mol)) {
 
9112
              sfp->data.value.ptrvalue = ImpFeatFree (ifp);
 
9113
              sfp->data.choice = SEQFEAT_PROT;
 
9114
              prp = ProtRefNew ();
 
9115
              sfp->data.value.ptrvalue = prp;
 
9116
              prp->processed = processed;
 
9117
              sfp->idx.subtype = FindFeatDefType (sfp);
 
9118
            }
 
9119
          }
 
9120
        }
 
9121
      }
 
9122
    }
8194
9123
  }
8195
9124
  if (crp != NULL && crp->frame == 0 && (! sfp->pseudo)) {
8196
 
        crp->frame = GetFrameFromLoc (sfp->location);
 
9125
    crp->frame = GetFrameFromLoc (sfp->location);
8197
9126
  }
8198
9127
  ModernizeFeatureGBQuals (sfp);
8199
9128
  sfp->qual = SortFeatureGBQuals (sfp->qual);
8207
9136
  CleanupDuplicateDbxrefs (&(sfp->dbxref));
8208
9137
  psp = sfp->cit;
8209
9138
  if (psp != NULL && psp->data.ptrvalue) {
8210
 
        psp->data.ptrvalue = ValNodeSort ((ValNodePtr) psp->data.ptrvalue, SortCits);
8211
 
        CleanupDuplicateCits ((ValNodePtr PNTR) &(psp->data.ptrvalue));
 
9139
    psp->data.ptrvalue = ValNodeSort ((ValNodePtr) psp->data.ptrvalue, SortCits);
 
9140
    CleanupDuplicateCits ((ValNodePtr PNTR) &(psp->data.ptrvalue));
8212
9141
  }
8213
9142
  CleanupSeqLoc (sfp->location);
8214
9143
  strand = SeqLocStrand (sfp->location);
8222
9151
      }
8223
9152
    }
8224
9153
  } else if (sfp->data.choice == SEQFEAT_CDREGION) {
8225
 
        crp = (CdRegionPtr) sfp->data.value.ptrvalue;
8226
 
        if (crp != NULL) {
8227
 
          crp->code_break = SortCodeBreaks (sfp, crp->code_break);
8228
 
          CleanupDuplicatedCodeBreaks (&(crp->code_break));
8229
 
          for (cbp = crp->code_break; cbp != NULL; cbp = cbp->next) {
8230
 
                CleanupSeqLoc (cbp->loc);
8231
 
                if (strand == Seq_strand_minus && id != NULL) {
8232
 
                  slp = cbp->loc;
8233
 
                  if (slp != NULL && slp->choice == SEQLOC_INT) {
8234
 
                        sip = SeqLocId (slp);
8235
 
                        if (sip != NULL && SeqIdComp (id, sip) == SIC_YES) {
8236
 
                          sintp = (SeqIntPtr) slp->data.ptrvalue;
8237
 
                          if (sintp != NULL) {
8238
 
                                sintp->strand = Seq_strand_minus;
8239
 
                          }
8240
 
                        }
8241
 
                  }
8242
 
                }
8243
 
          }
8244
 
        }
 
9154
    crp = (CdRegionPtr) sfp->data.value.ptrvalue;
 
9155
    if (crp != NULL) {
 
9156
      crp->code_break = SortCodeBreaks (sfp, crp->code_break);
 
9157
      CleanupDuplicatedCodeBreaks (&(crp->code_break));
 
9158
      for (cbp = crp->code_break; cbp != NULL; cbp = cbp->next) {
 
9159
        CleanupSeqLoc (cbp->loc);
 
9160
        if (strand == Seq_strand_minus && id != NULL) {
 
9161
          slp = cbp->loc;
 
9162
          if (slp != NULL && slp->choice == SEQLOC_INT) {
 
9163
            sip = SeqLocId (slp);
 
9164
            if (sip != NULL && SeqIdComp (id, sip) == SIC_YES) {
 
9165
              sintp = (SeqIntPtr) slp->data.ptrvalue;
 
9166
              if (sintp != NULL) {
 
9167
                sintp->strand = Seq_strand_minus;
 
9168
              }
 
9169
            }
 
9170
          }
 
9171
        }
 
9172
      }
 
9173
    }
8245
9174
  } else if (sfp->data.choice == SEQFEAT_RNA) {
8246
 
        rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
 
9175
    rrp = (RnaRefPtr) sfp->data.value.ptrvalue;
8247
9176
    if (rrp != NULL) {
8248
9177
      if (rrp->pseudo) {
8249
9178
        sfp->pseudo = TRUE;
8250
9179
        rrp->pseudo = FALSE;
8251
9180
      }
8252
9181
    }
8253
 
        if (rrp != NULL && rrp->ext.choice == 2) {
8254
 
          trp = (tRNAPtr) rrp->ext.value.ptrvalue;
8255
 
          if (trp != NULL && trp->anticodon != NULL) {
8256
 
                CleanupSeqLoc (trp->anticodon);
8257
 
                if (strand == Seq_strand_minus && id != NULL) {
8258
 
                  slp = trp->anticodon;
8259
 
                  if (slp != NULL && slp->choice == SEQLOC_INT) {
8260
 
                        sip = SeqLocId (slp);
8261
 
                        if (sip != NULL && SeqIdComp (id, sip) == SIC_YES) {
8262
 
                          sintp = (SeqIntPtr) slp->data.ptrvalue;
8263
 
                          if (sintp != NULL) {
8264
 
                                sintp->strand = Seq_strand_minus;
8265
 
                          }
8266
 
                        }
8267
 
                  }
8268
 
                }
8269
 
          }
8270
 
        }
 
9182
    if (rrp != NULL && rrp->ext.choice == 2) {
 
9183
      trp = (tRNAPtr) rrp->ext.value.ptrvalue;
 
9184
      if (trp != NULL && trp->anticodon != NULL) {
 
9185
        CleanupSeqLoc (trp->anticodon);
 
9186
        if (strand == Seq_strand_minus && id != NULL) {
 
9187
          slp = trp->anticodon;
 
9188
          if (slp != NULL && slp->choice == SEQLOC_INT) {
 
9189
            sip = SeqLocId (slp);
 
9190
            if (sip != NULL && SeqIdComp (id, sip) == SIC_YES) {
 
9191
              sintp = (SeqIntPtr) slp->data.ptrvalue;
 
9192
              if (sintp != NULL) {
 
9193
                sintp->strand = Seq_strand_minus;
 
9194
              }
 
9195
            }
 
9196
          }
 
9197
        }
 
9198
      }
 
9199
    }
 
9200
    if (ConvertToNcRNA (sfp)) {
 
9201
      sfp->idx.subtype = FindFeatDefType (sfp);
 
9202
    }
8271
9203
  } else if (sfp->data.choice == SEQFEAT_REGION ||
8272
9204
             sfp->data.choice == SEQFEAT_SITE ||
8273
9205
             sfp->data.choice == SEQFEAT_BOND ||
8309
9241
  }
8310
9242
}
8311
9243
 
8312
 
static void BasicSeqEntryCleanupInternal (SeqEntryPtr sep, ValNodePtr PNTR publist)
 
9244
static void BasicSeqEntryCleanupInternal (SeqEntryPtr sep, ValNodePtr PNTR publist, Boolean isEmblOrDdbj, Boolean stripSerial)
8313
9245
 
8314
9246
{
8315
9247
  BioSourcePtr  biop;
8318
9250
  SeqDescrPtr   desc;
8319
9251
  Char          div [10];
8320
9252
  GBBlockPtr    gbp;
8321
 
  Boolean       isEmblOrDdbj = FALSE;
8322
9253
  MolInfoPtr    mip;
8323
9254
  OrgNamePtr    onp;
8324
9255
  OrgRefPtr     orp;
8325
9256
  SeqAnnotPtr   sap = NULL;
8326
9257
  ValNodePtr    sdp = NULL;
8327
9258
  SeqFeatPtr    sfp;
8328
 
  Boolean       stripSerial = TRUE;
8329
9259
  SeqEntryPtr   tmp;
8330
9260
 
8331
9261
  if (sep == NULL) return;
8332
 
  SeqEntryExplore (sep, (Pointer) &stripSerial, CheckForSwissProtID);
8333
 
  SeqEntryExplore (sep, (Pointer) &isEmblOrDdbj, CheckForEmblDdbjID);
8334
 
#ifdef SUPPRESS_STRIP_SERIAL_DIFFERENCES
8335
 
  stripSerial = FALSE;
8336
 
#endif
8337
9262
  if (IS_Bioseq (sep)) {
8338
9263
    bsp = (BioseqPtr) sep->data.ptrvalue;
8339
9264
    if (bsp == NULL) return;
8358
9283
            case MOLECULE_TYPE_CRNA :
8359
9284
            case MOLECULE_TYPE_SNORNA :
8360
9285
            case MOLECULE_TYPE_TRANSCRIBED_RNA :
 
9286
            case MOLECULE_TYPE_NCRNA :
 
9287
            case MOLECULE_TYPE_TMRNA :
8361
9288
              bsp->mol = Seq_mol_rna;
8362
9289
              break;
8363
9290
            case MOLECULE_TYPE_PEPTIDE :
8379
9306
    bssp = (BioseqSetPtr) sep->data.ptrvalue;
8380
9307
    if (bssp == NULL) return;
8381
9308
    for (tmp = bssp->seq_set; tmp != NULL; tmp = tmp->next) {
8382
 
      BasicSeqEntryCleanupInternal (tmp, publist);
 
9309
      BasicSeqEntryCleanupInternal (tmp, publist, isEmblOrDdbj, stripSerial);
8383
9310
    }
8384
9311
    sap = bssp->annot;
8385
9312
    sdp = bssp->descr;
8759
9686
NLM_EXTERN void BasicSeqEntryCleanup (SeqEntryPtr sep)
8760
9687
 
8761
9688
{
 
9689
  AuthorPtr       ap;
 
9690
  ContactInfoPtr  cip;
8762
9691
  CitSubPtr       csp;
8763
9692
  Uint2           entityID;
 
9693
  Boolean         isEmblOrDdbj = FALSE;
8764
9694
  ValNodePtr      labellist = NULL;
8765
9695
  ValNodePtr      pairlist = NULL;
8766
9696
  ValNodePtr      publist = NULL;
8768
9698
  ObjMgrDataPtr   omdp;
8769
9699
  SubmitBlockPtr  sbp;
8770
9700
  SeqSubmitPtr    ssp;
 
9701
  Boolean         stripSerial = TRUE;
8771
9702
 
8772
9703
  if (sep == NULL) return;
8773
9704
 
8785
9716
  VisitPubdescsInSep (sep, NULL, FlattenPubdesc);
8786
9717
  VisitFeaturesInSep (sep, NULL, FlattenSfpCit);
8787
9718
 
8788
 
  BasicSeqEntryCleanupInternal (sep, &publist);
 
9719
  SeqEntryExplore (sep, (Pointer) &stripSerial, CheckForSwissProtID);
 
9720
  SeqEntryExplore (sep, (Pointer) &isEmblOrDdbj, CheckForEmblDdbjID);
 
9721
#ifdef SUPPRESS_STRIP_SERIAL_DIFFERENCES
 
9722
  stripSerial = FALSE;
 
9723
#endif
 
9724
 
 
9725
  BasicSeqEntryCleanupInternal (sep, &publist, isEmblOrDdbj, stripSerial);
8789
9726
  if (publist != NULL) {
8790
9727
    VisitFeaturesInSep (sep, (Pointer) publist, ChangeCitsOnFeats);
8791
9728
  }
8820
9757
        if (csp != NULL) {
8821
9758
          NormalizeAuthors (csp->authors, TRUE);
8822
9759
        }
 
9760
        cip = sbp->contact;
 
9761
        if (cip != NULL) {
 
9762
          ap = cip->contact;
 
9763
          if (ap != NULL) {
 
9764
            ap->affil = CleanAffil (ap->affil);
 
9765
          }
 
9766
        }
8823
9767
      }
8824
9768
    }
8825
9769
  }
9282
10226
    }
9283
10227
  }
9284
10228
#ifdef OS_UNIX_DARWIN
9285
 
  if (! (dataFound) &&  IsApplicationPackage(appPath)) {
 
10229
  if (! (dataFound) && IsApplicationPackage (appPath)) {
9286
10230
      /* is data inside our application within Contents/Resources? */
9287
 
      StrCpy(path, appPath);
9288
 
      FileBuildPath(path, "Contents", NULL);
 
10231
      StrCpy (path, appPath);
 
10232
      FileBuildPath (path, "Contents", NULL);
9289
10233
      FileBuildPath (path, "Resources", NULL);
9290
10234
      dataFound = CheckDataPath (path, "data");
 
10235
      if (! dataFound) {
 
10236
        StrCpy (path, appPath);
 
10237
        ptr = StringStr (path, "/ncbi/build/");
 
10238
        if (ptr != NULL) {
 
10239
          /* see if running under Xcode build environment */
 
10240
          ptr [5] = '\0';
 
10241
          dataFound = CheckDataPath (path, "data");
 
10242
        }
 
10243
      }
9291
10244
  }
9292
10245
#endif
9293
10246
  if (dataFound) {
9683
10636
      if (subtype == FEATDEF_snoRNA) {
9684
10637
        return SEQFEAT_RNA;
9685
10638
      }
9686
 
      if (subtype >= FEATDEF_IMP && subtype <= FEATDEF_site_ref) {
9687
 
        return SEQFEAT_IMP;
9688
 
      }
9689
 
      if (subtype == FEATDEF_oriT) {
9690
 
        return SEQFEAT_IMP;
 
10639
      if (subtype >= FEATDEF_ncRNA && subtype <= FEATDEF_tmRNA) {
 
10640
        return SEQFEAT_RNA;
9691
10641
      }
9692
10642
      if (subtype >= FEATDEF_preprotein && subtype <= FEATDEF_transit_peptide_aa) {
9693
10643
        return SEQFEAT_PROT;
9694
10644
      }
9695
 
      if (subtype == FEATDEF_operon) {
 
10645
      if (subtype >= FEATDEF_IMP && subtype <= FEATDEF_site_ref) {
9696
10646
        return SEQFEAT_IMP;
9697
10647
      }
9698
 
      if (subtype == FEATDEF_gap) {
 
10648
      if (subtype >= FEATDEF_gap && subtype <= FEATDEF_oriT) {
9699
10649
        return SEQFEAT_IMP;
9700
10650
      }
9701
10651
  }
9726
10676
NLM_EXTERN SeqIdPtr MakeUniqueSeqID (CharPtr prefix)
9727
10677
 
9728
10678
{
9729
 
        Char buf[40];
9730
 
        CharPtr tmp;
9731
 
        Int2 ctr;
9732
 
        ValNodePtr newid;
9733
 
        ObjectIdPtr oid;
9734
 
        ValNode vn;
9735
 
        TextSeqId tsi;
9736
 
        ValNodePtr altid;
9737
 
        size_t len;
9738
 
 
9739
 
        altid = &vn;
9740
 
        vn.choice = SEQID_GENBANK;
9741
 
        vn.next = NULL;
9742
 
        vn.data.ptrvalue = &tsi;
9743
 
        tsi.name = NULL;
9744
 
        tsi.accession = NULL;
9745
 
        tsi.release = NULL;
9746
 
        tsi.version = INT2_MIN;
9747
 
 
9748
 
        len = StringLen (prefix);
9749
 
        if (len > 0 && len < 32) {
9750
 
                tmp = StringMove(buf, prefix);
9751
 
        } else {
9752
 
                tmp = StringMove(buf, "tmpseq_");
9753
 
        }
9754
 
 
9755
 
        newid = ValNodeNew(NULL);
9756
 
        oid = ObjectIdNew();
9757
 
        oid->str = buf;   /* allocate this later */
9758
 
        newid->choice = SEQID_LOCAL;
9759
 
        newid->data.ptrvalue = oid;
9760
 
 
9761
 
        tsi.name = buf;   /* check for alternative form */
9762
 
 
9763
 
        for (ctr = 1; ctr < 32000; ctr++)
9764
 
        {
9765
 
                sprintf(tmp, "%d", (int)ctr);
9766
 
                if ((BioseqFindCore(newid) == NULL) && (BioseqFindCore(altid) == NULL))
9767
 
                {
9768
 
                        oid->str = StringSave(buf);
9769
 
                        return newid;
9770
 
                }
9771
 
        }
9772
 
 
9773
 
        return NULL;
 
10679
    Char buf[40];
 
10680
    CharPtr tmp;
 
10681
    Int2 ctr;
 
10682
    ValNodePtr newid;
 
10683
    ObjectIdPtr oid;
 
10684
    ValNode vn;
 
10685
    TextSeqId tsi;
 
10686
    ValNodePtr altid;
 
10687
    size_t len;
 
10688
 
 
10689
    altid = &vn;
 
10690
    vn.choice = SEQID_GENBANK;
 
10691
    vn.next = NULL;
 
10692
    vn.data.ptrvalue = &tsi;
 
10693
    tsi.name = NULL;
 
10694
    tsi.accession = NULL;
 
10695
    tsi.release = NULL;
 
10696
    tsi.version = INT2_MIN;
 
10697
 
 
10698
    len = StringLen (prefix);
 
10699
    if (len > 0 && len < 32) {
 
10700
        tmp = StringMove(buf, prefix);
 
10701
    } else {
 
10702
        tmp = StringMove(buf, "tmpseq_");
 
10703
    }
 
10704
 
 
10705
    newid = ValNodeNew(NULL);
 
10706
    oid = ObjectIdNew();
 
10707
    oid->str = buf;   /* allocate this later */
 
10708
    newid->choice = SEQID_LOCAL;
 
10709
    newid->data.ptrvalue = oid;
 
10710
 
 
10711
    tsi.name = buf;   /* check for alternative form */
 
10712
 
 
10713
    for (ctr = 1; ctr < 32000; ctr++)
 
10714
    {
 
10715
        sprintf(tmp, "%d", (int)ctr);
 
10716
        if ((BioseqFindCore(newid) == NULL) && (BioseqFindCore(altid) == NULL))
 
10717
        {
 
10718
            oid->str = StringSave(buf);
 
10719
            return newid;
 
10720
        }
 
10721
    }
 
10722
 
 
10723
    return NULL;
9774
10724
}
9775
10725
 
9776
10726
NLM_EXTERN SeqIdPtr SeqIdFindWorst (SeqIdPtr sip)