make Sequence a subclass of std::string
[mussa.git] / alg / sequence.hpp
index 86acee503b4726697de7e2acb6b19ccedde8dd52..e2a37d38766df9fa0bf5a5055998e561c39b26bd 100644 (file)
@@ -28,11 +28,14 @@ struct annot
 {
   annot();
   annot(int start, int end, std::string type, std::string name);
+  ~annot();
   
   int start;
   int end;
   std::string type;
   std::string name;
+
+  friend bool operator==(const annot& left, const annot& right);
 };
 
 /* The way that motifs are found currently doesn't really 
@@ -44,13 +47,13 @@ struct motif : public annot
 
   //! this constructor is for when we're adding motifs to our annotations
   motif(int start, std::string motif);
+  ~motif();
 };
 
 //! sequence track for mussa.
-class Sequence
+class Sequence : public std::string
 {
   private:
-    std::string sequence;
     std::string header;
     std::string species;
 
@@ -64,17 +67,13 @@ class Sequence
     void add_string_annotation(std::string a_seq, std::string name);
 
   public:
-    typedef std::string::iterator iterator;
-    typedef std::string::const_iterator const_iterator;
-    typedef std::string::size_type size_type;
-
     Sequence();
-    Sequence(std::string seq);
+    ~Sequence();
+    Sequence(const std::string& seq);
+    Sequence(const Sequence& seq);
     //! assignment to constant sequences
     Sequence &operator=(const Sequence&);
     Sequence &operator=(const std::string &);
-    char operator[](int) const;
-    friend std::ostream& operator<<(std::ostream& out, const Sequence& seq);
 
     //! set sequence to a (sub)string containing nothing but AGCTN
     void set_filtered_sequence(const std::string& seq, 
@@ -100,27 +99,18 @@ class Sequence
     //! \throws mussa_load_error 
     void load_annot(std::fstream& data_stream, int start_index, int end_index);
     void parse_annot(std::string data, int start_index, int end_index);
+    //! add an annotation to our list of annotations
+    void add_annotation(const annot& a);
     const std::list<annot>& annotations() const;
     const std::list<motif>& motifs() const;
     const std::string& get_species() const;
 
-    // simple access functions
-    void set_seq(const std::string& a_seq);
-    const std::string& get_seq() const;
-    const char *c_seq() const;
-    std::string subseq(int start, int count) const;
+    //! return a subsequence, copying over any appropriate annotation
+    Sequence subseq(int start=0, int count = std::string::npos) const;
+    //! return a reverse compliment
     std::string rev_comp() const;
 
-    // string-like functions
-    iterator begin();
-    const_iterator begin() const;
-    iterator end();
-    const_iterator end() const;
-    bool empty() const;
-    //! alias for size, (included as this is much like a string)
-    std::string::size_type length() const;
-    //! the number of base pairs in this sequence
-    std::string::size_type size() const;
+    //! clear the sequence and its annotations
     void clear();
 
     void set_header(std::string header);