incorporate drawable and annotations
[mussa.git] / alg / seq_span.hpp
index ec94c2717cf8d074933261f7d61863497b663b4d..f5e574814c532b7ea95246695fc837e7d534bd40 100644 (file)
@@ -2,6 +2,7 @@
 #define SEQ_SPAN_HPP_
 
 #include <string>
+#include <map>
 
 #include <boost/serialization/base_object.hpp>
 #include <boost/serialization/export.hpp>
@@ -18,6 +19,8 @@
 
 //! These classes provide for the internal implementation for the Sequence class
 #include "seq.hpp"
+#include "annotations.hpp"
+#include "drawable.hpp"
 
 class SeqSpan;
 typedef boost::shared_ptr<SeqSpan> SeqSpanRef;
@@ -35,12 +38,34 @@ public:
   typedef SeqString::size_type size_type;
   typedef SeqString::value_type value_type;
   static const size_type npos = SeqString::npos;
+  //! Define strand types
+  /**!
+   *  Unknown strand is treated as "either" strand
+   *  Plus refers to the initially created strand
+   *  Minus is the opposite strand
+   *  Both is for any feature that applies to "both" strands
+   *    (which may not actually be useful) 
+   *  Same strand is only used when creating a subsequence
+   *    and implies the subsequence has the same orientation as the parent
+   *  Opposite is only used for creating a subsequence
+   *    and implies the subsequence has the opposite orientation as the parent
+   *  Single indicates that this is single stranded and there can't be
+   *    an opposite strand.
+   */ 
+  enum strand_type { UnknownStrand, MinusStrand, PlusStrand, 
+                     BothStrand, SameStrand, OppositeStrand, SingleStrand };
 
 public:
   SeqSpan(const SeqSpan &);
   SeqSpan(const SeqSpan *);
-  explicit SeqSpan(const std::string &);
-  SeqSpan(const SeqSpanRef, size_type start=0, size_type count=npos);
+  explicit SeqSpan(const std::string &, 
+               AlphabetRef a = dna_alphabet,
+               strand_type strand=PlusStrand
+           );
+  SeqSpan(const SeqSpanRef, 
+          size_type start=0, 
+          size_type count=npos, 
+          strand_type strand=SameStrand);
 
   //! assignment
   SeqSpan& operator=(const SeqSpan&);
@@ -50,6 +75,7 @@ public:
   friend bool operator==(const SeqSpan&, const SeqSpan&);
   friend bool operator!=(const SeqSpan&, const SeqSpan&);
     
+  const Alphabet& get_alphabet() const { return seq->get_alphabet(); }
   //! \defgroup string_operators
   //! @{
   //! retrive element at specific position
@@ -84,6 +110,7 @@ public:
   size_type stop() const { return seq_start + seq_count; }
   //! set one past the last position relative to the root sequence.
   void setStop(size_type);
+  strand_type strand() const { return seq_strand; }
   
   //! get start position relative to the parent sequence
   size_type parentStart() const;
@@ -97,13 +124,23 @@ public:
   
 
   //! return a subsequence, copying over any appropriate annotation
-  SeqSpanRef subseq(size_type start=0, size_type count = std::string::npos);
+  SeqSpanRef subseq(size_type start=0, 
+                    size_type count = std::string::npos, 
+                    strand_type = PlusStrand);
   //! get sequence
   std::string sequence() const; 
   //! are both sequences derived from the same sequence tree?
   static bool isFamily(const SeqSpan& a, const SeqSpan& b);
+
+  //! access annotations dictionary
+  AnnotationsRef annotations() const { return seq_annotations; }
+  //! set annotations dictionary
+  void setAnnotations(AnnotationsRef a) { seq_annotations = a; }
+  //! get data for drawing
+  DrawableRef drawable() const { return seq_drawable; }
+  //! store drawing data
+  void setDrawable(DrawableRef d) { seq_drawable = d; }
   
-  friend class Sequence;
 private:
   //! do not statically initialize, only create with new
   SeqSpan() {};
@@ -114,11 +151,23 @@ protected:
   size_type seq_start;
   //! how big we ware
   size_type seq_count;  
-  // Do I need to track the strand here?
+  //! strand orientation
+  strand_type seq_strand;
   
   //! keep a reference to who our parent span is 
   SeqSpanRef parent;
-
+  
+  //! hold a reverse complement version of our sequence if needed
+  SeqStringRef rc_seq;  
+  //! fill in our rc_seq variable 
+  void initialize_rc_seq() const;
+  
+  //! annotations provides a python-dictionary like place for metadata
+  AnnotationsRef seq_annotations;
+  //! store information needed for drawing
+  DrawableRef seq_drawable;
+  
+  friend class Sequence;
   // boost::serialization support
   friend class boost::serialization::access;
   template<class Archive>
@@ -126,6 +175,7 @@ protected:
     ar & BOOST_SERIALIZATION_NVP(seq);
     ar & BOOST_SERIALIZATION_NVP(seq_start);
     ar & BOOST_SERIALIZATION_NVP(seq_count);
+    ar & BOOST_SERIALIZATION_NVP(seq_strand);
     ar & BOOST_SERIALIZATION_NVP(parent);
   }
 };