+
+// I mostly split the ifstream out so I can use a stringstream to test it.
+void Mussa::load_motifs(std::istream &in)
+{
+ string seq;
+ float red;
+ float green;
+ float blue;
+
+ while(in.good())
+ {
+ in >> seq >> red >> green >> blue;
+ // if we couldn't read this line 'cause we're like at the end of the file
+ // try to exit the loop
+ if (!in.good())
+ break;
+ try {
+ seq = Sequence::motif_normalize(seq);
+ } catch(motif_normalize_error e) {
+ clog << "unable to parse " << seq << " skipping" << endl;
+ clog << e.what() << endl;
+ continue;
+ }
+ if (red < 0.0 or red > 1.0) {
+ clog << "invalid red value " << red << ". must be in range [0..1]"
+ << endl;
+ continue;
+ }
+ if (green < 0.0 or green > 1.0) {
+ clog << "invalid green value " << green << ". must be in range [0..1]"
+ << endl;
+ continue;
+ }
+ if (blue < 0.0 or blue > 1.0) {
+ clog << "invalid blue value " << blue << ". must be in range [0..1]"
+ << endl;
+ continue;
+ }
+ if (motif_sequences.find(seq) == motif_sequences.end()) {
+ // sequence wasn't found
+ motif_sequences.insert(seq);
+ Color c(red, green, blue);
+ color_mapper.appendInstanceColor("motif", seq, c);
+ } else {
+ clog << "sequence " << seq << " was already defined skipping"
+ << endl;
+ continue;
+ }
+ }
+ // once we've loaded all the motifs from the file,
+ // lets attach them to the sequences
+ for(vector<Sequence>::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<string>::iterator motif_i = motif_sequences.begin();
+ motif_i != motif_sequences.end();
+ ++motif_i)
+ {
+ seq_i->add_motif(*motif_i);
+ }
+ }
+}
+
+void Mussa::load_motifs(string filename)
+{
+ ifstream f;
+ f.open(filename.c_str(), ifstream::in);
+ load_motifs(f);
+}
+
+AnnotationColors& Mussa::colorMapper()
+{
+ return color_mapper;
+}