~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to api/sequtil.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
*   
30
30
* Version Creation Date: 4/1/91
31
31
*
32
 
* $Revision: 6.101 $
 
32
* $Revision: 6.161 $
33
33
*
34
34
* File Description:  Sequence Utilities for objseq and objsset
35
35
*
36
36
* Modifications:  
37
37
* --------------------------------------------------------------------------
38
38
* $Log: sequtil.c,v $
 
39
* Revision 6.161  2004/10/13 16:46:52  kans
 
40
* added DA, DB, DC as DDBJ_EST
 
41
*
 
42
* Revision 6.160  2004/09/21 22:34:36  dondosha
 
43
* Get the number of linked HSPs for a DenDiag from the first segment, not from the largest linked set
 
44
*
 
45
* Revision 6.159  2004/09/15 13:02:02  kans
 
46
* added CW to WHICH_db_accession as NCBI GSS
 
47
*
 
48
* Revision 6.158  2004/08/20 18:55:27  kans
 
49
* SeqLocStrand skips NULL or EMPTY components of MIX to avoid giving incorrect unknown result
 
50
*
 
51
* Revision 6.157  2004/08/17 19:35:44  kans
 
52
* BSPack uses BSRead instead of BSGetByte for significant speed increase
 
53
*
 
54
* Revision 6.156  2004/08/06 17:15:50  kans
 
55
* added CV as NCBI EST
 
56
*
 
57
* Revision 6.155  2004/08/04 17:15:16  kans
 
58
* added AccnInUniProt - still need AccnIsSWISSPROT for old style
 
59
*
 
60
* Revision 6.154  2004/07/21 18:05:00  rsmith
 
61
* SeqLocStart and SeqLocStop were not handling SEQLOC_PACKED_PNTs properly
 
62
*
 
63
* Revision 6.153  2004/07/14 22:55:04  dondosha
 
64
* Add version in GetAccessionVersionFromSeqId only if it is > 0
 
65
*
 
66
* Revision 6.152  2004/07/14 22:46:08  dondosha
 
67
* Added GetAccessionVersionFromSeqId function to extract Accession.version from a Seq-id
 
68
*
 
69
* Revision 6.151  2004/07/14 19:09:19  kans
 
70
* added CP for ACCN_NCBI_GENOME in WHICH_db_accession
 
71
*
 
72
* Revision 6.150  2004/06/04 17:31:34  kans
 
73
* added CN and CO accession prefixes
 
74
*
 
75
* Revision 6.149  2004/05/27 15:37:31  kans
 
76
* fixed typo in WHICH_db_accession - new 12-character RefSeq test used wrong comparison for underscore test
 
77
*
 
78
* Revision 6.148  2004/05/25 20:46:18  kans
 
79
* WHICH_db_accession handles 12-character RefSeq accessions
 
80
*
 
81
* Revision 6.147  2004/03/30 20:29:33  kans
 
82
* in static std_order array within SeqIdBestRank, demoted gibbsq, gibbmt, and patent
 
83
*
 
84
* Revision 6.146  2004/03/16 22:08:31  kans
 
85
* added CL to WHICH_db_accession as NCBI EST
 
86
*
 
87
* Revision 6.145  2004/03/15 18:42:59  coulouri
 
88
* Handle memory allocation failure gracefully with BSRebuildDNA_4na
 
89
*
 
90
* Revision 6.144  2004/01/16 16:37:01  kans
 
91
* added CM as scaffold/CON record
 
92
*
 
93
* Revision 6.143  2003/12/18 19:35:53  kans
 
94
* added CQ and CR prefixes
 
95
*
 
96
* Revision 6.142  2003/12/16 16:03:04  kans
 
97
* added CL as ncbi gss
 
98
*
 
99
* Revision 6.141  2003/11/10 16:12:33  kans
 
100
* added CK as genbank est
 
101
*
 
102
* Revision 6.140  2003/10/31 20:51:24  kans
 
103
* added CI and CJ as DDBJ ESTs to WHICH_db_accession
 
104
*
 
105
* Revision 6.139  2003/10/24 14:36:12  kans
 
106
* added CH as GenBank CONN to WHICH_db_accession
 
107
*
 
108
* Revision 6.138  2003/09/09 20:08:18  kans
 
109
* SeqLocPartialCheck locks bioseq if seqloc_whole and far
 
110
*
 
111
* Revision 6.137  2003/09/02 15:11:50  kans
 
112
* WHICH_db_accession takes ZP_ with 8 digits as refseq_prot_predicted
 
113
*
 
114
* Revision 6.136  2003/08/11 13:45:18  kans
 
115
* added CG as ncbi gss
 
116
*
 
117
* Revision 6.135  2003/07/14 20:17:53  kans
 
118
* added CF as ncbi est to WHICH_db_accession
 
119
*
 
120
* Revision 6.134  2003/07/02 14:35:21  kans
 
121
* added CE as ncbi gss
 
122
*
 
123
* Revision 6.133  2003/05/20 22:15:24  yaschenk
 
124
* SeqIdSelect loops indefinitely on corrupted memory
 
125
*
 
126
* Revision 6.132  2003/04/30 16:40:41  kans
 
127
* added CD as GenBank EST
 
128
*
 
129
* Revision 6.131  2003/03/25 13:32:22  kans
 
130
* added CC as ncbi gss accession prefix
 
131
*
 
132
* Revision 6.130  2003/03/24 19:41:56  kans
 
133
* added tmsmart_order, use in SeqIdWrite to prevent TMSMART temporary ID from being used
 
134
*
 
135
* Revision 6.129  2003/02/20 19:05:31  ford
 
136
* Modified MakeNewProteinSeqIdExMT() to create an ID of maximum length 30 instead of 20.
 
137
*
 
138
* Revision 6.128  2003/01/21 17:06:57  kans
 
139
* implement PRINTID_FASTA_ALL SeqIdWrite
 
140
*
 
141
* Revision 6.127  2003/01/13 18:15:35  kans
 
142
* added CB as NCBI EST prefix
 
143
*
 
144
* Revision 6.126  2002/11/05 18:50:31  kans
 
145
* fixed bug in SeqLocPartialCheck
 
146
*
 
147
* Revision 6.125  2002/10/19 19:11:21  kans
 
148
* added CA as GenBank EST
 
149
*
 
150
* Revision 6.124  2002/10/03 16:18:35  kans
 
151
* added BZ as NCBI GSS
 
152
*
 
153
* Revision 6.123  2002/09/20 20:47:51  kans
 
154
* added BY as DDBJ EST prefix
 
155
*
 
156
* Revision 6.122  2002/08/28 13:28:54  kans
 
157
* added BX prefix
 
158
*
 
159
* Revision 6.121  2002/08/26 20:38:26  kans
 
160
* added BW as ddbj est prefix
 
161
*
 
162
* Revision 6.120  2002/08/19 15:57:28  kans
 
163
* BV is NCBI STS prefix
 
164
*
 
165
* Revision 6.119  2002/08/19 15:54:47  kans
 
166
* added BU as NCBI EST prefix
 
167
*
 
168
* Revision 6.118  2002/07/12 18:47:46  kans
 
169
* WHICH_db_accession was using the result of AccnIsSWISSPROT incorrectly
 
170
*
 
171
* Revision 6.117  2002/07/08 20:25:45  kans
 
172
* added BT as FLI_cDNA type
 
173
*
 
174
* Revision 6.116  2002/06/28 14:48:03  kans
 
175
* added BS as ddbj genome project prefix
 
176
*
 
177
* Revision 6.115  2002/06/20 18:38:43  kans
 
178
* added FAA and GAA, ACCN_NCBI_WGS_PROT, ACCN_EMBL_WGS_PROT, ACCN_DDBJ_WGS_PROT, and ACCN_IS_WGS
 
179
*
 
180
* Revision 6.114  2002/06/19 17:13:48  kans
 
181
* added ACCN_PDB, support for PDB in SeqIdFromAccessionDotVersion
 
182
*
 
183
* Revision 6.113  2002/06/10 18:06:16  kans
 
184
* SeqLocLen use of smp->seq_len_lookup_func first checks sip for NULL
 
185
*
 
186
* Revision 6.112  2002/06/10 14:07:12  kans
 
187
* SeqLocLen on whole tries new smp->seq_len_lookup_func registered function
 
188
*
 
189
* Revision 6.111  2002/05/29 19:19:53  bazhin
 
190
* Added support for new EAA-EZZ protein's WGS accessions.
 
191
*
 
192
* Revision 6.110  2002/04/24 17:11:03  kans
 
193
* added BR as DDBJ TPA accession prefix
 
194
*
 
195
* Revision 6.109  2002/04/02 18:19:56  kans
 
196
* SeqLocPartialCheck fixes
 
197
*
 
198
* Revision 6.108  2002/03/26 18:11:26  kans
 
199
* WHICH_db_accession WGS assignments - A*** NCBI, B*** DDBJ, C*** EMBL
 
200
*
 
201
* Revision 6.107  2002/03/12 17:08:32  kans
 
202
* added BQ as NCBI EST
 
203
*
 
204
* Revision 6.106  2002/02/14 18:30:27  kans
 
205
* SeqIdFromAccessionDotVersion defaults version to INT2_MIN
 
206
*
 
207
* Revision 6.105  2002/01/29 19:28:16  kans
 
208
* SeqIdParse can parse type|accession.ver with no trailing vertical bars for RefSeq and DNA database types
 
209
*
 
210
* Revision 6.104  2002/01/22 18:49:15  kans
 
211
* added ACCN_NCBI_WGS, ACCN_EMBL_WGS, and ACCN_DDBJ_WGS
 
212
*
 
213
* Revision 6.103  2002/01/17 13:49:32  kans
 
214
* BP added as DDBJ EST accession prefix
 
215
*
 
216
* Revision 6.102  2002/01/16 16:59:38  camacho
 
217
* Changed the type of buflen parameter in SeqIdWrite from Int2 to Uint4
 
218
*
39
219
* Revision 6.101  2001/11/29 14:04:29  kans
40
220
* reverted GetThePointForOffset, deal with trans-splicing in feature indexing left/right extreme calculation itself
41
221
*
1177
1357
  Uint1 newcode, byte;
1178
1358
  Char Code4na[256], CodeIna[256];
1179
1359
  Boolean remained;
 
1360
  Int2 actual, j;
 
1361
  Int4 cntr;
 
1362
  Uint1 tmp [401];
1180
1363
 
1181
1364
  Uint1 set4na[16] = {17, 18, 20, 24,  33,  34,  36,  40,
1182
1365
                      65, 66, 68, 72, 129, 130, 132, 136}; 
1187
1370
  
1188
1371
  if (oldcode == Seq_code_ncbi2na)   /* already packed */
1189
1372
    return NULL;
1190
 
  
 
1373
 
 
1374
  MemSet ((Pointer) tmp, 0, sizeof (tmp));
 
1375
 
1191
1376
  BSSeek(from, 0L, SEEK_SET);
1192
1377
  newcode = Seq_code_ncbi2na;    /* go for broke */
1193
1378
 
1200
1385
    MemSet(Code4na, 1, sizeof(Code4na));
1201
1386
    for(i=0; i< 16; i++)
1202
1387
      Code4na[set4na[i]] = 0;
1203
 
  
1204
 
    while(seqlen) {
1205
 
      byte = (Uint1) BSGetByte(from);    
 
1388
 
 
1389
    cntr = (Int4) MIN ((Int4) seqlen, (Int4) (sizeof (tmp) - 1));
 
1390
    actual = (Int2) BSRead (from, tmp, (Int4) cntr);
 
1391
    j = 0;
 
1392
 
 
1393
    while(seqlen && actual > 0) {
 
1394
      if (j == actual) {
 
1395
        cntr = (Int4) MIN ((Int4) seqlen, (Int4) (sizeof (tmp) - 1));
 
1396
        actual = (Int2) BSRead (from, tmp, (Int4) cntr);
 
1397
        j = 0;
 
1398
      }
 
1399
      /* byte = (Uint1) BSGetByte(from); */
 
1400
      byte = (Int2) (Uint1) tmp [j];
 
1401
      j++;
1206
1402
      if(Code4na[byte]) {
1207
1403
        newcode = Seq_code_ncbi4na;
1208
1404
        if (newcodeptr != NULL) {
1223
1419
    for(i=0; i < 4; i++)
1224
1420
      CodeIna[setIna[i]] = 0;
1225
1421
    seqlen = length;
1226
 
    while(seqlen) {
1227
 
      byte = (Uint1) BSGetByte(from);    
 
1422
 
 
1423
    cntr = (Int4) MIN ((Int4) seqlen, (Int4) (sizeof (tmp) - 1));
 
1424
    actual = (Int2) BSRead (from, tmp, (Int4) cntr);
 
1425
    j = 0;
 
1426
 
 
1427
    while(seqlen && actual > 0) {
 
1428
      if (j == actual) {
 
1429
        cntr = (Int4) MIN ((Int4) seqlen, (Int4) (sizeof (tmp) - 1));
 
1430
        actual = (Int2) BSRead (from, tmp, (Int4) cntr);
 
1431
        j = 0;
 
1432
      }
 
1433
      /* byte = (Uint1) BSGetByte(from); */
 
1434
      byte = (Int2) (Uint1) tmp [j];
 
1435
      j++;
1228
1436
      if(CodeIna[byte]) {
1229
1437
        newcode = Seq_code_ncbi4na;
1230
1438
        break;
1543
1751
        return from;
1544
1752
    
1545
1753
    bs_length = BSLen(from);
1546
 
    buffer = (Uint1Ptr) MemNew(bs_length + sizeof(Char));
 
1754
    buffer = (Uint1Ptr) Nlm_Malloc(bs_length);
 
1755
    if (buffer == NULL)
 
1756
        return NULL;
 
1757
 
1547
1758
    BSSeek(from, 0, SEEK_SET);
1548
1759
 
1549
1760
    if((num_bytes = BSRead(from, buffer, bs_length)) != bs_length)
2847
3058
        static Uint1 std_order[NUM_SEQID] = {
2848
3059
        83, /* 0 = not set */
2849
3060
        80, /* 1 = local Object-id */
2850
 
        55,  /* 2 = gibbsq */
2851
 
        56,  /* 3 = gibbmt */
 
3061
        70,  /* 2 = gibbsq */
 
3062
        70,  /* 3 = gibbmt */
2852
3063
        70, /* 4 = giim Giimport-id */
2853
3064
        60, /* 5 = genbank */
2854
3065
        60, /* 6 = embl */
2855
3066
        60, /* 7 = pir */
2856
3067
        60, /* 8 = swissprot */
2857
 
        55,  /* 9 = patent */
 
3068
        67,  /* 9 = patent */
2858
3069
        65, /* 10 = other TextSeqId */
2859
3070
        80, /* 11 = general Dbtag */
2860
3071
        51,  /* 12 = gi */
2861
3072
        60, /* 13 = ddbj */
2862
3073
        60, /* 14 = prf */
2863
3074
        60, /* 15 = pdb */
2864
 
        60,  /* 16 = tpg */
2865
 
        60,  /* 17 = tpe */
2866
 
        60   /* 18 = tpd */
2867
 
    };
 
3075
        60,  /* 16 = tpg */
 
3076
        60,  /* 17 = tpe */
 
3077
        60   /* 18 = tpd */
 
3078
        };
2868
3079
 
2869
3080
        if (buf == NULL) return NUM_SEQID;
2870
3081
 
2973
3184
                                else if (order[sip->choice] < order[bestid->choice])
2974
3185
                                        bestid = sip;
2975
3186
                        }
2976
 
                }
2977
 
                else
 
3187
                } else {
2978
3188
                        ErrPostEx(SEV_ERROR, 0,0, "SeqIdSelect: choice [%d] out of range [%d]",
2979
3189
                                (int)(sip->choice), (int)num);
 
3190
                        if(sip->choice > NUM_SEQID) /*** something is really wrong ***/
 
3191
                                return NULL;
 
3192
                }
2980
3193
    }
2981
3194
 
2982
3195
    return bestid;
3057
3270
*               last '\0' 
3058
3271
*
3059
3272
*****************************************************************************/
3060
 
NLM_EXTERN CharPtr SeqIdWrite (SeqIdPtr isip, CharPtr buf, Uint1 format, Int2 buflen)
 
3273
NLM_EXTERN CharPtr SeqIdWrite (SeqIdPtr isip, CharPtr buf, Uint1 format, Uint4 buflen)
3061
3274
 
3062
3275
{
3063
3276
        SeqIdPtr sip;
3086
3299
        10,  /* 17 = tpe */
3087
3300
        10   /* 18 = tpd */
3088
3301
    };
 
3302
        static Uint1 tmsmart_order[NUM_SEQID] = {  /* order for other id FASTA_LONG */
 
3303
        33, /* 0 = not set */
 
3304
        20, /* 1 = local Object-id */
 
3305
        15,  /* 2 = gibbsq */
 
3306
        16,  /* 3 = gibbmt */
 
3307
        30, /* 4 = giim Giimport-id */
 
3308
        10, /* 5 = genbank */
 
3309
        10, /* 6 = embl */
 
3310
        10, /* 7 = pir */
 
3311
        10, /* 8 = swissprot */
 
3312
        15,  /* 9 = patent */
 
3313
        12, /* 10 = other TextSeqId */
 
3314
        29, /* 11 = general Dbtag */
 
3315
        255,  /* 12 = gi */
 
3316
        10, /* 13 = ddbj */
 
3317
        10, /* 14 = prf */
 
3318
        12,  /* 15 = pdb */
 
3319
        10,  /* 16 = tpg */
 
3320
        10,  /* 17 = tpe */
 
3321
        10   /* 18 = tpd */
 
3322
    };
3089
3323
        static Uint1 general_order[NUM_SEQID] = {  /* order for other id FASTA_LONG */
3090
3324
        33, /* 0 = not set */
3091
3325
        20, /* 1 = local Object-id */
3113
3347
        ObjectIdPtr oip;
3114
3348
        PatentSeqIdPtr patsip;
3115
3349
        Boolean got_gi = FALSE;
 
3350
        Boolean got_tmsmart = FALSE;
 
3351
        DbtagPtr dbt;
3116
3352
        Char chainbuf[3];
3117
3353
        Char versionbuf[10];
3118
3354
        Int2 version = 0;
3139
3375
                useGeneral = TRUE;
3140
3376
                format = PRINTID_FASTA_LONG;
3141
3377
        }
 
3378
 
 
3379
        if (format == PRINTID_FASTA_ALL) {
 
3380
                Char allbuf [41];
 
3381
                ValNodePtr vnp, head = NULL;
 
3382
                size_t len = 0;
 
3383
                CharPtr str;
 
3384
                Boolean notfirst;
 
3385
 
 
3386
                for (sip = isip; sip != NULL; sip = sip->next) {
 
3387
                        SeqIdWrite (sip, allbuf, PRINTID_FASTA_SHORT, sizeof (allbuf) - 1);
 
3388
                        ValNodeCopyStr (&head, 0, allbuf);
 
3389
                }
 
3390
                for (vnp = head; vnp != NULL; vnp = vnp->next) {
 
3391
                  str = (CharPtr) vnp->data.ptrvalue;
 
3392
                  if (! StringHasNoText (str)) {
 
3393
                    len += StringLen (str) + 1;
 
3394
                  }
 
3395
                }
 
3396
                if (len < 1) return buf;
 
3397
                tmp = MemNew (len + 2);
 
3398
                if (tmp == NULL) return buf;
 
3399
                notfirst = FALSE;
 
3400
                for (vnp = head; vnp != NULL; vnp = vnp->next) {
 
3401
                  str = (CharPtr) vnp->data.ptrvalue;
 
3402
                  if (! StringHasNoText (str)) {
 
3403
                    if (notfirst) {
 
3404
                      StringCat (tmp, "|");
 
3405
                    }
 
3406
                    StringCat (tmp, str);
 
3407
                    notfirst = TRUE;
 
3408
                  }
 
3409
                }
 
3410
                ValNodeFreeData (head);
 
3411
                StringNCpy_0 (buf, tmp, buflen + 1);
 
3412
                MemFree (tmp);
 
3413
                return buf;
 
3414
        }
3142
3415
        
3143
3416
        localbuf[0] = '\0';
3144
3417
                                                        /* error on input, return ??? */
3159
3432
                                        (long)(sip->data.intvalue));
3160
3433
                                Nlm_LabelCopyNext(&tmp, localbuf, &buflen);
3161
3434
                                got_gi = TRUE;
3162
 
                                break;
 
3435
                        } else if (sip->choice == SEQID_GENERAL) {
 
3436
                                dbt = (DbtagPtr) sip->data.ptrvalue;
 
3437
                                if (dbt != NULL && StringICmp (dbt->db, "TMSMART") == 0) {
 
3438
                                        got_tmsmart = TRUE;
 
3439
                                }
3163
3440
                        }
3164
3441
                }
3165
3442
                if (useGeneral) {
3166
3443
                        sip = SeqIdSelect(isip, general_order, NUM_SEQID);
 
3444
                } else if (got_tmsmart) {
 
3445
                        sip = SeqIdSelect(isip, tmsmart_order, NUM_SEQID);
3167
3446
                } else {
3168
3447
                        sip = SeqIdSelect(isip, fasta_order, NUM_SEQID);
3169
3448
                }
3359
3638
Boolean GetAccessionFromSeqId(SeqIdPtr sip, Int4Ptr gi, 
3360
3639
                                     CharPtr PNTR id)
3361
3640
{
 
3641
   return GetAccessionVersionFromSeqId(sip, gi, id, FALSE);
 
3642
}
 
3643
 
 
3644
/* Maximal length of a version number in Accession.version identifiers */
 
3645
#define MAX_VERSION_LENGTH 10
 
3646
 
 
3647
Boolean GetAccessionVersionFromSeqId(SeqIdPtr sip, Int4Ptr gi, 
 
3648
                                     CharPtr PNTR id, Boolean get_version)
 
3649
{
3362
3650
   Boolean numeric_id_type = FALSE;
3363
3651
   Int2 id_len;
3364
3652
   GiimPtr gip;
3398
3686
   case SEQID_OTHER: case SEQID_TPG: case SEQID_TPE: case SEQID_TPD:
3399
3687
      textsip = (TextSeqIdPtr)sip->data.ptrvalue;
3400
3688
      if (textsip->accession) {
3401
 
         id_len = StringLen(textsip->accession);
3402
 
         *id = (CharPtr) MemNew(id_len+1);
3403
 
         sprintf(*id, "%s", textsip->accession);
 
3689
         if (get_version && textsip->version > 0) {
 
3690
            /* Assume versions are no longer than MAX_VERSION_LENGTH digits */
 
3691
            id_len = StringLen(textsip->accession) + MAX_VERSION_LENGTH + 1;
 
3692
            *id = (CharPtr) MemNew(id_len+1);
 
3693
            sprintf(*id, "%s.%ld", textsip->accession, textsip->version);
 
3694
         } else {
 
3695
            id_len = StringLen(textsip->accession);
 
3696
            *id = (CharPtr) MemNew(id_len+1);
 
3697
            sprintf(*id, "%s", textsip->accession);
 
3698
         }
3404
3699
      } else if (textsip->name) {
3405
3700
         id_len = StringLen(textsip->name);
3406
3701
         *id = (CharPtr) MemNew(id_len+1);
3531
3826
                                numtoken++;
3532
3827
                                if (*buf == '\0')
3533
3828
                                {
3534
 
                                        if (type == SEQID_OTHER && numtoken == 2)
 
3829
                                        if (type == SEQID_OTHER && (numtoken == 2 || numtoken == 1))
 
3830
                                                done = TRUE;
 
3831
                                        else if ((type == SEQID_GENBANK || type == SEQID_EMBL || type == SEQID_DDBJ ||
 
3832
                                                        type == SEQID_TPG || type == SEQID_TPE || type == SEQID_TPD) && numtoken == 1)
3535
3833
                                                done = TRUE;
3536
3834
                                        else if (numtoken < (Int2)(expect_tokens[type]))
3537
3835
                                                goto erret;
4047
4345
    }
4048
4346
    
4049
4347
    if (sip != NULL) {
4050
 
        SeqIdWrite(sip, buf, PRINTID_TEXTID_ACCESSION, 20);
 
4348
        SeqIdWrite(sip, buf, PRINTID_TEXTID_ACCESSION, 30);
4051
4349
        tmp = buf;
4052
4350
        while (*tmp != '\0')
4053
4351
            tmp++;
4445
4743
                        numpnt = PackSeqPntNum((PackSeqPntPtr)anp->data.ptrvalue);
4446
4744
                        while (numpnt)
4447
4745
                        {
 
4746
                                numpnt--;
4448
4747
                                tpos = PackSeqPntGet((PackSeqPntPtr)anp->data.ptrvalue, numpnt);
4449
4748
                                if (pos < 0)
4450
4749
                                        pos = tpos;
4451
4750
                                else if (tpos < pos)
4452
4751
                                        pos = tpos;
4453
 
                                numpnt--;
4454
4752
                        }
4455
4753
            break;
4456
4754
        default:
4531
4829
                        numpnt = PackSeqPntNum((PackSeqPntPtr)anp->data.ptrvalue);
4532
4830
                        while (numpnt)
4533
4831
                        {
 
4832
                                numpnt--;
4534
4833
                                tpos = PackSeqPntGet((PackSeqPntPtr)anp->data.ptrvalue, numpnt);
4535
4834
                                if (pos < 0)
4536
4835
                                        pos = tpos;
4537
4836
                                else if (tpos > pos)
4538
4837
                                        pos = tpos;
4539
 
                                numpnt--;
4540
4838
                        }
4541
4839
            break;
4542
4840
        default:
4585
4883
                                                strand = SeqLocStrand(slp), slp = slp -> next;
4586
4884
                                                slp != NULL ; slp = slp->next)
4587
4885
                                {
 
4886
                                    if (slp->choice == SEQLOC_NULL || slp->choice == SEQLOC_EMPTY) continue;
4588
4887
                                        tstrand = SeqLocStrand(slp);
4589
4888
                                        if (strand == Seq_strand_unknown && tstrand == Seq_strand_plus) {
4590
4889
                                                strand = Seq_strand_plus;
4711
5010
        Boolean locked = FALSE;
4712
5011
        Boolean average = FALSE;
4713
5012
    Int2 num;
 
5013
    SeqIdPtr sip;
 
5014
    Int4 gi;
 
5015
    SeqMgrPtr smp;
 
5016
    SeqLenLookupFunc func;
4714
5017
 
4715
5018
 
4716
5019
    if (anp == NULL)
4726
5029
                        len = 0;
4727
5030
                        break;
4728
5031
        case SEQLOC_WHOLE:    /* whole */
4729
 
            bsp = BioseqFindCore((SeqIdPtr)anp->data.ptrvalue);
4730
 
                                if (bsp == NULL)
4731
 
                                {
4732
 
                                        bsp = BioseqLockById((SeqIdPtr)anp->data.ptrvalue);
4733
 
                                        if (bsp != NULL)
4734
 
                                                locked = TRUE;
 
5032
                        sip = (SeqIdPtr) anp->data.ptrvalue;
 
5033
                        bsp = BioseqFindCore(sip);
 
5034
                        if (bsp == NULL) {
 
5035
                                if (sip != NULL && sip->choice == SEQID_GI) {
 
5036
                                        gi = (Int4) sip->data.intvalue;
 
5037
                                        /* try registered service for rapid length lookup */
 
5038
                                        smp = SeqMgrWriteLock ();
 
5039
                                        if (smp != NULL) {
 
5040
                                                func = smp->seq_len_lookup_func;
 
5041
                                                SeqMgrUnlock ();
 
5042
                                                if (func != NULL) {
 
5043
                                                        len = (*func) (gi);
 
5044
                                                        if (len > 0) break;
 
5045
                                                }
 
5046
                                        }
4735
5047
                                }
4736
 
            len = BioseqGetLen(bsp);
4737
 
                                if (locked)
4738
 
                                        BioseqUnlock(bsp);
 
5048
                                bsp = BioseqLockById(sip);
 
5049
                                if (bsp != NULL)
 
5050
                                        locked = TRUE;
 
5051
                        }
 
5052
                        len = BioseqGetLen(bsp);
 
5053
                        if (locked)
 
5054
                                BioseqUnlock(bsp);
4739
5055
                        break;
4740
5056
        case SEQLOC_EQUIV:    /* equiv -- ditto */
4741
5057
                average = TRUE;
5734
6050
                                                                        retval |= SLP_INTERNAL;
5735
6051
                                                                if (miss_end)
5736
6052
                                                                {
5737
 
                                                                        if (slp == last)
 
6053
                                                                        if (slp == first /* was last */)
5738
6054
                                                                                retval |= SLP_NOSTART;
5739
6055
                                                                        else
5740
6056
                                                                                retval |= SLP_NOINTERNAL;
5798
6114
                                break;
5799
6115
                        case SEQLOC_WHOLE:
5800
6116
                                found_molinfo = FALSE;
5801
 
                                bsp = BioseqFind((SeqIdPtr)(slp->data.ptrvalue));
 
6117
                                locked = FALSE;
 
6118
                                bsp = BioseqFindCore((SeqIdPtr)(slp->data.ptrvalue));
 
6119
                                if (bsp == NULL)
 
6120
                                {
 
6121
                                        bsp = BioseqLockById((SeqIdPtr)(slp->data.ptrvalue));
 
6122
                                        if (bsp != NULL)
 
6123
                                                locked = TRUE;
 
6124
                                }
5802
6125
                                if (bsp == NULL) break;
5803
6126
                                bcp = BioseqContextNew(bsp);
5804
 
                                if (bcp == NULL) break;
5805
 
                                vnp = NULL;
5806
 
                                while ((vnp = BioseqContextGetSeqDescr(bcp, Seq_descr_molinfo, vnp, NULL)) != NULL)
5807
 
                                {
5808
 
                                        found_molinfo = TRUE;
5809
 
                                        mip = (MolInfoPtr)(vnp->data.ptrvalue);
5810
 
                                        switch (mip->completeness)
5811
 
                                        {
5812
 
                                                case 3: /* no left */
5813
 
                                                        if (slp == first)
5814
 
                                                                retval |= SLP_START;
5815
 
                                                        else
5816
 
                                                                retval |= SLP_INTERNAL;
5817
 
                                                        break;
5818
 
                                                case 4:    /* no right */
5819
 
                                                        if (slp == last)
5820
 
                                                                retval |= SLP_STOP;
5821
 
                                                        else
5822
 
                                                                retval |= SLP_INTERNAL;
5823
 
                                                        break;
5824
 
                                                case 2:    /* partial */
5825
 
                                                case 5:    /* no ends */
5826
 
                                                        retval |= SLP_OTHER;
5827
 
                                                        break;
5828
 
                                                default:
5829
 
                                                        break;
5830
 
                                        }
5831
 
                                }
5832
 
                                if (! found_molinfo)
5833
 
                                {
5834
 
                                while ((vnp = BioseqContextGetSeqDescr(bcp, Seq_descr_modif, vnp, NULL)) != NULL)
5835
 
                                {
5836
 
                                        for (vnp2 = (ValNodePtr)(vnp->data.ptrvalue); vnp2 != NULL; vnp2 = vnp2->next)
5837
 
                                        {
5838
 
                                                switch (vnp2->data.intvalue)
 
6127
                                if (bcp != NULL) {
 
6128
                                        vnp = NULL;
 
6129
                                        while ((vnp = BioseqContextGetSeqDescr(bcp, Seq_descr_molinfo, vnp, NULL)) != NULL)
 
6130
                                        {
 
6131
                                                found_molinfo = TRUE;
 
6132
                                                mip = (MolInfoPtr)(vnp->data.ptrvalue);
 
6133
                                                switch (mip->completeness)
5839
6134
                                                {
5840
 
                                                        case 16:        /* no left */
 
6135
                                                        case 3: /* no left */
5841
6136
                                                                if (slp == first)
5842
6137
                                                                        retval |= SLP_START;
5843
6138
                                                                else
5844
6139
                                                                        retval |= SLP_INTERNAL;
5845
6140
                                                                break;
5846
 
                                                        case 17:    /* no right */
 
6141
                                                        case 4:    /* no right */
5847
6142
                                                                if (slp == last)
5848
6143
                                                                        retval |= SLP_STOP;
5849
6144
                                                                else
5850
6145
                                                                        retval |= SLP_INTERNAL;
5851
6146
                                                                break;
5852
 
                                                        case 10:    /* partial */
 
6147
                                                        case 2:    /* partial */
5853
6148
                                                                retval |= SLP_OTHER;
5854
6149
                                                                break;
5855
 
                                                }
5856
 
                                        }
5857
 
                                }
5858
 
                                }
5859
 
                                BioseqContextFree(bcp);
 
6150
                                                        case 5:    /* no ends */
 
6151
                                                                retval |= SLP_START;
 
6152
                                                                retval |= SLP_STOP;
 
6153
                                                                break;
 
6154
                                                        default:
 
6155
                                                                break;
 
6156
                                                }
 
6157
                                        }
 
6158
                                        if (! found_molinfo)
 
6159
                                        {
 
6160
                                                while ((vnp = BioseqContextGetSeqDescr(bcp, Seq_descr_modif, vnp, NULL)) != NULL)
 
6161
                                                {
 
6162
                                                        for (vnp2 = (ValNodePtr)(vnp->data.ptrvalue); vnp2 != NULL; vnp2 = vnp2->next)
 
6163
                                                        {
 
6164
                                                                switch (vnp2->data.intvalue)
 
6165
                                                                {
 
6166
                                                
 
6167
                                                                        case 16:        /* no left */
 
6168
                                                        
 
6169
                                                                                if (slp == first)
 
6170
                                                                
 
6171
                                                                                        retval |= SLP_START;
 
6172
                                                                        
 
6173
                                                                                else
 
6174
                                                                                        retval |= SLP_INTERNAL;
 
6175
                                                                                break;
 
6176
                                                                        case 17:    /* no right */
 
6177
                                                                                if (slp == last)
 
6178
                                                                                        retval |= SLP_STOP;
 
6179
                                                                                else
 
6180
                                                                                        retval |= SLP_INTERNAL;
 
6181
                                                                                break;
 
6182
                                                                        case 10:    /* partial */
 
6183
                                                                                retval |= SLP_OTHER;
 
6184
                                                                                break;
 
6185
                                                                }
 
6186
                                                        }
 
6187
                                                }
 
6188
                                        }
 
6189
                                        BioseqContextFree(bcp);
 
6190
                                }
 
6191
                                if (locked)
 
6192
                                        BioseqUnlock (bsp);
5860
6193
                                break;
5861
6194
                        default:
5862
6195
                                break;
7545
7878
                switch (seqalign->segtype)
7546
7879
                {
7547
7880
                        case 1: /*Dense-diag*/
 
7881
                        {
 
7882
                                Boolean number_set = FALSE;
7548
7883
                                ddp = seqalign->segs;
7549
7884
                                while (ddp)
7550
7885
                                {
7551
 
                                        local_retval = GetBestScoreAndEvalueFromScorePtr(ddp->scores, score, bit_score, evalue, number);        
7552
 
                                        if (local_retval == TRUE)
7553
 
                                                retval = TRUE;
7554
 
                                        ddp = ddp->next;
 
7886
                                   Int4 number_tmp = 1;
 
7887
                                   local_retval =
 
7888
                                      GetBestScoreAndEvalueFromScorePtr(ddp->scores, score, 
 
7889
                                         bit_score, evalue, &number_tmp);       
 
7890
                                   /* Number of linked HSPs should be returned
 
7891
                                      for the segment with best e-value, which
 
7892
                                      must be first on the list. */
 
7893
                                   if (!number_set) {
 
7894
                                      *number = number_tmp;
 
7895
                                      number_set = TRUE;
 
7896
                                   }
 
7897
                                   if (local_retval == TRUE)
 
7898
                                      retval = TRUE;
 
7899
                                   ddp = ddp->next;
7555
7900
                                }
7556
7901
                                break;
 
7902
                        }
7557
7903
                        case 2:
7558
7904
                                dsp = seqalign->segs;
7559
7905
                                if (dsp)
7915
8261
        Boolean formally_assigned;
7916
8262
        formally_assigned = !(ACCN_IS_UNASSIGNED(status));
7917
8263
        if(formally_assigned || Permissive) {
 
8264
                /* new support for PDB */
 
8265
                if (status == ACCN_PDB) {
 
8266
                        Char pdbstr [41];
 
8267
                        if (StringLen (accession) < 8) {
 
8268
                                sprintf (pdbstr, "pdb|%s", accession);
 
8269
                                sip = SeqIdParse (pdbstr);
 
8270
                                return sip;
 
8271
                        }
 
8272
                        return NULL;
 
8273
                }
7918
8274
            sip = ValNodeNew(NULL);
7919
8275
            tsp = TextSeqIdNew();
7920
8276
            tsp->accession = StringSave(accession);
8118
8474
{
8119
8475
  Char      accn [41];
8120
8476
  CharPtr   ptr;
8121
 
  long int  ver = 0;
 
8477
  long int  ver = INT2_MIN;
8122
8478
 
8123
8479
  StringNCpy_0 (accn, accession, sizeof (accn));
8124
8480
  ptr = StringChr (accn, '.');
8126
8482
    *ptr = '\0';
8127
8483
    ptr++;
8128
8484
    if (sscanf (ptr, "%ld", &ver) != 1) {
8129
 
      ver = 0;
 
8485
      ver = INT2_MIN;
8130
8486
    }
8131
8487
  }
8132
8488
  return SeqIdFromAccession (accn, (Uint4) ver, NULL);
8276
8632
    return retstatus;
8277
8633
}
8278
8634
 
8279
 
 NLM_EXTERN Boolean LIBCALL AccnIsSWISSPROT( CharPtr s) {
 
8635
NLM_EXTERN Boolean LIBCALL AccnIsSWISSPROT( CharPtr s) {
8280
8636
     Boolean retstatus = FALSE;
8281
8637
     if(s && *s && *(s+1) && *(s+2) && *(s+3) && *(s+4) && *(s+5) && *(s+6) ==NULLB) {
8282
8638
         if(*s == 'o' || *s == 'O' ||
8297
8653
     }
8298
8654
 
8299
8655
     return retstatus;
8300
 
 }
 
8656
}
 
8657
 
 
8658
NLM_EXTERN Boolean LIBCALL AccnIsUniProt (CharPtr s)
 
8659
 
 
8660
{
 
8661
  Char  ch;
 
8662
 
 
8663
  if (StringLen (s) != 6) return FALSE;
 
8664
 
 
8665
  ch = *s;
 
8666
  if (! IS_ALPHA (ch)) return FALSE;
 
8667
 
 
8668
  s++;
 
8669
  ch = *s;
 
8670
  if (! IS_DIGIT (ch)) return FALSE;
 
8671
 
 
8672
  s++;
 
8673
  ch = *s;
 
8674
  if (! IS_ALPHA (ch)) return FALSE;
 
8675
 
 
8676
  s++;
 
8677
  ch = *s;
 
8678
  if (! (IS_ALPHA (ch) || IS_DIGIT (ch))) return FALSE;
 
8679
 
 
8680
  s++;
 
8681
  ch = *s;
 
8682
  if (! (IS_ALPHA (ch) || IS_DIGIT (ch))) return FALSE;
 
8683
 
 
8684
  s++;
 
8685
  ch = *s;
 
8686
  if (! IS_DIGIT (ch)) return FALSE;
 
8687
 
 
8688
   return TRUE;
 
8689
}
8301
8690
 
8302
8691
 /*
8303
8692
   function to tell if an accession is in the format
8375
8764
  Uint4 retcode = 0;
8376
8765
  Boolean retval = TRUE;
8377
8766
  Boolean first = TRUE;
8378
 
  CharPtr temp=NULL;
 
8767
  size_t len;
 
8768
  Char temp [16];
8379
8769
 
8380
8770
  if (s == NULL || ! *s)
8381
8771
    return FALSE;
8382
 
 
8383
 
  switch (StringLen(s)) {
 
8772
 
 
8773
  len = StringLen (s);
 
8774
 
 
8775
  if (IS_DIGIT (*s)) {
 
8776
    if (len == 4 || (len > 4 && s [4] == '|')) {
 
8777
      return ACCN_PDB;
 
8778
    }
 
8779
    return ACCN_UNKNOWN;
 
8780
  }
 
8781
 
 
8782
  switch (len) {
8384
8783
 
8385
8784
  case 6:                       /* Old-style 6-character accession */
 
8785
    if (AccnIsUniProt (s)) {
 
8786
      return ACCN_SWISSPROT;
 
8787
    }
8386
8788
    while (*s) {
8387
8789
      if (retval == FALSE)
8388
8790
        break;
8397
8799
 
8398
8800
/* Protein SWISS-PROT accessions */
8399
8801
        case 'O': case 'P': case 'Q':  
8400
 
            retcode = AccnIsSWISSPROT(s);
 
8802
            if (AccnIsSWISSPROT(s)) {
 
8803
                retcode = ACCN_SWISSPROT;
 
8804
            }
8401
8805
            break;
8402
8806
 
8403
8807
/* GenBank : EST */
8481
8885
          break;
8482
8886
      if(IS_ALPHA(*(s+2))) {
8483
8887
          /* New(1999) 8-character protein accession, three letters + 5 digits */
8484
 
          temp = (CharPtr) MemNew(4);
8485
8888
          temp[0] = *s; s++;
8486
8889
          temp[1] = *s; s++;
8487
8890
          temp[2] = *s; s++;
8489
8892
          
8490
8893
          if ((StringICmp(temp,"AAA") >= 0) && (StringICmp(temp,"AZZ") <= 0)) { 
8491
8894
              retcode = ACCN_NCBI_PROT;
8492
 
          } else if ((StringICmp(temp,"DAA") >= 0) && (StringICmp(temp,"DZZ") <= 0)) { 
8493
 
              retcode = ACCN_NCBI_PROT;
8494
 
              if ((StringICmp(temp,"DAA") == 0)) {
8495
 
                retcode = ACCN_NCBI_TPA_PROT;
8496
 
              }
 
8895
          } else  if ((StringICmp(temp,"BAA") >= 0) && (StringICmp(temp,"BZZ") <= 0)) { 
 
8896
              retcode = ACCN_DDBJ_PROT;
8497
8897
          } else if ((StringICmp(temp,"CAA") >= 0) && (StringICmp(temp,"CZZ") <= 0)) { 
8498
8898
              retcode = ACCN_EMBL_PROT;
8499
 
          } else  if ((StringICmp(temp,"BAA") >= 0) && (StringICmp(temp,"BZZ") <= 0)) { 
8500
 
              retcode = ACCN_DDBJ_PROT;
 
8899
          } else if ((StringICmp(temp,"DAA") >= 0) && (StringICmp(temp,"DZZ") <= 0)) { 
 
8900
              retcode = ACCN_NCBI_TPA_PROT;
 
8901
          } else if ((StringICmp(temp,"EAA") >= 0) && (StringICmp(temp,"EZZ") <= 0)) { 
 
8902
              retcode = ACCN_NCBI_WGS_PROT;
 
8903
          } else  if ((StringICmp(temp,"FAA") >= 0) && (StringICmp(temp,"FZZ") <= 0)) { 
 
8904
              retcode = ACCN_DDBJ_TPA_PROT;
 
8905
          } else  if ((StringICmp(temp,"GAA") >= 0) && (StringICmp(temp,"GZZ") <= 0)) { 
 
8906
              retcode = ACCN_DDBJ_WGS_PROT;
8501
8907
          } else {
8502
8908
              retcode = ACCN_IS_PROTEIN;
8503
8909
              retval = TRUE;
8505
8911
          }
8506
8912
      } else if (IS_DIGIT(*(s+2))) {
8507
8913
          /* New 8-character accession, two letters + 6 digits */
8508
 
          temp = (CharPtr) MemNew(3);
8509
8914
          temp[0] = *s; s++;
8510
8915
          temp[1] = *s; s++;
8511
8916
          temp[2] = '\0';
8516
8921
              (StringICmp(temp,"BE") == 0) || 
8517
8922
              (StringICmp(temp,"BF") == 0) || 
8518
8923
              (StringICmp(temp,"BI") == 0) || 
8519
 
              (StringICmp(temp,"BM") == 0) ) {             /* NCBI EST */
 
8924
              (StringICmp(temp,"BM") == 0) || 
 
8925
              (StringICmp(temp,"BQ") == 0) || 
 
8926
              (StringICmp(temp,"BU") == 0) || 
 
8927
              (StringICmp(temp,"CA") == 0) || 
 
8928
              (StringICmp(temp,"CB") == 0) || 
 
8929
              (StringICmp(temp,"CD") == 0) || 
 
8930
              (StringICmp(temp,"CF") == 0) || 
 
8931
              (StringICmp(temp,"CK") == 0) || 
 
8932
              (StringICmp(temp,"CN") == 0) || 
 
8933
              (StringICmp(temp,"CO") == 0) || 
 
8934
              (StringICmp(temp,"CV") == 0) ) {                /* NCBI EST */
8520
8935
              retcode = ACCN_NCBI_EST;
 
8936
          } else if ((StringICmp(temp,"BV") == 0)) {      /* NCBI STS */
 
8937
              retcode = ACCN_NCBI_STS;
8521
8938
          } else if ((StringICmp(temp,"AC") == 0)) {      /* NCBI HTGS */
8522
8939
              retcode = ACCN_NCBI_HTGS;
8523
8940
          } else if ((StringICmp(temp,"AF") == 0) ||
8524
8941
                     (StringICmp(temp,"AY") == 0)) {      /* NCBI direct submission */
8525
8942
              retcode = ACCN_NCBI_DIRSUB;
8526
 
          } else if ((StringICmp(temp,"AE") == 0)) {      /* NCBI genome project data */
 
8943
          } else if ((StringICmp(temp,"AE") == 0) ||
 
8944
                     (StringICmp(temp,"CP") == 0)) {      /* NCBI genome project data */
8527
8945
              retcode = ACCN_NCBI_GENOME;
8528
 
          } else if ((StringICmp(temp,"AH") == 0)) {      /* NCBI segmented set header Bioseq */
 
8946
          } else if ((StringICmp(temp,"AH") == 0) ||
 
8947
                     (StringICmp(temp,"CH") == 0) ||      /* NCBI segmented set header Bioseq */
 
8948
                     (StringICmp(temp,"CM") == 0)) {
8529
8949
              retcode = ACCN_NCBI_SEGSET | ACCN_AMBIGOUS_MOL; /* A few segmented
8530
8950
                                                                 proteins are AH */
8531
8951
          } else if ((StringICmp(temp,"AS") == 0)) {      /* NCBI "other" */
8534
8954
              retcode = ACCN_NCBI_GSDB;
8535
8955
          } else if ((StringICmp(temp,"AQ") == 0) ||
8536
8956
                     (StringICmp(temp,"AZ") == 0) ||
8537
 
                     (StringICmp(temp,"BH") == 0) )  {     /* NCBI GSS */
 
8957
                     (StringICmp(temp,"BH") == 0) ||
 
8958
                     (StringICmp(temp,"BZ") == 0) ||
 
8959
                     (StringICmp(temp,"CC") == 0) ||
 
8960
                     (StringICmp(temp,"CE") == 0) ||
 
8961
                     (StringICmp(temp,"CG") == 0) ||
 
8962
                     (StringICmp(temp,"CL") == 0) ||
 
8963
                     (StringICmp(temp,"CW") == 0) )  {     /* NCBI GSS */
8538
8964
              retcode = ACCN_NCBI_GSS;
8539
8965
          } else if ((StringICmp(temp,"AR") == 0)) {      /* NCBI patent */
8540
8966
              retcode = ACCN_NCBI_PATENT;
8541
8967
          } else if((StringICmp(temp,"BC")==0)) {         /* NCBI long cDNA project : MGC */
8542
8968
              retcode = ACCN_NCBI_cDNA;
 
8969
          } else if((StringICmp(temp,"BT")==0)) {         /* NCBI FLI_cDNA */
 
8970
              retcode = ACCN_NCBI_cDNA;
8543
8971
          } else if((StringICmp(temp,"BK")==0) ||         /* NCBI third-party annotation */
8544
8972
                    (StringICmp(temp,"BL") == 0)) {
8545
8973
              retcode = ACCN_NCBI_TPA;
8546
8974
          } else if ((StringICmp(temp,"BN") == 0)) {      /* EMBL third-party annotation */
8547
8975
              retcode = ACCN_EMBL_TPA;
 
8976
          } else if ((StringICmp(temp,"BR") == 0)) {      /* DDBJ third-party annotation */
 
8977
              retcode = ACCN_DDBJ_TPA;
8548
8978
          } else if ((StringICmp(temp,"AJ") == 0) ||
8549
8979
                     (StringICmp(temp,"AM") == 0)) {     /* EMBL direct submission */
8550
8980
              retcode = ACCN_EMBL_DIRSUB;
8551
 
          } else if ((StringICmp(temp,"AL") == 0)) {      /* EMBL genome project data */
 
8981
          } else if ((StringICmp(temp,"AL") == 0) ||
 
8982
                     (StringICmp(temp,"BX") == 0)||
 
8983
                     (StringICmp(temp,"CR") == 0)) {      /* EMBL genome project data */
8552
8984
              retcode = ACCN_EMBL_GENOME;
8553
8985
          } else if ((StringICmp(temp,"AN") == 0)) {      /* EMBL CON division */
8554
8986
              retcode = ACCN_EMBL_CON;
8555
 
          } else if ((StringICmp(temp,"AX") == 0)) {      /* EMBL patent division */
 
8987
          } else if ((StringICmp(temp,"AX") == 0) ||
 
8988
                     (StringICmp(temp,"CQ") == 0)) {      /* EMBL patent division */
8556
8989
              retcode = ACCN_EMBL_PATENT;
8557
8990
          } else if ((StringICmp(temp,"AT") == 0) || 
8558
8991
                     (StringICmp(temp,"AU") == 0) ||
8559
8992
                     (StringICmp(temp,"AV") == 0) ||
8560
8993
                     (StringICmp(temp,"BB") == 0) ||
8561
 
                     (StringICmp(temp,"BJ") == 0)) {      /* DDBJ EST's */
 
8994
                     (StringICmp(temp,"BJ") == 0) ||
 
8995
                     (StringICmp(temp,"BP") == 0) ||
 
8996
                     (StringICmp(temp,"BW") == 0) ||
 
8997
                     (StringICmp(temp,"BY") == 0) ||
 
8998
                     (StringICmp(temp,"CI") == 0) ||
 
8999
                     (StringICmp(temp,"CJ") == 0) ||
 
9000
                     (StringICmp(temp,"DA") == 0) ||
 
9001
                     (StringICmp(temp,"DB") == 0) ||
 
9002
                     (StringICmp(temp,"DC") == 0)) {      /* DDBJ EST's */
8562
9003
              retcode = ACCN_DDBJ_EST;
8563
9004
          } else if ((StringICmp(temp,"AB") == 0)) {      /* DDBJ direct submission */
8564
9005
              retcode = ACCN_DDBJ_DIRSUB;
8565
9006
          } else if ((StringICmp(temp,"AG") == 0) || 
8566
 
                     (StringICmp(temp,"AP") == 0)) {      /* DDBJ genome project data */
 
9007
                     (StringICmp(temp,"AP") == 0) || 
 
9008
                     (StringICmp(temp,"BS") == 0)) {      /* DDBJ genome project data */
8567
9009
              retcode = ACCN_DDBJ_GENOME;
8568
9010
          } else if ((StringICmp(temp,"AK") == 0))  {     /* DDBJ HTGS */
8569
9011
              retcode = ACCN_DDBJ_HTGS;
8595
9037
      if(*(s+2)!='_')
8596
9038
          break;
8597
9039
      /* New(1999) 8-character protein accession, three letters + 5 digits */
8598
 
      temp = (CharPtr) MemNew(4);
8599
9040
      temp[0] = *s; s++;
8600
9041
      temp[1] = *s; s++;
8601
9042
      temp[2] = NULLB; s++;
8626
9067
          s++;
8627
9068
      }
8628
9069
      break;
 
9070
    case 11: /* New 11-character accession, two letters +"_"+ 8 digits */
 
9071
      if(!IS_ALPHA(*s) || !IS_ALPHA(*(s+1)))
 
9072
          break;
 
9073
      if(*(s+2)!='_')
 
9074
          break;
 
9075
      temp[0] = *s; s++;
 
9076
      temp[1] = *s; s++;
 
9077
      temp[2] = NULLB; s++;
 
9078
      
 
9079
      if ((StringICmp(temp,"ZP") == 0)) { 
 
9080
          retcode = ACCN_REFSEQ_PROT_PREDICTED;
 
9081
      } else
 
9082
          retval = FALSE;
 
9083
      while (*s) {
 
9084
          if (! IS_DIGIT(*s)) {
 
9085
              retval = FALSE;
 
9086
              break;
 
9087
          }
 
9088
          s++;
 
9089
      }
 
9090
      break;
 
9091
    case 12:
 
9092
      if(IS_ALPHA(*s) && IS_ALPHA(*(s+1)) && IS_ALPHA(*(s+2)) && IS_ALPHA(*(s+3))) {
 
9093
        /* whole genome shotgun 12-character accession, four letters + 8 digits */
 
9094
        temp[0] = *s; s++;
 
9095
        temp[1] = *s; s++;
 
9096
        temp[2] = *s; s++;
 
9097
        temp[3] = *s; s++;
 
9098
        temp[4] = '\0';
 
9099
        if ((StringNICmp(temp,"A", 1) == 0)) { 
 
9100
          retcode = ACCN_NCBI_WGS;
 
9101
        } else if ((StringNICmp(temp,"B", 1) == 0)) {
 
9102
          retcode = ACCN_DDBJ_WGS;
 
9103
        } else if ((StringNICmp(temp,"C", 1) == 0)) {
 
9104
          retcode = ACCN_EMBL_WGS;
 
9105
        } else
 
9106
          retval = FALSE;
 
9107
        while (*s) {
 
9108
          if (! IS_DIGIT(*s)) {
 
9109
              retval = FALSE;
 
9110
              break;
 
9111
          }
 
9112
          s++;
 
9113
        }
 
9114
      } else if(IS_ALPHA(*s) && IS_ALPHA(*(s+1)) && (*(s+2)=='_')) {
 
9115
        /* New 12-character accession, two letters +"_"+ 9 digits */
 
9116
        temp[0] = *s; s++;
 
9117
        temp[1] = *s; s++;
 
9118
        temp[2] = NULLB; s++;
 
9119
      
 
9120
        if ((StringICmp(temp,"NP") == 0)) { 
 
9121
          retcode = ACCN_REFSEQ_PROT;
 
9122
        } else if ((StringICmp(temp,"NM") == 0)) { 
 
9123
          retcode = ACCN_REFSEQ_mRNA;
 
9124
        } else if (IS_ALPHA(*temp) && IS_ALPHA(*(temp+1))) {
 
9125
          retcode =ACCN_REFSEQ | ACCN_AMBIGOUS_MOL;
 
9126
        } else
 
9127
          retval = FALSE;
 
9128
        while (*s) {
 
9129
          if (! IS_DIGIT(*s)) {
 
9130
              retval = FALSE;
 
9131
              break;
 
9132
          }
 
9133
          s++;
 
9134
        }
 
9135
      }
 
9136
      break;
8629
9137
  default:   
8630
9138
    retval = FALSE;
8631
9139
    break;
8632
9140
  }                     /* Endswitch, StringLen(s) */
8633
9141
 
8634
 
  if(temp)
8635
 
      MemFree(temp);
8636
9142
  return (retval ? retcode : ACCN_UNKNOWN);
8637
9143
}
8638
9144