1 #ifndef EQUIV_RANGE__HPP 2 #define EQUIV_RANGE__HPP 3 4 /* $Id: equiv_range.hpp 434423 2014-05-07 16:41:16Z boukn $ 5 * =========================================================================== 6 * 7 * PUBLIC DOMAIN NOTICE 8 * National Center for Biotechnology Information 9 * 10 * This software/database is a "United States Government Work" under the 11 * terms of the United States Copyright Act. It was written as part of 12 * the author's official duties as a United States Government employee and 13 * thus cannot be copyrighted. This software/database is freely available 14 * to the public for use. The National Library of Medicine and the U.S. 15 * Government have not placed any restriction on its use or reproduction. 16 * 17 * Although all reasonable efforts have been taken to ensure the accuracy 18 * and reliability of the software and data, the NLM and the U.S. 19 * Government do not and cannot warrant the performance or results that 20 * may be obtained by using this software or data. The NLM and the U.S. 21 * Government disclaim all warranties, express or implied, including 22 * warranties of performance, merchantability or fitness for any particular 23 * purpose. 24 * 25 * Please cite the author in any work or product based on this material. 26 * 27 * =========================================================================== 28 * 29 * Author: Nathan Bouk 30 * 31 * File Description: 32 * 33 */ 34 35 #include <objects/seqloc/seqloc__.hpp> 36 #include <objmgr/scope.hpp> 37 #include <util/range.hpp> 38 39 40 41 BEGIN_SCOPE(ncbi) 42 43 BEGIN_SCOPE(objects) 44 class CSeq_id; 45 class CSeq_align; 46 END_SCOPE(objects) 47 48 class CEquivRange; 49 typedef vector<CEquivRange> TEquivList; 50 51 class CEquivRange 52 { 53 public: CEquivRange()54 CEquivRange() : AlignId(0),SegmtId(0),SplitId(0) { ; } 55 56 CRange<TSeqPos> Query; 57 CRange<TSeqPos> Subjt; 58 objects::ENa_strand Strand; 59 int Intercept; 60 int Matches; 61 int MisMatches; 62 vector<TSeqPos> MisMatchSubjtPoints; 63 64 int AlignId; 65 int SegmtId; 66 int SplitId; 67 Empty() const68 bool Empty() const { 69 return (Query.Empty() || Subjt.Empty()); 70 } 71 NotEmpty() const72 bool NotEmpty() const { 73 return (Query.NotEmpty() && Subjt.NotEmpty()); 74 } 75 IntersectingWith(const CEquivRange & Other) const76 bool IntersectingWith(const CEquivRange& Other) const { 77 return (Query.IntersectingWith(Other.Query) || 78 Subjt.IntersectingWith(Other.Subjt)); 79 } 80 AbuttingWith(const CEquivRange & Other) const81 bool AbuttingWith(const CEquivRange& Other) const { 82 if(Strand != Other.Strand) 83 return false; 84 85 if (!Query.AbuttingWith(Other.Query) || 86 !Subjt.AbuttingWith(Other.Subjt)) 87 return false; 88 89 90 return true; 91 } 92 93 94 enum ERelative { 95 eWtf = 0x00, 96 eIntersects = 0x01, 97 eInterQuery = 0x02, 98 eInterSubjt = 0x04, 99 eBefore = 0x10, 100 eAfter = 0x20, 101 eAbove = 0x40, 102 eUnder = 0x80 103 }; 104 105 // How is Check positioned relative to this 106 ERelative CalcRelative(const CEquivRange& Check) const; 107 ERelative CalcRelativeDuo(const CEquivRange& Check) const; 108 109 static TSeqPos Distance(const CEquivRange& A, const CEquivRange& B); 110 static TSeqPos Distance(const TEquivList& A, const TEquivList& B); 111 }; 112 113 class CEquivRangeBuilder 114 { 115 public: 116 117 CEquivRangeBuilder(); 118 119 bool SplitIntersections(const TEquivList& Originals, 120 TEquivList& Splits); 121 bool MergeAbuttings(const TEquivList& Originals, TEquivList& Merges); 122 123 124 void ExtractRangesFromSeqAlign(const objects::CSeq_align& Alignment, 125 TEquivList& Equivs); 126 127 void CalcMatches(objects::CBioseq_Handle QueryHandle, 128 objects::CBioseq_Handle SubjtHandle, 129 TEquivList& Equivs); 130 131 private: 132 int x_GAlignId; 133 int x_GSegmtId; 134 int x_GSplitId; 135 136 CEquivRange SliceOnQuery(const CEquivRange& Original, const CRange<TSeqPos>& pQuery); 137 CEquivRange SliceOnSubjt(const CEquivRange& Original, const CRange<TSeqPos>& pSubjt); 138 CEquivRange Merge(const CEquivRange& First, const CEquivRange& Second); 139 140 }; 141 142 143 CNcbiOstream& operator<<(CNcbiOstream& out, const CEquivRange& range); 144 145 string s_RelToStr(CEquivRange::ERelative rel); 146 147 bool operator==(const CEquivRange& A, const CEquivRange& B); 148 bool operator<(const CEquivRange& A, const CEquivRange& B); 149 150 bool s_SortEquivBySubjt(const CEquivRange& A, const CEquivRange& B); 151 152 END_SCOPE(ncbi) 153 154 #endif // end EQUIV_RANGE__HPP 155