More progress toward subanalysis
[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 void Mussa::append_sequence(Sequence a_seq)
257 {
258   the_seqs.push_back(a_seq);
259 }
260
261 const vector<Sequence>& 
262 Mussa::sequences() const
263 {
264   return the_seqs;
265 }
266
267 void Mussa::load_sequence(fs::path seq_file, fs::path annot_file, 
268                           int fasta_index, int sub_seq_start, int sub_seq_end)
269 {
270   Sequence aseq;
271   aseq.load_fasta(seq_file, fasta_index, sub_seq_start, sub_seq_end);
272   if ( not annot_file.empty() ) {
273     aseq.load_annot(annot_file, sub_seq_start, sub_seq_end);
274   }
275   the_seqs.push_back(aseq);
276 }
277
278 void
279 Mussa::load_mupa_file(fs::path para_file_path)
280 {
281   fs::ifstream para_file;
282   string file_data_line;
283   string param, value; 
284   fs::path annot_file;
285   int split_index, fasta_index;
286   int sub_seq_start, sub_seq_end;
287   bool seq_params, did_seq;
288   string err_msg;
289   bool parsing_path;
290   string::size_type new_index, dir_index;
291
292   // initialize values
293   clear();
294
295   // if file was opened, read the parameter values
296   if (fs::exists(para_file_path))
297   {
298     para_file.open(para_file_path, ios::in);
299
300     // what directory is the mupa file in?
301     fs::path file_path_base = para_file_path.branch_path();
302
303     // setup loop by getting file's first line
304     getline(para_file,file_data_line);
305     split_index = file_data_line.find(" ");
306     param = file_data_line.substr(0,split_index);
307     value = file_data_line.substr(split_index+1);
308     
309     while (!para_file.eof())
310     {
311       did_seq = false;
312       if (param == "ANA_NAME")
313         analysis_name = value;
314       else if (param == "APPEND_WIN")
315         win_append = true;
316       else if (param == "APPEND_THRES")
317         thres_append = true;
318       else if (param == "SEQUENCE_NUM")
319         ; // ignore sequence_num now
320       else if (param == "WINDOW")
321         window = atoi(value.c_str());
322       else if (param == "THRESHOLD")
323         threshold = atoi(value.c_str());
324       else if (param == "SEQUENCE")
325       {
326         fs::path seq_file = file_path_base / value;
327         //cout << "seq_file_name " << seq_files.back() << endl;
328         fasta_index = 1;
329         annot_file = "";
330         sub_seq_start = 0;
331         sub_seq_end = 0;
332         seq_params = true;
333
334         while ((!para_file.eof()) && seq_params)
335         {
336           getline(para_file,file_data_line);
337           split_index = file_data_line.find(" ");
338           param = file_data_line.substr(0,split_index);
339           value = file_data_line.substr(split_index+1);
340
341           if (param == "FASTA_INDEX")
342             fasta_index = atoi(value.c_str());
343           else if (param == "ANNOTATION")
344             annot_file = file_path_base / value;
345           else if (param == "SEQ_START")
346             sub_seq_start = atoi(value.c_str());
347           else if (param == "SEQ_END")
348           {
349             sub_seq_end = atoi(value.c_str());
350           }
351           //ignore empty lines or that start with '#'
352           else if ((param == "") || (param == "#")) {}
353           else seq_params = false;
354         }
355         load_sequence(seq_file, annot_file, fasta_index, sub_seq_start, 
356                       sub_seq_end);
357         did_seq = true;
358       }
359       //ignore empty lines or that start with '#'
360       else if ((param == "") || (param == "#")) {}
361       else
362       {
363         clog << "Illegal/misplaced mussa parameter in file\n";
364         clog << param << "\n";
365       }
366
367       if (!did_seq)
368       {
369         getline(para_file,file_data_line);
370         split_index = file_data_line.find(" ");
371         param = file_data_line.substr(0,split_index);
372         value = file_data_line.substr(split_index+1);
373         did_seq = false;
374       }
375     }
376
377     para_file.close();
378
379     soft_thres = threshold;
380     //cout << "nway mupa: analysis_name = " << analysis_name 
381     //     << " window = " << window 
382     //     << " threshold = " << threshold << endl;
383   }
384   // no file was loaded, signal error
385   else
386   {
387     throw mussa_load_error("Config File: " + para_file_path.string() + " not found");
388   }
389 }
390
391
392 void
393 Mussa::analyze()
394 {
395   time_t t1, t2, begin, end;
396   double seqloadtime, seqcomptime, nwaytime, savetime, totaltime;
397
398   begin = time(NULL);
399
400   t1 = time(NULL);
401         
402   if (the_seqs.size() < 2) {
403     throw mussa_analysis_error("you need to have at least 2 sequences to "
404                                "do an analysis.");
405   }
406   //cout << "nway ana: seq_num = " << the_seqs.size() << endl;
407
408   t2 = time(NULL);
409   seqloadtime = difftime(t2, t1);
410
411   t1 = time(NULL);
412   seqcomp();
413   t2 = time(NULL);
414   seqcomptime = difftime(t2, t1);
415
416   t1 = time(NULL);
417   the_paths.setup(window, threshold);
418   nway();
419   t2 = time(NULL);
420   nwaytime = difftime(t2, t1);
421
422   t1 = time(NULL);
423   save();
424   t2 = time(NULL);
425   savetime = difftime(t2, t1);
426
427   end = time(NULL);
428   totaltime = difftime(end, begin);
429
430   //cout << "seqload\tseqcomp\tnway\tsave\ttotal\n";
431   //cout << seqloadtime << "\t";
432   //cout << seqcomptime << "\t";
433   //cout << nwaytime << "\t";
434   //cout << savetime << "\t";
435   //cout << totaltime << "\n";
436 }
437
438 void
439 Mussa::seqcomp()
440 {
441   vector<int> seq_lens;
442   vector<FLPs> empty_FLP_vector;
443   FLPs dummy_comp;
444   string save_file_string;
445
446   empty_FLP_vector.clear();
447   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
448   {
449     all_comps.push_back(empty_FLP_vector); 
450     for(vector<Sequence>::size_type i2 = 0; i2 < the_seqs.size(); i2++)
451       all_comps[i].push_back(dummy_comp);
452   }
453   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++) {
454     seq_lens.push_back(the_seqs[i].size());
455   }
456   int seqcomps_done = 0;
457   int seqcomps_todo = (the_seqs.size() * (the_seqs.size()-1)) / 2;
458   emit progress("seqcomp", seqcomps_done, seqcomps_todo);
459
460   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
461     for(vector<Sequence>::size_type i2 = i+1; i2 < the_seqs.size(); i2++)
462     {
463       //cout << "seqcomping: " << i << " v. " << i2 << endl;
464       all_comps[i][i2].setup(window, threshold);
465       all_comps[i][i2].seqcomp(the_seqs[i], the_seqs[i2], false);
466       all_comps[i][i2].seqcomp(the_seqs[i], the_seqs[i2].rev_comp(),true);
467       ++seqcomps_done;
468       emit progress("seqcomp", seqcomps_done, seqcomps_todo);
469     }
470 }
471
472 void
473 Mussa::nway()
474 {
475   vector<string> some_Seqs;
476
477   the_paths.set_soft_threshold(soft_thres);
478
479   if (ana_mode == TransitiveNway) {
480     the_paths.trans_path_search(all_comps);
481   }
482   else if (ana_mode == RadialNway) {
483     the_paths.radiate_path_search(all_comps);
484   }
485   else if (ana_mode == EntropyNway)
486   {
487     //unlike other methods, entropy needs to look at the sequence at this stage
488     some_Seqs.clear();
489     for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
490     {
491       some_Seqs.push_back(the_seqs[i]);
492     }
493
494     the_paths.setup_ent(ent_thres, some_Seqs); // ent analysis extra setup
495     the_paths.entropy_path_search(all_comps);
496   }
497
498   // old recursive transitive analysis function
499   else if (ana_mode == RecursiveNway)
500     the_paths.find_paths_r(all_comps);
501
502   the_paths.simple_refine();
503 }
504
505 void
506 Mussa::save()
507 {
508   string save_name;
509   fs::path flp_filepath;
510   fs::fstream save_file;
511   ostringstream append_info;
512   int dir_create_status;
513
514   if (not analysis_name.empty()) {
515     // not sure why, but gotta close file each time since can't pass 
516     // file streams
517     save_name = analysis_name;
518
519     // gotta do bit with adding win & thres if to be appended
520     if (win_append)
521     {
522       append_info.str("");
523       append_info <<  "_w" << window;
524       save_name += append_info.str();
525     }
526
527     if (thres_append)
528     {
529       append_info.str("");
530       append_info <<  "_t" << threshold;
531       save_name += append_info.str();
532     }
533     fs::path save_path( save_name);
534
535     if (not fs::exists(save_path)) {
536       fs::create_directory(save_path);
537     }
538     // save sequence and annots to a special mussa file
539     save_file.open(save_path / (save_name+".museq"), ios::out);
540     save_file << "<Mussa_Sequence>" << endl;
541
542     for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
543     {
544       the_seqs[i].save(save_file);
545     }
546
547     save_file << "</Mussa_Sequence>" << endl;
548     save_file.close();
549
550     // save nway paths to its mussa save file
551     the_paths.save(save_path / (save_name + ".muway"));
552
553     for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
554       for(vector<Sequence>::size_type i2 = i+1; i2 < the_seqs.size(); i2++)
555       {
556         append_info.str("");
557         append_info <<  "_sp_" << i << "v" << i2;
558         all_comps[i][i2].save(save_path/(save_name+append_info.str()+".flp"));
559       }
560   }
561 }
562
563 void
564 Mussa::save_muway(fs::path save_path)
565 {
566   the_paths.save(save_path);
567 }
568
569 void
570 Mussa::load(fs::path ana_file)
571 {
572   int i, i2;
573   fs::path file_path_base;
574   fs::path a_file_path; 
575   fs::path ana_path(ana_file);
576   bool parsing_path;
577   Sequence tmp_seq;
578   string err_msg;
579   ostringstream append_info;
580   vector<FLPs> empty_FLP_vector;
581   FLPs dummy_comp;
582
583   //cout << "ana_file name " << ana_file.string() << endl;
584   analysis_name = ana_path.leaf();
585   //cout << " ana_name " << analysis_name << endl;
586   file_path_base =  ana_path.branch_path() / analysis_name;
587   a_file_path = file_path_base / (analysis_name + ".muway");
588   //cout << " loading museq: " << a_file_path.string() << endl;
589   the_paths.load(a_file_path);
590   // perhaps this could be more elegent, but at least this'll let
591   // us know what our threshold and window sizes were when we load a muway
592   window = the_paths.get_window();
593   threshold = the_paths.get_threshold();
594   soft_thres = threshold;
595
596   int seq_num = the_paths.sequence_count();
597
598   a_file_path = file_path_base / (analysis_name + ".museq");
599
600   // this is a bit of a hack due to C++ not acting like it should with files
601   for (i = 1; i <= seq_num; i++)
602   {
603     tmp_seq.clear();
604     //cout << "mussa_class: loading museq frag... " << a_file_path.string() << endl;
605     tmp_seq.load_museq(a_file_path, i);
606     the_seqs.push_back(tmp_seq);
607   }
608   
609   empty_FLP_vector.clear();
610   for(i = 0; i < seq_num; i++)
611   {
612     all_comps.push_back(empty_FLP_vector); 
613     for(i2 = 0; i2 < seq_num; i2++)
614       all_comps[i].push_back(dummy_comp);
615   }
616   
617   for(i = 0; i < seq_num; i++)
618   {
619     for(i2 = i+1; i2 < seq_num; i2++)
620     {
621       append_info.str("");
622       append_info << analysis_name <<  "_sp_" << i << "v" << i2 << ".flp";
623       //cout << append_info.str() << endl;
624       a_file_path = file_path_base / append_info.str();
625       //cout << "path " << a_file_path.string() << endl;
626       all_comps[i][i2].load(a_file_path);
627       //cout << "real size = " << all_comps[i][i2].size() << endl;
628     }
629   }
630 }
631
632
633 void
634 Mussa::save_old()
635 {
636   fs::fstream save_file;
637
638   save_file.open(analysis_name, ios::out);
639
640   for(vector<Sequence>::size_type i = 0; i < the_seqs.size(); i++)
641     save_file << the_seqs[i] << endl;
642
643   save_file << window << endl;
644   save_file.close();
645   //note more complex eventually since analysis_name may need to have
646   //window size, threshold and other stuff to modify it...
647   the_paths.save_old(analysis_name);
648 }
649
650
651 void
652 Mussa::load_old(char * load_file_path, int s_num)
653 {
654   fstream save_file;
655   string file_data_line; 
656   int i, space_split_i, comma_split_i;
657   vector<int> loaded_path;
658   string node_pair, node;
659   Sequence a_seq;
660
661   int seq_num = s_num;
662   the_paths.setup(0, 0);
663   save_file.open(load_file_path, ios::in);
664
665   // currently loads old mussa format
666
667   // get sequences
668   for(i = 0; i < seq_num; i++)
669   {
670     getline(save_file, file_data_line);
671     a_seq = file_data_line;
672     the_seqs.push_back(a_seq);
673   }
674
675   // get window size
676   getline(save_file, file_data_line);
677   window = atoi(file_data_line.c_str());
678   // get paths
679
680   while (!save_file.eof())
681   {
682     loaded_path.clear();
683     getline(save_file, file_data_line);
684     if (file_data_line != "")
685     for(i = 0; i < seq_num; i++)
686     {
687       space_split_i = file_data_line.find(" ");
688       node_pair = file_data_line.substr(0,space_split_i);
689       //cout << "np= " << node_pair;
690       comma_split_i = node_pair.find(",");
691       node = node_pair.substr(comma_split_i+1);
692       //cout << "n= " << node << " ";
693       loaded_path.push_back(atoi (node.c_str()));
694       file_data_line = file_data_line.substr(space_split_i+1);
695     }
696     //cout << endl;
697     // FIXME: do we have any information about what the threshold should be?
698     the_paths.add_path(0, loaded_path);
699   }
700   save_file.close();
701
702   //the_paths.save("tmp.save");
703 }
704
705 void Mussa::add_motifs(const vector<string>& motifs, 
706                        const vector<Color>& colors)
707 {
708   if (motifs.size() != colors.size()) {
709     throw mussa_error("motif and color vectors must be the same size");
710   }
711
712   for(size_t i = 0; i != motifs.size(); ++i)
713   {
714     motif_sequences.insert(motifs[i]);
715     color_mapper.appendInstanceColor("motif", motifs[i], colors[i]);
716   }
717   update_sequences_motifs();
718 }
719
720 // I mostly split the ifstream out so I can use a stringstream to test it.
721 void Mussa::load_motifs(std::istream &in)
722 {
723   string seq;
724   float red;
725   float green;
726   float blue;
727
728   while(in.good())
729   {
730     in >> seq >> red >> green >> blue;
731     // if we couldn't read this line 'cause we're like at the end of the file
732     // try to exit the loop
733     if (!in.good())
734       break;
735     try {
736       seq = Sequence::motif_normalize(seq);
737     } catch(motif_normalize_error e) {
738       clog << "unable to parse " << seq << " skipping" << endl;
739       clog << e.what() << endl;
740       continue;
741     }
742     if (red < 0.0 or red > 1.0) {
743       clog << "invalid red value " << red << ". must be in range [0..1]" 
744            << endl;
745       continue;
746     }
747     if (green < 0.0 or green > 1.0) {
748       clog << "invalid green value " << green << ". must be in range [0..1]" 
749            << endl;
750       continue;
751     }
752     if (blue < 0.0 or blue > 1.0) {
753       clog << "invalid blue value " << blue << ". must be in range [0..1]" 
754            << endl;
755       continue;
756     }
757     if (motif_sequences.find(seq) == motif_sequences.end()) {
758       // sequence wasn't found
759       motif_sequences.insert(seq);
760       Color c(red, green, blue);
761       color_mapper.appendInstanceColor("motif", seq, c);
762     } else {
763       clog << "sequence " << seq << " was already defined skipping" 
764            << endl;
765       continue;
766     }
767   }
768   update_sequences_motifs();
769 }
770
771 void Mussa::load_motifs(fs::path filename)
772 {
773   fs::ifstream f;
774   f.open(filename, ifstream::in);
775   load_motifs(f);
776 }
777
778 void Mussa::update_sequences_motifs()
779 {
780   // once we've loaded all the motifs from the file, 
781   // lets attach them to the sequences
782   for(vector<Sequence>::iterator seq_i = the_seqs.begin();
783       seq_i != the_seqs.end();
784       ++seq_i)
785   {
786     // clear out old motifs
787     seq_i->clear_motifs();
788     // for all the motifs in our set, attach them to the current sequence
789     for(set<string>::iterator motif_i = motif_sequences.begin();
790         motif_i != motif_sequences.end();
791         ++motif_i)
792     {
793       seq_i->add_motif(*motif_i);
794     }
795   }
796 }
797
798 const set<string>& Mussa::motifs() const
799 {
800   return motif_sequences;
801 }
802
803 AnnotationColors& Mussa::colorMapper()
804 {
805   return color_mapper;
806 }