sequence.cpp
来自「ncbi源码」· C++ 代码 · 共 2,155 行 · 第 1/5 页
CPP
2,155 行
// The second point of the bond is set -- overlap return eOverlap; // The second point of the bond is not set -- same } else { return eSame; } case 2: // Unlikely case -- can happen if both points of the bond are the same return eSame; default: // All that's left is no overlap return eNoOverlap; }}// Compare packed point with an intervalinlineECompare s_Compare(const CPacked_seqpnt& points, const CSeq_interval& interval, CScope* scope){ // If points and interval are from same bioseq and some points are // in interval, then overlap. If all points are in interval, then // contained. Else, no overlap. if ( IsSameBioseq(points.GetId(), interval.GetId(), scope) ) { bool got_one = false; bool missed_one = false; TSeqPos from = interval.GetFrom(); TSeqPos to = interval.GetTo(); // This loop will only be executed if points.GetPoints().size() > 0 ITERATE(CSeq_loc::TPoints, it, points.GetPoints()) { if (from <= *it && to >= *it) { got_one = true; } else { missed_one = true; } if (got_one && missed_one) { break; } } if ( !got_one ) { return eNoOverlap; } else if ( missed_one ) { return eOverlap; } else { return eContained; } } return eNoOverlap;}// Compare two packed pointsinlineECompare s_Compare(const CPacked_seqpnt& pntsA, const CPacked_seqpnt& pntsB, CScope* scope){ // If CPacked_seqpnts from different CBioseqs, then no overlap if ( !IsSameBioseq(pntsA.GetId(), pntsB.GetId(), scope) ) { return eNoOverlap; } const CSeq_loc::TPoints& pointsA = pntsA.GetPoints(); const CSeq_loc::TPoints& pointsB = pntsB.GetPoints(); // Check for equality. Note order of points is significant if (pointsA.size() == pointsB.size()) { CSeq_loc::TPoints::const_iterator iA = pointsA.begin(); CSeq_loc::TPoints::const_iterator iB = pointsB.begin(); bool check_containtment = false; // This loop will only be executed if pointsA.size() > 0 while (iA != pointsA.end()) { if (*iA != *iB) { check_containtment = true; break; } ++iA; ++iB; } if ( !check_containtment ) { return eSame; } } // Check for containment size_t hits = 0; // This loop will only be executed if pointsA.size() > 0 ITERATE(CSeq_loc::TPoints, iA, pointsA) { ITERATE(CSeq_loc::TPoints, iB, pointsB) { hits += (*iA == *iB) ? 1 : 0; } } if (hits == pointsA.size()) { return eContained; } else if (hits == pointsB.size()) { return eContains; } else if (hits == 0) { return eNoOverlap; } else { return eOverlap; }}// Compare packed point with bondinlineECompare s_Compare(const CPacked_seqpnt& points, const CSeq_bond& bond, CScope* scope){ // If all set bond points (can be just 1) are in points, then contains. If // one, but not all bond points in points, then overlap, else, no overlap const CSeq_point& bondA = bond.GetA(); ECompare cmp = eNoOverlap; // Check for containment of the first residue in the bond if ( IsSameBioseq(points.GetId(), bondA.GetId(), scope) ) { TSeqPos pntA = bondA.GetPoint(); // This loop will only be executed if points.GetPoints().size() > 0 ITERATE(CSeq_loc::TPoints, it, points.GetPoints()) { if (pntA == *it) { cmp = eContains; break; } } } // Check for containment of the second residue of the bond if it exists if ( !bond.IsSetB() ) { return cmp; } const CSeq_point& bondB = bond.GetB(); if ( !IsSameBioseq(points.GetId(), bondB.GetId(), scope) ) { return cmp; } TSeqPos pntB = bondB.GetPoint(); // This loop will only be executed if points.GetPoints().size() > 0 ITERATE(CSeq_loc::TPoints, it, points.GetPoints()) { if (pntB == *it) { if (cmp == eContains) { return eContains; } else { return eOverlap; } } } return cmp == eContains ? eOverlap : cmp;}// Compare a bond with a bondinlineECompare s_Compare(const CSeq_bond& bndA, const CSeq_bond& bndB, CScope* scope){ // Performs two comparisons. First comparison is comparing the a points // of each bond and the b points of each bond. The second comparison // compares point a of bndA with point b of bndB and point b of bndA // with point a of bndB. The best match is used. ECompare cmp1, cmp2; int div = static_cast<int> (eSame); // Compare first points in each bond cmp1 = s_Compare(bndA.GetA(), bndB.GetA(), scope); // Compare second points in each bond if both exist if (bndA.IsSetB() && bndB.IsSetB() ) { cmp2 = s_Compare(bndA.GetB(), bndB.GetB(), scope); } else { cmp2 = eNoOverlap; } int count1 = (static_cast<int> (cmp1) + static_cast<int> (cmp2)) / div; // Compare point A of bndA with point B of bndB (if it exists) if ( bndB.IsSetB() ) { cmp1 = s_Compare(bndA.GetA(), bndB.GetB(), scope); } else { cmp1 = eNoOverlap; } // Compare point B of bndA (if it exists) with point A of bndB. if ( bndA.IsSetB() ) { cmp2 = s_Compare(bndA.GetB(), bndB.GetA(), scope); } else { cmp2 = eNoOverlap; } int count2 = (static_cast<int> (cmp1) + static_cast<int> (cmp2)) / div; // Determine best match int count = (count1 > count2) ? count1 : count2; // Return based upon count in the obvious way switch ( count ) { case 1: if (!bndA.IsSetB() && !bndB.IsSetB()) { return eSame; } else if ( !bndB.IsSetB() ) { return eContains; } else if ( !bndA.IsSetB() ) { return eContained; } else { return eOverlap; } case 2: return eSame; default: return eNoOverlap; }}// Compare an interval with a whole sequenceinlineECompare s_Compare(const CSeq_interval& interval, const CSeq_id& id, CScope* scope){ // Return the complement of comparing id with interval return s_Complement(s_Compare(id, interval, scope));}// Compare an interval with a packed pointinlineECompare s_Compare(const CSeq_interval& interval, const CPacked_seqpnt& packed, CScope* scope){ // Return the complement of comparing packed points and an interval return s_Complement(s_Compare(packed, interval, scope));}// Compare a Packed Interval with one of Whole, Interval, Point,// Packed Point, or Bond.template <class T>ECompare s_Compare(const CPacked_seqint& intervals, const T& slt, CScope* scope){ // Check that intervals is not empty if(intervals.Get().size() == 0) { return eNoOverlap; } ECompare cmp1 , cmp2; CSeq_loc::TIntervals::const_iterator it = intervals.Get().begin(); cmp1 = s_Compare(**it, slt, scope); // This loop will be executed only if intervals.Get().size() > 1 for (++it; it != intervals.Get().end(); ++it) { cmp2 = s_Compare(**it, slt, scope); cmp1 = static_cast<ECompare> (s_RetA[cmp1][cmp2]); } return cmp1;}// Compare one of Whole, Interval, Point, Packed Point, or Bond with a// Packed Interval.template <class T>ECompare s_Compare(const T& slt, const CPacked_seqint& intervals, CScope* scope){ // Check that intervals is not empty if(intervals.Get().size() == 0) { return eNoOverlap; } ECompare cmp1 , cmp2; CSeq_loc::TIntervals::const_iterator it = intervals.Get().begin(); cmp1 = s_Compare(slt, **it, scope); // This loop will be executed only if intervals.Get().size() > 1 for (++it; it != intervals.Get().end(); ++it) { cmp2 = s_Compare(slt, **it, scope); cmp1 = static_cast<ECompare> (s_RetB[cmp1][cmp2]); } return cmp1;}// Compare a CSeq_loc and a CSeq_interval. Used by s_Compare_Help below// when comparing list<CRef<CSeq_loc>> with list<CRef<CSeq_interval>>.// By wrapping the CSeq_interval in a CSeq_loc, s_Compare(const CSeq_loc&,// const CSeq_loc&, CScope*) can be called. This permits CPacked_seqint type// CSeq_locs to be treated the same as CSeq_loc_mix and CSeq_loc_equiv type// CSeq_locsinlineECompare s_Compare(const CSeq_loc& sl, const CSeq_interval& si, CScope* scope){ CSeq_loc nsl; nsl.SetInt(const_cast<CSeq_interval&>(si)); return s_Compare(sl, nsl, scope);}// Compare a CSeq_interval and a CSeq_loc. Used by s_Compare_Help below// when comparing TLocations with TIntervals. By// wrapping the CSeq_interval in a CSeq_loc, s_Compare(const CSeq_loc&,// const CSeq_loc&, CScope*) can be called. This permits CPacked_seqint type// CSeq_locs to be treated the same as CSeq_loc_mix and CSeq_loc_equiv type// CSeq_locsinlineECompare s_Compare(const CSeq_interval& si, const CSeq_loc& sl, CScope* scope){ CSeq_loc nsl; nsl.SetInt(const_cast<CSeq_interval&>(si)); return s_Compare(nsl, sl, scope);}// Called by s_Compare() below for <CSeq_loc, CSeq_loc>,// <CSeq_loc, CSeq_interval>, <CSeq_interval, CSeq_loc>, and// <CSeq_interval, CSeq_interval>template <class T1, class T2>ECompare s_Compare_Help(const list<CRef<T1> >& mec, const list<CRef<T2> >& youc, const CSeq_loc& you, CScope* scope){ // If either mec or youc is empty, return eNoOverlap if(mec.size() == 0 || youc.size() == 0) { return eNoOverlap; } typename list<CRef<T1> >::const_iterator mit = mec.begin(); typename list<CRef<T2> >::const_iterator yit = youc.begin(); ECompare cmp1, cmp2; // Check for equality of the lists. Note, order of the lists contents are // significant if (mec.size() == youc.size()) { bool check_contained = false; for ( ; mit != mec.end() && yit != youc.end(); ++mit, ++yit) { if (s_Compare(**mit, ** yit, scope) != eSame) { check_contained = true; break; } } if ( !check_contained ) { return eSame; } } // Check if mec contained in youc mit = mec.begin(); yit = youc.begin(); bool got_one = false; while (mit != mec.end() && yit != youc.end()) { cmp1 = s_Compare(**mit, **yit, scope); switch ( cmp1 ) { case eNoOverlap: ++yit; break; case eSame: ++mit; ++yit; got_one = true; break; case eContained: ++mit; got_one = true; break; default: got_one = true; // artificial trick -- just to get out the loop "prematurely" yit = youc.end(); } } if (mit == mec.end()) { return eContained; } // Check if mec contains youc mit = mec.begin(); yit = youc.begin(); while (mit != mec.end() && yit != youc.end() ) { cmp1 = s_Compare(**yit, **mit, scope); switch ( cmp1 ) { case eNoOverlap: ++mit; break; case eSame: ++mit; ++yit; got_one = true; break; case eContained: ++yit; got_one = true; break; default: got_one = true; // artificial trick -- just to get out the loop "prematurely" mit = mec.end(); } } if (yit == youc.end()) { return eContains; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?