use Qt Signals & Slots for progress tracking
[mussa.git] / alg / mussa.cpp
1 //  This file is part of the Mussa source distribution.
2 //  http://mussa.caltech.edu/
3 //  Contact author: Tristan  De Buysscher, tristan@caltech.edu
4
5 // This program and all associated source code files are Copyright (C) 2005
6 // the California Institute of Technology, Pasadena, CA, 91125 USA.  It is
7 // under the GNU Public License; please see the included LICENSE.txt
8 // file for more information, or contact Tristan directly.
9
10
11 //                        ----------------------------------------
12 //                          ---------- mussa_class.cc -----------
13 //                        ----------------------------------------
14
15 #include <boost/filesystem/operations.hpp>
16 #include <boost/filesystem/fstream.hpp>
17 namespace fs = boost::filesystem;
18
19 #include <iostream>
20 #include <sstream>
21
22 #include "mussa_exceptions.hpp"
23 #include "alg/mussa.hpp"
24 #include "alg/flp.hpp"
25
26 using namespace std;
27
28
29 Mussa::Mussa()
30 {
31   clear();
32   connect(&the_paths, SIGNAL(progress(const std::string&, int, int)), 
33           this, SIGNAL(progress(const std::string&, int, int)));
34 }
35
36 Mussa::Mussa(const Mussa& m)
37   : analysis_name(m.analysis_name),
38     window(m.window),
39     threshold(m.threshold),
40     soft_thres(m.soft_thres),
41     ana_mode(m.ana_mode),
42     win_append(m.win_append),
43     thres_append(m.thres_append),
44     motif_sequences(m.motif_sequences),
45     color_mapper(m.color_mapper)
46 {
47   connect(&the_paths, SIGNAL(progress(const std::string&, int, int)), 
48           this, SIGNAL(progress(const std::string&, int, int)));
49 }
50
51 // set all parameters to null state
52 void
53 Mussa::clear()
54 {
55   analysis_name = "";
56   ana_mode = TransitiveNway;
57   window = 0;
58   threshold = 0;
59   soft_thres = 0;
60   win_append = false;
61   thres_append = false;
62   motif_sequences.clear();
63   color_mapper.clear();
64   the_paths.clear();
65 }
66
67 // these 5 simple methods manually set the parameters for doing an analysis
68 // used so that the gui can take input from user and setup the analysis
69 // note - still need a set_append(bool, bool) method...
70 void
71 Mussa::set_name(string a_name)
72 {
73   analysis_name = a_name;
74 }
75
76 string Mussa::get_name()
77 {
78   return analysis_name;
79 }
80
81 int 
82 Mussa::size() const
83 {
84   if (the_seqs.size() > 0)
85     return the_seqs.size();
86   else
87     return 0;
88 }
89
90 void
91 Mussa::set_window(int a_window)
92 {
93   window = a_window;
94 }
95
96 int Mussa::get_window() const
97 {
98   return window;
99 }
100
101 void
102 Mussa::set_threshold(int a_threshold)
103 {
104   threshold = a_threshold;
105   if (a_threshold > soft_thres) 
106     soft_thres = a_threshold;
107 }
108
109 int Mussa::get_threshold() const
110 {
111   return threshold;
112 }
113
114 void
115 Mussa::set_soft_threshold(int new_threshold)
116 {
117   if (new_threshold < threshold) {
118     soft_thres = threshold;
119   } else if (new_threshold > window) {
120     soft_thres = window; 
121   } else {
122     soft_thres = new_threshold;
123   }
124 }
125
126 int Mussa::get_soft_threshold() const
127 {
128   return soft_thres;
129 }
130
131 void
132 Mussa::set_analysis_mode(enum analysis_modes new_ana_mode)
133 {
134   ana_mode = new_ana_mode;
135 }
136
137 enum Mussa::analysis_modes Mussa::get_analysis_mode() const
138 {
139   return ana_mode;
140 }
141
142 string Mussa::get_analysis_mode_name() const
143 {
144   switch (ana_mode)
145   {
146   case TransitiveNway:
147     return string("Transitive");
148     break;
149   case RadialNway:
150     return string("Radial");
151     break;
152   case EntropyNway:
153     return string("Entropy");
154     break;
155   case RecursiveNway:
156     return string("[deprecated] Recursive");
157     break;
158   default:
159     throw runtime_error("invalid analysis mode type");
160     break;
161   }
162 }
163
164 const NwayPaths& Mussa::paths() const
165 {
166   return the_paths;
167 }
168
169 //template <class IteratorT>
170 //void Mussa::createLocalAlignment(IteratorT begin, IteratorT end)
171 void Mussa::createLocalAlignment(std::list<ConservedPath>::iterator begin, 
172                                  std::list<ConservedPath>::iterator end, 
173                                  std::list<ConservedPath::path_type>& result,
174                                  std::list<std::vector<bool> >& reversed)
175 {
176   const vector<Sequence>& raw_seq = the_seqs;
177   ConservedPath::path_type aligned_path;
178   size_t i2, i3;
179   int x_start, x_end;
180   int window_length, win_i;
181   int rc_1 = 0; 
182   int rc_2 = 0;
183   vector<bool> rc_list;
184   bool full_match;
185   vector<bool> matched;
186   int align_counter;
187
188   align_counter = 0;
189   for(std::list<ConservedPath>::iterator pathz_i=begin; pathz_i != end; ++pathz_i)
190   {
191     ConservedPath& a_path = *pathz_i;
192     window_length = a_path.window_size;
193     // determine which parts of the path are RC relative to first species
194     rc_list = a_path.reverseComplimented();
195     
196     // loop over each bp in the conserved region for all sequences
197     for(win_i = 0; win_i < window_length; win_i++)
198     {
199       aligned_path.clear();
200       // determine which exact base pairs match between the sequences
201       full_match = true;
202       for(i2 = 0; i2 < a_path.size()-1; i2++)
203       {
204         // assume not rc as most likely, adjust below
205         rc_1 = 0;
206         rc_2 = 0;
207         // no matter the case, any RC node needs adjustments
208         if (a_path[i2] < 0)
209           rc_1 = window_length-1;
210         if (a_path[i2+1] < 0)
211           rc_2 = window_length-1;        
212          
213         x_start = (abs(a_path[i2]-rc_1+win_i));
214         x_end =   (abs(a_path[i2+1]-rc_2+win_i));
215         
216         // RC case handling
217         // ugh, and xor...only want rc coloring if just one of the nodes is rc
218         // if both nodes are rc, then they are 'normal' relative to each other
219         if((rc_list[i2] || rc_list[i2+1] )&&!(rc_list[i2] && rc_list[i2+1]))
220         { //the hideous rc matching logic - not complex, but annoying
221           if(!(( (raw_seq[i2][x_start]=='A')&&(raw_seq[i2+1][x_end]=='T')) ||
222                 ((raw_seq[i2][x_start]=='T')&&(raw_seq[i2+1][x_end]=='A')) ||
223                 ((raw_seq[i2][x_start]=='G')&&(raw_seq[i2+1][x_end]=='C')) ||
224                 ((raw_seq[i2][x_start]=='C')&&(raw_seq[i2+1][x_end]=='G'))) ) 
225           {
226             full_match = false;
227           } else {
228             aligned_path.push_back(x_start);
229           }
230         }
231         else
232         { // forward match
233           if (!( (raw_seq[i2][x_start] == raw_seq[i2+1][x_end]) &&
234                 (raw_seq[i2][x_start] != 'N') &&
235                 (raw_seq[i2+1][x_end] != 'N') ) ) {
236             full_match = false;
237           } else {
238             aligned_path.push_back(x_start);
239           }
240         }
241       }
242       // grab the last part of our path, assuming we matched
243       if (full_match)
244         aligned_path.push_back(x_end);
245
246       if (aligned_path.size() == a_path.size()) {
247         result.push_back(aligned_path);
248         reversed.push_back(rc_list);
249       }
250     }
251     align_counter++;
252   }
253 }
254
255
256 // takes a string and sets it as the next seq 
257 void
258 Mussa::add_a_seq(string a_seq)
259 {
260   Sequence aSeq;
261
262   aSeq.set_seq(a_seq);
263   the_seqs.push_back(aSeq);
264 }
265
266 const vector<Sequence>& 
267 Mussa::sequences() const
268 {
269   return the_seqs;
270 }
271
272 void Mussa::load_sequence(fs::path seq_file, fs::path annot_file, 
273                           int fasta_index, int sub_seq_start, int sub_seq_end)
274 {
275   Sequence aseq;
276   aseq.load_fasta(seq_file, fasta_index, sub_seq_start, sub_seq_end);
277   if ( not annot_file.empty() ) {
278     aseq.load_annot(annot_file, sub_seq_start, sub_seq_end);
279   }
280   the_seqs.push_back(aseq);
281 }
282
283 void
284 Mussa::load_mupa_file(fs::path para_file_path)
285 {
286   fs::ifstream para_file;
287   string file_data_line;
288   string param, value; 
289   fs::path annot_file;
290   int split_index, fasta_index;
291   int sub_seq_start, sub_seq_end;
292   bool seq_params, did_seq;
293   string err_msg;
294   bool parsing_path;
295   string::size_type new_index, dir_index;
296
297   // initialize values
298   clear();
299
300   // if file was opened, read the parameter values
301   if (fs::exists(para_file_path))
302   {
303     para_file.open(para_file_path, ios::in);
304
305     // what directory is the mupa file in?
306     fs::path file_path_base = para_file_path.branch_path();
307
308     // setup loop by getting file's first line
309     getline(para_file,file_data_line);
310     split_index = file_data_line.find(" ");
311     param = file_data_line.substr(0,split_index);
312     value = file_data_line.substr(split_index+1);
313     
314     while (!para_file.eof())
315     {
316       did_seq = false;
317       if (param == "ANA_NAME")
318         analysis_name = value;
319       else if (param == "APPEND_WIN")
320         win_append = true;
321       else if (param == "APPEND_THRES")
322         thres_append = true;
323       else if (param == "SEQUENCE_NUM")
324         ; // ignore sequence_num now
325       else if (param == "WINDOW")
326         window = atoi(value.c_str());
327       else if (param == "THRESHOLD")
328         threshold = atoi(value.c_str());
329       else if (param == "SEQUENCE")
330       {
331         fs::path seq_file = file_path_base / value;
332         //cout << "seq_file_name " << seq_files.back() << endl;
333         fasta_index = 1;
334         annot_file = "";
335         sub_seq_start = 0;
336         sub_seq_end = 0;
337         seq_params = true;
338
339         while ((!para_file.eof()) && seq_params)
340         {
341           getline(para_file,file_data_line);
342           split_index = file_data_line.find(" ");
343           param = file_data_line.substr(0,split_index);
344           value = file_data_line.substr(split_index+1);
345
346           if (param == "FASTA_INDEX")
347             fasta_index = atoi(value.c_str());
348           else if (param == "ANNOTATION")
349             annot_file = file_path_base / value;
350           else if (param == "SEQ_START")
351             sub_seq_start = atoi(value.c_str());
352           else if (param == "SEQ_END")
353           {
354             sub_seq_end = atoi(value.c_str());
355           }
356           //ignore empty lines or that start with '#'
357           else if ((param == "") || (param == "#")) {}
358           else seq_params = false;
359         }
360         load_sequence(seq_file, annot_file, fasta_index, sub_seq_start, 
361                       sub_seq_end);
362         did_seq = true;
363       }
364       //ignore empty lines or that start with '#'
365       else if ((param == "") || (param == "#")) {}
366       else
367       {
368         clog << "Illegal/misplaced mussa parameter in file\n";
369         clog << param << "\n";
370       }
371
372       if (!did_seq)
373       {
374         getline(para_file,file_data_line);
375         split_index = file_data_line.find(" ");
376         param = file_data_line.substr(0,split_index);
377         value = file_data_line.substr(split_index+1);
378         did_seq = false;
379       }
380     }
381
382     para_file.close();
383
384     soft_thres = threshold;
385     //cout << "nway mupa: analysis_name = " << analysis_name 
386     //     << " window = " << window 
387     //     << " threshold = " << threshold << endl;
388   }
389   // no file was loaded, signal error
390   else
391   {
392     throw mussa_load_error("Config File: " + para_file_path.string() + " not found");
393   }
394 }
395
396
397 void
398 Mussa::analyze()
399 {
400   time_t t1, t2, begin, end;
401   double seqloadtime, seqcomptime, nwaytime, savetime, totaltime;
402
403   begin = time(NULL);
404
405   t1 = time(NULL);
406         
407   if (the_seqs.size() < 2) {
408     throw mussa_analysis_error("you need to have at least 2 sequences to "
409                                "do an analysis.");
410   }
411   //cout << "nway ana: seq_num = " << the_seqs.size() << endl;
412
413   t2 = time(NULL);
414   seqloadtime = difftime(t2, t1);
415
416   t1 = time(NULL);
417   seqcomp();
418   t2 = time(NULL);
419   seqcomptime = difftime(t2, t1);
420
421   t1 = time(NULL);
422   the_paths.setup(window, threshold);
423   nway();
424   t2 = time(NULL);
425   nwaytime = difftime(t2, t1);
426
427   t1 = time(NULL);
428   save();
429   t2 = time(NULL);
430   savetime = difftime(t2, t1);
431
432   end = time(NULL);
433   totaltime = difftime(end, begin);
434
435   //cout << "seqload\tseqcomp\tnway\tsave\ttotal\n";
436   //cout << seqloadtime << "\t";
437   //cout << seqcomptime << "\t";
438   //cout << nwaytime << "\t";
439   //cout << savetime << "\t";
440   //cout << totaltime << "\n";
441 }
442
443 void
444 Mussa::seqcomp()
445 {
446   vector<int> seq_lens;
447   vector<FLPs> empty_FLP_vector;
448   FLPs dummy_comp;
449   string save_file_string;
450
451   empty_FLP_vector.clear();
452   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
453   {
454     all_comps.push_back(empty_FLP_vector); 
455     for(vector<Sequence>::size_type i2 = 0; i2 < the_seqs.size(); i2++)
456       all_comps[i].push_back(dummy_comp);
457   }
458   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++) {
459     seq_lens.push_back(the_seqs[i].size());
460   }
461   int seqcomps_done = 0;
462   int seqcomps_todo = (the_seqs.size() * (the_seqs.size()-1)) / 2;
463   emit progress("seqcomp", seqcomps_done, seqcomps_todo);
464
465   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
466     for(vector<Sequence>::size_type i2 = i+1; i2 < the_seqs.size(); i2++)
467     {
468       //cout << "seqcomping: " << i << " v. " << i2 << endl;
469       all_comps[i][i2].setup(window, threshold);
470       all_comps[i][i2].seqcomp(the_seqs[i].get_seq(), the_seqs[i2].get_seq(), false);
471       all_comps[i][i2].seqcomp(the_seqs[i].get_seq(),the_seqs[i2].rev_comp(),true);
472       ++seqcomps_done;
473       emit progress("seqcomp", seqcomps_done, seqcomps_todo);
474     }
475 }
476
477 void
478 Mussa::nway()
479 {
480   vector<string> some_Seqs;
481
482   the_paths.set_soft_threshold(soft_thres);
483
484   if (ana_mode == TransitiveNway) {
485     the_paths.trans_path_search(all_comps);
486   }
487   else if (ana_mode == RadialNway) {
488     the_paths.radiate_path_search(all_comps);
489   }
490   else if (ana_mode == EntropyNway)
491   {
492     //unlike other methods, entropy needs to look at the sequence at this stage
493     some_Seqs.clear();
494     for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
495     {
496       some_Seqs.push_back(the_seqs[i].get_seq());
497     }
498
499     the_paths.setup_ent(ent_thres, some_Seqs); // ent analysis extra setup
500     the_paths.entropy_path_search(all_comps);
501   }
502
503   // old recursive transitive analysis function
504   else if (ana_mode == RecursiveNway)
505     the_paths.find_paths_r(all_comps);
506
507   the_paths.simple_refine();
508 }
509
510 void
511 Mussa::save()
512 {
513   string save_name;
514   fs::path flp_filepath;
515   fs::fstream save_file;
516   ostringstream append_info;
517   int dir_create_status;
518
519   if (not analysis_name.empty()) {
520     // not sure why, but gotta close file each time since can't pass 
521     // file streams
522     save_name = analysis_name;
523
524     // gotta do bit with adding win & thres if to be appended
525     if (win_append)
526     {
527       append_info.str("");
528       append_info <<  "_w" << window;
529       save_name += append_info.str();
530     }
531
532     if (thres_append)
533     {
534       append_info.str("");
535       append_info <<  "_t" << threshold;
536       save_name += append_info.str();
537     }
538     fs::path save_path( save_name);
539
540     if (not fs::exists(save_path)) {
541       fs::create_directory(save_path);
542     }
543     // save sequence and annots to a special mussa file
544     save_file.open(save_path / (save_name+".museq"), ios::out);
545     save_file << "<Mussa_Sequence>" << endl;
546
547     for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
548     {
549       the_seqs[i].save(save_file);
550     }
551
552     save_file << "</Mussa_Sequence>" << endl;
553     save_file.close();
554
555     // save nway paths to its mussa save file
556     the_paths.save(save_path / (save_name + ".muway"));
557
558     for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
559       for(vector<Sequence>::size_type i2 = i+1; i2 < the_seqs.size(); i2++)
560       {
561         append_info.str("");
562         append_info <<  "_sp_" << i << "v" << i2;
563         all_comps[i][i2].save(save_path/(save_name+append_info.str()+".flp"));
564       }
565   }
566 }
567
568 void
569 Mussa::save_muway(fs::path save_path)
570 {
571   the_paths.save(save_path);
572 }
573
574 void
575 Mussa::load(fs::path ana_file)
576 {
577   int i, i2;
578   fs::path file_path_base;
579   fs::path a_file_path; 
580   fs::path ana_path(ana_file);
581   bool parsing_path;
582   Sequence tmp_seq;
583   string err_msg;
584   ostringstream append_info;
585   vector<FLPs> empty_FLP_vector;
586   FLPs dummy_comp;
587
588   //cout << "ana_file name " << ana_file.string() << endl;
589   analysis_name = ana_path.leaf();
590   //cout << " ana_name " << analysis_name << endl;
591   file_path_base =  ana_path.branch_path() / analysis_name;
592   a_file_path = file_path_base / (analysis_name + ".muway");
593   //cout << " loading museq: " << a_file_path.string() << endl;
594   the_paths.load(a_file_path);
595   // perhaps this could be more elegent, but at least this'll let
596   // us know what our threshold and window sizes were when we load a muway
597   window = the_paths.get_window();
598   threshold = the_paths.get_threshold();
599   soft_thres = threshold;
600
601   int seq_num = the_paths.sequence_count();
602
603   a_file_path = file_path_base / (analysis_name + ".museq");
604
605   // this is a bit of a hack due to C++ not acting like it should with files
606   for (i = 1; i <= seq_num; i++)
607   {
608     tmp_seq.clear();
609     //cout << "mussa_class: loading museq frag... " << a_file_path.string() << endl;
610     tmp_seq.load_museq(a_file_path, i);
611     the_seqs.push_back(tmp_seq);
612   }
613   
614   empty_FLP_vector.clear();
615   for(i = 0; i < seq_num; i++)
616   {
617     all_comps.push_back(empty_FLP_vector); 
618     for(i2 = 0; i2 < seq_num; i2++)
619       all_comps[i].push_back(dummy_comp);
620   }
621   
622   for(i = 0; i < seq_num; i++)
623   {
624     for(i2 = i+1; i2 < seq_num; i2++)
625     {
626       append_info.str("");
627       append_info << analysis_name <<  "_sp_" << i << "v" << i2 << ".flp";
628       //cout << append_info.str() << endl;
629       a_file_path = file_path_base / append_info.str();
630       //cout << "path " << a_file_path.string() << endl;
631       all_comps[i][i2].load(a_file_path);
632       //cout << "real size = " << all_comps[i][i2].size() << endl;
633     }
634   }
635 }
636
637
638 void
639 Mussa::save_old()
640 {
641   fs::fstream save_file;
642
643   save_file.open(analysis_name, ios::out);
644
645   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
646     save_file << the_seqs[i].get_seq() << endl;
647
648   save_file << window << endl;
649   save_file.close();
650   //note more complex eventually since analysis_name may need to have
651   //window size, threshold and other stuff to modify it...
652   the_paths.save_old(analysis_name);
653 }
654
655
656 void
657 Mussa::load_old(char * load_file_path, int s_num)
658 {
659   fstream save_file;
660   string file_data_line; 
661   int i, space_split_i, comma_split_i;
662   vector<int> loaded_path;
663   string node_pair, node;
664   Sequence a_seq;
665
666   int seq_num = s_num;
667   the_paths.setup(0, 0);
668   save_file.open(load_file_path, ios::in);
669
670   // currently loads old mussa format
671
672   // get sequences
673   for(i = 0; i < seq_num; i++)
674   {
675     getline(save_file, file_data_line);
676     a_seq.set_seq(file_data_line);
677     the_seqs.push_back(a_seq);
678   }
679
680   // get window size
681   getline(save_file, file_data_line);
682   window = atoi(file_data_line.c_str());
683   // get paths
684
685   while (!save_file.eof())
686   {
687     loaded_path.clear();
688     getline(save_file, file_data_line);
689     if (file_data_line != "")
690     for(i = 0; i < seq_num; i++)
691     {
692       space_split_i = file_data_line.find(" ");
693       node_pair = file_data_line.substr(0,space_split_i);
694       //cout << "np= " << node_pair;
695       comma_split_i = node_pair.find(",");
696       node = node_pair.substr(comma_split_i+1);
697       //cout << "n= " << node << " ";
698       loaded_path.push_back(atoi (node.c_str()));
699       file_data_line = file_data_line.substr(space_split_i+1);
700     }
701     //cout << endl;
702     // FIXME: do we have any information about what the threshold should be?
703     the_paths.add_path(0, loaded_path);
704   }
705   save_file.close();
706
707   //the_paths.save("tmp.save");
708 }
709
710 void Mussa::add_motifs(const vector<string>& motifs, 
711                        const vector<Color>& colors)
712 {
713   if (motifs.size() != colors.size()) {
714     throw mussa_error("motif and color vectors must be the same size");
715   }
716
717   for(size_t i = 0; i != motifs.size(); ++i)
718   {
719     motif_sequences.insert(motifs[i]);
720     color_mapper.appendInstanceColor("motif", motifs[i], colors[i]);
721   }
722   update_sequences_motifs();
723 }
724
725 // I mostly split the ifstream out so I can use a stringstream to test it.
726 void Mussa::load_motifs(std::istream &in)
727 {
728   string seq;
729   float red;
730   float green;
731   float blue;
732
733   while(in.good())
734   {
735     in >> seq >> red >> green >> blue;
736     // if we couldn't read this line 'cause we're like at the end of the file
737     // try to exit the loop
738     if (!in.good())
739       break;
740     try {
741       seq = Sequence::motif_normalize(seq);
742     } catch(motif_normalize_error e) {
743       clog << "unable to parse " << seq << " skipping" << endl;
744       clog << e.what() << endl;
745       continue;
746     }
747     if (red < 0.0 or red > 1.0) {
748       clog << "invalid red value " << red << ". must be in range [0..1]" 
749            << endl;
750       continue;
751     }
752     if (green < 0.0 or green > 1.0) {
753       clog << "invalid green value " << green << ". must be in range [0..1]" 
754            << endl;
755       continue;
756     }
757     if (blue < 0.0 or blue > 1.0) {
758       clog << "invalid blue value " << blue << ". must be in range [0..1]" 
759            << endl;
760       continue;
761     }
762     if (motif_sequences.find(seq) == motif_sequences.end()) {
763       // sequence wasn't found
764       motif_sequences.insert(seq);
765       Color c(red, green, blue);
766       color_mapper.appendInstanceColor("motif", seq, c);
767     } else {
768       clog << "sequence " << seq << " was already defined skipping" 
769            << endl;
770       continue;
771     }
772   }
773   update_sequences_motifs();
774 }
775
776 void Mussa::load_motifs(fs::path filename)
777 {
778   fs::ifstream f;
779   f.open(filename, ifstream::in);
780   load_motifs(f);
781 }
782
783 void Mussa::update_sequences_motifs()
784 {
785   // once we've loaded all the motifs from the file, 
786   // lets attach them to the sequences
787   for(vector<Sequence>::iterator seq_i = the_seqs.begin();
788       seq_i != the_seqs.end();
789       ++seq_i)
790   {
791     // clear out old motifs
792     seq_i->clear_motifs();
793     // for all the motifs in our set, attach them to the current sequence
794     for(set<string>::iterator motif_i = motif_sequences.begin();
795         motif_i != motif_sequences.end();
796         ++motif_i)
797     {
798       seq_i->add_motif(*motif_i);
799     }
800   }
801 }
802
803 const set<string>& Mussa::motifs() const
804 {
805   return motif_sequences;
806 }
807
808 AnnotationColors& Mussa::colorMapper()
809 {
810   return color_mapper;
811 }