1 // This file is part of the Mussa source distribution.
2 // http://mussa.caltech.edu/
3 // Contact author: Tristan De Buysscher, tristan@caltech.edu
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.
11 // This file is part of the Mussa source distribution.
12 // http://mussa.caltech.edu/
13 // Contact author: Tristan De Buysscher, tristan@caltech.edu
15 // This program and all associated source code files are Copyright (C) 2005
16 // the California Institute of Technology, Pasadena, CA, 91125 USA. It is
17 // under the GNU Public License; please see the included LICENSE.txt
18 // file for more information, or contact Tristan directly.
21 // ----------------------------------------
22 // ---------- sequence.cc -----------
23 // ----------------------------------------
24 #include <boost/filesystem/fstream.hpp>
25 namespace fs = boost::filesystem;
27 #include <boost/spirit/core.hpp>
28 #include <boost/spirit/actor/push_back_actor.hpp>
29 #include <boost/spirit/iterator/file_iterator.hpp>
30 #include <boost/spirit/utility/chset.hpp>
31 namespace spirit = boost::spirit;
33 #include "alg/sequence.hpp"
34 #include "mussa_exceptions.hpp"
48 annot::annot(int begin, int end, std::string type, std::string name)
60 bool operator==(const annot& left, const annot& right)
62 return ((left.begin== right.begin) and
63 (left.end == right.end) and
64 (left.type == right.type) and
65 (left.name == right.name));
68 motif::motif(int begin, std::string motif)
69 : annot(begin, begin+motif.size(), "motif", motif),
78 const std::string Sequence::dna_alphabet("AaCcGgTtNn\012\015");
79 const std::string Sequence::rna_alphabet("AaCcGgNnUu\012\015");
80 //! this is the general iupac alphabet for nucleotides
81 const std::string Sequence::nucleic_iupac_alphabet("AaCcGgTtUuRrYyMmKkSsWwBbDdHhVvNn\012\015");
82 //! the protein alphabet
83 const std::string Sequence::protein_alphabet("AaCcDdEeFfGgHhIiKkLlMmNnPpQqRrSsTtVvWwYy\012\015");
93 Sequence::Sequence(const char *seq)
97 set_filtered_sequence(seq);
100 Sequence::Sequence(const std::string& seq)
104 set_filtered_sequence(seq);
107 Sequence::Sequence(const Sequence& o)
112 motif_list(o.motif_list)
116 Sequence &Sequence::operator=(const Sequence& s)
119 //sequence = s.sequence;
124 motif_list = s.motif_list;
129 static void multiplatform_getline(std::istream& in, std::string& line)
134 while(in.good() and !(c == '\012' or c == '\015') ) {
138 // if we have cr-lf eat it
140 if (c=='\012' or c == '\015') {
145 //! load a fasta file into a sequence
147 * \param file_path the location of the fasta file in the filesystem
148 * \param seq_num which sequence in the file to load
149 * \param start_index starting position in the fasta sequence, 0 for beginning
150 * \param end_index ending position in the fasta sequence, 0 for end
151 * \return error message, empty string if no error. (gag!)
153 void Sequence::load_fasta(fs::path file_path, int seq_num,
154 int start_index, int end_index)
156 fs::fstream data_file;
157 data_file.open(file_path, std::ios::in);
159 if (!data_file.good())
161 throw mussa_load_error("Sequence File: "+file_path.string()+" not found");
164 load_fasta(data_file, seq_num, start_index, end_index);
165 } catch(sequence_empty_error e) {
166 // there doesn't appear to be any sequence
167 // catch and rethrow to include the filename
168 std::stringstream msg;
169 msg << "The selected sequence in "
170 << file_path.native_file_string()
171 << " appears to be empty";
172 throw sequence_empty_error(msg.str());
173 } catch(sequence_empty_file_error e) {
174 std::stringstream errormsg;
175 errormsg << file_path.native_file_string()
176 << " did not have any fasta sequences" << std::endl;
177 throw sequence_empty_file_error(errormsg.str());
183 Sequence::load_fasta(std::iostream& data_file, int seq_num,
184 int start_index, int end_index)
186 std::string file_data_line;
187 int header_counter = 0;
188 bool read_seq = true;
189 std::string rev_comp;
190 std::string sequence_raw;
191 std::string seq_tmp; // holds sequence during basic filtering
194 throw mussa_load_error("fasta sequence number is 1 based (can't be 0)");
197 // search for the header of the fasta sequence we want
198 while ( (!data_file.eof()) && (header_counter < seq_num) )
200 multiplatform_getline(data_file, file_data_line);
201 if (file_data_line.substr(0,1) == ">")
205 if (header_counter > 0) {
206 header = file_data_line.substr(1);
210 while ( !data_file.eof() && read_seq ) {
211 multiplatform_getline(data_file,file_data_line);
212 if (file_data_line.substr(0,1) == ">")
214 else sequence_raw += file_data_line;
217 // Lastly, if subselection of the sequence was specified we keep cut out
218 // and only keep that part
219 // end_index = 0 means no end was specified, so cut to the end
221 end_index = sequence_raw.size();
223 // sequence filtering for upcasing agctn and convert non AGCTN to N
224 if (end_index-start_index <= 0) {
225 std::string msg("The selected sequence appears to be empty");
226 throw sequence_empty_error(msg);
228 set_filtered_sequence(sequence_raw, start_index, end_index-start_index);
230 std::string errormsg("There were no fasta sequences");
231 throw sequence_empty_file_error(errormsg);
235 void Sequence::set_filtered_sequence(const std::string &old_seq,
236 std::string::size_type start,
237 std::string::size_type count)
239 char conversionTable[257];
242 count = old_seq.size() - start;
243 boost::shared_ptr<seq_string> new_seq(new seq_string);
244 new_seq->reserve(count);
246 // Make a conversion table
248 // everything we don't specify below will become 'N'
249 for(int table_i=0; table_i < 256; table_i++)
251 conversionTable[table_i] = 'N';
253 // add end of string character for printing out table for testing purposes
254 conversionTable[256] = '\0';
256 // we want these to map to themselves - ie not to change
257 conversionTable[(int)'A'] = 'A';
258 conversionTable[(int)'T'] = 'T';
259 conversionTable[(int)'G'] = 'G';
260 conversionTable[(int)'C'] = 'C';
262 conversionTable[(int)'a'] = 'A';
263 conversionTable[(int)'t'] = 'T';
264 conversionTable[(int)'g'] = 'G';
265 conversionTable[(int)'c'] = 'C';
267 // finally, the actual conversion loop
268 for(std::string::size_type seq_index = 0; seq_index < count; seq_index++)
270 new_seq->append(1, conversionTable[ (int)old_seq[seq_index+start]]);
276 Sequence::load_annot(fs::path file_path, int start_index, int end_index)
278 fs::fstream data_stream(file_path, std::ios::in);
281 throw mussa_load_error("Sequence File: " + file_path.string() + " not found");
284 // so i should probably be passing the parse function some iterators
285 // but the annotations files are (currently) small, so i think i can
286 // get away with loading the whole file into memory
289 while(data_stream.good()) {
295 parse_annot(data, start_index, end_index);
298 /* If this works, yikes, this is some brain hurting code.
300 * what's going on is that when pb_annot is instantiated it stores references
301 * to begin, end, name, type, declared in the parse function, then
302 * when operator() is called it grabs values from those references
303 * and uses that to instantiate an annot object and append that to our
306 * This weirdness is because the spirit library requires that actions
307 * conform to a specific prototype operator()(IteratorT, IteratorT)
308 * which doesn't provide any useful opportunity for me to actually
309 * grab the results of our parsing.
311 * so I instantiate this structure in order to have a place to grab
315 struct push_back_annot {
316 std::list<annot>& annot_list;
322 push_back_annot(std::list<annot>& annot_list_,
327 : annot_list(annot_list_),
335 void operator()(std::string::const_iterator,
336 std::string::const_iterator) const
338 //std::cout << "adding annot: " << begin << "|" << end << "|" << name << "|" << type << std::endl;
339 annot_list.push_back(annot(begin, end, name, type));
343 struct push_back_seq {
344 std::list<Sequence>& seq_list;
348 push_back_seq(std::list<Sequence>& seq_list_,
351 : seq_list(seq_list_),
357 void operator()(std::string::const_iterator,
358 std::string::const_iterator) const
360 // filter out newlines from our sequence
362 for(std::string::const_iterator seq_i = seq.begin();
366 if (*seq_i != '\015' && *seq_i != '\012') new_seq += *seq_i;
368 //std::cout << "adding seq: " << name << " " << new_seq << std::endl;
371 s.set_fasta_header(name);
372 seq_list.push_back(s);
377 Sequence::parse_annot(std::string data, int start_index, int end_index)
384 std::list<Sequence> query_seqs;
386 bool status = spirit::parse(data.begin(), data.end(),
393 )[spirit::assign_a(species)] >>
397 ( // ignore html tags
398 *(spirit::space_p) >>
400 +(~spirit::ch_p('>')) >>
405 ( // parse an absolute location name
406 (spirit::uint_p[spirit::assign_a(start)] >>
408 spirit::uint_p[spirit::assign_a(end)] >>
413 )[spirit::assign_a(name)] >>
420 )[spirit::assign_a(type)]
422 // to understand how this group gets set
423 // read the comment above struct push_back_annot
424 )[push_back_annot(annots, start, end, type, name)]
426 ((spirit::ch_p('>')|spirit::str_p(">")) >>
427 (*(spirit::print_p))[spirit::assign_a(name)] >>
429 (+(spirit::chset<>(nucleic_iupac_alphabet.c_str())))[spirit::assign_a(seq)]
430 )[push_back_seq(query_seqs, name, seq)]
436 spirit::space_p*/).full;
438 // go seearch for query sequences
439 find_sequences(query_seqs.begin(), query_seqs.end());
443 void Sequence::add_annotation(const annot& a)
448 const std::list<annot>& Sequence::annotations() const
454 Sequence::subseq(int start, int count) const
456 // there might be an off by one error with start+count > size()
457 if ( count == npos || start+count > size()) {
458 count = size()-start;
460 Sequence new_seq(seq->substr(start, count));
461 new_seq.set_fasta_header(get_fasta_header());
462 new_seq.set_species(get_species());
464 new_seq.motif_list = motif_list;
465 // attempt to copy & reannotate position based annotations
466 int end = start+count;
468 for(std::list<annot>::const_iterator annot_i = annots.begin();
469 annot_i != annots.end();
472 int annot_begin= annot_i->begin;
473 int annot_end = annot_i->end;
475 if (annot_begin < end) {
476 if (annot_begin >= start) {
477 annot_begin -= start;
482 if (annot_end < end) {
488 annot new_annot(annot_begin, annot_end, annot_i->type, annot_i->name);
489 new_seq.annots.push_back(new_annot);
497 Sequence::rev_comp() const
499 std::string rev_comp;
500 char conversionTable[257];
501 int seq_i, table_i, len;
504 rev_comp.reserve(len);
505 // make a conversion table
506 // init all parts of conversion table to '~' character
507 // '~' I doubt will ever appear in a sequence file (jeez, I hope)
508 // and may the fleas of 1000 camels infest the genitals of any biologist (and
509 // seven generations of their progeny) who decides to make it mean
510 // something special!!!
511 // PS - double the curse for any smartass non-biologist who tries it as well
512 for(table_i=0; table_i < 256; table_i++)
514 conversionTable[table_i] = '~';
516 // add end of string character for printing out table for testing purposes
517 conversionTable[256] = '\0';
519 // add in the characters for the bases we want to convert
520 conversionTable[(int)'A'] = 'T';
521 conversionTable[(int)'T'] = 'A';
522 conversionTable[(int)'G'] = 'C';
523 conversionTable[(int)'C'] = 'G';
524 conversionTable[(int)'N'] = 'N';
526 // finally, the actual conversion loop
527 for(seq_i = len - 1; seq_i >= 0; seq_i--)
529 table_i = (int) seq->at(seq_i);
530 rev_comp += conversionTable[table_i];
536 void Sequence::set_fasta_header(std::string header_)
541 void Sequence::set_species(const std::string& name)
546 std::string Sequence::get_species() const
553 Sequence::get_fasta_header() const
559 Sequence::get_name() const
561 if (header.size() > 0)
563 else if (species.size() > 0)
569 void Sequence::set_sequence(const std::string& s)
571 set_filtered_sequence(s);
574 std::string Sequence::get_sequence() const
579 Sequence::const_reference Sequence::operator[](Sequence::size_type i) const
584 Sequence::const_reference Sequence::at(Sequence::size_type i) const
599 const char *Sequence::c_str() const
607 Sequence::const_iterator Sequence::begin() const
612 return Sequence::const_iterator(0);
615 Sequence::const_iterator Sequence::end() const
620 return Sequence::const_iterator(0);
623 bool Sequence::empty() const
631 Sequence::size_type Sequence::size() const
639 Sequence::size_type Sequence::length() const
644 Sequence::save(fs::fstream &save_file)
645 //std::string save_file_path)
648 std::list<annot>::iterator annots_i;
650 // not sure why, or if i'm doing something wrong, but can't seem to pass
651 // file pointers down to this method from the mussa control class
652 // so each call to save a sequence appends to the file started by mussa_class
653 //save_file.open(save_file_path.c_str(), std::ios::app);
655 save_file << "<Sequence>" << std::endl;
656 save_file << *this << std::endl;
657 save_file << "</Sequence>" << std::endl;
659 save_file << "<Annotations>" << std::endl;
660 save_file << species << std::endl;
661 for (annots_i = annots.begin(); annots_i != annots.end(); ++annots_i)
663 save_file << annots_i->begin << " " << annots_i->end << " " ;
664 save_file << annots_i->name << " " << annots_i->type << std::endl;
666 save_file << "</Annotations>" << std::endl;
671 Sequence::load_museq(fs::path load_file_path, int seq_num)
673 fs::fstream load_file;
674 std::string file_data_line;
677 std::string::size_type space_split_i;
678 std::string annot_value;
681 load_file.open(load_file_path, std::ios::in);
684 // search for the seq_num-th sequence
685 while ( (!load_file.eof()) && (seq_counter < seq_num) )
687 getline(load_file,file_data_line);
688 if (file_data_line == "<Sequence>")
691 getline(load_file, file_data_line);
692 // looks like the sequence is written as a single line
693 set_filtered_sequence(file_data_line);
694 getline(load_file, file_data_line);
695 getline(load_file, file_data_line);
696 if (file_data_line == "<Annotations>")
698 getline(load_file, file_data_line);
699 species = file_data_line;
700 while ( (!load_file.eof()) && (file_data_line != "</Annotations>") )
702 getline(load_file,file_data_line);
703 if ((file_data_line != "") && (file_data_line != "</Annotations>"))
705 // need to get 4 values...almost same code 4 times...
706 // get annot start index
707 space_split_i = file_data_line.find(" ");
708 annot_value = file_data_line.substr(0,space_split_i);
709 an_annot.begin = atoi (annot_value.c_str());
710 file_data_line = file_data_line.substr(space_split_i+1);
711 // get annot end index
712 space_split_i = file_data_line.find(" ");
713 annot_value = file_data_line.substr(0,space_split_i);
714 an_annot.end = atoi (annot_value.c_str());
716 if (space_split_i == std::string::npos) // no entry for type or name
718 std::cout << "seq, annots - no type or name\n";
722 else // else get annot type
724 file_data_line = file_data_line.substr(space_split_i+1);
725 space_split_i = file_data_line.find(" ");
726 annot_value = file_data_line.substr(0,space_split_i);
727 an_annot.type = annot_value;
728 if (space_split_i == std::string::npos) // no entry for name
730 std::cout << "seq, annots - no name\n";
733 else // get annot name
735 file_data_line = file_data_line.substr(space_split_i+1);
736 space_split_i = file_data_line.find(" ");
737 annot_value = file_data_line.substr(0,space_split_i);
738 an_annot.type = annot_value;
741 annots.push_back(an_annot); // don't forget to actually add the annot
743 //std::cout << "seq, annots: " << an_annot.start << ", " << an_annot.end
744 // << "-->" << an_annot.type << "::" << an_annot.name << std::endl;
751 Sequence::rc_motif(std::string a_motif) const
753 std::string rev_comp;
754 char conversionTable[257];
755 int seq_i, table_i, len;
757 len = a_motif.length();
758 rev_comp.reserve(len);
760 for(table_i=0; table_i < 256; table_i++)
762 conversionTable[table_i] = '~';
764 // add end of std::string character for printing out table for testing purposes
765 conversionTable[256] = '\0';
767 // add in the characters for the bases we want to convert (IUPAC)
768 conversionTable[(int)'A'] = 'T';
769 conversionTable[(int)'T'] = 'A';
770 conversionTable[(int)'G'] = 'C';
771 conversionTable[(int)'C'] = 'G';
772 conversionTable[(int)'N'] = 'N';
773 conversionTable[(int)'M'] = 'K';
774 conversionTable[(int)'R'] = 'Y';
775 conversionTable[(int)'W'] = 'W';
776 conversionTable[(int)'S'] = 'S';
777 conversionTable[(int)'Y'] = 'R';
778 conversionTable[(int)'K'] = 'M';
779 conversionTable[(int)'V'] = 'B';
780 conversionTable[(int)'H'] = 'D';
781 conversionTable[(int)'D'] = 'H';
782 conversionTable[(int)'B'] = 'V';
784 // finally, the actual conversion loop
785 for(seq_i = len - 1; seq_i >= 0; seq_i--)
787 //std::cout << "** i = " << seq_i << " bp = " <<
788 table_i = (int) a_motif[seq_i];
789 rev_comp += conversionTable[table_i];
792 //std::cout << "seq: " << a_motif << std::endl;
793 //std::cout << "rc: " << rev_comp << std::endl;
799 Sequence::motif_normalize(const std::string& a_motif)
801 std::string valid_motif;
804 len = a_motif.length();
805 valid_motif.reserve(len);
807 // this just upcases IUPAC symbols. Eventually should return an error if non IUPAC is present.
808 // current nonIUPAC symbols are omitted, which is not reported atm
809 for(seq_i = 0; seq_i < len; seq_i++)
811 if ((a_motif[seq_i] == 'a') || (a_motif[seq_i] == 'A'))
813 else if ((a_motif[seq_i] == 't') || (a_motif[seq_i] == 'T'))
815 else if ((a_motif[seq_i] == 'g') || (a_motif[seq_i] == 'G'))
817 else if ((a_motif[seq_i] == 'c') || (a_motif[seq_i] == 'C'))
819 else if ((a_motif[seq_i] == 'n') || (a_motif[seq_i] == 'N'))
821 else if ((a_motif[seq_i] == 'm') || (a_motif[seq_i] == 'M'))
823 else if ((a_motif[seq_i] == 'r') || (a_motif[seq_i] == 'R'))
825 else if ((a_motif[seq_i] == 'w') || (a_motif[seq_i] == 'W'))
827 else if ((a_motif[seq_i] == 's') || (a_motif[seq_i] == 'S'))
829 else if ((a_motif[seq_i] == 'y') || (a_motif[seq_i] == 'Y'))
831 else if ((a_motif[seq_i] == 'k') || (a_motif[seq_i] == 'K'))
833 else if ((a_motif[seq_i] == 'v') || (a_motif[seq_i] == 'V'))
835 else if ((a_motif[seq_i] == 'h') || (a_motif[seq_i] == 'H'))
837 else if ((a_motif[seq_i] == 'd') || (a_motif[seq_i] == 'D'))
839 else if ((a_motif[seq_i] == 'b') || (a_motif[seq_i] == 'B'))
842 std::string msg = "Letter ";
843 msg += a_motif[seq_i];
844 msg += " is not a valid IUPAC symbol";
845 throw motif_normalize_error(msg);
848 //std::cout << "valid_motif is: " << valid_motif << std::endl;
852 void Sequence::add_motif(const Sequence& a_motif)
854 std::vector<int> motif_starts = find_motif(a_motif);
856 for(std::vector<int>::iterator motif_start_i = motif_starts.begin();
857 motif_start_i != motif_starts.end();
860 motif_list.push_back(motif(*motif_start_i, a_motif.get_sequence()));
864 void Sequence::clear_motifs()
869 const std::list<motif>& Sequence::motifs() const
875 Sequence::find_motif(const std::string& a_motif) const
877 std::vector<int> motif_match_starts;
878 std::string norm_motif_rc;
880 motif_match_starts.clear();
882 //std::cout << "motif is: " << a_motif << std::endl;
883 std::string norm_motif = motif_normalize(a_motif);
884 //std::cout << "motif is: " << a_motif << std::endl;
886 if (norm_motif.size() > 0)
888 //std::cout << "Sequence: none blank motif\n";
889 motif_scan(norm_motif, &motif_match_starts);
891 norm_motif_rc = rc_motif(a_motif);
892 // make sure not to do search again if it is a palindrome
893 if (norm_motif_rc != norm_motif) {
894 motif_scan(norm_motif_rc, &motif_match_starts);
897 return motif_match_starts;
901 Sequence::find_motif(const Sequence& a_motif) const
903 return find_motif(a_motif.get_sequence());
907 Sequence::motif_scan(std::string a_motif, std::vector<int> * motif_match_starts) const
909 std::string::const_iterator seq_c = seq->begin();
910 std::string::size_type seq_i;
911 int motif_i, motif_len;
913 //std::cout << "Sequence: motif, seq len = " << sequence.length() << std::endl;
914 motif_len = a_motif.length();
916 //std::cout << "motif_length: " << motif_len << std::endl;
917 //std::cout << "RAAARRRRR\n";
921 //std::cout << "motif: " << a_motif << std::endl;
923 //std::cout << "Sequence: motif, length= " << length << std::endl;
925 while (seq_i < length())
927 //std::cout << seq_c[seq_i];
928 //std::cout << seq_c[seq_i] << "?" << a_motif[motif_i] << ":" << motif_i << " ";
929 // this is pretty much a straight translation of Nora's python code
930 // to match iupac letter codes
931 if (a_motif[motif_i] =='N')
933 else if (a_motif[motif_i] == seq_c[seq_i])
935 else if ((a_motif[motif_i] =='M') &&
936 ((seq_c[seq_i]=='A') || (seq_c[seq_i]=='C')))
938 else if ((a_motif[motif_i] =='R') &&
939 ((seq_c[seq_i]=='A') || (seq_c[seq_i]=='G')))
941 else if ((a_motif[motif_i] =='W') &&
942 ((seq_c[seq_i]=='A') || (seq_c[seq_i]=='T')))
944 else if ((a_motif[motif_i] =='S') &&
945 ((seq_c[seq_i]=='C') || (seq_c[seq_i]=='G')))
947 else if ((a_motif[motif_i] =='Y') &&
948 ((seq_c[seq_i]=='C') || (seq_c[seq_i]=='T')))
950 else if ((a_motif[motif_i] =='K') &&
951 ((seq_c[seq_i]=='G') || (seq_c[seq_i]=='T')))
953 else if ((a_motif[motif_i] =='V') &&
954 ((seq_c[seq_i]=='A') || (seq_c[seq_i]=='C') ||
955 (seq_c[seq_i]=='G')))
957 else if ((a_motif[seq_i] =='H') &&
958 ((seq_c[seq_i]=='A') || (seq_c[seq_i]=='C') ||
959 (seq_c[seq_i]=='T')))
961 else if ((a_motif[motif_i] =='D') &&
962 ((seq_c[seq_i]=='A') || (seq_c[seq_i]=='G') ||
963 (seq_c[seq_i]=='T')))
965 else if ((a_motif[motif_i] =='B') &&
966 ((seq_c[seq_i]=='C') || (seq_c[seq_i]=='G') ||
967 (seq_c[seq_i]=='T')))
976 // end Nora stuff, now we see if a match is found this pass
977 if (motif_i == motif_len)
981 motif_match_starts->push_back(seq_i - motif_len + 1);
987 //std::cout << std::endl;
990 void Sequence::add_string_annotation(std::string a_seq,
993 std::vector<int> seq_starts = find_motif(a_seq);
995 //std::cout << "searching for " << a_seq << " found " << seq_starts.size() << std::endl;
997 for(std::vector<int>::iterator seq_start_i = seq_starts.begin();
998 seq_start_i != seq_starts.end();
1001 annots.push_back(annot(*seq_start_i,
1002 *seq_start_i+a_seq.size(),
1008 void Sequence::find_sequences(std::list<Sequence>::iterator start,
1009 std::list<Sequence>::iterator end)
1011 while (start != end) {
1012 add_string_annotation(start->get_sequence(), start->get_fasta_header());
1018 std::ostream& operator<<(std::ostream& out, const Sequence& s)
1020 for(Sequence::const_iterator s_i = s.begin(); s_i != s.end(); ++s_i) {
1026 bool operator<(const Sequence& x, const Sequence& y)
1028 Sequence::const_iterator x_i = x.begin();
1029 Sequence::const_iterator y_i = y.begin();
1032 if( x_i == x.end() and y_i == y.end() ) {
1034 } else if ( x_i == x.end() ) {
1036 } else if ( y_i == y.end() ) {
1038 } else if ( (*x_i) < (*y_i)) {
1040 } else if ( (*x_i) > (*y_i) ) {
1049 bool operator==(const Sequence& x, const Sequence& y)
1051 if (x.empty() and y.empty()) {
1052 // if there's no sequence in either sequence structure, they're equal
1054 } else if (x.empty() or y.empty()) {
1055 // if we fail the first test, and we discover one is empty,
1056 // we know they can't be equal. (and we need to do this
1057 // to prevent dereferencing an empty pointer)
1059 } else if ( *(x.seq) == *(y.seq)) {
1060 // and x.annots == y.annots and x.motif_list == y.motif_list) {