X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=sequence.cpp;h=efeb88ce65183135c2a0aaef36d8d3a1c8f432cc;hp=4c631a23451d4d9723aec3a29bed423737b243ba;hb=b206f634aae1b4ce13978d203247fb64757d5482;hpb=75cff1a83a64cd46e9dd603e02597a2bb6a76119 diff --git a/sequence.cpp b/sequence.cpp index 4c631a2..efeb88c 100644 --- a/sequence.cpp +++ b/sequence.cpp @@ -21,9 +21,7 @@ Sequence::Sequence(string newName, string sequence) { initialize(); name = newName; - for (int i = 0; i < name.length(); i++) { - if (name[i] == ':') { name[i] = '_'; m->changedSeqNames = true; } - } + m->checkName(name); //setUnaligned removes any gap characters for us setUnaligned(sequence); @@ -41,9 +39,7 @@ Sequence::Sequence(string newName, string sequence, string justUnAligned) { initialize(); name = newName; - for (int i = 0; i < name.length(); i++) { - if (name[i] == ':') { name[i] = '_'; m->changedSeqNames = true; } - } + m->checkName(name); //setUnaligned removes any gap characters for us setUnaligned(sequence); @@ -80,7 +76,8 @@ Sequence::Sequence(istringstream& fastaString){ } } - while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + //while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + comment = getCommentString(fastaString); int numAmbig = 0; sequence = getSequenceString(fastaString, numAmbig); @@ -124,7 +121,8 @@ Sequence::Sequence(istringstream& fastaString, string JustUnaligned){ } } - while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + //while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + comment = getCommentString(fastaString); int numAmbig = 0; sequence = getSequenceString(fastaString, numAmbig); @@ -170,8 +168,8 @@ Sequence::Sequence(ifstream& fastaFile){ } } - //read real sequence - while (!fastaFile.eof()) { char c = fastaFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + //while (!fastaFile.eof()) { char c = fastaFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + comment = getCommentString(fastaFile); int numAmbig = 0; sequence = getSequenceString(fastaFile, numAmbig); @@ -220,9 +218,11 @@ Sequence::Sequence(ifstream& fastaFile, string& extraInfo, bool getInfo){ //read info after sequence name while (!fastaFile.eof()) { char c = fastaFile.get(); - if (c == 10 || c == 13){ break; } + if (c == 10 || c == 13 || c == -1){ break; } extraInfo += c; - } + } + + comment = extraInfo; int numAmbig = 0; sequence = getSequenceString(fastaFile, numAmbig); @@ -265,8 +265,8 @@ Sequence::Sequence(ifstream& fastaFile, string JustUnaligned){ } } - //read real sequence - while (!fastaFile.eof()) { char c = fastaFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + //while (!fastaFile.eof()) { char c = fastaFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + comment = getCommentString(fastaFile); int numAmbig = 0; sequence = getSequenceString(fastaFile, numAmbig); @@ -295,9 +295,7 @@ string Sequence::getSequenceName(ifstream& fastaFile) { name = name.substr(1); - for (int i = 0; i < name.length(); i++) { - if (name[i] == ':') { name[i] = '_'; m->changedSeqNames = true; } - } + m->checkName(name); }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); m->control_pressed = true; } @@ -319,9 +317,7 @@ string Sequence::getSequenceName(istringstream& fastaFile) { name = name.substr(1); - for (int i = 0; i < name.length(); i++) { - if (name[i] == ':') { name[i] = '_'; m->changedSeqNames = true; } - } + m->checkName(name); }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); m->control_pressed = true; } @@ -368,17 +364,19 @@ string Sequence::getSequenceString(ifstream& fastaFile, int& numAmbig) { string Sequence::getCommentString(ifstream& fastaFile) { try { char letter; - string sequence = ""; + string temp = ""; while(fastaFile){ letter=fastaFile.get(); - if((letter == '\r') || (letter == '\n')){ + if((letter == '\r') || (letter == '\n') || letter == -1){ m->gobble(fastaFile); //in case its a \r\n situation break; - } + }else { + temp += letter; + } } - return sequence; + return temp; } catch(exception& e) { m->errorOut(e, "Sequence", "getCommentString"); @@ -422,17 +420,19 @@ string Sequence::getSequenceString(istringstream& fastaFile, int& numAmbig) { string Sequence::getCommentString(istringstream& fastaFile) { try { char letter; - string sequence = ""; + string temp = ""; while(fastaFile){ letter=fastaFile.get(); - if((letter == '\r') || (letter == '\n')){ + if((letter == '\r') || (letter == '\n') || letter == -1){ m->gobble(fastaFile); //in case its a \r\n situation break; - } + }else { + temp += letter; + } } - return sequence; + return temp; } catch(exception& e) { m->errorOut(e, "Sequence", "getCommentString"); @@ -447,6 +447,7 @@ void Sequence::initialize(){ unaligned = ""; aligned = ""; pairwise = ""; + comment = ""; numBases = 0; alignmentLength = 0; @@ -589,7 +590,7 @@ int Sequence::getNumNs(){ void Sequence::printSequence(ostream& out){ - out << ">" << name << endl; + out << ">" << name << comment << endl; if(isAligned){ out << aligned << endl; } @@ -683,12 +684,12 @@ int Sequence::filterToPos(int start){ if (start > aligned.length()) { start = aligned.length(); m->mothurOut("[ERROR]: start to large.\n"); } - for(int j = 0; j < start-1; j++) { + for(int j = 0; j < start; j++) { aligned[j] = '.'; } //things like ......----------AT become ................AT - for(int j = start-1; j < aligned.length(); j++) { + for(int j = start; j < aligned.length(); j++) { if (isalpha(aligned[j])) { break; } else { aligned[j] = '.'; } }