X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=chimera.cpp;h=bf16de4e34b795694d1a894ea1005f32353be110;hb=5a1e62397b91f57d0d3aff635891df04b8999a88;hp=7e997b9824439e4e42f495f95a2d101b58a89600;hpb=ec92647e652017e0cd4ba0488a815094f88373b3;p=mothur.git diff --git a/chimera.cpp b/chimera.cpp index 7e997b9..bf16de4 100644 --- a/chimera.cpp +++ b/chimera.cpp @@ -10,10 +10,10 @@ #include "chimera.h" //*************************************************************************************************************** -//this is a vertical filter +//this is a vertical soft filter void Chimera::createFilter(vector seqs) { try { - + filterString = ""; int threshold = int (0.5 * seqs.size()); //cout << "threshhold = " << threshold << endl; @@ -40,6 +40,7 @@ void Chimera::createFilter(vector seqs) { } } + //zero out spot where all sequences have blanks //zero out spot where all sequences have blanks int numColRemoved = 0; for(int i = 0;i < seqs[0]->getAligned().length(); i++){ @@ -48,6 +49,7 @@ void Chimera::createFilter(vector seqs) { else if (((a[i] < threshold) && (t[i] < threshold) && (g[i] < threshold) && (c[i] < threshold))) { filterString[i] = '0'; numColRemoved++; } //cout << "a = " << a[i] << " t = " << t[i] << " g = " << g[i] << " c = " << c[i] << endl; } + //cout << "filter = " << filterString << endl; mothurOut("Filter removed " + toString(numColRemoved) + " columns."); mothurOutEndLine(); @@ -58,46 +60,52 @@ void Chimera::createFilter(vector seqs) { } } //*************************************************************************************************************** -void Chimera::runFilter(vector seqs) { +void Chimera::runFilter(Sequence* seq) { try { - //for each sequence - for (int i = 0; i < seqs.size(); i++) { - - string seqAligned = seqs[i]->getAligned(); - string newAligned = ""; - - for (int j = 0; j < seqAligned.length(); j++) { - //if this spot is a gap - if (filterString[j] == '1') { newAligned += seqAligned[j]; } - } + string seqAligned = seq->getAligned(); + string newAligned = ""; - seqs[i]->setAligned(newAligned); + for (int j = 0; j < seqAligned.length(); j++) { + //if this spot is a gap + if (filterString[j] == '1') { newAligned += seqAligned[j]; } } - + + seq->setAligned(newAligned); } catch(exception& e) { errorOut(e, "Chimera", "runFilter"); exit(1); } } - //*************************************************************************************************************** vector Chimera::readSeqs(string file) { try { + + mothurOut("Reading sequences... "); cout.flush(); ifstream in; openInputFile(file, in); vector container; + int count = 0; + int length = 0; + unaligned = false; //read in seqs and store in vector while(!in.eof()){ - Sequence* current = new Sequence(in); - container.push_back(current); - gobble(in); + Sequence* current = new Sequence(in); gobble(in); + + if (count == 0) { length = current->getAligned().length(); count++; } //gets first seqs length + else if (length != current->getAligned().length()) { //seqs are unaligned + unaligned = true; + } + + if (current->getName() != "") { container.push_back(current); } } in.close(); + mothurOut("Done."); mothurOutEndLine(); + return container; } catch(exception& e) { @@ -142,7 +150,7 @@ vector< vector > Chimera::readQuantiles() { openInputFile(quanfile, in); vector< vector > quan; - vector temp; + vector temp; temp.resize(6, 0); //to fill 0 quan.push_back(temp); @@ -177,6 +185,31 @@ vector< vector > Chimera::readQuantiles() { } } //*************************************************************************************************************** +Sequence* Chimera::getSequence(string name) { + try{ + Sequence* temp; + + //look through templateSeqs til you find it + int spot = -1; + for (int i = 0; i < templateSeqs.size(); i++) { + if (name == templateSeqs[i]->getName()) { + spot = i; + break; + } + } + + if(spot == -1) { mothurOut("Error: Could not find sequence."); mothurOutEndLine(); return NULL; } + + temp = new Sequence(templateSeqs[spot]->getName(), templateSeqs[spot]->getAligned()); + + return temp; + } + catch(exception& e) { + errorOut(e, "Chimera", "getSequence"); + exit(1); + } +} +//***************************************************************************************************************