00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CGATOOLS_CGDATA_LIBRARY_READER_HPP_
00016 #define CGATOOLS_CGDATA_LIBRARY_READER_HPP_ 1
00017
00019
00020 #include "cgatools/core.hpp"
00021 #include <boost/noncopyable.hpp>
00022 #include <boost/filesystem.hpp>
00023 #include <boost/regex.hpp>
00024 #include <boost/array.hpp>
00025
00026 namespace cgatools { namespace cgdata {
00027
00029 template <class T>
00030 class GapTable
00031 {
00032 public:
00033 class GapsRecord
00034 {
00035 friend class GapTable;
00036 public:
00037 bool operator== (const T& gaps) const {
00038 return gaps_ == gaps;
00039 }
00040
00041 bool operator< (const GapsRecord& r) const {
00042 return gaps_ < r.gaps_;
00043 }
00044
00045 GapsRecord(const T &gaps, double frequency_ = 0)
00046 : gaps_(gaps), frequency_(frequency_) {}
00047
00048 T gaps_;
00049 double frequency_;
00050
00051 protected:
00052 GapsRecord()
00053 : frequency_(0) {}
00054
00055 };
00056 typedef std::vector<GapsRecord> Table;
00057
00058 GapTable(const std::string& fname)
00059 {
00060 load(fname);
00061 }
00062
00063 double getFrequency( const T& gaps, double outsideTheRange=0 )
00064 {
00065 GapsRecord record(gaps);
00066 typename Table::const_iterator it=std::lower_bound(records_.begin(),records_.end(),GapsRecord(gaps));
00067
00068 if (it!=records_.end())
00069 {
00070 if (it->gaps_==gaps)
00071 return it->frequency_;
00072 if (records_.front()<it->gaps_)
00073 return 0;
00074 }
00075 return outsideTheRange;
00076 }
00077
00078
00079 protected:
00080 void load(const std::string& fname);
00081
00082 Table records_;
00083 };
00084
00086 typedef boost::array<int8_t,3> SmallGapTuple;
00087 typedef int MateGapSize;
00088
00089 typedef GapTable<SmallGapTuple> WobbleGapTable;
00090 typedef GapTable<MateGapSize> MateGapTable;
00091
00092 } }
00093
00094 #endif // CGATOOLS_CGDATA_LIBRARY_READER_HPP_