fix problems with motif changes not showing up in sequencebrowser
[mussa.git] / alg / sequence.hpp
index 09c53c4bf3a1a911e793add0a8730335285b437a..9c7ddd4a1e9fb8a397e1332f95dd346ac19ca462 100644 (file)
@@ -72,7 +72,7 @@ struct motif : public annot
 {
   std::string sequence;
 
-  motif() :  annot(), sequence("") {};
+  motif() : annot(), sequence("") {};
   //! this constructor is for when we're adding motifs to our annotations
   motif(int begin, std::string motif);
   ~motif();
@@ -88,6 +88,8 @@ private:
 };
 BOOST_CLASS_EXPORT(motif);
 
+class Sequence;
+typedef boost::shared_ptr<Sequence> SequenceRef;
 
 //! sequence track for mussa.
 class Sequence 
@@ -103,16 +105,24 @@ public:
   typedef SeqString::const_reference const_reference;
   typedef SeqString::size_type size_type;
   static const size_type npos = SeqString::npos;
-  enum strand_type { UnknownStrand, PlusStrand, MinusStrand, BothStrand };
-  enum alphabet_ref { reduced_dna_alphabet, reduced_rna_alphabet, reduced_nucleic_alphabet, 
-                      nucleic_alphabet, protein_alphabet };
+  
+  typedef std::list<motif> MotifList;
+  typedef boost::shared_ptr<MotifList> MotifListRef;
                       
-  Sequence(alphabet_ref a = reduced_nucleic_alphabet);
-  Sequence(const char* seq, alphabet_ref a = reduced_nucleic_alphabet);
-  Sequence(const std::string& seq, alphabet_ref a = reduced_nucleic_alphabet);
+  Sequence(AlphabetRef a = reduced_dna_alphabet);
+  Sequence(const char* seq, 
+           AlphabetRef a = reduced_dna_alphabet,
+           SeqSpan::strand_type strand = SeqSpan::PlusStrand);
+  Sequence(const std::string& seq,
+           AlphabetRef a = reduced_dna_alphabet,
+           SeqSpan::strand_type strand = SeqSpan::PlusStrand);
+  //! make a new sequence, with the same SeqSpan
   Sequence(const Sequence& seq);
+  //! make a new sequence, with the same SeqSpan
   Sequence(const Sequence *);
-  Sequence(const SeqSpanRef&, alphabet_ref a = reduced_nucleic_alphabet); 
+  //! Make a new sequence using a copy of SeqSpan
+  Sequence(const SequenceRef); 
+  Sequence(const SeqSpanRef&);
   ~Sequence();
   //! assignment to constant sequences
   Sequence &operator=(const Sequence&);
@@ -125,10 +135,10 @@ public:
 
   //! set sequence to a (sub)string containing nothing but AGCTN
   void set_filtered_sequence(const std::string& seq,
-                             alphabet_ref a
+                             AlphabetRef a=reduced_dna_alphabet
                              size_type start=0,
                              size_type count=npos,
-                             strand_type strand=UnknownStrand);
+                             SeqSpan::strand_type strand=SeqSpan::PlusStrand);
 
   //! retrive element at specific position
   const_reference at(size_type i) const { return seq->at(i); }
@@ -159,14 +169,16 @@ public:
   size_type stop() const { return seq->parentStop(); }
 
   //! return a subsequence, copying over any appropriate annotation
-  Sequence subseq(size_type start=0, size_type count = npos) const;
+  Sequence subseq(size_type start=0, 
+                  size_type count = npos,
+                  SeqSpan::strand_type strand = SeqSpan::SameStrand) const;
   //! reverse a character
   std::string create_reverse_map() const;
   //! return a reverse compliment (this needs to be improved?)
   Sequence rev_comp() const;
 
   //! set sequence (filtered)
-  void set_sequence(const std::string &, alphabet_ref);
+  void set_sequence(const std::string &, AlphabetRef);
   //! get sequence
   std::string get_sequence() const;
   //! set species name
@@ -181,8 +193,6 @@ public:
   std::string get_name() const;
   //! return a reference to whichever alphabet we're currently representing
   const Alphabet& get_alphabet() const; 
-  //! return a reference to whichever alphabet we're currently representing
-  const Alphabet& get_alphabet(alphabet_ref) const; 
   
   //! load sequence from fasta file using the sequences current alphabet
   void load_fasta(const boost::filesystem::path file_path, int seq_num=1,
@@ -192,7 +202,7 @@ public:
   //! \throw sequence_empty_error
   //! \throw sequence_empty_file_error
   void load_fasta(const boost::filesystem::path file_path, 
-                  alphabet_ref a, 
+                  AlphabetRef a, 
                   int seq_num=1, 
                              int start_index=0, int end_index=0);
   void load_fasta(std::istream& file, 
@@ -202,7 +212,7 @@ public:
   //! \throw sequence_empty_error
   //! \throw sequence_empty_file_error
   void load_fasta(std::istream& file, 
-                  alphabet_ref a,
+                  AlphabetRef a,
                   int seq_num=1, 
                              int start_index=0, int end_index=0);
   //! load sequence annotations
@@ -218,7 +228,7 @@ public:
   //! 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 MotifList& motifs() const;
 
   //! add a motif to our list of motifs
   void add_motif(const Sequence& a_motif);
@@ -236,10 +246,6 @@ public:
   
 protected:  
   SeqSpanRef seq;
-  //! which alphabet we're using
-  alphabet_ref alphabet;
-  //! strand orientation
-  strand_type strand;
   //! fasta header
   std::string header;
   //! species name
@@ -248,7 +254,7 @@ protected:
   //! store our oldstyle annotations
   std::list<annot> annots;
   //! a seperate list for motifs since we're currently not saving them
-  std::list<motif> motif_list;
+  MotifListRef motif_list;
 
   //! copy over all our annotation children
   void copy_children(Sequence &, size_type start, size_type count) const;
@@ -263,8 +269,6 @@ protected:
   template<class Archive>
   void serialize(Archive& ar, const unsigned int /*version*/) {
     ar & BOOST_SERIALIZATION_NVP(seq);
-    ar & BOOST_SERIALIZATION_NVP(alphabet);
-    ar & BOOST_SERIALIZATION_NVP(strand);
     ar & BOOST_SERIALIZATION_NVP(header);
     ar & BOOST_SERIALIZATION_NVP(species);
     ar & BOOST_SERIALIZATION_NVP(annots);