X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sequence.cpp;h=580f68ae7706ed15a11f9f460e29a56bd441767b;hb=786d5631d9cd5baa6ed6ef16f8b4b384cbc7470f;hp=e9487c519e0d3e0378266eb537d15e28979546dc;hpb=a6c698b20eda3671d22466ab6b98b36331a30804;p=mothur.git diff --git a/sequence.cpp b/sequence.cpp index e9487c5..580f68a 100644 --- a/sequence.cpp +++ b/sequence.cpp @@ -7,8 +7,6 @@ * */ -using namespace std; - #include "sequence.hpp" /***********************************************************************/ @@ -25,7 +23,6 @@ Sequence::Sequence(string newName, string sequence) { name = newName; if(sequence.find_first_of('-') != string::npos) { setAligned(sequence); - isAligned = 1; } setUnaligned(sequence); @@ -33,10 +30,12 @@ Sequence::Sequence(string newName, string sequence) { //******************************************************************************************************************** Sequence::Sequence(ifstream& fastaFile){ + + initialize(); + fastaFile >> name; + name = name.substr(1); - string accession; // provided a file handle to a fasta-formatted sequence file, read in the next - fastaFile >> accession; // accession number and sequence we find... - setName(accession); + while (!fastaFile.eof()) { char c = fastaFile.get(); if (c == 10 || c == 13){ break; } } // get rest of line if there's any crap there char letter; string sequence; @@ -52,7 +51,6 @@ Sequence::Sequence(ifstream& fastaFile){ if(letter == 'U'){letter = 'T';} sequence += letter; } - } if(sequence.find_first_of('-') != string::npos){ // if there are any gaps in the sequence, assume that it is @@ -131,7 +129,7 @@ void Sequence::setAligned(string sequence){ } } } - + isAligned = 1; } //******************************************************************************************************************** @@ -249,11 +247,13 @@ int Sequence::getStartPos(){ if(endPos == -1){ for(int j = 0; j < alignmentLength; j++) { if(aligned[j] != '.'){ - startPos = j; + startPos = j + 1; break; } } - } + } + if(isAligned == 0){ startPos = 1; } + return startPos; } @@ -263,11 +263,13 @@ int Sequence::getEndPos(){ if(endPos == -1){ for(int j=alignmentLength-1;j>=0;j--){ if(aligned[j] != '.'){ - endPos = j; + endPos = j + 1; break; } } } + if(isAligned == 0){ endPos = numBases; } + return endPos; } @@ -278,3 +280,19 @@ bool Sequence::getIsAligned(){ } //******************************************************************************************************************** + +void Sequence::reverseComplement(){ + + string temp; + for(int i=numBases-1;i>=0;i--){ + if(unaligned[i] == 'A') { temp += 'T'; } + else if(unaligned[i] == 'T'){ temp += 'A'; } + else if(unaligned[i] == 'G'){ temp += 'C'; } + else if(unaligned[i] == 'C'){ temp += 'G'; } + else { temp += 'N'; } + } + unaligned = temp; + +} + +//********************************************************************************************************************