Interval.h
Go to the documentation of this file.00001 #ifndef INTERVAL_H
00002 #define INTERVAL_H
00003
00004 #include <iostream>
00005 #include <list>
00006 #include <vector>
00007 #include <cstdlib>
00008
00009 using namespace std;
00010
00024 class Interval {
00025 public:
00026 Interval() : b(-1), e(-1) { }
00027 Interval(const int bb, const int ee) : b(bb), e(ee) { }
00028 Interval(const Interval &iv) : b(iv.b), e(iv.e) { }
00032 Interval(const string &str);
00033 virtual ~Interval() { }
00034
00035 friend ostream& operator<<(ostream& ous, const Interval& iv) {
00036 ous << iv.b << "-" << iv.e; return ous; }
00037
00038 int overlap(const Interval &i) const;
00039 int overlap(const int bb, const int ee) const;
00049 virtual int merge(Interval *i, const int cut=5);
00050 virtual string toDelimitedString(const string &dl="\t") const;
00051 bool less(const Interval &iv) const {
00052 return b<iv.b? true : (e<iv.e? true : false); }
00053 bool operator<(const Interval &iv) const { return less(iv); }
00054 bool before(const Interval &iv) const { return e < iv.b; }
00055 bool after(const Interval &iv) const { return b > iv.e; }
00056 bool isNull() const { return b==-1 && e==-1; }
00057
00058 void setBegin(const int bb) { b=bb; }
00059 void setEnd(const int ee) { e=ee; }
00060 void set(const Interval &iv) { b=iv.b; e=iv.e; }
00063 int getBegin() const { return b; }
00065 int begin() const { return b; }
00066 int getEnd() const { return e; }
00067 int end() const { return e; }
00072 virtual int size() const { return 0; }
00078 int length() const { return e-b+1; }
00079
00080 private:
00081 int b, e;
00082 };
00083
00092 class IntervalPile : public Interval {
00093 public:
00094 IntervalPile() : Interval(), members() { }
00095 IntervalPile(Interval* ip) : Interval(*ip), members() {
00096 members.push_back(ip); }
00099 ~IntervalPile();
00116 int merge(Interval *ip, const int cut=5);
00124 int add(Interval *i);
00127 int size() const { return members.size(); }
00128 string toDelimitedString(const string &dl="\t") const;
00129
00130 protected:
00135 vector<Interval*> members;
00136 };
00137
00147 class HalfAlignInterval : public Interval {
00148 public:
00149 HalfAlignInterval(const int bb, const int ee, int iden, int alen, float cc)
00150 : Interval(bb,ee), identical(iden), alnlen(alen), cov(cc) { }
00151 HalfAlignInterval(const HalfAlignInterval &i)
00152 : Interval(i), identical(i.identical), alnlen(i.alnlen), cov(i.cov) { }
00153 int getIdentical() const { return identical; }
00154 float getIdentity() const { return static_cast<float>(identical)/alnlen; }
00155 int getAlnlen() const { return alnlen; }
00156 float getCov() const { return cov; }
00157
00158 private:
00160 int identical;
00162 int alnlen;
00169 float cov;
00170 };
00171
00175 class HalfAlignPile : public IntervalPile {
00176 public:
00177 HalfAlignPile() : IntervalPile(), identity(-1.0), qcov(-1.0),
00178 tcov(-1.0) { }
00179 HalfAlignPile(const HalfAlignPile &p)
00180 : IntervalPile(p), identity(p.identity), qcov(p.qcov) { }
00181 HalfAlignPile(HalfAlignInterval* hp)
00182 : IntervalPile(hp), identity(-1.0), qcov(-1.0), tcov(-1.0) { }
00186 float getIdentity() const;
00191 float getCov() const { return getTcov(); }
00199 float getQcov() const;
00200 float getTcov() const;
00208 string toDelimitedString(const string &dl="\t") const;
00209
00210 private:
00216 void computeIntermediateResult() const;
00220 mutable float identity;
00224 mutable float qcov;
00226 mutable float tcov;
00227 };
00228
00229
00230
00231
00232
00233
00234
00235
00249 class IntervalChain : public Interval {
00250 public:
00251 typedef list<Interval*>::iterator iterator;
00252 typedef list<Interval*>::const_iterator const_iterator;
00253 iterator begin() { return chain.begin(); }
00254 iterator end() { return chain.end(); }
00255 IntervalChain() : Interval(-1, -1), chain() { }
00256
00257 IntervalChain(const int bb, const int ee)
00258 : Interval(bb, ee), chain() { chain.push_back(new Interval(bb,ee)); }
00259 IntervalChain(const Interval &iv) : Interval(iv), chain()
00260 { chain.push_back(new Interval(iv)); }
00261 IntervalChain(Interval* iv) : Interval(*iv), chain() { chain.push_back(iv); }
00262 ~IntervalChain();
00263
00277 void add(Interval *iv);
00282 void add(const int bb, const int ee);
00283 int size() const { return chain.size(); }
00284
00285 friend ostream& operator<<(ostream &ous, const IntervalChain &iv);
00286
00290 int getInnerLength() const;
00292 int getOuterLength() const;
00293
00294 private:
00301
00302 list<Interval*> chain;
00303 };
00304
00305
00306 #endif