fixes for Mussa::load_motif
[mussa.git] / alg / mussa.cpp
index c93990b72e81ef371cdcb615d234231c5ac3a466..47a6b0fe464e72670a0e55b2726d8001ece47de6 100644 (file)
@@ -762,7 +762,6 @@ void Mussa::set_motifs(const vector<Sequence>& motifs,
   update_sequences_motifs();
 }
 
-
 // Helper functor to append created motifs to our Mussa analysis
 struct push_back_motif {
   std::set<Sequence>& motif_set;
@@ -772,27 +771,27 @@ struct push_back_motif {
   float& red;
   float& green;
   float& blue;
+  float& alpha;
 
   push_back_motif(std::set<Sequence>& motif_set_,
                   boost::shared_ptr<AnnotationColors> color_mapper_,
                   std::string& seq_, 
                   std::string& name_,
-                  float red_, float green_, float blue_)
+                  float &red_, float &green_, float &blue_, float &alpha_)
     : motif_set(motif_set_),
       color_mapper(color_mapper_),
       seq_string(seq_),
       name(name_),
       red(red_),
       green(green_),
-      blue(blue_)
+      blue(blue_),
+      alpha(alpha_)
   {
   }
 
   void operator()(std::string::const_iterator, 
                   std::string::const_iterator) const 
   {
-    //std::cout << "motif: " << seq_string << "/" << name << endl;
-
     Sequence seq(seq_string);
     // shouldn't we have a better field than "fasta header" and speices?
     seq.set_fasta_header(name);
@@ -813,9 +812,10 @@ void Mussa::load_motifs(std::istream &in)
   const char *alphabet = Sequence::nucleic_iupac_alphabet.c_str();
   string seq;
   string name;
-  float red;
-  float green;
-  float blue;
+  float red = 1.0;
+  float green = 0.0;
+  float blue = 0.0;
+  float alpha = 1.0;
 
   // slurp our data into a string
   std::streamsize bytes_read = 1;
@@ -826,7 +826,7 @@ void Mussa::load_motifs(std::istream &in)
     data.append(buf, buf+bytes_read);
   }
   // parse our string
-  bool status = spirit::parse(data.begin(), data.end(),
+  bool ok = spirit::parse(data.begin(), data.end(),
      *( 
        ( 
         (
@@ -834,14 +834,17 @@ void Mussa::load_motifs(std::istream &in)
          +spirit::space_p
         ) >>
         !(
-          (spirit::alpha_p >> *spirit::alnum_p)[spirit::assign_a(name)]
+          (spirit::alpha_p >> *spirit::graph_p)[spirit::assign_a(name)]
           >> +spirit::space_p
         ) >>
         spirit::real_p[spirit::assign_a(red)] >> +spirit::space_p >>
         spirit::real_p[spirit::assign_a(green)] >> +spirit::space_p >>
         spirit::real_p[spirit::assign_a(blue)] >> +spirit::space_p
-       )[push_back_motif(motif_sequences, color_mapper, seq, name, red, green, blue)]
+       )[push_back_motif(motif_sequences, color_mapper, seq, name, red, green, blue, alpha)]
      )).full;
+  if (not ok) {
+    std::clog << "Error parsing motif stream " << std::endl;
+  }
   update_sequences_motifs();
 }