+
+void Mussa::add_motif(const Sequence& motif, const Color& color)
+{
+ motif_sequences.insert(motif);
+ color_mapper->appendInstanceColor("motif", motif.get_sequence(), color);
+ set_dirty(true);
+}
+
+void Mussa::set_motifs(const vector<Sequence>& motifs,
+ const vector<Color>& colors)
+{
+ if (motifs.size() != colors.size()) {
+ throw mussa_error("motif and color vectors must be the same size");
+ }
+
+ motif_sequences.clear();
+ for(size_t i = 0; i != motifs.size(); ++i)
+ {
+ add_motif(motifs[i], colors[i]);
+ }
+ update_sequences_motifs();
+}
+
+void Mussa::load_motifs(fs::path filename)
+{
+ fs::ifstream f;
+ f.open(filename, ifstream::in);
+ load_motifs(f);
+}
+
+void Mussa::load_motifs(std::istream &in)
+{
+ std::string data;
+ const char *alphabet = Alphabet::dna_cstr;
+ motif_parser::ParsedMotifs parsed_motifs(motif_sequences, color_mapper);
+
+ // slurp our data into a string
+ std::streamsize bytes_read = 1;
+ while (in.good() and bytes_read) {
+ const std::streamsize bufsiz=512;
+ char buf[bufsiz];
+ bytes_read = in.readsome(buf, bufsiz);
+ data.append(buf, buf+bytes_read);
+ }
+ parsed_motifs.parse(data);
+ update_sequences_motifs();
+}
+
+void Mussa::save_motifs(fs::path filename)
+{
+ fs::ofstream out_stream;
+ out_stream.open(filename, ofstream::out);
+ save_motifs(out_stream);
+}
+
+void Mussa::save_motifs(std::ostream& out)
+{
+ for(motif_set::iterator motif_i = motif_sequences.begin();
+ motif_i != motif_sequences.end();
+ ++motif_i)
+ {
+ out << motif_i->get_sequence() << " ";
+ if (motif_i->get_name().size() > 0) {
+ out << "\"" << motif_i->get_name() << "\" ";
+ }
+ out << color_mapper->lookup("motif", motif_i->get_sequence());
+ out << std::endl;
+ }
+}
+
+void Mussa::update_sequences_motifs()
+{
+ // once we've loaded all the motifs from the file,
+ // lets attach them to the sequences
+ for(vector<SequenceRef >::iterator seq_i = the_seqs.begin();
+ seq_i != the_seqs.end();
+ ++seq_i)
+ {
+ // clear out old motifs
+ (*seq_i)->clear_motifs();
+ // for all the motifs in our set, attach them to the current sequence
+ for(set<Sequence>::iterator motif_i = motif_sequences.begin();
+ motif_i != motif_sequences.end();
+ ++motif_i)
+ {
+ (*seq_i)->add_motif(*motif_i);
+ }
+ }
+}
+
+const set<Sequence>& Mussa::motifs() const
+{
+ return motif_sequences;
+}
+
+boost::shared_ptr<AnnotationColors> Mussa::colorMapper()
+{
+ return color_mapper;
+}