fix uninitialized pointer
[mussa.git] / alg / sequence.cpp
index 68fa01460542956a6dabf5864786a50f47080737..6cb4e2cf001b443be1bb5f10d0ceda96be9eb7aa 100644 (file)
@@ -80,7 +80,8 @@ motif::~motif()
 
 
 Sequence::Sequence(AlphabetRef alphabet)
-  : seq(new SeqSpan("", alphabet, SeqSpan::PlusStrand))
+  : seq(new SeqSpan("", alphabet, SeqSpan::PlusStrand)),    
+    motif_list(new MotifList)
 {
 }
 
@@ -90,7 +91,8 @@ Sequence::~Sequence()
 
 Sequence::Sequence(const char *seq, AlphabetRef alphabet_, SeqSpan::strand_type strand_)
   : header(""),
-    species("")
+    species(""),
+    motif_list(new MotifList)
 {
   set_filtered_sequence(seq, alphabet_, 0, npos, strand_);
 }
@@ -99,7 +101,8 @@ Sequence::Sequence(const std::string& seq,
                    AlphabetRef alphabet_,
                    SeqSpan::strand_type strand_) 
   : header(""),
-    species("")
+    species(""),
+    motif_list(new MotifList)
 {
   set_filtered_sequence(seq, alphabet_, 0, seq.size(), strand_);
 }
@@ -122,10 +125,20 @@ Sequence::Sequence(const Sequence* o)
 {
 }
 
+Sequence::Sequence(const SequenceRef o)
+  : seq(new SeqSpan(o->seq)),
+    header(o->header),
+    species(o->species),
+    annots(o->annots),
+    motif_list(o->motif_list)
+{
+}
+
 Sequence::Sequence(const SeqSpanRef& seq_ref)
   : seq(seq_ref),
     header(""),
-    species("")
+    species(""),
+    motif_list(new MotifList)
 {
 }
 
@@ -538,8 +551,8 @@ void Sequence::copy_children(Sequence &new_seq, size_type start, size_type count
       new_seq.annots.push_back(new_annot);
     }
   }
-  
 }
+
 Sequence
 Sequence::subseq(size_type start, size_type count, SeqSpan::strand_type strand) const
 {
@@ -551,7 +564,10 @@ Sequence::subseq(size_type start, size_type count, SeqSpan::strand_type strand)
 
   Sequence new_seq = *this;
   new_seq.seq = seq->subseq(start, count, strand);
-
+  if (seq->annotations()) {
+    AnnotationsRef a(new Annotations(*(seq->annotations())));
+    new_seq.seq->setAnnotations(a);
+  }
   copy_children(new_seq, start, count);
   
   return new_seq;
@@ -625,7 +641,7 @@ Sequence::clear()
   header.clear();
   species.clear();
   annots.clear();
-  motif_list.clear();
+  motif_list.reset(new MotifList);
 }
 
 void
@@ -743,18 +759,21 @@ void Sequence::add_motif(const Sequence& a_motif)
       motif_start_i != motif_starts.end();
       ++motif_start_i)
   {
-    motif_list.push_back(motif(*motif_start_i, a_motif.get_sequence()));
+    motif_list->push_back(motif(*motif_start_i, a_motif.get_sequence()));
   }
 }
 
 void Sequence::clear_motifs()
 {
-  motif_list.clear();
+  if (motif_list) 
+    motif_list->clear();
+  else 
+    motif_list.reset(new MotifList);
 }
 
-const std::list<motif>& Sequence::motifs() const
+const Sequence::MotifList& Sequence::motifs() const
 {
-  return motif_list;
+  return *motif_list;
 }
 
 std::vector<int>