LocARNA-1.9.2
|
00001 #ifndef LOCARNA_BASE_PAIR_FILTER 00002 #define LOCARNA_BASE_PAIR_FILTER 00003 00004 #ifdef HAVE_CONFIG_H 00005 #include <config.h> 00006 #endif 00007 00008 namespace LocARNA { 00009 namespace BasePairFilter { 00010 00012 typedef std::pair<size_t, size_t> bp_t; 00013 00017 class Filter { 00018 public: 00019 Filter(){}; 00020 00021 virtual ~Filter(){}; 00022 00023 virtual bool 00024 operator()(size_t i, size_t j) const { 00025 assert(1 <= i); // sequences are 1-based 00026 assert(i <= j); 00027 return true; 00028 } 00029 00030 virtual bool 00031 operator()(const bp_t &bp) const { 00032 return (*this)(bp.first, bp.second); 00033 } 00034 }; 00035 00039 class BPMinLoopSize : public Filter { 00040 size_t mls_; 00041 00042 public: 00046 explicit BPMinLoopSize(size_t mls) : Filter(), mls_(mls) {} 00047 00050 ~BPMinLoopSize(){}; 00051 00057 bool 00058 operator()(size_t i, size_t j) const { 00059 assert(i >= 1); 00060 return i + mls_ < j; 00061 } 00062 }; 00063 00067 class SpanRange : public Filter { 00068 size_t lo_; 00069 size_t up_; 00070 00071 public: 00078 SpanRange(size_t lo, size_t up) : Filter(), lo_(lo), up_(up) {} 00079 00082 ~SpanRange(){}; 00083 00089 bool 00090 operator()(size_t i, size_t j) const { 00091 assert(i <= j); 00092 return lo_ <= (j - i + 1) && (up_ == 0 || (j - i + 1) <= up_); 00093 } 00094 }; 00095 00099 class Canonical : public Filter { 00100 const std::string &sequence_; 00101 00102 public: 00106 explicit Canonical(const std::string &sequence) 00107 : Filter(), sequence_(sequence) {} 00108 00111 ~Canonical(){}; 00112 00119 bool 00120 operator()(size_t i, size_t j) const { 00121 return Filter::operator()(i, j) && 00122 canonical(sequence_[i], sequence_[j]); 00123 } 00124 00125 private: 00126 static bool 00127 canonical(char x, char y) { 00128 static std::string cpairs = "AUCGGUUAGCUG"; 00129 for (size_t i = 0; i < cpairs.length(); i += 2) { 00130 if (x == cpairs[i] && y == cpairs[i + 1]) 00131 return true; 00132 } 00133 return false; 00134 } 00135 }; 00136 00137 class Combined : public Filter { 00138 const Filter &fa_; 00139 const Filter &fb_; 00140 00141 public: 00142 Combined(const Filter &fa, const Filter &fb) 00143 : Filter(), fa_(fa), fb_(fb) {} 00144 00145 ~Combined() {} 00146 00147 bool 00148 operator()(size_t i, size_t j) const { 00149 return fa_(i, j) && fb_(i, j); 00150 } 00151 }; 00152 00153 } // end namespace BasePairFilter 00154 } // end namespace LocARNA 00155 00156 #endif // LOCARNA_BASE_PAIR_FILTER