00001 #ifndef MODEL_H 00002 #define MODEL_H 00003 00004 #include <string> 00005 #include <vector> 00006 #include <list> 00007 #include <iostream> 00008 00009 using namespace std; 00010 00011 class ExondirectionError : public exception { 00012 public: 00013 ExondirectionError() : message("Different direction of exon inside the same gene") { } 00014 ExondirectionError(const string &msg) : message(msg) { } 00015 const char* what() const throw() { return message.c_str(); } 00016 ~ExondirectionError() throw() { } 00017 private: 00018 string message; 00019 }; 00020 00021 /* 00022 * A exon model of genes. 00023 */ 00024 class Model { 00025 public: 00026 Model() : id(), exons() { } 00027 Model(const string &name) : id(name), exons() { } 00028 //void addExon(int bb, int ee) { exons.push_back(make_pair(bb,ee)); } 00029 void addExon(int bb, int ee) throw(ExondirectionError); 00030 bool operator==(const Model &mm) const; 00031 // return +, -, or ' ' if now known 00032 char direction() const; 00033 //pair<int,int> bound() const { return make_pair(exons[0].first, exons[exons.size()-1].second); } 00034 pair<int,int> bound() const { 00035 return make_pair(exons.front().first, exons.back().second); } 00036 /* one model contains another model 00037 * Both ends ousdide of mm, and the intron of 00038 * mm is a subset of this object. 00039 */ 00040 bool contain(const Model &mm) const; 00041 /* only check for the introns, disregard the ends 00042 * This method is useful where some simple extension 00043 * of the partial models might have been wrong. 00044 */ 00045 bool containIntron(const Model &mm) const; 00046 // checking only the begin and end of the model 00047 bool endsContain(const Model &mm) const; 00048 int numExons() const { return exons.size(); } 00049 //int start() const { return exons[0].first; } 00050 int start() const { return exons.front().first; } 00051 //int end() const { return exons[exons.size()-1].second; } 00052 int end() const { return exons.back().second; } 00053 // return all the intron boundaries 00054 vector<int> introns() const; 00055 friend ostream& operator<<(ostream& ous, const Model &mm); 00056 const string& getId() const { return id; } 00057 00058 private: 00059 string id; 00060 //vector< pair<int,int> > exons; 00061 list< pair<int,int> > exons; 00062 }; 00063 00064 00065 #endif
1.5.6