X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=removegroupscommand.cpp;h=42f088b953d2f3657dd98dcec4f184f87eb8a70b;hp=1e5fe11de39f34b30f59249895bcf393506e32f9;hb=cf9987b67aa49777a4c91c2d21f96e58bf17aa82;hpb=af0a94ea8f02421b2b73e77e68753a2b4c37768e diff --git a/removegroupscommand.cpp b/removegroupscommand.cpp index 1e5fe11..42f088b 100644 --- a/removegroupscommand.cpp +++ b/removegroupscommand.cpp @@ -70,7 +70,7 @@ string RemoveGroupsCommand::getOutputPattern(string type) { else if (type == "count") { pattern = "[filename],pick,[extension]"; } else if (type == "list") { pattern = "[filename],pick,[extension]"; } else if (type == "shared") { pattern = "[filename],[tag],pick,[extension]"; } - else if (type == "design") { pattern = "[filename],pick,[extension]"; } + else if (type == "design") { pattern = "[filename],[tag],pick,[extension]"; } else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } return pattern; @@ -355,11 +355,19 @@ int RemoveGroupsCommand::execute(){ //make sure groups are valid //takes care of user setting groupNames that are invalid or setting groups=all - SharedUtil* util = new SharedUtil(); vector namesGroups = groupMap->getNamesOfGroups(); - util->setGroups(Groups, namesGroups); - delete util; - + vector checkedGroups; + for (int i = 0; i < Groups.size(); i++) { + if (m->inUsersGroups(Groups[i], namesGroups)) { checkedGroups.push_back(Groups[i]); } + else { m->mothurOut("[WARNING]: " + Groups[i] + " is not a valid group in your groupfile, ignoring.\n"); } + } + + if (checkedGroups.size() == 0) { m->mothurOut("[ERROR]: no valid groups, aborting.\n"); delete groupMap; return 0; } + else { + Groups = checkedGroups; + m->setGroups(Groups); + } + //fill names with names of sequences that are from the groups we want to remove fillNames(); @@ -369,7 +377,7 @@ int RemoveGroupsCommand::execute(){ m->mothurOut("\n[NOTE]: The count file should contain only unique names, so mothur assumes your fasta, list and taxonomy files also contain only uniques.\n\n"); } CountTable ct; - ct.readTable(countfile, true); + ct.readTable(countfile, true, false); if (!ct.hasGroupInfo()) { m->mothurOut("[ERROR]: your count file does not contain group info, aborting.\n"); return 0; } vector gNamesOfGroups = ct.getNamesOfGroups(); @@ -552,9 +560,9 @@ int RemoveGroupsCommand::readShared(){ m->setGroups(groupsToKeep); m->clearAllGroups(); m->saveNextLabel = ""; - m->printedHeaders = false; - m->currentBinLabels.clear(); - m->binLabelsInFile.clear(); + m->printedSharedHeaders = false; + m->currentSharedBinLabels.clear(); + m->sharedBinLabelsInFile.clear(); InputData input(sharedfile, "sharedfile"); lookup = input.getSharedRAbundVectors(); @@ -615,12 +623,7 @@ int RemoveGroupsCommand::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); @@ -633,6 +636,16 @@ int RemoveGroupsCommand::readList(){ //read in list vector ListVector list(in); + + variables["[tag]"] = 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; //make a new list vector ListVector newList; @@ -673,24 +686,26 @@ int RemoveGroupsCommand::readList(){ //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 groups you wish to remove."); m->mothurOutEndLine(); } - outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); + if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the groups you wish to remove."); m->mothurOutEndLine(); } m->mothurOut("Removed " + toString(removedCount) + " sequences from your list file."); m->mothurOutEndLine(); return 0;