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 #include <boost/filesystem/operations.hpp>
26 namespace fs = boost::filesystem;
28 #include <boost/spirit/core.hpp>
29 #include <boost/spirit/actor/push_back_actor.hpp>
30 #include <boost/spirit/iterator/file_iterator.hpp>
31 #include <boost/spirit/utility/chset.hpp>
32 namespace spirit = boost::spirit;
34 #include "alg/sequence.hpp"
35 #include "mussa_exceptions.hpp"
51 annot::annot(int begin, int end, std::string type, std::string name)
63 bool operator==(const annot& left, const annot& right)
65 return ((left.begin== right.begin) and
66 (left.end == right.end) and
67 (left.type == right.type) and
68 (left.name == right.name));
71 motif::motif(int begin, std::string motif)
72 : annot(begin, begin+motif.size(), "motif", motif),
82 Sequence::Sequence(alphabet_ref alphabet_)
95 Sequence::Sequence(const char *seq, alphabet_ref alphabet_)
100 strand(UnknownStrand),
104 set_filtered_sequence(seq, alphabet);
107 Sequence::Sequence(const std::string& seq, alphabet_ref alphabet_)
112 strand(UnknownStrand),
116 set_filtered_sequence(seq, alphabet);
119 Sequence::Sequence(const Sequence& o)
122 alphabet(o.alphabet),
123 seq_start(o.seq_start),
124 seq_count(o.seq_count),
129 motif_list(o.motif_list)
133 Sequence &Sequence::operator=(const Sequence& s)
138 alphabet = s.alphabet;
139 seq_start = s.seq_start;
140 seq_count = s.seq_count;
145 motif_list = s.motif_list;
150 static void multiplatform_getline(std::istream& in, std::string& line)
155 while(in.good() and !(c == '\012' or c == '\015') ) {
159 // if we have cr-lf eat it
161 if (c=='\012' or c == '\015') {
166 void Sequence::load_fasta(fs::path file_path, int seq_num, int start_index, int end_index)
168 load_fasta(file_path, alphabet, seq_num, start_index, end_index);
171 //! load a fasta file into a sequence
172 void Sequence::load_fasta(fs::path file_path, alphabet_ref a,
173 int seq_num, int start_index, int end_index)
175 fs::fstream data_file;
176 data_file.open(file_path, std::ios::in);
178 if (!data_file.good())
180 throw mussa_load_error("Sequence File: "+file_path.string()+" not found");
183 load_fasta(data_file, a, seq_num, start_index, end_index);
184 } catch(sequence_empty_error e) {
185 // there doesn't appear to be any sequence
186 // catch and rethrow to include the filename
187 std::stringstream msg;
188 msg << "The selected sequence in "
189 << file_path.native_file_string()
190 << " appears to be empty";
191 throw sequence_empty_error(msg.str());
192 } catch(sequence_empty_file_error e) {
193 std::stringstream errormsg;
194 errormsg << file_path.native_file_string()
195 << " did not have any fasta sequences" << std::endl;
196 throw sequence_empty_file_error(errormsg.str());
197 } catch(sequence_invalid_load_error e) {
198 std::ostringstream msg;
199 msg << file_path.native_file_string();
200 msg << " " << e.what();
201 throw sequence_invalid_load_error(msg.str());
206 void Sequence::load_fasta(std::istream& file,
207 int seq_num, int start_index, int end_index)
209 load_fasta(file, alphabet, seq_num, start_index, end_index);
213 Sequence::load_fasta(std::istream& data_file, alphabet_ref a,
215 int start_index, int end_index)
217 std::string file_data_line;
218 int header_counter = 0;
219 size_t line_counter = 0;
220 bool read_seq = true;
221 std::string rev_comp;
222 std::string sequence_raw;
223 std::string seq_tmp; // holds sequence during basic filtering
224 const Alphabet &alpha = get_alphabet(a);
227 throw mussa_load_error("fasta sequence number is 1 based (can't be 0)");
230 // search for the header of the fasta sequence we want
231 while ( (!data_file.eof()) && (header_counter < seq_num) )
233 multiplatform_getline(data_file, file_data_line);
235 if (file_data_line.substr(0,1) == ">")
239 if (header_counter > 0) {
240 header = file_data_line.substr(1);
244 while ( !data_file.eof() && read_seq ) {
245 multiplatform_getline(data_file,file_data_line);
247 if (file_data_line.substr(0,1) == ">")
250 for (std::string::const_iterator line_i = file_data_line.begin();
251 line_i != file_data_line.end();
254 if(alpha.exists(*line_i)) {
255 sequence_raw += *line_i;
257 std::ostringstream msg;
258 msg << "Unrecognized characters in fasta sequence at line ";
260 throw sequence_invalid_load_error(msg.str());
266 // Lastly, if subselection of the sequence was specified we keep cut out
267 // and only keep that part
268 // end_index = 0 means no end was specified, so cut to the end
270 end_index = sequence_raw.size();
272 // sequence filtering for upcasing agctn and convert non AGCTN to N
273 if (end_index-start_index <= 0) {
274 std::string msg("The selected sequence appears to be empty");
275 throw sequence_empty_error(msg);
277 set_filtered_sequence(sequence_raw, a, start_index, end_index-start_index);
279 std::string errormsg("There were no fasta sequences");
280 throw sequence_empty_file_error(errormsg);
284 void Sequence::set_filtered_sequence(const std::string &in_seq,
285 alphabet_ref alphabet_,
290 alphabet = alphabet_;
292 count = in_seq.size() - start;
293 boost::shared_ptr<seq_string> new_seq(new seq_string);
294 new_seq->reserve(count);
296 // finally, the actual conversion loop
297 const Alphabet& alpha_impl = get_alphabet(); // go get one of our actual alphabets
298 std::string::const_iterator seq_i = in_seq.begin()+start;
299 for(size_type i = 0; i != count; ++i, ++seq_i)
301 if (alpha_impl.exists(*seq_i)) {
302 new_seq->append(1, toupper(*seq_i));
304 new_seq->append(1, 'N');
315 Sequence::load_annot(fs::path file_path, int start_index, int end_index)
317 if (not fs::exists(file_path)) {
318 throw mussa_load_error("Annotation File " + file_path.string() + " was not found");
320 if (fs::is_directory(file_path)) {
321 throw mussa_load_error(file_path.string() +
322 " is a directory, please provide a file for annotations."
325 fs::fstream data_stream(file_path, std::ios::in);
328 throw mussa_load_error("Error loading annotation file " + file_path.string());
331 // so i should probably be passing the parse function some iterators
332 // but the annotations files are (currently) small, so i think i can
333 // get away with loading the whole file into memory
336 while(data_stream.good()) {
343 parse_annot(data, start_index, end_index);
344 } catch(annotation_load_error e) {
345 std::ostringstream msg;
346 msg << file_path.native_file_string()
349 throw annotation_load_error(msg.str());
353 /* If this works, yikes, this is some brain hurting code.
355 * what's going on is that when pb_annot is instantiated it stores references
356 * to begin, end, name, type, declared in the parse function, then
357 * when operator() is called it grabs values from those references
358 * and uses that to instantiate an annot object and append that to our
361 * This weirdness is because the spirit library requires that actions
362 * conform to a specific prototype operator()(IteratorT, IteratorT)
363 * which doesn't provide any useful opportunity for me to actually
364 * grab the results of our parsing.
366 * so I instantiate this structure in order to have a place to grab
370 struct push_back_annot {
371 std::list<annot>& annot_list;
378 push_back_annot(std::list<annot>& annot_list_,
384 : annot_list(annot_list_),
393 void operator()(std::string::const_iterator,
394 std::string::const_iterator) const
396 //std::cout << "adding annot: " << begin << "|" << end << "|" << name << "|" << type << std::endl;
397 annot_list.push_back(annot(begin, end, name, type));
402 struct push_back_seq {
403 std::list<Sequence>& seq_list;
408 push_back_seq(std::list<Sequence>& seq_list_,
412 : seq_list(seq_list_),
419 void operator()(std::string::const_iterator,
420 std::string::const_iterator) const
422 // filter out newlines from our sequence
424 for(std::string::const_iterator seq_i = seq.begin();
428 if (*seq_i != '\015' && *seq_i != '\012') new_seq += *seq_i;
430 //std::cout << "adding seq: " << name << " " << new_seq << std::endl;
433 s.set_fasta_header(name);
434 seq_list.push_back(s);
440 Sequence::parse_annot(std::string data, int start_index, int end_index)
447 std::list<annot> parsed_annots;
448 std::list<Sequence> query_seqs;
451 bool ok = spirit::parse(data.begin(), data.end(),
458 )[spirit::assign_a(species)] >>
462 ( // ignore html tags
463 *(spirit::space_p) >>
465 +(~spirit::ch_p('>')) >>
470 ( // parse an absolute location name
471 (spirit::uint_p[spirit::assign_a(start)] >>
473 spirit::uint_p[spirit::assign_a(end)] >>
478 )[spirit::assign_a(name)] >>
485 )[spirit::assign_a(type)]
487 // to understand how this group gets set
488 // read the comment above struct push_back_annot
489 )[push_back_annot(parsed_annots, start, end, type, name, parsed)]
491 ((spirit::ch_p('>')|spirit::str_p(">")) >>
492 (*(spirit::print_p))[spirit::assign_a(name)] >>
494 (+(spirit::chset<>(Alphabet::nucleic_cstr)))[spirit::assign_a(seq)]
495 )[push_back_seq(query_seqs, name, seq, parsed)]
502 std::stringstream msg;
503 msg << "Error parsing annotation #" << parsed;
504 throw annotation_load_error(msg.str());
506 // add newly parsed annotations to our sequence
507 std::copy(parsed_annots.begin(), parsed_annots.end(), std::back_inserter(annots));
508 // go seearch for query sequences
509 find_sequences(query_seqs.begin(), query_seqs.end());
512 void Sequence::add_annotation(const annot& a)
517 const std::list<annot>& Sequence::annotations() const
523 Sequence::subseq(int start, int count)
530 // there might be an off by one error with start+count > size()
531 if ( count == npos || start+count > size()) {
532 count = size()-start;
534 Sequence new_seq(*this);
535 new_seq.parent = this;
536 new_seq.seq_start = seq_start+start;
537 new_seq.seq_count = count;
539 new_seq.motif_list = motif_list;
540 new_seq.annots.clear();
541 // attempt to copy & reannotate position based annotations
542 int end = start+count;
544 for(std::list<annot>::const_iterator annot_i = annots.begin();
545 annot_i != annots.end();
548 int annot_begin= annot_i->begin;
549 int annot_end = annot_i->end;
551 if (annot_begin < end) {
552 if (annot_begin >= start) {
553 annot_begin -= start;
558 if (annot_end < end) {
564 annot new_annot(annot_begin, annot_end, annot_i->type, annot_i->name);
565 new_seq.annots.push_back(new_annot);
572 std::string Sequence::create_reverse_map() const
574 std::string rc_map(256, '~');
575 // if we're rna, use U instead of T
576 // we might want to add an "is_rna" to sequence at somepoint
577 char TU = (alphabet == reduced_rna_alphabet) ? 'U' : 'T';
578 char tu = (alphabet == reduced_rna_alphabet) ? 'u' : 't';
579 rc_map['A'] = TU ; rc_map['a'] = tu ;
580 rc_map['T'] = 'A'; rc_map['t'] = 'a';
581 rc_map['U'] = 'A'; rc_map['u'] = 'a';
582 rc_map['G'] = 'C'; rc_map['g'] = 'c';
583 rc_map['C'] = 'G'; rc_map['c'] = 'g';
584 rc_map['M'] = 'K'; rc_map['m'] = 'k';
585 rc_map['R'] = 'Y'; rc_map['r'] = 'y';
586 rc_map['W'] = 'W'; rc_map['w'] = 'w';
587 rc_map['S'] = 'S'; rc_map['s'] = 's';
588 rc_map['Y'] = 'R'; rc_map['y'] = 'r';
589 rc_map['K'] = 'M'; rc_map['k'] = 'm';
590 rc_map['V'] = 'B'; rc_map['v'] = 'b';
591 rc_map['H'] = 'D'; rc_map['h'] = 'd';
592 rc_map['D'] = 'H'; rc_map['d'] = 'h';
593 rc_map['B'] = 'V'; rc_map['b'] = 'v';
594 rc_map['N'] = 'N'; rc_map['n'] = 'n';
595 rc_map['X'] = 'X'; rc_map['x'] = 'x';
599 rc_map['~'] = '~'; // not really needed, but perhaps it's clearer.
603 Sequence Sequence::rev_comp() const
605 std::string rev_comp;
606 rev_comp.reserve(length());
608 std::string rc_map = create_reverse_map();
610 // reverse and convert
611 Sequence::const_reverse_iterator seq_i;
612 Sequence::const_reverse_iterator seq_end = rend();
613 for(seq_i = rbegin();
617 rev_comp.append(1, rc_map[*seq_i]);
619 return Sequence(rev_comp, alphabet);
622 void Sequence::set_fasta_header(std::string header_)
627 void Sequence::set_species(const std::string& name)
632 std::string Sequence::get_species() const
639 Sequence::get_fasta_header() const
645 Sequence::get_name() const
647 if (header.size() > 0)
649 else if (species.size() > 0)
655 const Alphabet& Sequence::get_alphabet() const
657 return get_alphabet(alphabet);
660 const Alphabet& Sequence::get_alphabet(alphabet_ref alpha) const
663 case reduced_dna_alphabet:
664 return Alphabet::reduced_dna_alphabet();
665 case reduced_rna_alphabet:
666 return Alphabet::reduced_rna_alphabet();
667 case reduced_nucleic_alphabet:
668 return Alphabet::reduced_nucleic_alphabet();
669 case nucleic_alphabet:
670 return Alphabet::nucleic_alphabet();
671 case protein_alphabet:
672 return Alphabet::protein_alphabet();
674 throw std::runtime_error("unrecognized alphabet type");
679 void Sequence::set_sequence(const std::string& s, alphabet_ref a)
681 set_filtered_sequence(s, a);
684 std::string Sequence::get_sequence() const
689 return std::string();
692 Sequence::const_reference Sequence::operator[](Sequence::size_type i) const
697 Sequence::const_reference Sequence::at(Sequence::size_type i) const
699 if (!seq) throw std::out_of_range("empty sequence");
700 return seq->at(i+seq_start);
710 strand = UnknownStrand;
717 const char *Sequence::c_str() const
720 return seq->c_str()+seq_start;
725 Sequence::const_iterator Sequence::begin() const
727 if (seq and seq_count != 0)
728 return seq->begin()+seq_start;
730 return Sequence::const_iterator(0);
733 Sequence::const_iterator Sequence::end() const
735 if (seq and seq_count != 0) {
736 return seq->begin() + seq_start + seq_count;
738 return Sequence::const_iterator(0);
742 Sequence::const_reverse_iterator Sequence::rbegin() const
744 if (seq and seq_count != 0)
745 return seq->rbegin()+(seq->size()-(seq_start+seq_count));
747 return Sequence::const_reverse_iterator();
750 Sequence::const_reverse_iterator Sequence::rend() const
752 if (seq and seq_count != 0) {
753 return rbegin() + seq_count;
755 return Sequence::const_reverse_iterator();
759 bool Sequence::empty() const
761 return (seq_count == 0) ? true : false;
764 Sequence::size_type Sequence::find_first_not_of(
765 const std::string& query,
766 Sequence::size_type index)
768 typedef std::set<std::string::value_type> sequence_set;
769 sequence_set match_set;
771 for(const_iterator query_item = query.begin();
772 query_item != query.end();
775 match_set.insert(*query_item);
777 for(const_iterator base = begin();
781 if(match_set.find(*base) == match_set.end()) {
785 return Sequence::npos;
788 Sequence::size_type Sequence::start() const
791 return seq_start - parent->start();
796 Sequence::size_type Sequence::stop() const
798 return start() + seq_count;
801 Sequence::size_type Sequence::size() const
806 Sequence::size_type Sequence::length() const
812 Sequence::save(fs::fstream &save_file)
815 std::list<annot>::iterator annots_i;
817 // not sure why, or if i'm doing something wrong, but can't seem to pass
818 // file pointers down to this method from the mussa control class
819 // so each call to save a sequence appends to the file started by mussa_class
820 //save_file.open(save_file_path.c_str(), std::ios::app);
822 save_file << "<Sequence>" << std::endl;
823 save_file << *this << std::endl;
824 save_file << "</Sequence>" << std::endl;
826 save_file << "<Annotations>" << std::endl;
827 save_file << species << std::endl;
828 for (annots_i = annots.begin(); annots_i != annots.end(); ++annots_i)
830 save_file << annots_i->begin << " " << annots_i->end << " " ;
831 save_file << annots_i->name << " " << annots_i->type << std::endl;
833 save_file << "</Annotations>" << std::endl;
838 Sequence::load_museq(fs::path load_file_path, int seq_num)
840 fs::fstream load_file;
841 std::string file_data_line;
844 std::string::size_type space_split_i;
845 std::string annot_value;
848 load_file.open(load_file_path, std::ios::in);
851 // search for the seq_num-th sequence
852 while ( (!load_file.eof()) && (seq_counter < seq_num) )
854 getline(load_file,file_data_line);
855 if (file_data_line == "<Sequence>")
858 getline(load_file, file_data_line);
859 // looks like the sequence is written as a single line
860 set_filtered_sequence(file_data_line, reduced_dna_alphabet);
861 getline(load_file, file_data_line);
862 getline(load_file, file_data_line);
863 if (file_data_line == "<Annotations>")
865 getline(load_file, file_data_line);
866 species = file_data_line;
867 while ( (!load_file.eof()) && (file_data_line != "</Annotations>") )
869 getline(load_file,file_data_line);
870 if ((file_data_line != "") && (file_data_line != "</Annotations>"))
872 // need to get 4 values...almost same code 4 times...
873 // get annot start index
874 space_split_i = file_data_line.find(" ");
875 annot_value = file_data_line.substr(0,space_split_i);
876 an_annot.begin = atoi (annot_value.c_str());
877 file_data_line = file_data_line.substr(space_split_i+1);
878 // get annot end index
879 space_split_i = file_data_line.find(" ");
880 annot_value = file_data_line.substr(0,space_split_i);
881 an_annot.end = atoi (annot_value.c_str());
883 if (space_split_i == std::string::npos) // no entry for type or name
885 std::cout << "seq, annots - no type or name\n";
889 else // else get annot type
891 file_data_line = file_data_line.substr(space_split_i+1);
892 space_split_i = file_data_line.find(" ");
893 annot_value = file_data_line.substr(0,space_split_i);
894 an_annot.type = annot_value;
895 if (space_split_i == std::string::npos) // no entry for name
897 std::cout << "seq, annots - no name\n";
900 else // get annot name
902 file_data_line = file_data_line.substr(space_split_i+1);
903 space_split_i = file_data_line.find(" ");
904 annot_value = file_data_line.substr(0,space_split_i);
905 an_annot.type = annot_value;
908 annots.push_back(an_annot); // don't forget to actually add the annot
910 //std::cout << "seq, annots: " << an_annot.start << ", " << an_annot.end
911 // << "-->" << an_annot.type << "::" << an_annot.name << std::endl;
918 void Sequence::add_motif(const Sequence& a_motif)
920 std::vector<int> motif_starts = find_motif(a_motif);
922 for(std::vector<int>::iterator motif_start_i = motif_starts.begin();
923 motif_start_i != motif_starts.end();
926 motif_list.push_back(motif(*motif_start_i, a_motif.get_sequence()));
930 void Sequence::clear_motifs()
935 const std::list<motif>& Sequence::motifs() const
941 Sequence::find_motif(const Sequence& a_motif) const
943 std::vector<int> motif_match_starts;
944 Sequence norm_motif_rc;
946 motif_match_starts.clear();
947 // std::cout << "motif is: " << norm_motif << std::endl;
949 if (a_motif.size() > 0)
951 //std::cout << "Sequence: none blank motif\n";
952 motif_scan(a_motif, &motif_match_starts);
954 norm_motif_rc = a_motif.rev_comp();;
955 // make sure not to do search again if it is a palindrome
956 if (norm_motif_rc != a_motif) {
957 motif_scan(norm_motif_rc, &motif_match_starts);
960 return motif_match_starts;
964 Sequence::motif_scan(const Sequence& a_motif, std::vector<int> * motif_match_starts) const
966 // if there's no sequence we can't scan for it?
967 // should this throw an exception?
970 std::string::size_type seq_i = 0;
971 Sequence::size_type motif_i = 0;
972 Sequence::size_type motif_len = a_motif.length();
973 Sequence::value_type motif_char;
974 Sequence::value_type seq_char;
976 while (seq_i < size())
978 // this is pretty much a straight translation of Nora's python code
979 // to match iupac letter codes
980 motif_char = toupper(a_motif[motif_i]);
981 seq_char = toupper(seq->at(seq_start+seq_i));
982 if (motif_char =='N')
984 else if (motif_char == seq_char)
986 else if ((motif_char =='M') && ((seq_char=='A') || (seq_char=='C')))
988 else if ((motif_char =='R') && ((seq_char=='A') || (seq_char=='G')))
990 else if ((motif_char =='W') && ((seq_char=='A') || (seq_char=='T')))
992 else if ((motif_char =='S') && ((seq_char=='C') || (seq_char=='G')))
994 else if ((motif_char =='Y') && ((seq_char=='C') || (seq_char=='T')))
996 else if ((motif_char =='K') && ((seq_char=='G') || (seq_char=='T')))
998 else if ((motif_char =='V') &&
999 ((seq_char=='A') || (seq_char=='C') || (seq_char=='G')))
1001 else if ((motif_char =='H') &&
1002 ((seq_char=='A') || (seq_char=='C') || (seq_char=='T')))
1004 else if ((motif_char =='D') &&
1005 ((seq_char=='A') || (seq_char=='G') || (seq_char=='T')))
1007 else if ((motif_char =='B') &&
1008 ((seq_char=='C') || (seq_char=='G') || (seq_char=='T')))
1012 // if a motif doesn't match, erase our current trial and try again
1017 // end Nora stuff, now we see if a match is found this pass
1018 if (motif_i == motif_len)
1021 motif_match_starts->push_back(seq_i - motif_len + 1);
1027 //std::cout << std::endl;
1030 void Sequence::add_string_annotation(std::string a_seq,
1033 std::vector<int> seq_starts = find_motif(a_seq);
1035 //std::cout << "searching for " << a_seq << " found " << seq_starts.size() << std::endl;
1037 for(std::vector<int>::iterator seq_start_i = seq_starts.begin();
1038 seq_start_i != seq_starts.end();
1041 annots.push_back(annot(*seq_start_i,
1042 *seq_start_i+a_seq.size(),
1048 void Sequence::find_sequences(std::list<Sequence>::iterator start,
1049 std::list<Sequence>::iterator end)
1051 while (start != end) {
1052 add_string_annotation(start->get_sequence(), start->get_fasta_header());
1058 std::ostream& operator<<(std::ostream& out, const Sequence& s)
1060 for(Sequence::const_iterator s_i = s.begin(); s_i != s.end(); ++s_i) {
1066 bool operator<(const Sequence& x, const Sequence& y)
1068 Sequence::const_iterator x_i = x.begin();
1069 Sequence::const_iterator y_i = y.begin();
1070 // for sequences there's some computation associated with computing .end
1071 // so lets cache it.
1072 Sequence::const_iterator xend = x.end();
1073 Sequence::const_iterator yend = y.end();
1075 if( x_i == xend and y_i == yend ) {
1077 } else if ( x_i == xend ) {
1079 } else if ( y_i == yend ) {
1081 } else if ( (*x_i) < (*y_i)) {
1083 } else if ( (*x_i) > (*y_i) ) {
1092 bool operator==(const Sequence& x, const Sequence& y)
1094 if (x.empty() and y.empty()) {
1095 // if there's no sequence in either sequence structure, they're equal
1097 } else if (x.empty() or y.empty()) {
1098 // if we fail the first test, and we discover one is empty,
1099 // we know they can't be equal. (and we need to do this
1100 // to prevent dereferencing an empty pointer)
1102 } else if (x.seq_count != y.seq_count) {
1103 // if they're of different lenghts, they're not equal
1106 Sequence::const_iterator xseq_i = x.begin();
1107 Sequence::const_iterator yseq_i = y.begin();
1108 // since the length of the two sequences is equal, we only need to
1110 for(; xseq_i != x.end(); ++xseq_i, ++yseq_i) {
1111 if (toupper(*xseq_i) != toupper(*yseq_i)) {
1118 bool operator!=(const Sequence& x, const Sequence& y)
1120 return not operator==(x, y);