X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=sequence.cpp;h=6aa0c0f8ae2c46a32edde8a67276ccb966bc0003;hb=d0954e27635712cdbd8b86e3c4510670803a2665;hp=0afe3a971dcb1884160cd25f6c3d1b1d7012fa68;hpb=54a6cb0ef32b761ebd7ae35f1e60947edf44d699;p=mothur.git diff --git a/sequence.cpp b/sequence.cpp index 0afe3a9..6aa0c0f 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) { + + name = name.substr(1); + string sequence; - sequence = getSequenceString(fastaString); + //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,7 +139,7 @@ Sequence::Sequence(ifstream& fastaFile){ m = MothurOut::getInstance(); initialize(); fastaFile >> name; - + if (name.length() != 0) { name = name.substr(1); @@ -151,15 +161,15 @@ 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 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"); @@ -173,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"); @@ -240,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; } } @@ -289,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; } } @@ -413,6 +427,13 @@ string Sequence::getAligned(){ else { return aligned; } } +//******************************************************************************************************************** + +string Sequence::getInlineSeq(){ + return name + '\t' + aligned; +} + + //******************************************************************************************************************** string Sequence::getPairwise(){ @@ -467,6 +488,18 @@ int Sequence::getAmbigBases(){ //******************************************************************************************************************** +void Sequence::removeAmbigBases(){ + + for(int j=0;j=0;j--){ @@ -519,6 +563,17 @@ int Sequence::getEndPos(){ //******************************************************************************************************************** +void Sequence::padFromPos(int end){ + + for(int j = end; j < endPos; j++) { + aligned[j] = '.'; + } + endPos = end; + +} + +//******************************************************************************************************************** + bool Sequence::getIsAligned(){ return isAligned; } @@ -539,4 +594,16 @@ void Sequence::reverseComplement(){ aligned = temp; } -/**************************************************************************************************/ + +//******************************************************************************************************************** + +void Sequence::trim(int length){ + + if(numBases > length){ + unaligned = unaligned.substr(0,length); + numBases = length; + } + +} + +///**************************************************************************************************/