39
39
* ------- ---------- -----------------------------------------------------
41
41
* $Log: seqmgr.c,v $
42
* Revision 6.222 2004/09/07 18:50:47 bollin
43
* added new overlap type: RANGE_MATCH - left and right must match exactly
45
* Revision 6.221 2004/09/03 13:43:58 bollin
46
* added SegMgrGetLocationSupersetmRNA function
48
* Revision 6.220 2004/08/20 19:05:49 kans
49
* RecordFeaturesInBioseqs errors back to warning now that unindexed features are picked up by the validator
51
* Revision 6.219 2004/08/20 13:45:23 kans
52
* allocate ctmp again for second errpost on bad feature indexing location - was dangling
54
* Revision 6.218 2004/08/19 18:53:26 kans
55
* SeqMgr indexing messages raised from WARNING to ERROR
57
* Revision 6.217 2004/08/19 17:18:43 kans
58
* RecordFeaturesInBioseqs posts error if left or right are -1
60
* Revision 6.216 2004/06/22 17:37:25 kans
61
* added FreeSeqIdGiCache
63
* Revision 6.215 2004/05/13 19:38:08 kans
64
* SeqLocMergeExEx takes ignore_mixed so gene by overlap can ignore trans splicing confusion
66
* Revision 6.214 2004/05/04 17:34:23 bollin
67
* initialize variables
69
* Revision 6.213 2004/02/24 20:57:44 kans
70
* added genesByLocusTag field, SeqMgrGetNextGeneByLocusTag function, now that locus_tag should be a unique identifier
72
* Revision 6.212 2003/12/12 20:59:48 kans
73
* added StrandsMatch to consolate code after TestForOverlap, allow both on candidate to be treated as plus
75
* Revision 6.211 2003/11/13 21:59:24 kans
76
* GetSeqIdForGI separates SEQID_OTHER from other types, so RefSeq takes higher priority over General
78
* Revision 6.210 2003/10/24 19:49:11 kans
79
* operon feature of equal range sorted before gene, mRNA, CDS
81
* Revision 6.209 2003/10/23 17:40:01 kans
82
* added SeqMgrGetOverlappingOperon and bspextra operonsByPos and numoperons fields
84
* Revision 6.208 2003/10/02 16:12:31 bollin
85
* added COMMON_INTERVAL overlap type to TestForOverlap
87
* Revision 6.207 2003/09/22 17:27:29 kans
88
* strip RNA- prefix, not just - on RNAs
90
* Revision 6.206 2003/09/22 16:13:20 kans
91
* LockFarComponentsEx takes new SeqLocPtr parameter
93
* Revision 6.205 2003/09/22 15:55:06 kans
94
* all rna context labels were searched for dash, now just trna
96
* Revision 6.204 2003/08/04 20:41:20 kans
97
* SeqMgrProcessNonIndexedBioseq needed to reset version to 0 each time through outer loop (EY)
99
* Revision 6.203 2003/04/03 22:40:09 kans
100
* feature index location problem now reports latest identifier in record to make it easier to find problem
102
* Revision 6.202 2003/03/10 20:55:08 kans
103
* LockAllSegments calls LockAllBioseqs if component was itself far delta or seg
105
* Revision 6.201 2003/02/12 14:20:46 kans
106
* added IsNonGappedLiteral, used to allow compressed deltas as (previously always raw) parts of segsets
108
* Revision 6.200 2003/01/29 22:01:16 kans
109
* corrected printing in CountGapsInDeltaSeq
111
* Revision 6.199 2003/01/21 20:15:00 kans
112
* support for SeqMgrSetSeqIdSetFunc and GetSeqIdSetForGI needed for validator
114
* Revision 6.198 2002/12/17 17:30:10 kans
115
* CountGapsInDeltaSeq calls NextLitLength to sum up adjacent non-gap SeqLits, used to break up long literals or isolate small runs of ambiguous (uncompressible) sequence
117
* Revision 6.197 2002/12/03 23:09:03 kans
118
* added TestFeatOverlap
120
* Revision 6.196 2002/11/21 16:28:50 kans
121
* fixed test for INTERVAL_OVERLAP
123
* Revision 6.195 2002/11/04 21:11:58 kans
124
* SIMPLE_OVERLAP check now is more inclusive
126
* Revision 6.194 2002/10/23 12:57:53 kans
127
* do not report cds or rna already set if gps
129
* Revision 6.193 2002/06/11 14:41:20 kans
130
* added support for locus_tag
132
* Revision 6.192 2002/06/10 13:50:42 kans
133
* added SeqMgrSetLenFunc, SeqMgrSetAccnVerFunc
135
* Revision 6.191 2002/06/07 21:24:57 kans
136
* update entityID/omdp index in BioseqReloadFunc, ObjMgrConnectFunc, ObjMgrDetachFunc
138
* Revision 6.190 2002/06/03 17:02:27 kans
139
* SeqMgrGetBestOverlappingFeat calls SeqLocMergeEx for CHECK_INTERVALS without fusing joints
141
* Revision 6.189 2002/05/08 18:58:09 kans
144
* Revision 6.188 2002/05/07 16:16:58 kans
145
* Uint4 counts so as not to allocate array based on Uint2 wrapped around number
147
* Revision 6.187 2002/04/12 20:42:37 kans
148
* LookupFarSeqIDs has separate parameter for alignments and history
150
* Revision 6.186 2002/03/18 22:38:23 kans
151
* added SeqMgrGetAllOverlappingFeatures
153
* Revision 6.185 2002/03/14 18:30:00 kans
154
* index featsByRev on the fly if not already done when requested
156
* Revision 6.184 2002/03/14 16:40:02 kans
157
* SeqMgrIndexFeaturesEx takes dorevfeats, SeqMgrExploreFeaturesRev and featsByRev added for asn2gb
159
* Revision 6.183 2002/03/07 16:12:29 kans
160
* TrimLocInSegment for asn2gb master style to constrain feature locations within the part sequence range used by the contig
162
* Revision 6.182 2002/02/27 23:21:51 kans
163
* do not SeqLocMerge to get left and right extremes - it was needed for trans splicing but broke (gene) features spanning the origin
165
* Revision 6.181 2002/02/14 19:10:44 kans
166
* added SeqMgrGetPROTgivenProduct, index protein->product
168
* Revision 6.180 2002/02/07 14:34:51 kans
169
* added LOCATION_SUBSET type, use in CDS-mRNA overlap check to subclassify problem
171
* Revision 6.179 2002/02/01 21:55:48 kans
172
* wrong test for hit already past location to check hierarchy
174
* Revision 6.178 2002/01/23 19:26:00 kans
175
* swap ivals if minus strand, check internal exon boundaries only if > 1 interval
177
* Revision 6.177 2002/01/22 21:22:52 kans
178
* CheckInternalExonBoundaries for CHECK_INTERVALS overlap test
180
* Revision 6.176 2002/01/07 19:28:25 kans
181
* pass result of SeqLocMerge to GetOffsetInNearBioseq to get left and right even with trans spliced feature
183
* Revision 6.175 2001/12/28 13:33:16 kans
184
* LookupFarSeqIDs uses smp->seq_id_precache_func
186
* Revision 6.174 2001/12/28 13:19:11 kans
187
* added seq_id_precache_func, SeqMgrSetPreCache, LookupFarSeqIDs
189
* Revision 6.173 2001/12/27 17:01:53 kans
190
* FetchFromSeqIdGiCache can take NULL sipp
192
* Revision 6.172 2001/12/26 15:29:22 kans
193
* FetchFromSeqIdGiCache and RecordInSeqIdGiCache are extern
42
195
* Revision 6.171 2001/12/17 12:48:06 kans
43
196
* sort by position callback tests for numivals > 0
1864
static Boolean FetchFromSeqIdGiCache (Int4 gi, SeqIdPtr PNTR sipp)
2019
NLM_EXTERN void FreeSeqIdGiCache (void)
2026
ret = NlmRWwrlock(sgi_RWlock);
2028
ErrPostEx(SEV_ERROR,0,0,"FreeSeqIdGiCache: RWwrlock error [%ld]", (long) ret);
2033
seqidgiarray = MemFree (seqidgiarray);
2035
for (vnp = seqidgicache; vnp != NULL; vnp = vnp->next) {
2036
sibp = (SeqIdBlockPtr) vnp->data.ptrvalue;
2037
if (sibp == NULL) continue;
2038
sibp->sip = SeqIdFree (sibp->sip);
2040
seqidgicache = ValNodeFreeData (seqidgicache);
2042
ret = NlmRWunlock(sgi_RWlock);
2044
ErrPostEx(SEV_ERROR,0,0,"FreeSeqIdGiCache: RWwrlock error [%ld]", (long) ret);
2049
NLM_EXTERN Boolean FetchFromSeqIdGiCache (Int4 gi, SeqIdPtr PNTR sipp)
2052
ValNodePtr vnp, tmp;
1868
2053
SeqIdBlockPtr sibp = NULL;
1870
2055
Int2 left, right, mid;
1871
2056
Int4 compare, ret;
1872
2057
Boolean done = FALSE;
1874
if (sipp == NULL) return done;
1876
2062
if (seqidgicache == NULL) return done;
1878
2064
if (seqidgiarray == NULL) {
5566
5858
/* get extreme left and right extents of feature location on near bioseqs */
5567
5859
/* merge here to get correct extremes even in case of trans-splicing */
5861
/* but this broke the handling of genes spanning the origin, so cannot do */
5569
5863
slp = SeqLocMergeEx (bsp, sfp->location, NULL, TRUE, TRUE, FALSE, FALSE);
5570
left = GetOffsetInNearBioseq (sfp->location, bsp, SEQLOC_LEFT_END);
5571
right = GetOffsetInNearBioseq (sfp->location, bsp, SEQLOC_RIGHT_END);
5865
slp = sfp->location;
5866
left = GetOffsetInNearBioseq (slp, bsp, SEQLOC_LEFT_END);
5867
right = GetOffsetInNearBioseq (slp, bsp, SEQLOC_RIGHT_END);
5572
5869
SeqLocFree (slp);
5573
if (left == -1 || right == -1) return TRUE;
5871
if (left == -1 || right == -1) {
5873
GatherContextPtr gcp;
5874
Char lastbspid [41];
5876
MemSet ((Pointer) &gc, 0, sizeof (GatherContext));
5878
gc.entityID = gop->entityID;
5879
gc.itemID = gop->itemID;
5880
gc.thistype = gop->itemtype;
5881
lastbspid [0] = '\0';
5882
if (exindx->lastbsp != NULL) {
5883
sip = SeqIdFindBest (exindx->lastbsp->id, 0);
5885
SeqIdWrite (sip, lastbspid, PRINTID_FASTA_LONG, sizeof (lastbspid));
5888
FeatDefLabel (sfp, buf, sizeof (buf) - 1, OM_LABEL_CONTENT);
5889
ctmp = SeqLocPrint (sfp->location);
5891
if (loclbl == NULL) {
5894
ErrPostItem (SEV_WARNING, 0, 0,
5895
"SeqMgr indexing feature mapping problem - Feature: %s - Location [%s] - Record [%s]",
5896
buf, loclbl, lastbspid);
5575
5901
/* if indexing protein bioseq, store largest protein feature */
6255
static int LIBCALLBACK SortFeatItemListByLocusTag (VoidPtr vp1, VoidPtr vp2)
6263
SMFeatItemPtr PNTR spp1 = vp1;
6264
SMFeatItemPtr PNTR spp2 = vp2;
6268
if (spp1 == NULL || spp2 == NULL) return 0;
6269
sp1 = *((SMFeatItemPtr PNTR) spp1);
6270
sp2 = *((SMFeatItemPtr PNTR) spp2);
6271
if (sp1 == NULL || sp2 == NULL) return 0;
6275
if (sfp1 == NULL || sfp2 == NULL) return 0;
6277
if (sfp1->data.choice != SEQFEAT_GENE || sfp2->data.choice != SEQFEAT_GENE) return 0;
6278
grp1 = (GeneRefPtr) sfp1->data.value.ptrvalue;
6279
grp2 = (GeneRefPtr) sfp2->data.value.ptrvalue;
6280
if (grp1 == NULL || grp2 == NULL) return 0;
6282
/* sort by locus_tag */
6284
compare = StringICmp (grp1->locus_tag, grp2->locus_tag);
6287
} else if (compare < 0) {
6291
/* sort by locus if locus_tag is identical */
6293
compare = StringICmp (grp1->locus, grp2->locus);
6296
} else if (compare < 0) {
6300
/* for duplicated genes that cross origin, put ignored item last for binary search */
6304
} else if (sp2->ignore) {
5920
6311
static int LIBCALLBACK SortFeatItemListByPos (VoidPtr vp1, VoidPtr vp2)
6480
static int LIBCALLBACK SortFeatItemListByRev (VoidPtr vp1, VoidPtr vp2)
6492
SMFeatItemPtr PNTR spp1 = vp1;
6493
SMFeatItemPtr PNTR spp2 = vp2;
6501
if (spp1 == NULL || spp2 == NULL) return 0;
6502
sp1 = *((SMFeatItemPtr PNTR) spp1);
6503
sp2 = *((SMFeatItemPtr PNTR) spp2);
6504
if (sp1 == NULL || sp2 == NULL) return 0;
6506
/* feature with largest right extreme is first */
6508
if (sp1->right < sp2->right) {
6510
} else if (sp1->right > sp2->right) {
6513
/* reversing order so that longest feature is first */
6515
} else if (sp1->left < sp2->left) {
6517
} else if (sp1->left > sp2->left) {
6521
/* given identical extremes, put operon features first */
6523
if (sp1->subtype == FEATDEF_operon && sp2->subtype != FEATDEF_operon) {
6525
} else if (sp2->subtype == FEATDEF_operon && sp1->subtype != FEATDEF_operon) {
6529
/* then gene features */
6531
if (sp1->subtype == FEATDEF_GENE && sp2->subtype != FEATDEF_GENE) {
6533
} else if (sp2->subtype == FEATDEF_GENE && sp1->subtype != FEATDEF_GENE) {
6537
/* then rna features */
6539
subtype1 = FindFeatFromFeatDefType (sp1->subtype);
6540
subtype2 = FindFeatFromFeatDefType (sp2->subtype);
6542
if (subtype1 == SEQFEAT_RNA && subtype2 != SEQFEAT_RNA) {
6544
} else if (subtype2 == SEQFEAT_RNA && subtype1 != SEQFEAT_RNA) {
6548
/* then cds features */
6550
if (sp1->subtype == FEATDEF_CDS && sp2->subtype != FEATDEF_CDS) {
6552
} else if (sp2->subtype == FEATDEF_CDS && sp1->subtype != FEATDEF_CDS) {
6556
/* next compare internal intervals */
6558
numivals = MIN (sp1->numivals, sp2->numivals);
6559
if (numivals > 0 && sp1->ivals != NULL && sp2->ivals != NULL) {
6560
for (i = 0, j = sp1->numivals * 2, k = sp2->numivals * 2; i < numivals; i++) {
6562
/* check right interval */
6566
if (sp1->ivals [j] < sp2->ivals [k]) {
6568
} else if (sp1->ivals [j] > sp2->ivals [k]) {
6572
/* check left interval */
6576
if (sp1->ivals [j] < sp2->ivals [k]) {
6578
} else if (sp1->ivals [j] > sp2->ivals [k]) {
6584
/* one with fewer intervals goes first */
6586
if (sp1->numivals > sp2->numivals) {
6588
} else if (sp1->numivals < sp2->numivals) {
6592
/* next compare other feature subtypes */
6594
if (sp1->subtype < sp2->subtype) {
6596
} else if (sp1->subtype > sp2->subtype) {
6600
/* if identical cds ranges, compare codon_start */
6602
if (sp1->subtype == FEATDEF_CDS && sp2->subtype == FEATDEF_CDS) {
6605
if (sfp1 != NULL && sfp2 != NULL) {
6606
crp1 = (CdRegionPtr) sfp1->data.value.ptrvalue;
6607
crp2 = (CdRegionPtr) sfp2->data.value.ptrvalue;
6608
if (crp1 != NULL && crp2 != NULL) {
6609
if (crp1->frame > 1 || crp2->frame > 1) {
6610
if (crp1->frame < crp2->frame) {
6612
} else if (crp1->frame < crp2->frame) {
6620
/* then compare feature label */
6622
compare = StringCmp (sp1->label, sp2->label);
6625
} else if (compare < 0) {
6629
/* compare parent seq-annot by itemID (was sap pointer value) */
6633
if (sap1 != NULL && sap2 != NULL) {
6634
if (sap1->idx.itemID > sap2->idx.itemID) {
6636
} else if (sap1->idx.itemID < sap2->idx.itemID) {
6641
/* last comparison to make it absolutely deterministic */
6643
if (sp1->itemID > sp2->itemID) {
6645
} else if (sp1->itemID < sp2->itemID) {
6080
6652
/*****************************************************************************
6082
6654
* IndexSegmentedParts callback builds index to speed up mapping
7190
7820
if (grp == NULL) return FALSE;
7191
7821
if (grp != NULL && HasNoText (grp->locus) && HasNoText (grp->allele) &&
7192
7822
HasNoText (grp->desc) && HasNoText (grp->maploc) &&
7193
grp->db == NULL && grp->syn == NULL) return TRUE;
7823
HasNoText (grp->locus_tag) && grp->db == NULL &&
7824
grp->syn == NULL) return TRUE;
7828
static Boolean CheckInternalExonBoundaries (Int2 numivalsA, Int4Ptr ivalsA, Int2 numivalsB, Int4Ptr ivalsB)
7834
if (numivalsA > numivalsB) return FALSE;
7835
if (ivalsA == NULL || ivalsB == NULL) return TRUE;
7837
/* scan first exon-intron boundary against candidate start positions */
7839
for (i = 0; i <= numivalsB - numivalsA; i++) {
7840
if (ivalsA [1] == ivalsB [2 * i + 1]) break;
7842
if (i > numivalsB - numivalsA) return FALSE;
7844
/* scan subsequent exon-intron and intron-exon boundaries */
7846
for (j = 2; j <= 2 * numivalsA - 2; j++) {
7847
if (ivalsA [j] != ivalsB [2 * i + j]) return FALSE;
7853
static Boolean StrandsMatch (Uint1 featstrand, Uint1 locstrand)
7856
if (featstrand == locstrand) return TRUE;
7857
if (locstrand == Seq_strand_unknown && featstrand != Seq_strand_minus) return TRUE;
7858
if (featstrand == Seq_strand_unknown && locstrand != Seq_strand_minus) return TRUE;
7859
if (featstrand == Seq_strand_both && locstrand != Seq_strand_minus) return TRUE;
7860
if (locstrand == Seq_strand_both) return TRUE;
7197
7864
static Int4 TestForOverlap (SMFeatItemPtr feat, SeqLocPtr slp,
7198
Int4 left, Int4 right, Int2 overlapType)
7865
Int4 left, Int4 right, Int2 overlapType,
7866
Int2 numivals, Int4Ptr ivals)
7201
7869
SeqLocPtr a, b;
7230
7905
if (sfp != NULL) {
7231
7906
diff = SeqLocAinB (slp, sfp->location);
7232
7907
if (diff >= 0) {
7908
if (overlapType == LOCATION_SUBSET || numivals == 1 ||
7909
CheckInternalExonBoundaries (numivals, ivals, feat->numivals, feat->ivals)) {
7238
} else if (overlapType == INTERVAL_OVERLAP) {
7240
/* requires overlap between at least one pair of intervals */
7242
if ((feat->left <= left && feat->right > left) ||
7243
(feat->left < right && feat->right >= right)) {
7916
} else if (overlapType == INTERVAL_OVERLAP || overlapType == COMMON_INTERVAL) {
7918
/* requires overlap between at least one pair of intervals (INTERVAL_OVERLAP) */
7919
/* or one complete shared interval (COMMON_INTERVAL) */
7921
if (feat->right >= left && feat->left <= right) {
7244
7922
sfp = feat->sfp;
7245
7923
if (sfp != NULL) {
7246
7924
a = SeqLocFindNext (slp, NULL);
7247
7925
while (a != NULL) {
7248
7926
b = SeqLocFindNext (sfp->location, NULL);
7249
7927
while (b != NULL) {
7250
if (SeqLocCompare (a, b) != SLC_NO_MATCH) {
7251
diff = (left - feat->left) + (feat->right - right);
7928
if ((overlapType == INTERVAL_OVERLAP
7929
&& SeqLocCompare (a, b) != SLC_NO_MATCH)
7930
|| (overlapType == COMMON_INTERVAL
7931
&& SeqLocCompare (a, b) == SLC_A_EQ_B))
7933
diff = ABS (left - feat->left) + ABS (feat->right - right);
7254
7936
b = SeqLocFindNext (sfp->location, b);
7943
else if (overlapType == RANGE_MATCH)
7945
/* left and right ends must match exactly */
7946
if (feat->right == right && feat->left == left)
7955
static void SeqMgrBestOverlapSetContext (
7959
SeqMgrFeatContext PNTR context
7965
if (best != NULL && omdp != NULL && context != NULL) {
7967
context->entityID = ObjMgrGetEntityIDForPointer (omdp->dataptr);
7968
context->itemID = best->itemID;
7969
context->sfp = best->sfp;
7970
context->sap = best->sap;
7971
context->bsp = best->bsp;
7972
context->label = best->label;
7973
context->left = best->left;
7974
context->right = best->right;
7975
context->dnaStop = best->dnaStop;
7976
context->partialL = best->partialL;
7977
context->partialR = best->partialR;
7978
context->farloc = best->farloc;
7979
context->strand = best->strand;
7981
context->seqfeattype = bst->data.choice;
7983
context->seqfeattype = FindFeatFromFeatDefType (best->subtype);
7985
context->featdeftype = best->subtype;
7986
context->numivals = best->numivals;
7987
context->ivals = best->ivals;
7988
context->userdata = userdata;
7989
context->omdp = (Pointer) omdp;
7990
context->index = best->index + 1;
7265
7994
static SeqFeatPtr SeqMgrGetBestOverlappingFeat (SeqLocPtr slp, Uint2 subtype,
7266
7995
SMFeatItemPtr PNTR array,
7267
7996
Int4 num, Int4Ptr pos,
7268
7997
Int2 overlapType,
7269
SeqMgrFeatContext PNTR context)
7998
SeqMgrFeatContext PNTR context,
8001
SeqMgrFeatExploreProc userfunc)
7272
8004
SMFeatItemPtr best = NULL;
7274
8006
BioseqExtraPtr bspextra;
7277
8008
Uint2 entityID;
7278
8009
SMFeatItemPtr feat;
8011
Boolean goOn = TRUE;
7279
8012
Int4 hier = -1;
8015
Int4Ptr ivals = NULL;
7284
8019
Int4 max = INT4_MAX;
7286
8022
SeqEntryPtr oldscope;
7287
8023
ObjMgrDataPtr omdp;
7288
8024
SMFeatItemPtr prev;
8234
if (ivals != NULL) {
8235
ivals = MemFree (ivals);
7447
8238
if (best != NULL) {
7448
8239
if (pos != NULL) {
7449
8240
*pos = index + 1;
7451
8242
if (context != NULL) {
7453
context->entityID = ObjMgrGetEntityIDForPointer (omdp->dataptr);
7454
context->itemID = best->itemID;
7455
context->sfp = best->sfp;
7456
context->sap = best->sap;
7457
context->bsp = best->bsp;
7458
context->label = best->label;
7459
context->left = best->left;
7460
context->right = best->right;
7461
context->dnaStop = best->dnaStop;
7462
context->partialL = best->partialL;
7463
context->partialR = best->partialR;
7464
context->farloc = best->farloc;
7465
context->strand = best->strand;
7467
context->seqfeattype = bst->data.choice;
7469
context->seqfeattype = FindFeatFromFeatDefType (best->subtype);
7471
context->featdeftype = best->subtype;
7472
context->numivals = best->numivals;
7473
context->ivals = best->ivals;
7474
context->userdata = NULL;
7475
context->omdp = (Pointer) omdp;
7476
context->index = best->index + 1;
8243
SeqMgrBestOverlapSetContext (best, omdp, userdata, context);
7478
8245
return best->sfp;
8251
NLM_EXTERN Int4 TestFeatOverlap (SeqFeatPtr sfpA, SeqFeatPtr sfpB, Int2 overlapType)
8255
SMFeatItemPtr sfipA, sfipB;
8257
if (sfpA == NULL || sfpB == NULL) return -1;
8258
sfipA = SeqMgrFindSMFeatItemPtr (sfpA);
8259
sfipB = SeqMgrFindSMFeatItemPtr (sfpB);
8260
if (sfipA == NULL || sfipB == NULL) return -1;
8262
diff = TestForOverlap (sfipB, sfpA->location, sfipA->left, sfipA->right,
8263
overlapType, sfipA->numivals, sfipA->ivals);
8264
if (diff < 0) return -1;
8266
if (StrandsMatch (sfipB->strand, sfipA->strand)) {
7484
8273
NLM_EXTERN SeqFeatPtr LIBCALL SeqMgrGetOverlappingGene (SeqLocPtr slp, SeqMgrFeatContext PNTR context)
7487
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_GENE, NULL, 0, NULL, CONTAINED_WITHIN, context);
8276
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_GENE, NULL, 0, NULL, CONTAINED_WITHIN, context, NULL, NULL, NULL);
7490
8279
NLM_EXTERN SeqFeatPtr LIBCALL SeqMgrGetOverlappingmRNA (SeqLocPtr slp, SeqMgrFeatContext PNTR context)
7493
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_mRNA, NULL, 0, NULL, CONTAINED_WITHIN, context);
8282
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_mRNA, NULL, 0, NULL, CONTAINED_WITHIN, context, NULL, NULL, NULL);
8285
NLM_EXTERN SeqFeatPtr LIBCALL SeqMgrGetLocationSupersetmRNA (SeqLocPtr slp, SeqMgrFeatContext PNTR context)
8288
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_mRNA, NULL, 0, NULL, LOCATION_SUBSET, context, NULL, NULL, NULL);
7496
8291
NLM_EXTERN SeqFeatPtr LIBCALL SeqMgrGetOverlappingCDS (SeqLocPtr slp, SeqMgrFeatContext PNTR context)
7499
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_CDS, NULL, 0, NULL, CONTAINED_WITHIN, context);
8294
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_CDS, NULL, 0, NULL, CONTAINED_WITHIN, context, NULL, NULL, NULL);
7502
8297
NLM_EXTERN SeqFeatPtr LIBCALL SeqMgrGetOverlappingPub (SeqLocPtr slp, SeqMgrFeatContext PNTR context)
7505
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_PUB, NULL, 0, NULL, CONTAINED_WITHIN, context);
8300
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_PUB, NULL, 0, NULL, CONTAINED_WITHIN, context, NULL, NULL, NULL);
7508
8303
NLM_EXTERN SeqFeatPtr LIBCALL SeqMgrGetOverlappingSource (SeqLocPtr slp, SeqMgrFeatContext PNTR context)
7511
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_BIOSRC, NULL, 0, NULL, CONTAINED_WITHIN, context);
8306
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_BIOSRC, NULL, 0, NULL, CONTAINED_WITHIN, context, NULL, NULL, NULL);
8309
NLM_EXTERN SeqFeatPtr LIBCALL SeqMgrGetOverlappingOperon (SeqLocPtr slp, SeqMgrFeatContext PNTR context)
8312
return SeqMgrGetBestOverlappingFeat (slp, FEATDEF_operon, NULL, 0, NULL, CONTAINED_WITHIN, context, NULL, NULL, NULL);
7514
8315
/*****************************************************************************
7717
8518
return SeqMgrGetBestOverlappingFeat (slp, subtype, (SMFeatItemPtr PNTR) featarray,
7718
numfeats, position, overlapType, context);
8519
numfeats, position, overlapType, context, NULL, NULL, NULL);
8522
NLM_EXTERN Int2 LIBCALL SeqMgrGetAllOverlappingFeatures (SeqLocPtr slp, Uint2 subtype,
8527
SeqMgrFeatExploreProc userfunc)
8530
SeqMgrFeatContext context;
8533
SeqMgrGetBestOverlappingFeat (slp, subtype, (SMFeatItemPtr PNTR) featarray,
8534
numfeats, NULL, overlapType, &context, &count,
8535
userdata, userfunc);
7721
8540
NLM_EXTERN SeqFeatPtr LIBCALL SeqMgrGetFeatureInIndex (BioseqPtr bsp, VoidPtr featarray,
7722
Int4 numfeats, Uint2 index,
8541
Int4 numfeats, Uint4 index,
7723
8542
SeqMgrFeatContext PNTR context)
9200
NLM_EXTERN Int4 LIBCALL SeqMgrExploreFeatures (BioseqPtr bsp, Pointer userdata,
9201
SeqMgrFeatExploreProc userfunc,
9202
SeqLocPtr locationFilter,
9203
BoolPtr seqFeatFilter,
9204
BoolPtr featDefFilter)
9207
return SeqMgrExploreFeaturesInt (bsp, userdata, userfunc, locationFilter, seqFeatFilter, featDefFilter, FALSE);
9210
NLM_EXTERN Int4 LIBCALL SeqMgrExploreFeaturesRev (BioseqPtr bsp, Pointer userdata,
9211
SeqMgrFeatExploreProc userfunc,
9212
SeqLocPtr locationFilter,
9213
BoolPtr seqFeatFilter,
9214
BoolPtr featDefFilter)
9217
return SeqMgrExploreFeaturesInt (bsp, userdata, userfunc, locationFilter, seqFeatFilter, featDefFilter, TRUE);
8336
9220
static Int2 VisitDescriptorsPerSeqEntry (Uint2 entityID, SeqEntryPtr sep,
8337
9221
Pointer userdata, SeqMgrDescExploreProc userfunc,
8338
9222
BoolPtr seqDescFilter)
9562
/*****************************************************************************
9564
* TrimLocInSegment takes a location on an indexed far segmented part and trims
9565
* trims it to the region referred to by the parent segmented or delta bioseq.
9567
* Only implemented for seqloc_int components, not seqloc_point
9569
*****************************************************************************/
9571
NLM_EXTERN SeqLocPtr TrimLocInSegment (
9580
BioseqExtraPtr bspextra;
9586
SMSeqIdxPtr PNTR partsBySeqId;
9587
SeqLocPtr rsult = NULL;
9588
SMSeqIdxPtr segpartptr;
9589
CharPtr seqIdOfPart;
9595
Int4 start, stop, swap;
9597
if (master == NULL || location == NULL) return NULL;
9599
omdp = SeqMgrGetOmdpForBioseq (master);
9600
if (omdp == NULL || omdp->datatype != OBJ_BIOSEQ) return NULL;
9601
bspextra = (BioseqExtraPtr) omdp->extradata;
9602
if (bspextra == NULL) return NULL;
9604
partsBySeqId = bspextra->partsBySeqId;
9605
if (partsBySeqId == NULL || bspextra->numsegs < 1) return NULL;
9610
if (p5ptr != NULL) {
9613
if (p3ptr != NULL) {
9617
for (slp = SeqLocFindNext (location, NULL);
9619
slp = SeqLocFindNext (location, slp)) {
9620
if (slp->choice != SEQLOC_INT) continue;
9621
sint = (SeqIntPtr) slp->data.ptrvalue;
9622
if (sint == NULL) continue;
9623
strand = sint->strand;
9625
bsp = BioseqFind (sint->id);
9626
if (bsp == NULL) continue;
9628
for (sip = bsp->id; sip != NULL; sip = sip->next) {
9629
if (! MakeReversedSeqIdString (sip, buf, sizeof (buf) - 1)) continue;
9632
R = bspextra->numsegs - 1;
9635
segpartptr = partsBySeqId [mid];
9636
compare = StringCmp (segpartptr->seqIdOfPart, buf);
9644
segpartptr = partsBySeqId [R];
9645
seqIdOfPart = segpartptr->seqIdOfPart;
9647
while (R < bspextra->numsegs && StringCmp (seqIdOfPart, buf) == 0) {
9652
if ((sint->from <= segpartptr->from && sint->to > segpartptr->from) ||
9653
(sint->from < segpartptr->to && sint->to >= segpartptr->to)) {
9655
if (sint->from < segpartptr->from) {
9656
start = segpartptr->from;
9657
if (strand == Seq_strand_minus || strand == Seq_strand_both_rev) {
9663
if (sint->to > segpartptr->to) {
9664
stop = segpartptr->to;
9665
if (strand == Seq_strand_minus || strand == Seq_strand_both_rev) {
9672
if (strand == Seq_strand_minus || strand == Seq_strand_both_rev) {
9678
rsult = AddIntervalToLocation (rsult, sint->id, start, stop, FALSE, FALSE);
9682
if (R < bspextra->numsegs) {
9683
segpartptr = partsBySeqId [R];
9684
seqIdOfPart = segpartptr->seqIdOfPart;
9692
if (p5ptr != NULL) {
9695
if (p3ptr != NULL) {
9702
static void LockAllBioseqs (BioseqPtr bsp, Pointer userdata);
8678
9704
static void LockAllSegments (SeqLocPtr slp, ValNodePtr PNTR vnpp)
8821
9875
return ValNodeFree (bsplist);
9878
/*****************************************************************************
9881
* registers the GiToSeqID precache function
9883
* calls any registered function to preload the cache
9885
*****************************************************************************/
9887
NLM_EXTERN void LIBCALL SeqMgrSetPreCache (SIDPreCacheFunc func)
9892
smp = SeqMgrWriteLock ();
9893
if (smp == NULL) return;
9894
smp->seq_id_precache_func = func;
9898
NLM_EXTERN Int4 LookupFarSeqIDs (
9908
SIDPreCacheFunc func;
9911
smp = SeqMgrReadLock ();
9912
if (smp == NULL) return 0;
9913
func = smp->seq_id_precache_func;
9915
if (func == NULL) return 0;
9916
return (*func) (sep, components, locations, products, alignments, history);
9919
/*****************************************************************************
9921
* SeqMgrSetSeqIdSetFunc
9922
* registers the GiToSeqIdSet lookup function
9924
* calls any registered function to lookup the set of SeqIds
9926
*****************************************************************************/
9928
NLM_EXTERN void LIBCALL SeqMgrSetSeqIdSetFunc (SeqIdSetLookupFunc func)
9933
smp = SeqMgrWriteLock ();
9934
if (smp == NULL) return;
9935
smp->seq_id_set_lookup_func = func;
9939
NLM_EXTERN SeqIdPtr LIBCALL GetSeqIdSetForGI (Int4 gi)
9942
SeqIdSetLookupFunc func;
9945
smp = SeqMgrReadLock ();
9946
if (smp == NULL) return 0;
9947
func = smp->seq_id_set_lookup_func;
9949
if (func == NULL) return 0;
9950
return (*func) (gi);
9953
/*****************************************************************************
9956
* registers the GiToSeqLen lookup function
9957
* SeqMgrSetAccnVerFunc
9958
* registers the GiToAccnVer lookup function
9960
*****************************************************************************/
9962
NLM_EXTERN void LIBCALL SeqMgrSetLenFunc (SeqLenLookupFunc func)
9967
smp = SeqMgrWriteLock ();
9968
if (smp == NULL) return;
9969
smp->seq_len_lookup_func = func;
9973
NLM_EXTERN void LIBCALL SeqMgrSetAccnVerFunc (AccnVerLookupFunc func)
9978
smp = SeqMgrWriteLock ();
9979
if (smp == NULL) return;
9980
smp->accn_ver_lookup_func = func;
8824
9984
/*******************************************************************
8826
9986
* SeqEntryAsnOut()