~ubuntu-branches/ubuntu/maverick/ncbi-tools6/maverick

« back to all changes in this revision

Viewing changes to api/subutil.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: 11/3/93
31
31
*
32
 
* $Revision: 6.45 $
 
32
* $Revision: 6.55 $
33
33
*
34
34
* File Description: Utilities for creating ASN.1 submissions
35
35
*
40
40
*
41
41
*
42
42
* $Log: subutil.c,v $
 
43
* Revision 6.55  2003/10/16 17:16:33  mjohnson
 
44
*
 
45
* Added ORG_* and IS_ORG_* defines for origins. Use these constants
 
46
* and macros instead of small integers.
 
47
*
 
48
* Revision 6.54  2003/10/08 16:46:44  kans
 
49
* fix in AddCompleteness (KT)
 
50
*
 
51
* Revision 6.53  2003/07/11 18:22:45  kans
 
52
* AddSourceToRefGeneTrackUserObject
 
53
*
 
54
* Revision 6.52  2002/11/05 17:01:55  kans
 
55
* refgene tracking user object uses comment as name if accession is empty
 
56
*
 
57
* Revision 6.51  2002/09/30 16:31:36  kans
 
58
* support for new BioseqseqSet_class_wgs_set
 
59
*
 
60
* Revision 6.50  2002/07/10 14:36:29  kans
 
61
* fixed TpaAssembly user object - from and to were being placed at wrong level
 
62
*
 
63
* Revision 6.49  2002/07/09 16:25:45  kans
 
64
* if from and to are 0, do not add those fields to TPA user object
 
65
*
 
66
* Revision 6.48  2002/07/09 16:17:35  kans
 
67
* AddAccessionToTpaAssemblyUserObject takes from and to parameters
 
68
*
 
69
* Revision 6.47  2002/06/04 14:40:29  kans
 
70
* added AddPntToSeqFeat
 
71
*
 
72
* Revision 6.46  2002/03/27 19:26:31  kans
 
73
* AddToGeneOntologyUserObject takes string for GO id to keep leading zeroes
 
74
*
43
75
* Revision 6.45  2001/12/11 16:50:41  kans
44
76
* added TpaAssembly user object creation functions
45
77
*
893
925
                if (tmp != NULL && tmp->choice == 2 && tmp->data.ptrvalue != NULL) {
894
926
                        targetbssp = (BioseqSetPtr) tmp->data.ptrvalue;
895
927
                        if (targetbssp->_class == 7 ||
896
 
                            (targetbssp->_class >= 13 && targetbssp->_class <= 16)) {
 
928
                            (targetbssp->_class >= 13 && targetbssp->_class <= 16) ||
 
929
                            targetbssp->_class == BioseqseqSet_class_wgs_set) {
897
930
                                tmp = targetbssp->seq_set;
898
931
                        }
899
932
                }
1134
1167
                if (tmp != NULL && tmp->choice == 2 && tmp->data.ptrvalue != NULL) {
1135
1168
                        targetbssp = (BioseqSetPtr) tmp->data.ptrvalue;
1136
1169
                        if (targetbssp->_class == 7 ||
1137
 
                            (targetbssp->_class >= 13 && targetbssp->_class <= 16)) {
 
1170
                            (targetbssp->_class >= 13 && targetbssp->_class <= 16) ||
 
1171
                            targetbssp->_class == BioseqseqSet_class_wgs_set) {
1138
1172
                                tmp = targetbssp->seq_set;
1139
1173
                        }
1140
1174
                }
1564
1598
                if (tmp != NULL && tmp->choice == 2 && tmp->data.ptrvalue != NULL) {
1565
1599
                        targetbssp = (BioseqSetPtr) tmp->data.ptrvalue;
1566
1600
                        if (targetbssp->_class == 7 ||
1567
 
                            (targetbssp->_class >= 13 && targetbssp->_class <= 16)) {
 
1601
                            (targetbssp->_class >= 13 && targetbssp->_class <= 16) ||
 
1602
                            targetbssp->_class == BioseqseqSet_class_wgs_set) {
1568
1603
                                tmp = targetbssp->seq_set;
1569
1604
                        }
1570
1605
                }
2546
2581
                bio = BioSourceNew();
2547
2582
        }
2548
2583
        bio->genome = (Uint1)type;
2549
 
        bio->origin = 0;               /* unknown */
 
2584
        bio->origin = ORG_DEFAULT;      /* unknown */
2550
2585
        vnp->data.ptrvalue = (Pointer) bio;
2551
2586
        
2552
2587
        return TRUE;
2708
2743
        Boolean partial = FALSE;
2709
2744
 
2710
2745
        retval = SeqLocPartialCheck(sfp->location);
2711
 
        if (retval & SLP_START) {
 
2746
        if ((retval & SLP_START) && (retval & SLP_STOP)) {
 
2747
                AddCompleteToEntry(submission, sep, 5);   /* no_ends */
 
2748
                partial = TRUE;
 
2749
        } else if (retval & SLP_START) {
2712
2750
                AddCompleteToEntry(submission, sep, 3);   /* no_left */
2713
2751
                partial = TRUE;
2714
 
        }
2715
 
        if (retval & SLP_STOP) {
 
2752
        } else if (retval & SLP_STOP) {
2716
2753
                AddCompleteToEntry(submission, sep, 4);  /* no_right */
2717
2754
                partial = TRUE;
2718
 
        }
2719
 
        if (retval & (SLP_OTHER | SLP_INTERNAL)) {
 
2755
        } else if (retval & (SLP_OTHER | SLP_INTERNAL)) {
2720
2756
                AddCompleteToEntry(submission, sep, 2);  /* partial */
2721
2757
                partial = TRUE;
2722
 
        }
2723
 
        if (!partial && sfp->partial) {
 
2758
        } else if (!partial && sfp->partial) {
2724
2759
                AddCompleteToEntry(submission, sep, 2);  /* partial */
2725
2760
        }
2726
2761
}
3260
3295
}
3261
3296
 
3262
3297
NLM_EXTERN Boolean AddIntToSeqFeat (SeqFeatPtr sfp, Int4 from, Int4 to, BioseqPtr bsp,
3263
 
                                                        Int2 fuzz_from, Int2 
3264
 
fuzz_to, Int2 strand)
 
3298
                                                        Int2 fuzz_from, Int2 fuzz_to, Int2 strand)
3265
3299
{
3266
3300
        SeqLocPtr slp, tmp, tmp2;
3267
3301
        SeqIntPtr sintp;
3317
3351
        return TRUE;
3318
3352
}
3319
3353
 
 
3354
NLM_EXTERN Boolean AddPntToSeqFeat (SeqFeatPtr sfp, Int4 point, BioseqPtr bsp, Int2 fuzz, Int2 strand)
 
3355
{
 
3356
        SeqLocPtr slp, tmp, tmp2;
 
3357
        SeqPntPtr spp;
 
3358
        IntFuzzPtr ifp;
 
3359
 
 
3360
        spp = SeqPntNew();
 
3361
        spp->point = point;
 
3362
        spp->id = SeqIdDup(SeqIdFindBest(bsp->id, 0));
 
3363
        spp->strand = (Uint1)strand;
 
3364
        if (fuzz >= 0)
 
3365
        {
 
3366
                ifp = IntFuzzNew();
 
3367
                ifp->choice = 4;   /* lim */
 
3368
                ifp->a = (Int4) fuzz;
 
3369
                spp->fuzz = ifp;
 
3370
        }
 
3371
 
 
3372
        slp = ValNodeNew(NULL);
 
3373
        slp->choice = SEQLOC_PNT;
 
3374
        slp->data.ptrvalue = (Pointer)spp;
 
3375
 
 
3376
        if (sfp->location == NULL)
 
3377
        {
 
3378
                sfp->location = slp;
 
3379
                return TRUE;
 
3380
        }
 
3381
 
 
3382
        tmp = sfp->location;
 
3383
        if (tmp->choice == SEQLOC_MIX)   /* second one already */
 
3384
        {
 
3385
                tmp2 = (ValNodePtr)(tmp->data.ptrvalue);
 
3386
                while (tmp2->next != NULL)
 
3387
                        tmp2 = tmp2->next;
 
3388
                tmp2->next = slp;
 
3389
        }
 
3390
        else                             /* create a chain */
 
3391
        {
 
3392
                tmp2 = ValNodeNew(NULL);
 
3393
                tmp2->choice = SEQLOC_MIX;
 
3394
                tmp2->data.ptrvalue = (Pointer)tmp;
 
3395
                tmp->next = slp;
 
3396
                sfp->location = tmp2;
 
3397
        }
 
3398
 
 
3399
        return TRUE;
 
3400
}
 
3401
 
3320
3402
static BioseqPtr GetBioseqFromChoice (NCBISubPtr nsp, SeqEntryPtr the_seq, CharPtr local_name, CharPtr the_routine)
3321
3403
{
3322
3404
        BioseqPtr bsp;
4349
4431
{
4350
4432
  UserFieldPtr  curr;
4351
4433
  ObjectIdPtr   oip;
 
4434
  UserFieldPtr  prev = NULL;
4352
4435
 
4353
4436
  if (uop == NULL || collaborator == NULL) return;
4354
4437
  oip = uop->type;
4359
4442
    if (oip != NULL && StringICmp (oip->str, "Collaborator") == 0) {
4360
4443
      break;
4361
4444
    }
 
4445
    prev = curr;
4362
4446
  }
4363
4447
 
4364
4448
  if (curr == NULL) {
4368
4452
    curr->label = oip;
4369
4453
    curr->choice = 1; /* visible string */
4370
4454
 
4371
 
    /* link status at beginning of list */
 
4455
    /* link curator at end of list */
4372
4456
 
4373
 
    curr->next = uop->data;
4374
 
    uop->data = curr;
 
4457
    if (prev != NULL) {
 
4458
      prev->next = curr;
 
4459
    } else {
 
4460
      uop->data = curr;
 
4461
    }
4375
4462
  }
4376
4463
 
4377
4464
  if (curr == NULL || curr->choice != 1) return;
4383
4470
  curr->data.ptrvalue = (Pointer) StringSave (collaborator);
4384
4471
}
4385
4472
 
 
4473
NLM_EXTERN void AddSourceToRefGeneTrackUserObject (UserObjectPtr uop, CharPtr genomicSource)
 
4474
 
 
4475
{
 
4476
  UserFieldPtr  curr;
 
4477
  ObjectIdPtr   oip;
 
4478
  UserFieldPtr  prev = NULL;
 
4479
 
 
4480
  if (uop == NULL || genomicSource == NULL) return;
 
4481
  oip = uop->type;
 
4482
  if (oip == NULL || StringICmp (oip->str, "RefGeneTracking") != 0) return;
 
4483
 
 
4484
  for (curr = uop->data; curr != NULL; curr = curr->next) {
 
4485
    oip = curr->label;
 
4486
    if (oip != NULL && StringICmp (oip->str, "GenomicSource") == 0) {
 
4487
      break;
 
4488
    }
 
4489
    prev = curr;
 
4490
  }
 
4491
 
 
4492
  if (curr == NULL) {
 
4493
    curr = UserFieldNew ();
 
4494
    oip = ObjectIdNew ();
 
4495
    oip->str = StringSave ("GenomicSource");
 
4496
    curr->label = oip;
 
4497
    curr->choice = 1; /* visible string */
 
4498
 
 
4499
    /* link source at end of list */
 
4500
 
 
4501
    if (prev != NULL) {
 
4502
      prev->next = curr;
 
4503
    } else {
 
4504
      uop->data = curr;
 
4505
    }
 
4506
  }
 
4507
 
 
4508
  if (curr == NULL || curr->choice != 1) return;
 
4509
 
 
4510
  /* replace any existing source indication */
 
4511
 
 
4512
  curr->data.ptrvalue = MemFree (curr->data.ptrvalue);
 
4513
 
 
4514
  curr->data.ptrvalue = (Pointer) StringSave (genomicSource);
 
4515
}
 
4516
 
4386
4517
NLM_EXTERN void AddAccessionToRefGeneTrackUserObject (UserObjectPtr uop, CharPtr field,
4387
4518
                                                      CharPtr accn, Int4 gi,
4388
4519
                                                      Boolean sequenceChange,
4444
4575
 
4445
4576
  /* entry is now in the appropriate list */
4446
4577
 
4447
 
  ufp = UserFieldNew ();
4448
 
  oip = ObjectIdNew ();
4449
 
  oip->str = StringSave ("accession");
4450
 
  ufp->label = oip;
4451
 
  ufp->choice = 1; /* visible string */
4452
 
  ufp->data.ptrvalue = (Pointer) StringSave (accn);
 
4578
  if (! StringHasNoText (accn)) {
 
4579
    ufp = UserFieldNew ();
 
4580
    oip = ObjectIdNew ();
 
4581
    oip->str = StringSave ("accession");
 
4582
    ufp->label = oip;
 
4583
    ufp->choice = 1; /* visible string */
 
4584
    ufp->data.ptrvalue = (Pointer) StringSave (accn);
 
4585
  } else if (comment != NULL && *comment != '\0') {
 
4586
    ufp = UserFieldNew ();
 
4587
    oip = ObjectIdNew ();
 
4588
    oip->str = StringSave ("name");
 
4589
    ufp->label = oip;
 
4590
    ufp->choice = 1; /* visible string */
 
4591
    ufp->data.ptrvalue = (Pointer) StringSave (comment);
 
4592
    comment = NULL;
 
4593
  }
4453
4594
 
4454
4595
  entry->data.ptrvalue = (Pointer) ufp;
4455
4596
  last = ufp;
4664
4805
  UserObjectPtr uop,
4665
4806
  CharPtr type,
4666
4807
  CharPtr text,
4667
 
  Int4 goid,
 
4808
  CharPtr goid,
4668
4809
  Int4 pmid,
4669
4810
  CharPtr evidence
4670
4811
)
4734
4875
  entry->data.ptrvalue = (Pointer) ufp;
4735
4876
  last = ufp;
4736
4877
 
4737
 
  if (goid > 0) {
 
4878
  if (goid != NULL && *goid != '\0') {
4738
4879
    ufp = UserFieldNew ();
4739
4880
    oip = ObjectIdNew ();
4740
4881
    oip->str = StringSave ("go id");
4741
4882
    ufp->label = oip;
4742
 
    ufp->choice = 2; /* integer */
4743
 
    ufp->data.intvalue = goid;
 
4883
    ufp->choice = 1; /* visible string - need to keep leading zeroes */
 
4884
    ufp->data.ptrvalue = (Pointer) StringSave (goid);
4744
4885
    last->next = ufp;
4745
4886
    last = ufp;
4746
4887
  }
5032
5173
  return uop;
5033
5174
}
5034
5175
 
5035
 
NLM_EXTERN void AddAccessionToTpaAssemblyUserObject (UserObjectPtr uop, CharPtr accn)
 
5176
NLM_EXTERN void AddAccessionToTpaAssemblyUserObject (UserObjectPtr uop, CharPtr accn, Int4 from, Int4 to)
5036
5177
 
5037
5178
{
5038
5179
  UserFieldPtr  curr;
5072
5213
  ufp->data.ptrvalue = (Pointer) StringSave (accn);
5073
5214
 
5074
5215
  curr->data.ptrvalue = (Pointer) ufp;
 
5216
  prev = ufp;
 
5217
 
 
5218
  if (from == 0 && to == 0) return;
 
5219
 
 
5220
  ufp = UserFieldNew ();
 
5221
  oip = ObjectIdNew ();
 
5222
  oip->str = StringSave ("from");
 
5223
  ufp->label = oip;
 
5224
  ufp->choice = 2; /* int */
 
5225
  ufp->data.intvalue = from;
 
5226
 
 
5227
  prev->next = ufp;
 
5228
  prev = ufp;
 
5229
 
 
5230
  ufp = UserFieldNew ();
 
5231
  oip = ObjectIdNew ();
 
5232
  oip->str = StringSave ("to");
 
5233
  ufp->label = oip;
 
5234
  ufp->choice = 2; /* int */
 
5235
  ufp->data.intvalue = to;
 
5236
 
 
5237
  prev->next = ufp;
5075
5238
}
5076
5239