alignseg.h

Go to the documentation of this file.
00001 #ifndef ALIGNSEG_H
00002 #define ALIGNSEG_H
00003 
00004 #include <iostream>
00005 #include <matrix.h>
00006 
00007 using namespace std;
00008 
00014 class Alignseg {
00015    public:
00018       Alignseg() : x(0), y(0), len(0), score(0) {}
00019       Alignseg(const int xx, const int yy, const int ll)
00020          : x(xx), y(yy), len(ll), score(0) { }
00024       Alignseg(const int xx, const int yy, const int ll, const int sc)
00025          : x(xx), y(yy), len(ll), score(sc) { }
00026       Alignseg(const Alignseg& as) 
00027          : x(as.getX()), y(as.getY()), len(as.getLength()),
00028            score(as.getScore()) { }
00033       int distanceX(const Alignseg& as) { return as.x-x-len; }
00038       int distanceY(const Alignseg& as) { return as.y-y-len; }
00039       bool before(const Alignseg& as) { return getEndX() < as.getX() && getEndY() < as.getY(); }
00040       bool before(const Alignseg* as) { return getEndX() < as->getX() && getEndY() < as->getY(); }
00041       int diagonal() const { return y-x; }
00042       bool sameDiagonal(const Alignseg& as) { return y-x == as.y-as.x; }
00046       bool contain(const Alignseg& as) const;
00054       void merge(const Alignseg& as);
00055       friend ostream& operator<<(ostream& ous, const Alignseg& as);
00056       bool operator==(const Alignseg& as) const {
00057               return x==as.x && y==as.y && len==as.len; }
00058       int getLength() const { return len; }
00059       int getScore() const { return score; }
00060       void setScore(const int sc) { score=sc; }
00061       int getX() const { return x; }
00062       int getEndX() const { return x+len-1; }
00063       int getY() const { return y; }
00064       int getEndY() const { return y+len-1; }
00065       void setX(const int xx) { x=xx; }
00066       void setY(const int yy) { y=yy; }
00067       void setLength(const int l) { len=l; }
00070       void addLength(const int l) { len += l; }
00075       void addScore(const int sc) { score += sc; }
00076       int YOverlap(const Alignseg& as) const { return as.y-getEndY()+1; }
00077       int XOverlap(const Alignseg& as) const { return as.x-getEndX()+1; }
00078       void shrink(int sz, const int* xsc, const int* ysc, const Matrix* mt);
00079 
00080    protected:
00081       int x, y, len; // len is the length in X axis
00082       int score;
00083 };
00084 
00085 class Alignsegex : public Alignseg {
00086    public:
00087       Alignsegex() : Alignseg(), prev(0), maxsc(0) { }
00088       Alignsegex(const int xx, const int yy, const int ll)
00089          : Alignseg(xx,yy,ll), prev(0), maxsc(0) { }
00090 
00091       Alignsegex(const Alignseg& as) 
00092          : Alignseg(as), prev(0), maxsc(as.getScore()) { }
00093 
00094       void setPreviousNode(Alignsegex* as) { prev=as; }
00095       void setPrevious(Alignsegex* as) { prev=as; }
00096       Alignsegex* previous() { return prev; }
00105       bool attachTo(Alignsegex* as, const int* xsc, const int* ysc, const Matrix* mtx);
00106       //void attachTo(const Alignsegex& as) { attachTo(&as); }
00107       void setDefault() { maxsc=score; prev=0; } 
00111       void shrink(int sz, const int* xsc, const int* ysc, const Matrix* mt);
00112       int getMaxScore() const { return maxsc; }
00113       void setMaxScore(const int sc) { maxsc=sc; }
00114       // this object should not know too much about other objects
00115       //void grow(int sz, const int* xsc, const int* ysc, const Matrix* mt);
00116       friend ostream& operator<<(ostream& ous, const Alignsegex& as);
00117       void print(ostream& ous) const;
00118       void addMaxScore(const int sc) { Alignseg::addScore(sc); maxsc += sc; }
00119       void setConnectPath(const int p) { connectpath=p; }
00120       int getConnectPath() const { return connectpath; }
00121 
00122       static void setParameters(int go, int ge, int gd) {
00123          gapopen=go; gapextend=ge; gapaligndropoff=gd; }
00124 
00125    protected:
00126       Alignsegex *prev; // build the chain
00127       int maxsc;        // maximum score so far on the chain
00128       int connectpath;  // 1, 2, 3 methods to connect to the previous node
00129 
00130       // class wide parameter, copy from blast parameters
00131       static int gapopen; // negative number
00132       static int gapextend; // negative number
00133       static int gapaligndropoff; // default 12
00134 };
00135 
00136 class ltAlignsegYXlen {
00137    public:
00138       bool operator()(const Alignseg& as1, const Alignseg& as2) const {
00139          if (as1.getY() < as2.getY()) return true;
00140          else if (as1.getY() == as2.getY()) {
00141             if (as1.getX() < as2.getX()) return true;
00142             else if (as1.getX() == as2.getX()) {
00143                if (as1.getLength() < as2.getLength()) return true;
00144                else return false;
00145             }
00146             return false;
00147          }
00148          else return false;
00149       }
00150 };
00151 
00152 #endif

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