X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=blobdiff_plain;f=alg%2Fsequence.cpp;h=b39c4d45eef964f7e6bea050be7d16cce9bba386;hp=521496d3497b2b96d4786819438d170f6ac50ce4;hb=510c9340528467a30a64d03d3936a4d8fdd18af4;hpb=f3c0553a22b0e4ddc39ee45f51725352d92e97f1 diff --git a/alg/sequence.cpp b/alg/sequence.cpp index 521496d..b39c4d4 100644 --- a/alg/sequence.cpp +++ b/alg/sequence.cpp @@ -423,16 +423,32 @@ struct push_back_seq { void operator()(std::string::const_iterator, std::string::const_iterator) const { + std::string::iterator seq_i = seq.begin(); + std::string::iterator seq_end = seq.end(); + + // this if block is a hack, for some reason spirit was + // duplicating the last character if the file didn't end + // with a new line. + // this checks for the trailing newline, and if it is missing + // removes the last character ( which should be the duplicated character. + // check test_sequence.cpp:sequence_no_trailing_newline for test case + // also see ticket:265 for more information + if (seq.size() > 0) { + std::string::value_type c = seq[seq.size()-1]; + if (not (c == '\015' or c == '\012')) { + // doesn't end with a new line character + seq_end--; + } + } + // end hack + // filter out newlines from our sequence std::string new_seq; - for(std::string::const_iterator seq_i = seq.begin(); - seq_i != seq.end(); - ++seq_i) + for(; seq_i != seq_end; ++seq_i) { if (*seq_i != '\015' && *seq_i != '\012') new_seq += *seq_i; } //std::cout << "adding seq: " << name << " " << new_seq << std::endl; - Sequence s(new_seq); s.set_fasta_header(name); seq_list.push_back(s); @@ -677,11 +693,6 @@ Sequence::save(fs::fstream &save_file) SeqSpanRefList::iterator annots_i; AnnotationsRef metadata; - // not sure why, or if i'm doing something wrong, but can't seem to pass - // file pointers down to this method from the mussa control class - // so each call to save a sequence appends to the file started by mussa_class - //save_file.open(save_file_path.c_str(), std::ios::app); - save_file << "" << std::endl; save_file << *this << std::endl; save_file << "" << std::endl;