eXpress “1.5”

src/sequence.h

00001 
00009 #ifndef express_sequence_h
00010 #define express_sequence_h
00011 
00012 #include <boost/scoped_array.hpp>
00013 #include <string>
00014 #include "frequencymatrix.h"
00015 
00021 inline char ctoi(const char c) {
00022   switch(c) {
00023     case 'A':
00024     case 'a':
00025        return 0;
00026     case 'C':
00027     case 'c':
00028        return 1;
00029     case 'G':
00030     case 'g':
00031        return 2;
00032     case 'T':
00033     case 't':
00034        return 3;
00035     default:
00036        return 0;
00037   }
00038 }
00045 inline char complement(const char c) {
00046   return c^3;
00047 }
00048 
00058 class Sequence {
00059  public:
00063   Sequence() {}
00067   virtual ~Sequence() {}
00075   virtual void set(const std::string& seq, bool rev) = 0;
00083   virtual size_t operator[](const size_t index) const = 0;
00091   virtual size_t get_ref(const size_t index) const = 0;
00099   virtual void update_est(const size_t index, const size_t nuc, float mass) = 0;
00107   virtual void update_obs(const size_t index, const size_t nuc, float mass) = 0;
00115   virtual void update_exp(const size_t index, const size_t nuc, float mass) = 0;
00123   virtual float get_prob(const size_t index, const size_t nuc) const = 0;
00131   virtual float get_obs(const size_t index, const size_t nuc) const = 0;
00139   virtual float get_exp(const size_t index, const size_t nuc) const = 0;
00144   virtual bool prob() const = 0;
00149   virtual size_t length() const = 0;
00154   virtual bool empty() const = 0;
00161   virtual void calc_p_vals(std::vector<double>& p_vals) const = 0;
00166   std::string serialize();
00167 };
00168 
00177 class SequenceFwd: public Sequence
00178 {
00183   boost::scoped_array<const char> _ref_seq;
00188   FrequencyMatrix<float> _est_seq;
00193   FrequencyMatrix<float> _obs_seq;
00198   FrequencyMatrix<float> _exp_seq;
00203   bool _prob;
00207   size_t _len;
00208 
00209  public:
00213   SequenceFwd();
00220   SequenceFwd(const std::string& seq, bool rev, bool prob=false);
00225   SequenceFwd(const SequenceFwd& other);
00230   SequenceFwd& operator=(const SequenceFwd& other);
00231   // The following methods are documented in the abstract Sequence class.
00232   void set(const std::string& seq, bool rev);
00233   size_t operator[](const size_t index) const;
00234   size_t get_ref(const size_t index) const;
00235   float get_exp(const size_t index, const size_t nuc) const;
00236   float get_obs(const size_t index, const size_t nuc) const;
00237   void update_est(const size_t index, const size_t nuc, float mass);
00238   void update_obs(const size_t index, const size_t nuc, float mass);
00239   void update_exp(const size_t index, const size_t nuc, float mass);
00240   float get_prob(const size_t index, const size_t nuc) const;
00241   bool prob() const { return _prob; }
00242   bool empty() const { return _len==0; }
00243   size_t length() const { return _len; }
00244   void calc_p_vals(std::vector<double>& p_vals) const;
00245 };
00246 
00258 class SequenceRev: public Sequence {
00263   SequenceFwd* _seq;
00264 
00265  public:
00266   SequenceRev() : _seq(NULL){}
00267   SequenceRev(SequenceFwd& seq) : _seq(&seq) {}
00268   size_t length() const {
00269     if (_seq == NULL) {
00270    return 0;
00271     }
00272       return _seq->length();
00273   }
00274   bool empty() const {
00275     if (_seq == NULL) {
00276       return true;
00277     }
00278     return _seq->empty();
00279   }
00280   // Set is not allowed in this class.
00281   void set(const std::string& seq, bool rev) { assert(false); exit(1); }
00282   size_t operator[](const size_t index) const {
00283     return complement(_seq->operator[](length()-index-1)); }
00284   size_t get_ref(const size_t index) const {
00285     return complement(_seq->get_ref(length()-index-1)); }
00286   float get_obs(const size_t index, const size_t nuc) const {
00287     return _seq->get_obs(length()-index-1, complement(nuc)); }
00288   float get_exp(const size_t index, const size_t nuc) const {
00289     return _seq->get_exp(length()-index-1, complement(nuc)); }
00290   void update_est(const size_t index, const size_t nuc, float mass) {
00291     _seq->update_est(length()-index-1, complement(nuc), mass); }
00292   void update_obs(const size_t index, const size_t nuc, float mass) {
00293     _seq->update_obs(length()-index-1, complement(nuc), mass); }
00294   void update_exp(const size_t index, const size_t nuc, float mass) {
00295     _seq->update_exp(length()-index-1, complement(nuc), mass); }
00296   float get_prob(const size_t index, const size_t nuc) const {
00297     return _seq->get_prob(length()-index-1, complement(nuc)); }
00298   bool prob() const { return _seq->prob(); }
00299   void calc_p_vals(std::vector<double>& p_vals) const;
00300 };
00301 
00302 #endif
 All Classes Functions Variables