~ubuntu-branches/ubuntu/feisty/ncbi-tools6/feisty

« back to all changes in this revision

Viewing changes to api/asn2gnb4.c

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-19 23:28:07 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20060719232807-et3cdmcjgmnyleyx
Tags: 6.1.20060507-3ubuntu1
Re-merge with Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
*
31
31
* Version Creation Date:   10/21/98
32
32
*
33
 
* $Revision: 1.85 $
 
33
* $Revision: 1.106 $
34
34
*
35
35
* File Description:  New GenBank flatfile generator - work in progress
36
36
*
110
110
 
111
111
  FTQUAL_pseudo,
112
112
  FTQUAL_selenocysteine,
 
113
  FTQUAL_pyrrolysine,
113
114
 
114
115
  FTQUAL_codon_start,
115
116
 
116
117
  FTQUAL_anticodon,
 
118
  FTQUAL_trna_codons,
117
119
  FTQUAL_bound_moiety,
118
120
  FTQUAL_clone,
119
121
  FTQUAL_compare,
179
181
  FTQUAL_transcript_id_note, /* !!! remove October 15, 2003 !!! */
180
182
  FTQUAL_gene_desc,
181
183
  FTQUAL_gene_syn,
182
 
  FTQUAL_trna_codons,
 
184
  FTQUAL_trna_codons_note,
183
185
  FTQUAL_encodes,
184
186
  FTQUAL_prot_desc,
185
187
  FTQUAL_prot_note,
194
196
  FTQUAL_exception_note,
195
197
  FTQUAL_region,
196
198
  FTQUAL_selenocysteine_note,
 
199
  FTQUAL_pyrrolysine_note,
197
200
  FTQUAL_prot_names,
198
201
  FTQUAL_bond,
199
202
  FTQUAL_site,
294
297
  { "prot_names",         Qual_class_protnames     },
295
298
  { "protein_id",         Qual_class_seq_id        },
296
299
  { "pseudo",             Qual_class_boolean       },
 
300
  { "pyrrolysine",        Qual_class_boolean       },
 
301
  { "pyrrolysine",        Qual_class_string        },
297
302
  { "region",             Qual_class_region        },
298
303
  { "region_name",        Qual_class_string        },
299
304
  { "replace",            Qual_class_replace       },
321
326
  { "transposon",         Qual_class_quote         },
322
327
  { "trans_splicing",     Qual_class_boolean       },
323
328
  { "trna_aa",            Qual_class_ignore        },
 
329
  { "codon_recognized",   Qual_class_trna_codons   },
324
330
  { "trna_codons",        Qual_class_trna_codons   },
325
331
  { "usedin",             Qual_class_usedin        },
326
332
  { "xtra_products",      Qual_class_xtraprds      }
456
462
  "tRNA-Gly",
457
463
  "tRNA-His",
458
464
  "tRNA-Ile",
 
465
  "tRNA-Xle",
459
466
  "tRNA-Lys",
460
467
  "tRNA-Leu",
461
468
  "tRNA-Met",
462
469
  "tRNA-Asn",
 
470
  "tRNA-Pyl",
463
471
  "tRNA-Pro",
464
472
  "tRNA-Gln",
465
473
  "tRNA-Arg",
1487
1495
    if (numAlpha == 2 && numDigits == 6) return 0;
1488
1496
    if (numAlpha == 3 && numDigits == 5) return 0;
1489
1497
    if (numAlpha == 4 && numDigits == 8) return 0;
 
1498
    if (numAlpha == 5 && numDigits == 7) return 0;
1490
1499
  } else if (numUndersc == 1) {
1491
1500
    if (numAlpha != 2 || (numDigits != 6 && numDigits != 8 && numDigits != 9)) return -2;
1492
1501
    if (accession [0] == 'N' || accession [0] == 'X' || accession [0] == 'Z') {
1578
1587
)
1579
1588
 
1580
1589
{
 
1590
  Int2          ce = 0, cm = 0, cp = 0, ne = 0, nm = 0, np = 0;
 
1591
  Boolean       has_counts = FALSE;
1581
1592
  size_t        len;
1582
1593
  CharPtr       method = NULL, prefix = NULL;
1583
 
  Int2          ne = 0, nm = 0, np = 0;
1584
1594
  ObjectIdPtr   oip;
1585
1595
  CharPtr       str = NULL;
1586
1596
  CharPtr PNTR  strp;
1598
1608
    if (oip == NULL || ufp->data.ptrvalue == NULL) continue;
1599
1609
    if (StringCmp (oip->str, "Method") == 0) {
1600
1610
      method = StringSaveNoNull ((CharPtr) ufp->data.ptrvalue);
1601
 
    }
1602
 
    if (StringCmp (oip->str, "mRNA") == 0) {
 
1611
    } else if (StringCmp (oip->str, "mRNA") == 0) {
1603
1612
      for (u = (UserFieldPtr) ufp->data.ptrvalue; u != NULL; u = u->next) {
1604
1613
        if (u->data.ptrvalue == NULL) continue;
1605
1614
        for (uu = (UserFieldPtr) u->data.ptrvalue; uu != NULL; uu = uu->next) {
1632
1641
          }
1633
1642
        }
1634
1643
      }
 
1644
    } else if (StringCmp (oip->str, "Counts") == 0) {
 
1645
      has_counts = TRUE;
 
1646
      for (u = (UserFieldPtr) ufp->data.ptrvalue; u != NULL; u = u->next) {
 
1647
        if (u->data.ptrvalue == NULL) continue;
 
1648
        if (u->choice != 2) continue;
 
1649
        oip = u->label;
 
1650
        if (oip == NULL) continue;
 
1651
        if (StringCmp (oip->str, "mRNA") == 0) {
 
1652
          cm = (Int2) u->data.intvalue;
 
1653
        } else if (StringCmp (oip->str, "EST") == 0) {
 
1654
          ce = (Int2) u->data.intvalue;
 
1655
        } else if (StringCmp (oip->str, "Protein") == 0) {
 
1656
          cp = (Int2) u->data.intvalue;
 
1657
        }
 
1658
      }
1635
1659
    }
1636
1660
  }
1637
1661
 
 
1662
  if (has_counts) {
 
1663
    nm = cm;
 
1664
    ne = ce;
 
1665
    np = cp;
 
1666
  }
 
1667
 
1638
1668
  len = StringLen (mrnaevtext1) + StringLen (mrnaevtext2) + StringLen (mrnaevtext3) + StringLen (method) + 80;
1639
1669
  str = (CharPtr) MemNew (len);
1640
1670
  if (str == NULL) return;
2330
2360
  return MolWtForLoc (sfp->location);
2331
2361
}
2332
2362
 
 
2363
static void ChangeOToX (CharPtr str)
 
2364
 
 
2365
{
 
2366
  Char  ch;
 
2367
 
 
2368
  if (str == NULL) return;
 
2369
  ch = *str;
 
2370
  while (ch != '\0') {
 
2371
    if (ch == 'O') {
 
2372
      *str = 'X';
 
2373
    } else if (ch == 'o') {
 
2374
      *str = 'x';
 
2375
    }
 
2376
    str++;
 
2377
    ch = *str;
 
2378
  }
 
2379
}
 
2380
 
2333
2381
static void FormatFeatureBlockQuals (
2334
2382
  StringItemPtr    ffstring,
2335
2383
  IntAsn2gbJobPtr  ajp,
3134
3182
                if (str != NULL) {
3135
3183
                  residue = cbaa.value.intvalue;
3136
3184
                  ptr = Get3LetterSymbol (ajp, seqcode, sctp, residue);
 
3185
                  if (ajp->mode == RELEASE_MODE || ajp->mode == ENTREZ_MODE) {
 
3186
                    if (StringICmp (ptr, "Pyl") == 0 || StringICmp (ptr, "Xle") == 0) {
 
3187
                      ptr = "OTHER";
 
3188
                    }
 
3189
                  }
3137
3190
                  if (ptr == NULL) {
3138
3191
                    ptr = "OTHER";
3139
3192
                  }
3200
3253
        }
3201
3254
        break;
3202
3255
 
 
3256
      case Qual_class_trna_codons :
 
3257
        trna = qvp [idx].trp;
 
3258
        if (trna) {
 
3259
          numcodons = ComposeCodonsRecognizedString (trna, numbuf, sizeof (numbuf));
 
3260
          if (numcodons < 1 || StringHasNoText (numbuf)) {
 
3261
          } else {
 
3262
            FFAddTextToString(ffstring, "/", "codon_recognized", "=\"",
 
3263
                              FALSE, TRUE, TILDE_IGNORE);
 
3264
            FFAddOneString(ffstring, numbuf, FALSE, TRUE, TILDE_TO_SPACES);
 
3265
            FFAddOneChar(ffstring, '\"', FALSE);
 
3266
            FFAddOneChar(ffstring, '\n', FALSE);
 
3267
          }
 
3268
        }
 
3269
        break;
 
3270
 
3203
3271
      case Qual_class_codon :
3204
3272
        gbq = qvp [idx].gbq;
3205
3273
        if (gbq == NULL || (ajp->flags.dropIllegalQuals && (! AllowedValQual (featdeftype, idx)))) break;
3246
3314
            pmid = (Int4) vnp->data.intvalue;
3247
3315
            if (pmid > 0) {
3248
3316
              sprintf (numbuf, "%ld", (long) pmid);
 
3317
              FFAddOneString(ffstring, "/citation=[PUBMED ", FALSE, TRUE, TILDE_TO_SPACES);
 
3318
              if (GetWWW (ajp)) {
 
3319
 
 
3320
                FFAddTextToString(ffstring, "<a href=", link_muid, NULL, FALSE, FALSE, TILDE_IGNORE);
 
3321
                FFAddTextToString(ffstring, NULL, numbuf, ">", FALSE, FALSE, TILDE_IGNORE);
 
3322
                FFAddOneString(ffstring, numbuf, FALSE, FALSE, TILDE_IGNORE);
 
3323
                FFAddOneString(ffstring, "</a>", FALSE, FALSE, TILDE_IGNORE);
 
3324
              } else {
 
3325
                FFAddOneString(ffstring, numbuf, FALSE, FALSE, TILDE_IGNORE);
 
3326
              }
 
3327
              FFAddOneString(ffstring, "]", FALSE, FALSE, TILDE_IGNORE);
 
3328
              /*
3249
3329
              FFAddTextToString(ffstring, "/citation=[PUBMED ", numbuf, "]",
3250
3330
                                FALSE, TRUE, TILDE_TO_SPACES);
 
3331
              */
3251
3332
              FFAddOneChar(ffstring, '\n', FALSE);
3252
3333
            }
3253
3334
          }
3313
3394
              }
3314
3395
              if (okay) {
3315
3396
                FFAddOneString(ffstring, "/db_xref=\"", FALSE, FALSE, TILDE_IGNORE);
3316
 
                FF_www_db_xref(ajp, ffstring, dbt->db, buf);
 
3397
                FF_www_db_xref(ajp, ffstring, dbt->db, buf, bsp);
3317
3398
                FFAddOneString(ffstring, "\"\n", FALSE, FALSE, TILDE_IGNORE);
3318
3399
              }
3319
3400
            }
3356
3437
                }
3357
3438
                sprintf (seqid, "%ld", (long) sip->data.intvalue);
3358
3439
                FFAddOneString(ffstring, "/db_xref=\"", FALSE, FALSE, TILDE_IGNORE);
3359
 
                FF_www_db_xref(ajp, ffstring, "GI", seqid);
 
3440
                FF_www_db_xref(ajp, ffstring, "GI", seqid, bsp);
3360
3441
                FFAddOneString(ffstring, "\"\n", FALSE, FALSE, TILDE_IGNORE);
3361
3442
              } else if (sip->choice == SEQID_GENERAL) {
3362
3443
                dbt = (DbtagPtr) sip->data.ptrvalue;
3388
3469
            if (sip->choice == SEQID_GI) {
3389
3470
              gi = sip->data.intvalue;
3390
3471
              if (GetAccnVerFromServer (gi, seqid)) {
 
3472
#ifdef OS_UNIX
 
3473
  if (getenv ("ASN2GB_PSF_DEBUG") != NULL) {
 
3474
    printf ("GetAccnVerFromServer returned %s\n", seqid);
 
3475
  }
 
3476
#endif
3391
3477
                if ((! ajp->flags.dropIllegalQuals) || ValidateAccn (seqid) == 0) {
3392
3478
                  FFAddTextToString(ffstring, "/", asn2gnbk_featur_quals [idx].name, "=\"",
3393
3479
                                    FALSE, FALSE, TILDE_IGNORE);
3399
3485
              } else {
3400
3486
                sip = GetSeqIdForGI (gi);
3401
3487
                if (sip != NULL && SeqIdWrite (sip, seqid, PRINTID_TEXTID_ACC_VER, sizeof (seqid)) != NULL) {
 
3488
#ifdef OS_UNIX
 
3489
  if (getenv ("ASN2GB_PSF_DEBUG") != NULL) {
 
3490
    printf ("GetSeqIdForGI returned %s\n", seqid);
 
3491
  }
 
3492
#endif
3402
3493
                  if ((! ajp->flags.dropIllegalQuals) || ValidateAccn (seqid) == 0) {
3403
3494
                    FFAddTextToString(ffstring, "/", asn2gnbk_featur_quals [idx].name, "=\"",
3404
3495
                                    FALSE, FALSE, TILDE_IGNORE);
3420
3511
 
3421
3512
              sprintf (seqid, "%ld", (long) gi);
3422
3513
              FFAddOneString(ffstring, "/db_xref=\"", FALSE, FALSE, TILDE_IGNORE);
3423
 
              FF_www_db_xref(ajp, ffstring, "GI", seqid);
 
3514
              FF_www_db_xref(ajp, ffstring, "GI", seqid, bsp);
3424
3515
              FFAddOneString(ffstring, "\"\n", FALSE, FALSE, TILDE_IGNORE);
3425
3516
            } else if (SeqIdWrite (sip, seqid, PRINTID_TEXTID_ACC_VER, sizeof (seqid)) != NULL) {
3426
3517
              if ((! ajp->flags.dropIllegalQuals) || ValidateAccn (seqid) == 0) {
3436
3527
              if (gi > 0) {
3437
3528
                sprintf (seqid, "%ld", (long) gi);
3438
3529
                FFAddOneString(ffstring, "/db_xref=\"", FALSE, FALSE, TILDE_IGNORE);
3439
 
                FF_www_db_xref(ajp, ffstring, "GI", seqid);
 
3530
                FF_www_db_xref(ajp, ffstring, "GI", seqid, bsp);
3440
3531
                FFAddOneString(ffstring, "\"\n", FALSE, FALSE, TILDE_IGNORE);
3441
3532
              }
3442
3533
            }
3483
3574
                   }
3484
3575
                }
3485
3576
                if (! StringHasNoText (str)) {
 
3577
                  if (ajp->mode == RELEASE_MODE || ajp->mode == ENTREZ_MODE) {
 
3578
                    ChangeOToX (str);
 
3579
                  }
3486
3580
                  FFAddTextToString(ffstring, "/translation=\"", str, "\"", 
3487
3581
                                    FALSE, TRUE, TILDE_TO_SPACES);
3488
3582
                  FFAddOneChar(ffstring, '\n', FALSE);
3509
3603
              */
3510
3604
              SeqPortStreamLoc (sfp->product, STREAM_EXPAND_GAPS | STREAM_CORRECT_INVAL, (Pointer) &protein_seq, SaveGBSeqSequence);
3511
3605
              if (! StringHasNoText (str)) {
 
3606
                if (ajp->mode == RELEASE_MODE || ajp->mode == ENTREZ_MODE) {
 
3607
                  ChangeOToX (str);
 
3608
                }
3512
3609
                FFAddTextToString(ffstring, "/translation=\"", str, "\"", 
3513
3610
                                  FALSE, TRUE, TILDE_TO_SPACES);
3514
3611
                FFAddOneChar(ffstring, '\n', FALSE);
4128
4225
}
4129
4226
 
4130
4227
 
4131
 
 
4132
4228
static void FF_asn2gb_www_featkey (
4133
4229
  StringItemPtr ffstring,
4134
4230
  CharPtr key,
4135
 
  SeqLocPtr slp,
 
4231
  SeqFeatPtr sfp,
4136
4232
  Int4 from,
4137
4233
  Int4 to,
4138
4234
  Uint1 strand,
4140
4236
)
4141
4237
 
4142
4238
{
4143
 
  BioseqPtr  bsp;
4144
 
  Int4       gi = 0;
4145
 
  SeqIdPtr   sip;
4146
 
  Boolean    is_aa = FALSE;
4147
 
  Char gi_buf[16];
4148
 
  Char itemID_buf[16];
 
4239
  BioseqPtr    bsp;
 
4240
  Char         buf [16];
 
4241
  Int4         featID = 0;
 
4242
  Int4         ffrom = 0;
 
4243
  Int4         fto = 0;
 
4244
  Int4         gi = 0;
 
4245
  Char         gi_buf[16];
 
4246
  Boolean      is_aa = FALSE;
 
4247
  ObjectIdPtr  oip;
 
4248
  SeqIntPtr    sintp;
 
4249
  SeqIdPtr     sip;
 
4250
  SeqLocPtr    slp;
4149
4251
 
 
4252
  if (sfp == NULL) return;
 
4253
  slp = sfp->location;
4150
4254
  bsp = BioseqFindFromSeqLoc (slp);
4151
4255
  if (bsp != NULL) {
4152
4256
    is_aa = ISA_aa (bsp->mol);
4155
4259
        gi = (Int4) sip->data.intvalue;
4156
4260
      }
4157
4261
    }
 
4262
  } else {
 
4263
    if (sfp->id.choice == 3) {
 
4264
      oip = (ObjectIdPtr) sfp->id.value.ptrvalue;
 
4265
      if (oip != NULL && oip->str == NULL) {
 
4266
        featID = oip->id;
 
4267
      }
 
4268
    }
 
4269
    if (slp->choice == SEQLOC_INT) {
 
4270
      sintp = (SeqIntPtr) slp->data.ptrvalue;
 
4271
      if (sintp != NULL) {
 
4272
        ffrom = sintp->from + 1;
 
4273
        fto = sintp->to + 1;
 
4274
        sip = sintp->id;
 
4275
        if (sip->choice == SEQID_GI) {
 
4276
          gi = (Int4) sip->data.intvalue;
 
4277
        }
 
4278
      }
 
4279
    }
4158
4280
  }
4159
4281
 
4160
 
  sprintf(gi_buf, "%ld", (long)gi);
4161
 
  sprintf(itemID_buf, "%ld", (long)itemID);
4162
 
 
 
4282
  sprintf (gi_buf, "%ld", (long)gi);
4163
4283
 
4164
4284
  FFAddOneString(ffstring, "<a href=", FALSE, FALSE, TILDE_IGNORE);
4165
4285
  FFAddOneString(ffstring, link_feat, FALSE, FALSE, TILDE_IGNORE);
4166
4286
  FFAddOneString(ffstring, "val=", FALSE, FALSE, TILDE_IGNORE);
4167
4287
  FFAddOneString(ffstring, gi_buf, FALSE, FALSE, TILDE_IGNORE);
4168
 
  if (itemID > 0) {
 
4288
  if (featID > 0) {
 
4289
    sprintf (buf, "%ld", (long) featID);
 
4290
    FFAddOneString(ffstring, "&featID=", FALSE, FALSE, TILDE_IGNORE);
 
4291
    FFAddOneString(ffstring, buf, FALSE, FALSE, TILDE_IGNORE);
 
4292
  } else if (ffrom > 0 && fto > 0) {
 
4293
    sprintf (buf, "%ld", (long) ffrom);
 
4294
    FFAddOneString(ffstring, "&from=", FALSE, FALSE, TILDE_IGNORE);
 
4295
    FFAddOneString(ffstring, buf, FALSE, FALSE, TILDE_IGNORE);
 
4296
    sprintf (buf, "%ld", (long) fto);
 
4297
    FFAddOneString(ffstring, "&to=", FALSE, FALSE, TILDE_IGNORE);
 
4298
    FFAddOneString(ffstring, buf, FALSE, FALSE, TILDE_IGNORE);
 
4299
  } else if (itemID > 0) {
 
4300
    sprintf (buf, "%ld", (long) itemID);
4169
4301
    FFAddOneString(ffstring, "&itemID=", FALSE, FALSE, TILDE_IGNORE);
4170
 
    FFAddOneString(ffstring, itemID_buf, FALSE, FALSE, TILDE_IGNORE);
 
4302
    FFAddOneString(ffstring, buf, FALSE, FALSE, TILDE_IGNORE);
4171
4303
  }
4172
4304
  
4173
4305
 
4280
4412
  Char           accn [41];
4281
4413
  SeqLocPtr      copy = NULL;
4282
4414
  Int4           from;
 
4415
  IntFuzzPtr     fuzz;
4283
4416
  GBIntervalPtr  gbint;
4284
4417
  Int4           gi;
 
4418
  Boolean        interbp;
 
4419
  Boolean        iscomp;
4285
4420
  GBIntervalPtr  last = NULL;
4286
4421
  Int4           point;
4287
4422
  SeqIntPtr      sint;
4302
4437
    from = 0;
4303
4438
    to = 0;
4304
4439
    point = 0;
 
4440
    iscomp = FALSE;
 
4441
    interbp = FALSE;
4305
4442
    sip = NULL;
4306
4443
    switch (slp->choice) {
4307
4444
      case SEQLOC_WHOLE :
4325
4462
            from = to;
4326
4463
            to = swap;
4327
4464
          }
 
4465
          if (sint->strand == Seq_strand_minus) {
 
4466
            iscomp = TRUE;
 
4467
          }
4328
4468
        }
4329
4469
        break;
4330
4470
      case SEQLOC_PNT :
4332
4472
        if (spp != NULL) {
4333
4473
          point = spp->point + 1;
4334
4474
          sip = spp->id;
 
4475
          if (spp->strand == Seq_strand_minus) {
 
4476
            iscomp = TRUE;
 
4477
          }
 
4478
          fuzz = spp->fuzz;
 
4479
          if (fuzz != NULL) {
 
4480
            if (fuzz->choice == 4) {
 
4481
              if (fuzz->a == 3) { /* space to right */
 
4482
                from = point;
 
4483
                to = point + 1;
 
4484
                point = 0;
 
4485
                interbp = TRUE;
 
4486
              } else if (fuzz->a == 4 && point > 1) { /* space to left */
 
4487
                from = point - 1;
 
4488
                to = point;
 
4489
                point = 0;
 
4490
                interbp = TRUE;
 
4491
              }
 
4492
            }
 
4493
          }
4335
4494
        }
4336
4495
        break;
4337
4496
      default :
4358
4517
          gbint->from = from;
4359
4518
          gbint->to = to;
4360
4519
          gbint->point = point;
 
4520
          gbint->iscomp = iscomp;
 
4521
          gbint->interbp = interbp;
4361
4522
          gbint->accession = StringSave (accn);
4362
4523
          if (gbfeat->intervals == NULL) {
4363
4524
            gbfeat->intervals = gbint;
4387
4548
  "nonconsensus splice site",
4388
4549
  "modified codon recognition",
4389
4550
  "alternative start codon",
 
4551
  "dicistronic gene",
4390
4552
  "unclassified transcription discrepancy",
4391
4553
  "unclassified translation discrepancy",
4392
4554
  "mismatches in transcription",
4393
4555
  "mismatches in translation",
 
4556
  "adjusted for low-quality genome",
4394
4557
  NULL
4395
4558
};
4396
4559
 
4591
4754
  *bad_inferenceP = bad;
4592
4755
}
4593
4756
 
 
4757
typedef struct geneprot {
 
4758
  SeqFeatPtr  gene;
 
4759
  SeqFeatPtr  cds;
 
4760
  Boolean     failed;
 
4761
} GeneProtData, PNTR GeneProtPtr;
 
4762
 
 
4763
static void CheckGeneOnIsolatedProtein (
 
4764
  SeqFeatPtr sfp,
 
4765
  Pointer userdata
 
4766
)
 
4767
 
 
4768
{
 
4769
  GeneProtPtr  gpp;
 
4770
 
 
4771
  if (sfp == NULL || sfp->data.choice != SEQFEAT_GENE) return;
 
4772
  gpp = (GeneProtPtr) userdata;
 
4773
  if (gpp == NULL) return;
 
4774
 
 
4775
  if (SeqLocAinB (gpp->cds->location, sfp->location) < 0) return;
 
4776
  if (gpp->gene != NULL) {
 
4777
    gpp->failed = TRUE;
 
4778
  } else {
 
4779
    gpp->gene = sfp;
 
4780
  }
 
4781
}
 
4782
 
 
4783
static SeqFeatPtr FindGeneOnIsolatedProtein (
 
4784
  SeqEntryPtr sep,
 
4785
  SeqFeatPtr cds
 
4786
)
 
4787
 
 
4788
{
 
4789
  GeneProtData  gpd;
 
4790
 
 
4791
  if (sep == NULL || cds == NULL) return NULL;
 
4792
 
 
4793
  MemSet ((Pointer) &gpd, 0, sizeof (GeneProtData));
 
4794
  gpd.cds = cds;
 
4795
  VisitFeaturesInSep (sep, (Pointer) &gpd, CheckGeneOnIsolatedProtein);
 
4796
 
 
4797
  if (gpd.failed) return NULL;
 
4798
 
 
4799
  return gpd.gene;
 
4800
}
 
4801
 
4594
4802
static SeqFeatPtr GetOverlappingGeneInEntity (
4595
4803
  Uint2 entityID,
4596
4804
  SeqMgrFeatContextPtr fcontext,
4645
4853
      }
4646
4854
    }
4647
4855
  } else {
4648
 
    gene = SeqMgrGetOverlappingGene (locforgene, gcontext);
 
4856
    if (fcontext->bad_order || fcontext->mixed_strand) {
 
4857
      gene = SeqMgrGetOverlappingFeature (locforgene, FEATDEF_GENE, NULL, 0, NULL, LOCATION_SUBSET, gcontext);
 
4858
    } else {
 
4859
      gene = SeqMgrGetOverlappingGene (locforgene, gcontext);
 
4860
    }
4649
4861
  }
4650
4862
  SeqEntrySetScope (oldscope);
4651
4863
  return gene;
4668
4880
{
4669
4881
  Uint1              aa;
4670
4882
  AnnotDescrPtr      adp;
 
4883
  Boolean            annotDescCommentToComment;
4671
4884
  ValNodePtr         bad_inference = NULL;
4672
4885
  Int2               bondidx;
4673
4886
  BioseqPtr          bsp_for_old_locus_tag = NULL;
4675
4888
  Choice             cbaa;
4676
4889
  CodeBreakPtr       cbp;
4677
4890
  BioseqPtr          cdna;
4678
 
  SeqFeatPtr         cds;
 
4891
  SeqFeatPtr         cds = NULL;
4679
4892
  Char               ch;
4680
4893
  Uint1              code = Seq_code_ncbieaa;
4681
4894
  CdRegionPtr        crp;
4718
4931
  Boolean            noLeft;
4719
4932
  Boolean            noRight;
4720
4933
  SeqMgrFeatContext  ocontext;
 
4934
  ObjectIdPtr        oip;
4721
4935
  SeqEntryPtr        oldscope;
4722
4936
  SeqFeatPtr         operon = NULL;
4723
4937
  Uint2              partial;
4732
4946
  ProtRefPtr         prpxref;
4733
4947
  Boolean            pseudo = FALSE;
4734
4948
  CharPtr            ptr;
 
4949
  Uint2              pEID;
4735
4950
  Int2               qualclass;
4736
4951
  Uint1              residue;
4737
4952
  Boolean            riboSlippage = FALSE;
4742
4957
  SeqDescrPtr        sdp;
4743
4958
  SeqEntryPtr        sep;
4744
4959
  Uint1              seqcode;
4745
 
  Uint1              shift;
 
4960
  Uint1              seqfeattype;
4746
4961
  SeqIdPtr           sip;
4747
4962
  Int2               siteidx;
4748
4963
  SeqMapTablePtr     smtp;
4752
4967
  CharPtr            tmp;
4753
4968
  Boolean            transSplice = FALSE;
4754
4969
  tRNAPtr            trna;
 
4970
  UserFieldPtr       ufp;
4755
4971
  BioseqPtr          unlockme = NULL;
 
4972
  UserObjectPtr      uop;
4756
4973
  ValNodePtr         vnp;
4757
4974
  StringItemPtr      ffstring;
4758
4975
 
4884
5101
      is_other = TRUE;
4885
5102
    }
4886
5103
 
4887
 
        featdeftype = fcontext->featdeftype;
 
5104
    featdeftype = fcontext->featdeftype;
 
5105
 
4888
5106
        if (featdeftype < FEATDEF_GENE || featdeftype >= FEATDEF_MAX) {
4889
5107
          featdeftype = FEATDEF_BAD;
4890
5108
        }
 
5109
        if (featdeftype == 0) {
 
5110
          featdeftype = sfp->idx.subtype;
 
5111
        }
4891
5112
        key = FindKeyFromFeatDefType (featdeftype, TRUE);
4892
5113
  
 
5114
    seqfeattype = fcontext->seqfeattype;
 
5115
    if (seqfeattype == 0) {
 
5116
      seqfeattype = sfp->data.choice;
 
5117
    }
 
5118
 
4893
5119
        if (format == GENPEPT_FMT && isProt) {
4894
5120
          if (featdeftype == FEATDEF_REGION) {
4895
5121
                key = "Region";
4916
5142
  
4917
5143
        /* deal with unmappable impfeats */
4918
5144
  
4919
 
        if (featdeftype == FEATDEF_BAD && fcontext->seqfeattype == SEQFEAT_IMP) {
 
5145
        if (featdeftype == FEATDEF_BAD && seqfeattype == SEQFEAT_IMP) {
4920
5146
          imp = (ImpFeatPtr) sfp->data.value.ptrvalue;
4921
5147
          if (imp != NULL) {
4922
5148
                key = imp->key;
4926
5152
        FFStartPrint(ffstring, format, 5, 21, NULL, 0, 5, 21, "FT", /* ifp->firstfeat */ FALSE);
4927
5153
        if (ajp->ajp.slp != NULL) {
4928
5154
          FFAddOneString(ffstring, key, FALSE, FALSE, TILDE_IGNORE);
4929
 
        } else if ( GetWWW(ajp) /* && SeqMgrGetParentOfPart (bsp, NULL) == NULL */ ) {
4930
 
          FF_asn2gb_www_featkey (ffstring, key, sfp->location, fcontext->left + 1, fcontext->right + 1, fcontext->strand, itemID);
 
5155
        } else if ( GetWWW(ajp) && StringICmp (key, "gap") != 0 /* && SeqMgrGetParentOfPart (bsp, NULL) == NULL */ ) {
 
5156
          FF_asn2gb_www_featkey (ffstring, key, sfp, fcontext->left + 1, fcontext->right + 1, fcontext->strand, itemID);
4931
5157
        } else {
4932
5158
          FFAddOneString(ffstring, key, FALSE, FALSE, TILDE_IGNORE);
4933
5159
        }
4973
5199
        if (gbseq != NULL) {
4974
5200
          if (gbfeat != NULL) {
4975
5201
                gbfeat->location = StringSave (str);
 
5202
            if (StringDoesHaveText (str)) {
 
5203
              if (StringStr (str, "join") != NULL) {
 
5204
                gbfeat->operator__ = StringSave ("join");
 
5205
              } else if (StringStr (str, "order") != NULL) {
 
5206
                gbfeat->operator__ = StringSave ("order");
 
5207
              }
 
5208
            }
 
5209
                gbfeat->partial5 = fcontext->partialL;
 
5210
                gbfeat->partial3 = fcontext->partialR;
4976
5211
                if (ajp->masterStyle) {
4977
5212
                  AddIntervalsToGbfeat (gbfeat, location, target);
4978
5213
                } else {
5038
5273
    pseudo = TRUE;
5039
5274
  }
5040
5275
 
5041
 
  if (fcontext->seqfeattype == SEQFEAT_GENE) {
 
5276
  if (seqfeattype == SEQFEAT_GENE) {
5042
5277
    grp = (GeneRefPtr) sfp->data.value.ptrvalue;
5043
5278
    if (grp != NULL) {
5044
5279
      if (! StringHasNoText (grp->locus)) {
5079
5314
      }
5080
5315
    }
5081
5316
 
5082
 
  } else if (fcontext->featdeftype != FEATDEF_operon && fcontext->featdeftype != FEATDEF_gap) {
 
5317
  } else if (featdeftype != FEATDEF_operon && featdeftype != FEATDEF_gap) {
5083
5318
 
5084
5319
    grp = SeqMgrGetGeneXref (sfp);
5085
5320
    if (grp != NULL) {
5091
5326
        gene_for_old_locus_tag = SeqMgrGetFeatureByLabel (bsp_for_old_locus_tag, grp->locus_tag, SEQFEAT_GENE, 0, &gcontext);
5092
5327
      }
5093
5328
    }
5094
 
    if (grp == NULL && fcontext->featdeftype != FEATDEF_primer_bind) {
 
5329
    if (grp == NULL && ifp->mapToNuc && cds != NULL) {
 
5330
      grp = SeqMgrGetGeneXref (cds);
 
5331
    }
 
5332
    if (grp == NULL && featdeftype != FEATDEF_primer_bind) {
5095
5333
      gene = GetOverlappingGeneInEntity (ajp->ajp.entityID, fcontext, &gcontext, locforgene);
5096
5334
      if (gene == NULL && ajp->ajp.entityID != sfp->idx.entityID) {
5097
5335
        gene = GetOverlappingGeneInEntity (sfp->idx.entityID, fcontext, &gcontext, locforgene);
5098
5336
      }
 
5337
 
 
5338
      /* special case to get gene by overlap for coded_by cds on isolated protein bioseq */
 
5339
      if (ifp->mapToProt && seqfeattype == SEQFEAT_CDREGION) {
 
5340
            sep = GetTopSeqEntryForEntityID (ajp->ajp.entityID);
 
5341
            if (sep != NULL && IS_Bioseq (sep)) {
 
5342
              bsp = (BioseqPtr) sep->data.ptrvalue;
 
5343
              if (bsp != NULL && ISA_aa (bsp->mol)) {
 
5344
                    gene = FindGeneOnIsolatedProtein (sep, sfp);
 
5345
              }
 
5346
            }
 
5347
      }
 
5348
 
5099
5349
      gene_for_old_locus_tag = gene;
5100
5350
      if (gene != NULL) {
5101
5351
        qvp [FTQUAL_gene_note].str = gene->comment;
5114
5364
      pseudo = TRUE;
5115
5365
    }
5116
5366
    if (grp != NULL && (! SeqMgrGeneIsSuppressed (grp)) &&
5117
 
        (fcontext->featdeftype != FEATDEF_repeat_region || gene == NULL)) {
 
5367
        (featdeftype != FEATDEF_repeat_region || gene == NULL)) {
5118
5368
      if (! StringHasNoText (grp->locus)) {
5119
5369
        qvp [FTQUAL_gene].str = grp->locus;
5120
5370
        qvp [FTQUAL_locus_tag].str = grp->locus_tag;
5133
5383
      }
5134
5384
    }
5135
5385
    if (grp != NULL &&
5136
 
        fcontext->featdeftype != FEATDEF_variation &&
5137
 
        fcontext->featdeftype != FEATDEF_repeat_region) {
 
5386
        featdeftype != FEATDEF_variation &&
 
5387
        featdeftype != FEATDEF_repeat_region) {
5138
5388
      qvp [FTQUAL_gene_allele].str = grp->allele; /* now propagating /allele */
5139
5389
    }
5140
 
    if (gene_for_old_locus_tag != NULL && fcontext->featdeftype != FEATDEF_repeat_region) {
 
5390
    if (gene_for_old_locus_tag != NULL && featdeftype != FEATDEF_repeat_region) {
5141
5391
      /* now propagate old_locus_tag to almost any underlying feature */
5142
5392
      for (gbq = gene_for_old_locus_tag->qual; gbq != NULL; gbq = gbq->next) {
5143
5393
        if (StringHasNoText (gbq->val)) continue;
5144
5394
        idx = GbqualToFeaturIndex (gbq->qual);
5145
5395
        if (idx == FTQUAL_old_locus_tag) {
5146
5396
          qvp [FTQUAL_old_locus_tag].gbq = gbq;
 
5397
          break; /* record first old_locus_tag gbqual to display all */
5147
5398
        }
5148
5399
      }
5149
5400
    }
5150
 
    if (fcontext->seqfeattype != SEQFEAT_CDREGION &&
5151
 
        fcontext->seqfeattype != SEQFEAT_RNA) {
 
5401
    if (seqfeattype != SEQFEAT_CDREGION && seqfeattype != SEQFEAT_RNA) {
5152
5402
      qvp [FTQUAL_gene_xref].vnp = NULL;
5153
5403
    }
5154
 
    if (fcontext->featdeftype != FEATDEF_operon) {
 
5404
    if (featdeftype != FEATDEF_operon) {
5155
5405
      grp = SeqMgrGetGeneXref (sfp);
5156
5406
      if (grp == NULL || (! SeqMgrGeneIsSuppressed (grp))) {
5157
5407
        operon = SeqMgrGetOverlappingOperon (locforgene, &ocontext);
5167
5417
 
5168
5418
    /* specific fields set here */
5169
5419
 
5170
 
    switch (fcontext->seqfeattype) {
 
5420
    switch (seqfeattype) {
5171
5421
      case SEQFEAT_CDREGION :
5172
5422
        if (! ifp->mapToProt) {
5173
5423
          crp = (CdRegionPtr) sfp->data.value.ptrvalue;
5210
5460
                      } else {
5211
5461
                        qvp [FTQUAL_selenocysteine].ble = TRUE;
5212
5462
                      }
 
5463
                    } else if (residue == 'O') {
 
5464
                      if (ajp->flags.pyrrolysineToNote) {
 
5465
                        qvp [FTQUAL_pyrrolysine_note].str = "pyrrolysine";
 
5466
                      } else {
 
5467
                        qvp [FTQUAL_pyrrolysine].ble = TRUE;
 
5468
                      }
5213
5469
                    }
5214
5470
                  }
5215
5471
                }
5293
5549
                }
5294
5550
              }
5295
5551
            }
 
5552
            pEID = ObjMgrGetEntityIDForPointer (prod);
 
5553
            if (pEID != 0 && pEID != ajp->ajp.entityID &&
 
5554
                SeqMgrFeaturesAreIndexed (pEID) == 0) {
 
5555
              /* index far record so SeqMgrGetBestProteinFeature can work */
 
5556
              SeqMgrIndexFeatures (pEID, NULL);
 
5557
            }
5296
5558
            prot = SeqMgrGetBestProteinFeature (prod, &pcontext);
5297
5559
            if (prot != NULL) {
5298
5560
              prp = (ProtRefPtr) prot->data.value.ptrvalue;
5395
5657
                      } else {
5396
5658
                        qvp [FTQUAL_selenocysteine].ble = TRUE;
5397
5659
                      }
 
5660
                    } else if (residue == 'O') {
 
5661
                      if (ajp->flags.pyrrolysineToNote) {
 
5662
                        qvp [FTQUAL_pyrrolysine_note].str = "pyrrolysine";
 
5663
                      } else {
 
5664
                        qvp [FTQUAL_pyrrolysine].ble = TRUE;
 
5665
                      }
5398
5666
                    }
5399
5667
                  }
5400
5668
                }
5567
5835
                  }
5568
5836
                }
5569
5837
                if (aa > 0 && aa != 255) {
 
5838
                  if (ajp->mode == RELEASE_MODE || ajp->mode == ENTREZ_MODE) {
 
5839
                    if (aa == 79 || aa == 74) { /* O or J quarantined */
 
5840
                      aa = 88; /* X */
 
5841
                    }
 
5842
                  }
 
5843
                  /* - no gaps now that O and J are added
5570
5844
                  if (aa <= 74) {
5571
5845
                    shift = 0;
5572
5846
                  } else if (aa > 79) {
5574
5848
                  } else {
5575
5849
                    shift = 1;
5576
5850
                  }
 
5851
                  */
5577
5852
                  if (aa != '*') {
5578
 
                    idx = aa - (64 + shift);
 
5853
                    idx = aa - (64 /* + shift */);
5579
5854
                  } else {
5580
5855
                    idx = 25;
5581
5856
                  }
5582
 
                  if (idx > 0 && idx < 26) {
 
5857
                  if (idx > 0 && idx < 28) {
5583
5858
                    str = trnaList [idx];
5584
5859
                    qvp [FTQUAL_product].str = str;
5585
5860
                    if (StringNICmp (str, "tRNA-", 5) == 0) {
5588
5863
                  }
5589
5864
                }
5590
5865
                qvp [FTQUAL_anticodon].slp = trna->anticodon;
5591
 
                qvp [FTQUAL_trna_codons].trp = trna;
 
5866
                if (ajp->flags.codonRecognizedToNote) {
 
5867
                  qvp [FTQUAL_trna_codons_note].trp = trna;
 
5868
                } else {
 
5869
                  qvp [FTQUAL_trna_codons].trp = trna;
 
5870
                }
5592
5871
              }
5593
5872
            }
5594
5873
          } else {
5673
5952
    qvp [FTQUAL_go_function].ufp = NULL;
5674
5953
  }
5675
5954
 
5676
 
  if (fcontext->featdeftype == FEATDEF_repeat_region) {
 
5955
  if (featdeftype == FEATDEF_repeat_region) {
5677
5956
    pseudo = FALSE;
5678
5957
  }
5679
5958
 
5683
5962
 
5684
5963
  sap = fcontext->sap;
5685
5964
  if (sap != NULL) {
 
5965
    annotDescCommentToComment = FALSE;
5686
5966
    for (adp = sap->desc; adp != NULL; adp = adp->next) {
5687
5967
      if (adp->choice == Annot_descr_comment) {
5688
5968
        if (StringDoesHaveText ((CharPtr) adp->data.ptrvalue)) {
5689
5969
          qvp [FTQUAL_seqannot_note].str = (CharPtr) adp->data.ptrvalue;
5690
5970
        }
 
5971
      } else if (adp->choice == Annot_descr_user) {
 
5972
        uop = (UserObjectPtr) adp->data.ptrvalue;
 
5973
        if (uop == NULL) continue;
 
5974
        oip = uop->type;
 
5975
        if (oip == NULL) continue;
 
5976
        if (StringCmp (oip->str, "AnnotDescCommentPolicy") == 0) {
 
5977
          for (ufp = uop->data; ufp != NULL; ufp = ufp->next) {
 
5978
            oip = ufp->label;
 
5979
            if (oip == NULL || ufp->data.ptrvalue == NULL) continue;
 
5980
            if (StringCmp (oip->str, "Policy") == 0) {
 
5981
              if (StringICmp ((CharPtr) ufp->data.ptrvalue, "ShowInComment") == 0) {
 
5982
                annotDescCommentToComment = TRUE;
 
5983
              }
 
5984
            }
 
5985
          }
 
5986
        }
5691
5987
      }
5692
5988
    }
 
5989
    if (annotDescCommentToComment) {
 
5990
      qvp [FTQUAL_seqannot_note].str = NULL;
 
5991
    }
5693
5992
  }
5694
5993
 
5695
5994
  /* if RELEASE_MODE, check list of features that can have /pseudo */
5696
5995
 
5697
5996
  if (ajp->flags.dropIllegalQuals && pseudo  &&
5698
 
      (fcontext->seqfeattype == SEQFEAT_RNA || fcontext->seqfeattype == SEQFEAT_IMP) ) {
 
5997
      (seqfeattype == SEQFEAT_RNA || seqfeattype == SEQFEAT_IMP) ) {
5699
5998
    switch (featdeftype) {
5700
5999
 
5701
6000
    case  FEATDEF_allele:
5993
6292
    qvp [FTQUAL_selenocysteine_note].str = NULL;
5994
6293
  }
5995
6294
 
 
6295
  /* suppress pyrrolysine note if already in comment */
 
6296
 
 
6297
  if (StringStr (sfp->comment, "pyrrolysine") != NULL) {
 
6298
    qvp [FTQUAL_pyrrolysine_note].str = NULL;
 
6299
  }
 
6300
 
5996
6301
  /* if /allele inherited from gene, suppress allele gbqual on feature */
5997
6302
 
5998
6303
  if (qvp [FTQUAL_gene_allele].str != NULL) {