LocARNA-1.9.2
|
00001 #ifndef LOCARNA_TRACE_CONTROLLER_HH 00002 #define LOCARNA_TRACE_CONTROLLER_HH 00003 00004 #ifdef HAVE_CONFIG_H 00005 #include <config.h> 00006 #endif 00007 00008 #include <vector> 00009 #include <assert.h> 00010 00011 #include "aux.hh" 00012 #include "multiple_alignment.hh" 00013 00014 namespace LocARNA { 00015 00016 class Sequence; 00017 class AnchorConstraints; 00018 00026 class TraceRange { 00027 public: 00029 typedef MultipleAlignment::SeqEntry SeqEntry; 00030 00032 typedef std::pair<SeqEntry, SeqEntry> seqentry_pair_t; 00033 00044 static seqentry_pair_t 00045 remove_common_gaps(const SeqEntry &aliA, const SeqEntry &aliB); 00046 00047 protected: 00048 std::vector<size_t> min_col_; 00049 std::vector<size_t> max_col_; 00050 00051 TraceRange() {} 00052 00053 public: 00075 TraceRange(const SeqEntry &pseqA, 00076 const SeqEntry &pseqB, 00077 const SeqEntry &aliA, 00078 const SeqEntry &aliB, 00079 size_type delta); 00080 00095 TraceRange(size_type lenA, 00096 size_type lenB, 00097 const std::vector<TraceRange> &trs, 00098 size_type delta); 00099 00108 size_type 00109 consensus_cost(size_type i, 00110 size_type j, 00111 const std::vector<TraceRange> &trs) const; 00112 00117 size_t 00118 rows() const { 00119 return min_col_.size() - 1; 00120 } 00121 00127 size_t 00128 min_col(size_t i) const { 00129 return min_col_[i]; 00130 } 00131 00137 size_t 00138 max_col(size_t i) const { 00139 return max_col_[i]; 00140 } 00141 00147 void 00148 print_debug(std::ostream &out) const; 00149 }; 00150 00152 class MatchController { 00153 public: 00160 virtual bool 00161 is_valid_match(size_t i, size_t j) const = 0; 00162 00163 virtual ~MatchController(); 00164 }; 00165 00177 class TraceController : public TraceRange, public MatchController { 00178 private: 00179 // The delimiter character separating the two sequences in the alignment 00180 // string 00181 static const char delimiter = '&'; 00182 00187 void 00188 merge_in_trace_range(const TraceRange &tr); 00189 00191 const size_type delta_; 00192 00193 // /** 00194 // * switch between strict and relaxed merging of pairwise trace 00195 // * ranges 00196 // */ 00197 // const bool relaxed_merging_; 00198 00199 public: 00214 TraceController(const Sequence &seqA, 00215 const Sequence &seqB, 00216 const MultipleAlignment *ma, 00217 int delta, 00218 bool relaxed_merging = false); 00219 00221 virtual ~TraceController(); 00222 00232 void 00233 restrict_by_anchors(const AnchorConstraints &constraints); 00234 00241 bool 00242 is_valid(size_type i, size_type j) const; 00243 00250 virtual bool 00251 is_valid_match(size_type i, size_type j) const; 00252 00257 size_type 00258 get_delta() const { 00259 return delta_; 00260 } 00261 00262 private: 00275 void 00276 constrain_wo_ref(size_type lenA, size_type lenB, size_type delta); 00277 }; 00278 00279 inline bool 00280 TraceController::is_valid(size_type i, size_type j) const { 00281 return min_col(i) <= j && j <= max_col(i); 00282 } 00283 00284 inline bool 00285 TraceController::is_valid_match(size_type i, size_type j) const { 00286 return is_valid(i, j) && is_valid(i - 1, j - 1); 00287 } 00288 00289 } // end namespace 00290 00291 #endif /* LOCARNA_TRACE_CONTROLLER_HH */