X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sequence.cpp;h=42c26d59ab4df8cd9e0d75937a476617135adbd7;hb=fe5bbb79f9434df947347881c47b430112f4253e;hp=71dd3a925fab8eb7771803c6db557dfb9d10200b;hpb=b447f829850ae054e42560c7c3ed71b14f3f40bb;p=mothur.git diff --git a/sequence.cpp b/sequence.cpp index 71dd3a9..42c26d5 100644 --- a/sequence.cpp +++ b/sequence.cpp @@ -54,29 +54,34 @@ Sequence::Sequence(istringstream& fastaString){ initialize(); fastaString >> name; - name = name.substr(1); - string sequence; - - //read comments - while ((name[0] == '#') && fastaString) { - while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there - sequence = getCommentString(fastaString); - - if (fastaString) { - fastaString >> name; - name = name.substr(1); - }else { - name = ""; - break; - } - } - while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + if (name.length() != 0) { + + name = name.substr(1); + string sequence; + + //read comments + while ((name[0] == '#') && fastaString) { + while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + sequence = getCommentString(fastaString); + + if (fastaString) { + fastaString >> name; + name = name.substr(1); + }else { + name = ""; + break; + } + } + + while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + + sequence = getSequenceString(fastaString); + setAligned(sequence); + //setUnaligned removes any gap characters for us + setUnaligned(sequence); + }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaString.tellg()) + ". Blank name."); m->mothurOutEndLine(); } - sequence = getSequenceString(fastaString); - setAligned(sequence); - //setUnaligned removes any gap characters for us - setUnaligned(sequence); } catch(exception& e) { m->errorOut(e, "Sequence", "Sequence"); @@ -91,29 +96,34 @@ Sequence::Sequence(istringstream& fastaString, string JustUnaligned){ initialize(); fastaString >> name; - name = name.substr(1); - string sequence; - - //read comments - while ((name[0] == '#') && fastaString) { - while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there - sequence = getCommentString(fastaString); - - if (fastaString) { - fastaString >> name; - name = name.substr(1); - }else { - name = ""; - break; - } - } - while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + if (name.length() != 0) { - sequence = getSequenceString(fastaString); + name = name.substr(1); + string sequence; + + //read comments + while ((name[0] == '#') && fastaString) { + while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + sequence = getCommentString(fastaString); + + if (fastaString) { + fastaString >> name; + name = name.substr(1); + }else { + name = ""; + break; + } + } + + while (!fastaString.eof()) { char c = fastaString.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + + sequence = getSequenceString(fastaString); + + //setUnaligned removes any gap characters for us + setUnaligned(sequence); + }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaString.tellg()) + ". Blank name."); m->mothurOutEndLine(); } - //setUnaligned removes any gap characters for us - setUnaligned(sequence); } catch(exception& e) { m->errorOut(e, "Sequence", "Sequence"); @@ -129,31 +139,37 @@ Sequence::Sequence(ifstream& fastaFile){ m = MothurOut::getInstance(); initialize(); fastaFile >> name; - name = name.substr(1); - string sequence; + + if (name.length() != 0) { - //read comments - while ((name[0] == '#') && fastaFile) { - while (!fastaFile.eof()) { char c = fastaFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there - sequence = getCommentString(fastaFile); + name = name.substr(1); - if (fastaFile) { - fastaFile >> name; - name = name.substr(1); - }else { - name = ""; - break; - } - } + string sequence; - //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 - - sequence = getSequenceString(fastaFile); - - setAligned(sequence); - //setUnaligned removes any gap characters for us - setUnaligned(sequence); + //read comments + while ((name[0] == '#') && fastaFile) { + while (!fastaFile.eof()) { char c = fastaFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + sequence = getCommentString(fastaFile); + + if (fastaFile) { + fastaFile >> name; + name = name.substr(1); + }else { + name = ""; + break; + } + } + + //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 + + sequence = getSequenceString(fastaFile); + + setAligned(sequence); + //setUnaligned removes any gap characters for us + setUnaligned(sequence); + }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); } + } catch(exception& e) { m->errorOut(e, "Sequence", "Sequence"); @@ -167,30 +183,34 @@ Sequence::Sequence(ifstream& fastaFile, string JustUnaligned){ m = MothurOut::getInstance(); initialize(); fastaFile >> name; - name = name.substr(1); - string sequence; - //read comments - while ((name[0] == '#') && fastaFile) { - while (!fastaFile.eof()) { char c = fastaFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there - sequence = getCommentString(fastaFile); + if (name.length() != 0) { + name = name.substr(1); + string sequence; - if (fastaFile) { - fastaFile >> name; - name = name.substr(1); - }else { - name = ""; - break; + //read comments + while ((name[0] == '#') && fastaFile) { + while (!fastaFile.eof()) { char c = fastaFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there + sequence = getCommentString(fastaFile); + + if (fastaFile) { + fastaFile >> name; + name = name.substr(1); + }else { + name = ""; + break; + } } - } - - //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 - - sequence = getSequenceString(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 + + sequence = getSequenceString(fastaFile); + + //setUnaligned removes any gap characters for us + setUnaligned(sequence); + }else{ m->mothurOut("Error in reading your fastafile, at position " + toString(fastaFile.tellg()) + ". Blank name."); m->mothurOutEndLine(); } - //setUnaligned removes any gap characters for us - setUnaligned(sequence); } catch(exception& e) { m->errorOut(e, "Sequence", "Sequence"); @@ -234,7 +254,7 @@ string Sequence::getCommentString(ifstream& fastaFile) { while(fastaFile){ letter=fastaFile.get(); if((letter == '\r') || (letter == '\n')){ - gobble(fastaFile); //in case its a \r\n situation + m->gobble(fastaFile); //in case its a \r\n situation break; } } @@ -283,7 +303,7 @@ string Sequence::getCommentString(istringstream& fastaFile) { while(fastaFile){ letter=fastaFile.get(); if((letter == '\r') || (letter == '\n')){ - gobble(fastaFile); //in case its a \r\n situation + m->gobble(fastaFile); //in case its a \r\n situation break; } } @@ -461,6 +481,18 @@ int Sequence::getAmbigBases(){ //******************************************************************************************************************** +void Sequence::removeAmbigBases(){ + + for(int j=0;j length){ + unaligned = unaligned.substr(0,length); + numBases = length; + } + +} + +///**************************************************************************************************/