~ubuntu-branches/ubuntu/edgy/ncbi-tools6/edgy

« back to all changes in this revision

Viewing changes to api/tofasta.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:
29
29
*   
30
30
* Version Creation Date: 7/12/91
31
31
*
32
 
* $Revision: 6.148 $
 
32
* $Revision: 6.152 $
33
33
*
34
34
* File Description:  various sequence objects to fasta output
35
35
*
39
39
* -------  ----------  -----------------------------------------------------
40
40
*
41
41
* $Log: tofasta.c,v $
 
42
* Revision 6.152  2006/03/29 16:04:47  kans
 
43
* in AddNcTitles, do not clear mip->completeness - cannot determine why this was done in the past
 
44
*
 
45
* Revision 6.151  2006/03/08 21:29:47  kans
 
46
* FindNMDefLine calls ReplaceFlyDashPwithDashR if Drosophila melanogaster curated RefSeq
 
47
*
 
48
* Revision 6.150  2006/01/10 22:19:29  kans
 
49
* CreateDefLine calls DoTpaPrefix to handle TPA_exp and TPA_inf
 
50
*
 
51
* Revision 6.149  2005/12/07 19:49:46  kans
 
52
* in BioseqFastaStreamInternal, bail if virtual Bioseq
 
53
*
42
54
* Revision 6.148  2005/09/12 17:44:21  kans
43
55
* in complete chromosome title, use virus instead of virion
44
56
*
1584
1596
  if (bsp == NULL && slp == NULL) return 0;
1585
1597
  if (fp == NULL && bs == NULL) return 0;
1586
1598
 
 
1599
  if (bsp != NULL && bsp->repr == Seq_repr_virtual) return 0;
 
1600
 
1587
1601
  if (linelen > 128) {
1588
1602
    linelen = 128;
1589
1603
  }
3328
3342
  }
3329
3343
}
3330
3344
 
 
3345
static Boolean IsFlyCG (CharPtr str)
 
3346
 
 
3347
{
 
3348
  Char  ch;
 
3349
 
 
3350
  if (StringHasNoText (str)) return FALSE;
 
3351
 
 
3352
  ch = *str;
 
3353
  if (ch != 'C') return FALSE;
 
3354
  str++;
 
3355
  ch = *str;
 
3356
  if (ch != 'G') return FALSE;
 
3357
  str++;
 
3358
  ch = *str;
 
3359
  while (IS_DIGIT (ch)) {
 
3360
    str++;
 
3361
    ch = *str;
 
3362
  }
 
3363
  if (ch != '-') return FALSE;
 
3364
  str++;
 
3365
  ch = *str;
 
3366
  if (ch != 'P') return FALSE;
 
3367
  str++;
 
3368
  ch = *str;
 
3369
  if (IS_ALPHA (ch)) {
 
3370
    str++;
 
3371
    ch = *str;
 
3372
    if (ch == '\0' || ch == ' ' || ch == ',' || ch == ';') return TRUE;
 
3373
  }
 
3374
 
 
3375
  return FALSE;
 
3376
}
 
3377
 
 
3378
static void ReplaceFlyDashPwithDashR (CharPtr str)
 
3379
 
 
3380
{
 
3381
  Char     ch;
 
3382
  CharPtr  ptr;
 
3383
 
 
3384
  while (StringDoesHaveText (str)) {
 
3385
    ch = *str;
 
3386
    while (IS_WHITESP (ch)) {
 
3387
      str++;
 
3388
      ch = *str;
 
3389
    }
 
3390
    if (IsFlyCG (str)) {
 
3391
      ptr = StringStr (str, "-P");
 
3392
      if (ptr != NULL) {
 
3393
        ptr [1] = 'R';
 
3394
        return;
 
3395
      }
 
3396
    }
 
3397
    while (ch != '\0' && (! IS_WHITESP (ch))) {
 
3398
      str++;
 
3399
      ch = *str;
 
3400
    }
 
3401
  }
 
3402
}
 
3403
 
3331
3404
static CharPtr FindNMDefLine (BioseqPtr bsp)
3332
3405
 
3333
3406
{
3369
3442
    }
3370
3443
  }
3371
3444
  if (is_refseq) {
 
3445
    /* special case Drosophila RefSeq NM titles */
 
3446
    if (StringICmp (orp->taxname, "Drosophila melanogaster") == 0) {
 
3447
      ReplaceFlyDashPwithDashR (buf);
 
3448
    }
3372
3449
    ptr = StringStr (buf, "isoform ");
3373
3450
    if (ptr != NULL) {
3374
3451
      *ptr = '\0';
4215
4292
  return TRUE;
4216
4293
}
4217
4294
 
 
4295
static Boolean DoTpaPrefix (
 
4296
  CharPtr title,
 
4297
  CharPtr PNTR ttl,
 
4298
  CharPtr PNTR pfx,
 
4299
  Boolean is_tpa,
 
4300
  Boolean tpa_exp,
 
4301
  Boolean tpa_inf
 
4302
)
 
4303
 
 
4304
{
 
4305
  /* must be called with ttl and pfx pointing to stack variables */
 
4306
  *ttl = title;
 
4307
  *pfx = NULL;
 
4308
 
 
4309
  if (title == NULL || *title == '\0') return FALSE;
 
4310
 
 
4311
  if (is_tpa) {
 
4312
    if (tpa_exp) {
 
4313
      if (StringNICmp (title, "TPA_exp: ", 9) == 0) return FALSE;
 
4314
      *pfx = "TPA_exp: ";
 
4315
      if (StringNICmp (title, "TPA: ", 5) == 0) {
 
4316
        *ttl = title +  5;
 
4317
      }
 
4318
      return TRUE;
 
4319
    } else if (tpa_inf) {
 
4320
      if (StringNICmp (title, "TPA_inf: ", 9) == 0) return FALSE;
 
4321
      *pfx = "TPA_inf: ";
 
4322
      if (StringNICmp (title, "TPA: ", 5) == 0) {
 
4323
        *ttl = title +  5;
 
4324
      }
 
4325
      return TRUE;
 
4326
    } else {
 
4327
      if (StringNICmp (title, "TPA: ", 5) == 0) return FALSE;
 
4328
      *pfx = "TPA: ";
 
4329
      return TRUE;
 
4330
    }
 
4331
  }
 
4332
  return FALSE;
 
4333
}
 
4334
 
4218
4335
/*****************************************************************************
4219
4336
*
4220
4337
*   CreateDefLine(iip, bsp, buf, buflen, tech)
4230
4347
                                      CharPtr accession, CharPtr organism, Boolean ignoreTitle, Boolean extProtTitle)
4231
4348
{
4232
4349
        ValNodePtr vnp = NULL;
4233
 
        CharPtr tmp = NULL, title = NULL;
 
4350
        CharPtr tmp = NULL, title = NULL, ttl = NULL, pfx = NULL;
4234
4351
        PdbBlockPtr pbp;
4235
4352
        PatentSeqIdPtr psip;
4236
4353
        PDBSeqIdPtr     pdbip;  
4245
4362
                "WORKING DRAFT SEQUENCE",
4246
4363
                "*** SEQUENCING IN PROGRESS ***" };
4247
4364
        Boolean htg_tech = FALSE, htgs_draft = FALSE, htgs_cancelled = FALSE,
4248
 
                is_nc = FALSE, is_nm = FALSE, is_nr = FALSE, is_tpa = FALSE;
 
4365
                is_nc = FALSE, is_nm = FALSE, is_nr = FALSE, is_tpa = FALSE,
 
4366
                tpa_exp = FALSE, tpa_inf = FALSE;
4249
4367
        MolInfoPtr mip;
4250
4368
        GBBlockPtr gbp = NULL;
4251
4369
        EMBLBlockPtr ebp = NULL;
4321
4439
                buf += diff;
4322
4440
        }
4323
4441
        diff = 0;
4324
 
        if (htg_tech) {
 
4442
        if (htg_tech || is_tpa) {
4325
4443
                vnp=GatherDescrOnBioseq(iip, bsp, Seq_descr_genbank,TRUE);
4326
4444
                if (vnp != NULL) {
4327
4445
                        gbp = (GBBlockPtr) vnp->data.ptrvalue;
4337
4455
                        }
4338
4456
                }
4339
4457
        }
 
4458
        if (keywords != NULL) {
 
4459
                for (vnp = keywords; vnp != NULL; vnp = vnp->next) {
 
4460
                        if (StringICmp ((CharPtr) vnp->data.ptrvalue, "HTGS_DRAFT") == 0) {
 
4461
                                htgs_draft = TRUE;
 
4462
                        } else if (StringICmp ((CharPtr) vnp->data.ptrvalue, "HTGS_CANCELLED") == 0) {
 
4463
                                htgs_cancelled = TRUE;
 
4464
                        } else if (StringICmp ((CharPtr) vnp->data.ptrvalue, "TPA:experimental") == 0) {
 
4465
                                tpa_exp = TRUE;
 
4466
                        } else if (StringICmp ((CharPtr) vnp->data.ptrvalue, "TPA:inferential") == 0) {
 
4467
                                tpa_inf = TRUE;
 
4468
                        }
 
4469
                }
 
4470
        }
 
4471
 
4340
4472
        if (! ignoreTitle)
4341
4473
          {
4342
4474
            vnp=GatherDescrOnBioseq(iip, bsp, Seq_descr_title,TRUE);
4409
4541
        }
4410
4542
/* some titles may have zero length */
4411
4543
        if (title != NULL && *title != '\0') {
4412
 
                if (is_tpa && StringNICmp (title, "TPA: ", 5) != 0) {
4413
 
                        diff = LabelCopy (buf, "TPA: ", buflen);
 
4544
            ttl = title;
 
4545
            pfx = NULL;
 
4546
        if (DoTpaPrefix (title, &ttl, &pfx, is_tpa, tpa_exp, tpa_inf)) {
 
4547
                        diff = LabelCopy (buf, pfx, buflen);
4414
4548
                        buflen -= diff;
4415
4549
                        buf += diff;
4416
4550
                }
4417
 
                diff = LabelCopy(buf, title, buflen);
 
4551
                diff = LabelCopy (buf, ttl, buflen);
4418
4552
                                        /* remove trailing blanks and periods */
4419
4553
                tmp = buf + diff - 1;   /* point at last character */
4420
4554
                while (tmp >= buf && ((*tmp <= ' ') || (*tmp == '.'))) {
4495
4629
                                        diff = LabelCopy(buf, title, buflen);
4496
4630
                                }
4497
4631
                                */
4498
 
                                if (is_tpa && StringNICmp (title, "TPA: ", 5) != 0) {
4499
 
                                        diff = LabelCopy (buf, "TPA: ", buflen);
4500
 
                                        buflen -= diff;
4501
 
                                        buf += diff;
4502
 
                                }
4503
 
                                diff = LabelCopy(buf, title, buflen);
 
4632
                  ttl = title;
 
4633
                  pfx = NULL;
 
4634
              if (DoTpaPrefix (title, &ttl, &pfx, is_tpa, tpa_exp, tpa_inf)) {
 
4635
                                diff = LabelCopy (buf, pfx, buflen);
 
4636
                                buflen -= diff;
 
4637
                                buf += diff;
 
4638
                        }
 
4639
                        diff = LabelCopy (buf, ttl, buflen);
4504
4640
                                if (organism == NULL && taxname != NULL) {
4505
4641
                                        organism = taxname;
4506
4642
                                        iip = NULL;
4512
4648
                                if (title == NULL) {
4513
4649
                                        title = UseOrgMods(bsp, NULL);
4514
4650
                                }
4515
 
                                if (is_tpa && StringNICmp (title, "TPA: ", 5) != 0) {
4516
 
                                        diff = LabelCopy (buf, "TPA: ", buflen);
4517
 
                                        buflen -= diff;
4518
 
                                        buf += diff;
4519
 
                                }
4520
 
                                if (title != NULL) {
4521
 
                                        diff = LabelCopy(buf, title, buflen);
 
4651
                ttl = title;
 
4652
                pfx = NULL;
 
4653
                if (DoTpaPrefix (title, &ttl, &pfx, is_tpa, tpa_exp, tpa_inf)) {
 
4654
                    diff = LabelCopy (buf, pfx, buflen);
 
4655
                    buflen -= diff;
 
4656
                    buf += diff;
 
4657
                }
 
4658
                                if (ttl != NULL) {
 
4659
                                        diff = LabelCopy (buf, ttl, buflen);
4522
4660
                                } else {
4523
 
                                        diff = LabelCopy(buf, "No definition line found", buflen);
 
4661
                                        diff = LabelCopy (buf, "No definition line found", buflen);
4524
4662
                                }
4525
4663
                        }
4526
4664
                }
4537
4675
                        title = UseOrgMods(bsp, NULL);
4538
4676
                        organism = NULL;
4539
4677
                        if (title != NULL) {
4540
 
                                if (is_tpa && StringNICmp (title, "TPA: ", 5) != 0) {
4541
 
                                        diff = LabelCopy (buf, "TPA: ", buflen);
4542
 
                                        buflen -= diff;
4543
 
                                        buf += diff;
4544
 
                                }
4545
 
                                diff = LabelCopy(buf, title, buflen);
 
4678
                ttl = title;
 
4679
                pfx = NULL;
 
4680
                if (DoTpaPrefix (title, &ttl, &pfx, is_tpa, tpa_exp, tpa_inf)) {
 
4681
                                diff = LabelCopy (buf, pfx, buflen);
 
4682
                                buflen -= diff;
 
4683
                                buf += diff;
 
4684
                        }
 
4685
                        diff = LabelCopy (buf, ttl, buflen);
4546
4686
                                buflen -= diff;
4547
4687
                                buf += diff;
4548
4688
                        }
4564
4704
                                        i = 0;
4565
4705
                                }
4566
4706
                        } else {
4567
 
                                if (keywords != NULL) {
4568
 
                                        for (vnp = keywords; vnp != NULL; vnp = vnp->next) {
4569
 
                                                if (StringICmp ((CharPtr) vnp->data.ptrvalue, "HTGS_DRAFT") == 0) {
4570
 
                                                        htgs_draft = TRUE;
4571
 
                                                } else if (StringICmp ((CharPtr) vnp->data.ptrvalue, "HTGS_CANCELLED") == 0) {
4572
 
                                                        htgs_cancelled = TRUE;
4573
 
                                                }
4574
 
                                        }
4575
 
                                }
4576
4707
                                if (htgs_draft) {
4577
4708
                                        if (StringStr(title, "WORKING DRAFT") == NULL) {
4578
4709
                                                doit = TRUE;
4629
4760
                        title = UseOrgMods(bsp, NULL);
4630
4761
                        organism = NULL;
4631
4762
                        if (title != NULL) {
4632
 
                                if (is_tpa && StringNICmp (title, "TPA: ", 5) != 0) {
4633
 
                                        diff = LabelCopy (buf, "TPA: ", buflen);
4634
 
                                        buflen -= diff;
4635
 
                                        buf += diff;
4636
 
                                }
4637
 
                                diff = LabelCopy(buf, title, buflen);
 
4763
                ttl = title;
 
4764
                pfx = NULL;
 
4765
                if (DoTpaPrefix (title, &ttl, &pfx, is_tpa, tpa_exp, tpa_inf)) {
 
4766
                    diff = LabelCopy (buf, pfx, buflen);
 
4767
                    buflen -= diff;
 
4768
                    buf += diff;
 
4769
                }
 
4770
                diff = LabelCopy (buf, ttl, buflen);
4638
4771
                                buflen -= diff;
4639
4772
                                buf += diff;
4640
4773
                        }
4864
4997
  BioseqPtr     bsp;
4865
4998
  Char          buf [512];
4866
4999
  Boolean       is_nc;
 
5000
  /*
4867
5001
  MolInfoPtr    mip;
4868
5002
  SeqDescrPtr   sdp;
 
5003
  */
4869
5004
  SeqIdPtr      sip;
4870
5005
  CharPtr       str;
4871
5006
  TextSeqIdPtr  tsip;
4898
5033
    }
4899
5034
  }
4900
5035
 
 
5036
  /*
4901
5037
  for (sdp = bsp->descr; sdp != NULL; sdp = sdp->next) {
4902
5038
    if (sdp->choice == Seq_descr_molinfo) {
4903
5039
      mip = (MolInfoPtr) sdp->data.ptrvalue;
4908
5044
      }
4909
5045
    }
4910
5046
  }
 
5047
  */
4911
5048
 
4912
5049
  return TRUE;
4913
5050
}