X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=removegroupscommand.cpp;h=e5a3bb2edc7fc97dacb89393ef3a2968b64247b4;hb=1b0bddfbf4ac5df7e2dad03c8a5350e71b052f78;hp=252a92573d036c47f4d45235113adef1fc44727a;hpb=8742edef7a51b82834289e570d336f5a81ba1f2b;p=mothur.git diff --git a/removegroupscommand.cpp b/removegroupscommand.cpp index 252a925..e5a3bb2 100644 --- a/removegroupscommand.cpp +++ b/removegroupscommand.cpp @@ -190,6 +190,11 @@ RemoveGroupsCommand::RemoveGroupsCommand(string option) { else if (namefile == "not found") { namefile = ""; } else { m->setNameFile(namefile); } + groupfile = validParameter.validFile(parameters, "group", true); + if (groupfile == "not open") { groupfile = ""; abort = true; } + else if (groupfile == "not found") { groupfile = ""; } + else { m->setGroupFile(groupfile); } + listfile = validParameter.validFile(parameters, "list", true); if (listfile == "not open") { listfile = ""; abort = true; } else if (listfile == "not found") { listfile = ""; } @@ -204,7 +209,7 @@ RemoveGroupsCommand::RemoveGroupsCommand(string option) { if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - m->Groups = Groups; + m->setGroups(Groups); } sharedfile = validParameter.validFile(parameters, "shared", true); @@ -273,7 +278,8 @@ 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(); - util->setGroups(Groups, groupMap->namesOfGroups); + vector namesGroups = groupMap->getNamesOfGroups(); + util->setGroups(Groups, namesGroups); delete util; //fill names with names of sequences that are from the groups we want to remove @@ -369,9 +375,16 @@ int RemoveGroupsCommand::readFasta(){ //if this name is in the accnos file if (names.count(name) == 0) { wroteSomething = true; - - currSeq.printSequence(out); - }else { removedCount++; } + currSeq.printSequence(out); + }else { + //if you are not in the accnos file check if you are a name that needs to be changed + map::iterator it = uniqueToRedundant.find(name); + if (it != uniqueToRedundant.end()) { + wroteSomething = true; + currSeq.setName(it->second); + currSeq.printSequence(out); + }else { removedCount++; } + } } m->gobble(in); } @@ -403,23 +416,23 @@ int RemoveGroupsCommand::readShared(){ vector lookup = tempInput->getSharedRAbundVectors(); //save m->Groups - vector allGroupsNames = m->namesOfGroups; - vector mothurOutGroups = m->Groups; + vector allGroupsNames = m->getAllGroups(); + vector mothurOutGroups = m->getGroups(); vector groupsToKeep; for (int i = 0; i < allGroupsNames.size(); i++) { - if (!m->inUsersGroups(allGroupsNames[i], m->Groups)) { + if (!m->inUsersGroups(allGroupsNames[i], m->getGroups())) { groupsToKeep.push_back(allGroupsNames[i]); } } - if (allGroupsNames.size() == groupsToKeep.size()) { m->mothurOut("Your file does not contain any groups you wish to remove."); m->mothurOutEndLine(); m->Groups = mothurOutGroups; delete tempInput; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } + if (allGroupsNames.size() == groupsToKeep.size()) { m->mothurOut("Your file does not contain any groups you wish to remove."); m->mothurOutEndLine(); m->setGroups(mothurOutGroups); delete tempInput; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } //reset read for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } delete tempInput; - m->Groups = groupsToKeep; - m->namesOfGroups.clear(); + m->setGroups(groupsToKeep); + m->clearAllGroups(); m->names.clear(); m->saveNextLabel = ""; m->printedHeaders = false; @@ -458,7 +471,7 @@ int RemoveGroupsCommand::readShared(){ } - m->Groups = mothurOutGroups; + m->setGroups(mothurOutGroups); if (wroteSomething == false) { m->mothurOut("Your file contains only the groups you wish to remove."); m->mothurOutEndLine(); } @@ -517,12 +530,23 @@ int RemoveGroupsCommand::readList(){ //if that name is in the .accnos file, add it if (names.count(name) == 0) { newNames += name + ","; } - else { removedCount++; } + else { + //if you are not in the accnos file check if you are a name that needs to be changed + map::iterator it = uniqueToRedundant.find(name); + if (it != uniqueToRedundant.end()) { + newNames += it->second + ","; + }else { removedCount++; } + } } //get last name if (names.count(binnames) == 0) { newNames += binnames + ","; } - else { removedCount++; } + else { //if you are not in the accnos file check if you are a name that needs to be changed + map::iterator it = uniqueToRedundant.find(binnames); + if (it != uniqueToRedundant.end()) { + newNames += it->second + ","; + }else { removedCount++; } + } //if there are names in this bin add to new list if (newNames != "") { @@ -614,6 +638,7 @@ int RemoveGroupsCommand::readName(){ //you know you have at least one valid second since first column is valid for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; } out << validSecond[validSecond.size()-1] << endl; + uniqueToRedundant[firstCol] = validSecond[0]; } } @@ -708,7 +733,12 @@ int RemoveGroupsCommand::readTax(){ if (names.count(name) == 0) { wroteSomething = true; out << name << '\t' << tax << endl; - }else { removedCount++; } + }else { //if you are not in the accnos file check if you are a name that needs to be changed + map::iterator it = uniqueToRedundant.find(name); + if (it != uniqueToRedundant.end()) { + wroteSomething = true; + out << it->second << '\t' << tax << endl; + }else { removedCount++; } } m->gobble(in); } @@ -745,7 +775,7 @@ void RemoveGroupsCommand::readAccnos(){ } in.close(); - m->Groups = Groups; + m->setGroups(Groups); } catch(exception& e) {