Coverdepth.h

Go to the documentation of this file.
00001 #ifndef COVERDEPTH_H
00002 #define COVERDEPTH_H
00003 
00004 #include "GenModel.h"
00005 #include <iostream>
00006 #include <cassert>
00007 #include <limits>
00008 
00009 class NegativeCoverage { };
00010 
00016 void computeDerivative(const int *in, int *out, int L, int dx=1) 
00017    throw(NegativeCoverage);
00022 void sumNumber(const int *A, int *&B, int L, int w);
00023 
00034 class Dip {
00035    public:
00036       Dip() : posTL(-1), posBL(-1), posBR(-1), posTR(-1),
00037          LH(0), RH(0), BLH(numeric_limits<int>::max()), 
00038          BRH(numeric_limits<int>::max()) { }
00041       Dip(int tl, int bl, int br, int tr, int lh, int blh, int brh, int rh) 
00042          : posTL(tl), posBL(bl), posBR(br), posTR(tr),
00043            LH(lh), BLH(blh), BRH(brh), RH(rh) { }
00045       //void setRightDropoff(int pTL, int pL, int pR, int tlH, lH, rH);
00046       //void setLeftDropoff(int pL, int pR, int pTR, int lH, int rH, int trH);
00047 
00048       friend ostream& operator<<(ostream& ous, const Dip &v);
00049       void incrementPosition(int B);
00055       bool isGood() const;
00059       bool betterThan(const Dip &dip) const;
00060       int bottomLeft() const { return posBL; }
00061       int bottomRight() const { return posBR; }
00062       int bottomWidth() const { return posBR - posBL + 1; }
00065       int height() const { return max(LH,RH)-min(BLH,BRH); }
00066       int leftHeight() const { return LH-BLH; }
00067       int rightHeight() const { return RH-BRH; }
00068       int bottomHeight() const { return min(BLH,BRH); }
00076       pair<int,int> breakPoint(char dir='+') const;
00077       int ratio() const { return max(LH, RH)/min(BLH,BRH); }
00080       float fineratio() const { return (float)max(LH, RH)/min(BLH,BRH); }
00081       float fineRatio() const { return (float)max(LH, RH)/min(BLH,BRH); }
00083       bool isNull() const { return posTL==-1 || posBL==-1 || posBR==-1 || posTR==-1; }
00091       int posTL, posBL, posBR, posTR;
00095       int LH, RH; 
00096       //int LH, RH, BH; 
00098       int BLH, BRH;
00100       static int intronAvoid; // 20
00101 };
00102 
00109 class RightDropoff : public Dip {
00110    public:
00111       RightDropoff() : Dip() {}
00112       RightDropoff(int pTL, int pL, int pR, int tlH, int lH, int rH) 
00113          : Dip(pTL, pL, pR, pR, tlH, lH, rH, rH) { }
00114       int height() const { return LH-BRH; }
00115       float fineRatio() const { return float(LH)/BRH; }
00116       int ratio() const { return LH/BRH; }
00117       bool better(const RightDropoff &drf) { return fineRatio() > drf.fineRatio() && BLH <= drf.BLH; }
00118       bool isGood() const { return (ratio()>30 && BRH<5) || ratio()>60; }
00119 };
00120 
00121 class LeftDropoff : public Dip {
00122    public:
00123       LeftDropoff() : Dip() {}
00124       LeftDropoff(int pL, int pR, int pTR, int blH, int brH, int trH) 
00125          : Dip(pL, pL, pR, pTR, blH, blH, brH, trH) { }
00126       int height() const { return RH-BLH; }
00127       float fineRatio() const { float(RH)/BLH; }
00128       int ratio() const { return RH/BLH; }
00129       //int ratio() const;
00130       bool better(const LeftDropoff &drf) { return fineRatio() > drf.fineRatio() && BRH <= drf.BRH; }
00131       bool isGood() const { return (ratio()>30 && BLH<6) || ratio()>60; }
00132       //bool isGood() const;
00133 };
00134 
00140 class Coverdepth {
00141    public:
00142       Coverdepth() : B(0), E(0), dep(0), direction('?'), der1(0)  { }
00145       Coverdepth(const Noschain &chain, int C=1);
00149       Coverdepth(const string &cdstr);
00151       Coverdepth(int *prof, int bb, int ee, char dir)
00152          : B(bb), E(ee), dep(prof), der1(0), direction(dir) { }
00153       ~Coverdepth();
00154       //~Coverdepth() { delete[] dep; }
00155       Coverdepth& assign(const Noschain &chain, int C);
00156       //Coverdepth& operator+(const Noschain &chain);
00160       Coverdepth& append(const Noschain &chain, int C=1);
00163       int length() const { if (dep == 0) return 0; return E-B+1; }
00164       int begin() const { return B; }
00165       int end() const { return E; }
00168       bool empty() const { return dep == 0; }
00169       void clear();
00175       friend ostream& operator<<(ostream &ous, const Coverdepth &cd);
00185       Noschain exons() const;
00186       char strand() const { return direction; }
00187       void setStrand(char dir) { direction=dir; }
00188       void reverseStrand() { if (direction=='+') direction='-';
00189          else if (direction=='-') direction='+'; }
00198       void trim(const Range &bound);
00202       void erase(const Range &bound);
00204       void erase(int bb, int ee);
00206       void fill(int bb, int ee, int height);
00210       void fillRight(int bb, int ee);
00215       void extendRight(int bb, int len);
00220       void fillLeft(int bb, int ee);
00221       void extendLeft(int ee, int len);
00229       bool findDip(int b, int e, Dip &dip) const throw(NegativeCoverage);
00246       bool searchDip(int b, int e, Dip &dip) const throw(PointOutChain);
00256       pair<float,float> relativeHeight(const Coverdepth &bcp) const;
00257 
00258    private:
00270       int findDropoff(list<pair<double, int> > &derivseg, int s, int f, Dip &dip) const;
00271       bool findRightDropoff(list<pair<double, int> > &derivseg, int s, int f, Dip &dip) const;
00272       bool findLeftDropoff(list<pair<double, int> > &derivseg, int s, int f, Dip &dip) const;
00273       //bool findRightDropoff(const vector<pair<double, int> > &derivseg, int s, int f, int &cut) const;
00274       //int findDropoff(list<pair<double, int> > &derivseg, int s, int f, LeftDropoff &ldrop, RightDropoff &rdrop) const;
00283       int digDip(int b, int e, vector<Dip> &dips, const int *deriv) const;
00291       int findVDip(const list<pair<double,int> > &seg, int b, vector<Dip> &dips) const;
00297       int localMax(int &x, int w=10) const;
00298       int localMin(int &x, int w=10) const;
00302       int indexGenomic2dep(int gpos) const { return gpos-B; }
00307       int indexdep2Genomic(int idx) const { return B+idx; }
00308 
00309    public:
00313       int* derivative(int dx=1);
00317       ostream& toPlot(ostream &ous) const;
00318       float averageHeight() const;
00319       int area() const;
00324       int area(int b, int e) const;
00326       int maxHeight() const;
00329       pair<int,int> maxAndSum() const;
00331       void maxAndSum(int &maxh, int &sum) const;
00336       int summary(int &maxc, int &maxi, int &minc, int &mini, int b=0, int e=-1) const;
00347       Coverdepth* subprofile(int b, int e, char dir='?') const;
00353       void truncateTail(int e) { E=e; }
00356       void truncateHead(int b);
00357 
00358    private:
00371       bool makeDip(Dip &dip, const int* deriv, const int s, const int ss, const int ff, int &i) const;
00381       void produceDip(Dip &dip, int dipx[], int b) const;
00385       void produceVDip(Dip &dip, int dipx[], int b) const;
00389       int *dep;
00395       int B, E; // inclusive [B,E]
00398       char direction; // + or - or ?
00399       int *der1;
00402       static int dipedgew;
00403 };
00404 
00405 #endif

Generated on Wed Aug 10 11:56:51 2011 for Softwares from Orpara by  doxygen 1.5.6