gfeature.h
Go to the documentation of this file.00001 #ifndef GFEATURE_H
00002 #define GFEATURE_H
00003
00004 #include "Range.h"
00005 #include "validqualifier.h"
00006 #include <vector>
00007
00008 #include <map>
00009
00010 using namespace std;
00011
00012 class InvalidQualifier : public exception {
00013 public:
00014 InvalidQualifier(const string &msg) {
00015 errmsg=msg;
00016 }
00017 const char* what() const throw() { return errmsg.c_str(); }
00018 ~InvalidQualifier() throw() { }
00019
00020 private:
00021 string errmsg;
00022 };
00023
00024 class Gfeature {
00025 public:
00026 Gfeature() : type(), qual(0), exons(), has_start(true), has_end(true) { }
00037 Gfeature(vector<string> &loc, const string &ftype, map<string,string> *qls) throw (InvalidQualifier);
00038 ~Gfeature() { delete qual; }
00040 void writeGBTab() const;
00041 const string& getQualifier(const string &key) const;
00042 const string& getType() const { return type; }
00043 const string& featureType() const { return type; }
00044
00045
00047 void writeGBTab(ostream &ous) const;
00048
00049 protected:
00053 map<string,string> *qual;
00060 string type;
00061 vector<Range> exons;
00062 bool has_start;
00063 bool has_end;
00064
00065 static bool validq(const string &ql) {
00066 return vq->valid(ql); }
00067
00068 private:
00069 ostream& writeGBLocation(ostream &ous) const;
00070
00071 static ValidQualifier* vq;
00072 };
00073
00074 class Genefeature : public Gfeature {
00075 public:
00076 Genefeature() : Gfeature(), mRNA(), CDS() { }
00077 Genefeature(vector<string> &loc, const string &ftype,
00078 map<string,string> *qls) throw (InvalidQualifier)
00079 : Gfeature(loc,ftype,qls), mRNA(), CDS() {}
00080 void addCoding(vector<Gfeature*> &m,
00081 vector<Gfeature*> &c) {
00082 mRNA=m; CDS=c; }
00083 const string& proteinid() const { return CDS[0]->getQualifier("protein_id"); }
00084 const string& product() const {
00085 return CDS[0]->getQualifier("product"); }
00087 bool deflineBetter(const string &oldef) const;
00088 ostream& writeGBTable(ostream &ous) const;
00089 int numberOfCoding() const { return CDS.size(); }
00090
00091 private:
00092 vector<Gfeature*> mRNA;
00093 vector<Gfeature*> CDS;
00094 };
00095
00096 #endif