From 57c7ed97408c77c15d341325f2a18d8530e74cf0 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Wed, 4 Oct 2006 01:02:21 +0000 Subject: [PATCH] fixes for Mussa::load_motif If you're using references to pass variables from the boost::spirit parser via a functor class, it might be useful to actually make sure the class constructors parameters are references too. This does improve how a motif file is parsed. --- alg/mussa.cpp | 25 ++++++++++++++----------- alg/test/test_glsequence.cpp | 2 +- alg/test/test_mussa.cpp | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/alg/mussa.cpp b/alg/mussa.cpp index c93990b..47a6b0f 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -762,7 +762,6 @@ void Mussa::set_motifs(const vector& motifs, update_sequences_motifs(); } - // Helper functor to append created motifs to our Mussa analysis struct push_back_motif { std::set& motif_set; @@ -772,27 +771,27 @@ struct push_back_motif { float& red; float& green; float& blue; + float& alpha; push_back_motif(std::set& motif_set_, boost::shared_ptr 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(); } diff --git a/alg/test/test_glsequence.cpp b/alg/test/test_glsequence.cpp index f0bf301..179f632 100644 --- a/alg/test/test_glsequence.cpp +++ b/alg/test/test_glsequence.cpp @@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE ( glsequence_operator_assignment ) BOOST_AUTO_TEST_CASE( glsequence_color ) { boost::shared_ptr cm(new AnnotationColors); - Color black(0.0, 0.0, 0.0, 0.0); + Color black(0.0, 0.0, 0.0, 1.0); Color c(0.1, 0.2, 0.3, 0.4); boost::shared_ptr seq(new Sequence("AAGGCCTT")); GlSequence s(seq, cm); diff --git a/alg/test/test_mussa.cpp b/alg/test/test_mussa.cpp index 068d44b..ae16ee8 100644 --- a/alg/test/test_mussa.cpp +++ b/alg/test/test_mussa.cpp @@ -213,6 +213,20 @@ BOOST_AUTO_TEST_CASE( mussa_named_motif ) BOOST_CHECK_EQUAL(motifs.begin()->get_name(), "cat"); } +BOOST_AUTO_TEST_CASE( mussa_weirdly_spaced_named_motif ) +{ + string data = "CCAATT cat_meow123 0.1 0.2 0.3\n"; + istringstream test_istream(data); + + Mussa m1; + m1.append_sequence("AAAAGGGGTTTT"); + m1.append_sequence("GGGCCCCTTCCAATT"); + m1.load_motifs(test_istream); + + std::set motifs = m1.motifs(); + BOOST_REQUIRE_EQUAL(motifs.size(), 1); + BOOST_CHECK_EQUAL(motifs.begin()->get_name(), "cat_meow123"); +} BOOST_AUTO_TEST_CASE( mussa_add_motif ) { vector motifs; -- 2.30.2