attach motifs to a sequence object
[mussa.git] / alg / sequence.cpp
index b05349ebba3ce99df6402fee1fa0f487cb3eecf4..5c7f069efce30c738e84e8bec769ef8cfec96896 100644 (file)
 
 using namespace std;
 
+annot::annot() 
+ : start(0),
+   end(0),
+   type(""),
+   name("")
+{
+}
+
+annot::annot(int start, int end, std::string type, std::string name)
+ : start(start),
+   end(end),
+   type(type),
+   name(name)
+{
+}
+
+motif::motif(int start, std::string motif)
+ : annot(start, start+motif.size(), "motif", motif),
+   sequence(motif)
+{
+}
+  
 Sequence::Sequence()
+  : sequence(""),
+    header(""),
+    species("")
 {
+  annots.clear();
+  motif_list.clear();
 }
 
 Sequence::Sequence(string seq)
@@ -266,7 +293,7 @@ bool Sequence::empty() const
   return (size() == 0);
 }
 
-const std::list<annot> Sequence::annotations() const
+const std::list<annot>& Sequence::annotations() const
 {
   return annots;
 }
@@ -606,6 +633,23 @@ Sequence::motif_validate(string a_motif)
   return valid_motif;
 }
 
+void Sequence::add_motif(string a_motif)
+{
+  vector<int> motif_starts = find_motif(a_motif);
+
+
+  for(vector<int>::iterator motif_start_i = motif_starts.begin();
+      motif_start_i != motif_starts.end();
+      ++motif_start_i)
+  {
+    motif_list.push_back(motif(*motif_start_i, a_motif));
+  }
+}
+
+const list<motif>& Sequence::motifs() const
+{
+  return motif_list;
+}
 
 vector<int>
 Sequence::find_motif(string a_motif)
@@ -613,7 +657,6 @@ Sequence::find_motif(string a_motif)
   vector<int> motif_match_starts;
   string a_motif_rc;
 
-
   motif_match_starts.clear();
 
   //cout << "motif is: " << a_motif << endl;
@@ -710,12 +753,13 @@ Sequence::motif_scan(string a_motif, vector<int> * motif_match_starts)
     if (motif_i == motif_len)
     {
       //cout << "!!";
+      annot new_motif;
       motif_match_starts->push_back(seq_i - motif_len + 1);
       motif_i = 0;
     }
 
     seq_i++;
   }
-  cout << endl;
+  //cout << endl;
 }