X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=chimerauchimecommand.cpp;h=e82dc1bc8dce5ffd0887025d5816b5eec8d0eab9;hb=67ea6ccd74dbd64828d31b952808255f206364ff;hp=3ed61707385f4859a4b4558bd35124fac1b2b417;hpb=2a29fceeeb8754c3fd97ba830d2fbed5c4349ee8;p=mothur.git diff --git a/chimerauchimecommand.cpp b/chimerauchimecommand.cpp index 3ed6170..e82dc1b 100644 --- a/chimerauchimecommand.cpp +++ b/chimerauchimecommand.cpp @@ -727,10 +727,8 @@ int ChimeraUchimeCommand::execute(){ if(processors == 1) { totalSeqs = driverGroups(outputFileName, newFasta, accnosFileName, alnsFileName, newCountFile, 0, groups.size(), groups); - //read my own - if (hasCount && !dups) { - CountTable newCount; newCount.readTable(nameFile); - + if (hasCount && dups) { + CountTable c; c.readTable(nameFile); if (!m->isBlank(newCountFile)) { ifstream in2; m->openInputFile(newCountFile, in2); @@ -738,12 +736,12 @@ int ChimeraUchimeCommand::execute(){ string name, group; while (!in2.eof()) { in2 >> name >> group; m->gobble(in2); - newCount.setAbund(name, group, 0); + c.setAbund(name, group, 0); } in2.close(); } m->mothurRemove(newCountFile); - newCount.printTable(newCountFile); + c.printTable(newCountFile); } }else { totalSeqs = createProcessesGroups(outputFileName, newFasta, accnosFileName, alnsFileName, newCountFile, groups, nameFile, groupFile, fastaFileNames[s]); } @@ -757,25 +755,27 @@ int ChimeraUchimeCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(totalSeqs) + " sequences. " + toString(totalChimeras) + " chimeras were found."); m->mothurOutEndLine(); m->mothurOut("The number of sequences checked may be larger than the number of unique sequences because some sequences are found in several samples."); m->mothurOutEndLine(); }else { - /*if (hasCount) { //removed empty seqs - ofstream out2; - m->openOutputFile(accnosFileName, out2); - + + if (hasCount) { + set doNotRemove; CountTable c; c.readTable(newCountFile); - vector nseqs = c.getNamesOfSeqs(); - vector ngroups = c.getNamesOfGroups(); - for (int l = 0; l < nseqs.size(); l++) { - if (c.getNumSeqs(nseqs[l]) == 0) { - c.remove(nseqs[l]); - out2 << nseqs[l] << endl; - } + vector namesInTable = c.getNamesOfSeqs(); + for (int i = 0; i < namesInTable.size(); i++) { + int temp = c.getNumSeqs(namesInTable[i]); + if (temp == 0) { c.remove(namesInTable[i]); } + else { doNotRemove.insert((namesInTable[i])); } } - for (int l = 0; l < ngroups.size(); l++) { - if (c.getGroupCount(ngroups[l]) == 0) { c.removeGroup(ngroups[l]); } + //remove names we want to keep from accnos file. + set accnosNames = m->readAccnos(accnosFileName); + ofstream out2; + m->openOutputFile(accnosFileName, out2); + for (set::iterator it = accnosNames.begin(); it != accnosNames.end(); it++) { + if (doNotRemove.count(*it) == 0) { out2 << (*it) << endl; } } out2.close(); c.printTable(newCountFile); - }*/ + outputNames.push_back(newCountFile); outputTypes["count"].push_back(newCountFile); + } } if (hasCount) { delete cparser; } @@ -820,6 +820,11 @@ int ChimeraUchimeCommand::execute(){ if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setAccnosFile(current); } } + + itTypes = outputTypes.find("count"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setCountTableFile(current); } + } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -840,10 +845,6 @@ int ChimeraUchimeCommand::deconvoluteResults(map& uniqueNames, s map::iterator itUnique; int total = 0; - //edit accnos file - ifstream in2; - m->openInputFile(accnosFileName, in2); - ofstream out2; m->openOutputFile(accnosFileName+".temp", out2); @@ -853,27 +854,32 @@ int ChimeraUchimeCommand::deconvoluteResults(map& uniqueNames, s set chimerasInFile; set::iterator itChimeras; - - while (!in2.eof()) { - if (m->control_pressed) { in2.close(); out2.close(); m->mothurRemove(outputFileName); m->mothurRemove((accnosFileName+".temp")); return 0; } - - in2 >> name; m->gobble(in2); - - //find unique name - itUnique = uniqueNames.find(name); - - if (itUnique == uniqueNames.end()) { m->mothurOut("[ERROR]: trouble parsing accnos results. Cannot find " + name + "."); m->mothurOutEndLine(); m->control_pressed = true; } - else { - itChimeras = chimerasInFile.find((itUnique->second)); - - if (itChimeras == chimerasInFile.end()) { - out2 << itUnique->second << endl; - chimerasInFile.insert((itUnique->second)); - total++; - } - } - } - in2.close(); + if (!m->isBlank(accnosFileName)) { + //edit accnos file + ifstream in2; + m->openInputFile(accnosFileName, in2); + + while (!in2.eof()) { + if (m->control_pressed) { in2.close(); out2.close(); m->mothurRemove(outputFileName); m->mothurRemove((accnosFileName+".temp")); return 0; } + + in2 >> name; m->gobble(in2); + + //find unique name + itUnique = uniqueNames.find(name); + + if (itUnique == uniqueNames.end()) { m->mothurOut("[ERROR]: trouble parsing accnos results. Cannot find " + name + "."); m->mothurOutEndLine(); m->control_pressed = true; } + else { + itChimeras = chimerasInFile.find((itUnique->second)); + + if (itChimeras == chimerasInFile.end()) { + out2 << itUnique->second << endl; + chimerasInFile.insert((itUnique->second)); + total++; + } + } + } + in2.close(); + } out2.close(); m->mothurRemove(accnosFileName); @@ -1182,6 +1188,7 @@ int ChimeraUchimeCommand::driverGroups(string outputFName, string filename, stri int totalSeqs = 0; int numChimeras = 0; + ofstream outCountList; if (hasCount && dups) { m->openOutputFile(countlist, outCountList); } @@ -1893,7 +1900,7 @@ int ChimeraUchimeCommand::createProcessesGroups(string outputFName, string filen #endif - + //read my own if (hasCount && dups) { if (!m->isBlank(accnos + ".byCount")) { @@ -1909,7 +1916,7 @@ int ChimeraUchimeCommand::createProcessesGroups(string outputFName, string filen } m->mothurRemove(accnos + ".byCount"); } - + //append output files for(int i=0;iappendFiles((outputFName + toString(processIDS[i]) + ".temp"), outputFName); @@ -1941,8 +1948,8 @@ int ChimeraUchimeCommand::createProcessesGroups(string outputFName, string filen } //print new *.pick.count_table - if (hasCount && dups) { newCount.printTable(newCountFile); } - + if (hasCount && dups) { newCount.printTable(newCountFile); } + return num; }