From bf446426ac0dadaa19a706213fa1aefdfa356cb3 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Fri, 30 Jun 2006 01:22:50 +0000 Subject: [PATCH] store motifs as sequences instead of strings this gives me a place to store at least some annotation information about a motif. --- alg/mussa.cpp | 8 ++++---- alg/mussa.hpp | 8 ++++---- alg/sequence.cpp | 2 +- alg/sequence.hpp | 2 +- alg/test/test_mussa.cpp | 2 +- alg/test/test_sequence.cpp | 17 +++++++++++++++++ qui/motif_editor/MotifEditor.cpp | 6 ++++-- 7 files changed, 32 insertions(+), 13 deletions(-) diff --git a/alg/mussa.cpp b/alg/mussa.cpp index af704e8..44f9adb 100644 --- a/alg/mussa.cpp +++ b/alg/mussa.cpp @@ -714,13 +714,13 @@ Mussa::load_old(char * load_file_path, int s_num) //the_paths.save("tmp.save"); } -void Mussa::add_motif(const string& motif, const Color& color) +void Mussa::add_motif(const Sequence& motif, const Color& color) { motif_sequences.insert(motif); color_mapper->appendInstanceColor("motif", motif, color); } -void Mussa::set_motifs(const vector& motifs, +void Mussa::set_motifs(const vector& motifs, const vector& colors) { if (motifs.size() != colors.size()) { @@ -804,7 +804,7 @@ void Mussa::update_sequences_motifs() // clear out old motifs (*seq_i)->clear_motifs(); // for all the motifs in our set, attach them to the current sequence - for(set::iterator motif_i = motif_sequences.begin(); + for(set::iterator motif_i = motif_sequences.begin(); motif_i != motif_sequences.end(); ++motif_i) { @@ -813,7 +813,7 @@ void Mussa::update_sequences_motifs() } } -const set& Mussa::motifs() const +const set& Mussa::motifs() const { return motif_sequences; } diff --git a/alg/mussa.hpp b/alg/mussa.hpp index 2d497f7..5713a6d 100644 --- a/alg/mussa.hpp +++ b/alg/mussa.hpp @@ -146,14 +146,14 @@ public: // manage motif lists //! add a motif it wont be applied until update_sequences_motif is called - void add_motif(const std::string& motifs, const Color& colors); + void add_motif(const Sequence& motifs, const Color& colors); //! add vector of motifs and colors to our motif collection /*! this will automatically call update_sequences_motif * this depends on sets and color maps being unique * (aka if you add the same item more than once it doesn't * increase the size of the data structure) */ - void set_motifs(const std::vector& motifs, + void set_motifs(const std::vector& motifs, const std::vector& colors); //! load motifs from an ifstream /*! The file should look something like @@ -166,7 +166,7 @@ public: //! load a list of motifs from a file named filename void load_motifs(boost::filesystem::path filename); //! return our motifs; - const std::set& motifs() const; + const std::set& motifs() const; //! return color mapper boost::shared_ptr colorMapper(); @@ -200,7 +200,7 @@ public: NwayPaths the_paths; //! motif list - std::set motif_sequences; + std::set motif_sequences; //! color manager boost::shared_ptr color_mapper; diff --git a/alg/sequence.cpp b/alg/sequence.cpp index b9163c0..b8488dc 100644 --- a/alg/sequence.cpp +++ b/alg/sequence.cpp @@ -778,7 +778,7 @@ Sequence::motif_normalize(std::string a_motif) return valid_motif; } -void Sequence::add_motif(std::string a_motif) +void Sequence::add_motif(const Sequence& a_motif) { std::vector motif_starts = find_motif(a_motif); diff --git a/alg/sequence.hpp b/alg/sequence.hpp index f3a93fa..407168e 100644 --- a/alg/sequence.hpp +++ b/alg/sequence.hpp @@ -118,7 +118,7 @@ class Sequence : public std::string std::string get_header() const; //! add a motif to our list of motifs //! \throws motif_normalize_error if there's something wrong with a_motif - void add_motif(std::string a_motif); + void add_motif(const Sequence& a_motif); //! clear our list of found motifs void clear_motifs(); //! search a sequence for a_motif diff --git a/alg/test/test_mussa.cpp b/alg/test/test_mussa.cpp index 2cf19c0..8961a1c 100644 --- a/alg/test/test_mussa.cpp +++ b/alg/test/test_mussa.cpp @@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE( mussa_load_motif ) BOOST_AUTO_TEST_CASE( mussa_add_motif ) { - vector motifs; + vector motifs; motifs.push_back("AAGG"); vector colors; colors.push_back(Color(1.0, 0.0, 0.0)); diff --git a/alg/test/test_sequence.cpp b/alg/test/test_sequence.cpp index cf543fd..812a7a3 100644 --- a/alg/test/test_sequence.cpp +++ b/alg/test/test_sequence.cpp @@ -246,6 +246,23 @@ BOOST_AUTO_TEST_CASE( sequence_motifs ) s1.clear_motifs(); BOOST_CHECK( s1.motifs().begin() == s1.motifs().end() ); + + /* FIXME: enable this when i find a way of passing storing the motif name + // does our annotation travel? + Sequence motif_seq(m); + motif_seq.set_header("hi"); + s1.add_motif(motif_seq); + + BOOST_CHECK_EQUAL(s1.motifs().size(), 2); + for(motif_i = s1.motifs().begin(); + motif_i != s1.motifs().end(); + ++motif_i) + { + BOOST_CHECK_EQUAL( motif_i->type, "motif" ); + BOOST_CHECK_EQUAL( motif_i->name, "hi"); + BOOST_CHECK_EQUAL( motif_i->sequence, m); + } + */ } BOOST_AUTO_TEST_CASE( annot_test ) diff --git a/qui/motif_editor/MotifEditor.cpp b/qui/motif_editor/MotifEditor.cpp index 288f713..12a1e9e 100644 --- a/qui/motif_editor/MotifEditor.cpp +++ b/qui/motif_editor/MotifEditor.cpp @@ -12,7 +12,7 @@ MotifEditor::MotifEditor(Mussa *m, QWidget *parent) applyButton("set motifs") { assert (m != 0); - const set &motif = analysis->motifs(); + const set &motif = analysis->motifs(); vector motif_seq(motif.begin(), motif.end()); connect(&applyButton, SIGNAL(clicked()), this, SLOT(updateMotifs())); @@ -47,7 +47,7 @@ void MotifEditor::updateMotifs() analysis->colorMapper()->appendTypeColor("motif", motif_default); // add our motifs back - vector motifs; + vector motifs; vector colors; for(std::vector::iterator md_i = motif_details.begin(); @@ -55,6 +55,8 @@ void MotifEditor::updateMotifs() ++md_i) { if ((*md_i)->motif().size() > 0 && (*md_i)->enabled()) { + Sequence new_motif((*md_i)->motif()); + new_motif.set_header((*md_i)->name()); motifs.push_back((*md_i)->motif()); colors.push_back((*md_i)->color()); } -- 2.30.2