X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=removeseqscommand.cpp;h=25d45a7c578c47167fac24164cac3322f3462772;hb=6b32d112bb60e9f7eb6d4407a4eed4c49b67bced;hp=019a659f44f446be2d3c87e5c195ab93663f1773;hpb=2ff2d03fbe46ce8cf2738bff4403a52be4f31e2f;p=mothur.git diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index 019a659..25d45a7 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -67,7 +67,7 @@ string RemoveSeqsCommand::getOutputPattern(string type) { else if (type == "name") { pattern = "[filename],pick,[extension]"; } else if (type == "group") { pattern = "[filename],pick,[extension]"; } else if (type == "count") { pattern = "[filename],pick,[extension]"; } - else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],[distance],pick,[extension]"; } else if (type == "qfile") { pattern = "[filename],pick,[extension]"; } else if (type == "alignreport") { pattern = "[filename],pick.align.report"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } @@ -664,10 +664,7 @@ int RemoveSeqsCommand::readList(){ map variables; variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); variables["[extension]"] = m->getExtension(listfile); - string outputFileName = getOutputFileName("list", variables); - ofstream out; - m->openOutputFile(outputFileName, out); - + ifstream in; m->openInputFile(listfile, in); @@ -684,48 +681,60 @@ int RemoveSeqsCommand::readList(){ //make a new list vector ListVector newList; newList.setLabel(list.getLabel()); + + variables["[distance]"] = list.getLabel(); + string outputFileName = getOutputFileName("list", variables); + ofstream out; + m->openOutputFile(outputFileName, out); + outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); + + vector binLabels = list.getLabels(); + vector newBinLabels; + + if (m->control_pressed) { in.close(); out.close(); return 0; } + //for each bin for (int i = 0; i < list.getNumBins(); i++) { if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; } //parse out names that are in accnos file - string binnames = list.get(i); + string bin = list.get(i); + vector bnames; + m->splitAtComma(bin, bnames); string newNames = ""; - while (binnames.find_first_of(',') != -1) { - string name = binnames.substr(0,binnames.find_first_of(',')); - binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length()); - - //if that name is in the .accnos file, add it + for (int j = 0; j < bnames.size(); j++) { + string name = bnames[j]; + //if that name is in the .accnos file, add it if (names.count(name) == 0) { newNames += name + ","; } else { removedCount++; } - } - - //get last name - if (names.count(binnames) == 0) { newNames += binnames + ","; } - else { removedCount++; } + } //if there are names in this bin add to new list if (newNames != "") { newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma - newList.push_back(newNames); + newList.push_back(newNames); + newBinLabels.push_back(binLabels[i]); } } //print new listvector if (newList.getNumBins() != 0) { wroteSomething = true; + newList.setLabels(newBinLabels); + newList.printHeaders(out); newList.print(out); + } m->gobble(in); + out.close(); } in.close(); - out.close(); + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); } - outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); m->mothurOut("Removed " + toString(removedCount) + " sequences from your list file."); m->mothurOutEndLine();