X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=removeotuscommand.cpp;h=54adeb244693bb13e22884248e71deadeb5e2144;hb=5c5c0428f6d548c28a8b903ac80efed4f92d59db;hp=3390c201809f1ddf48ba0db779e50bb34b341933;hpb=19fcbbdba99658f5eca244803280f9ee7f9f6607;p=mothur.git diff --git a/removeotuscommand.cpp b/removeotuscommand.cpp index 3390c20..54adeb2 100644 --- a/removeotuscommand.cpp +++ b/removeotuscommand.cpp @@ -52,7 +52,27 @@ string RemoveOtusCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string RemoveOtusCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string outputFileName = ""; + map >::iterator it; + + //is this a type this command creates + it = outputTypes.find(type); + if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } + else { + if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); } + else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; + } + catch(exception& e) { + m->errorOut(e, "RemoveOtusCommand", "getOutputFileNameTag"); + exit(1); + } +} ///********************************************************************************************************************** RemoveOtusCommand::RemoveOtusCommand(){ try { @@ -182,12 +202,13 @@ int RemoveOtusCommand::execute(){ groupMap->readMap(); //get groups you want to remove - if (accnosfile != "") { readAccnos(); } + if (accnosfile != "") { m->readAccnos(accnosfile, Groups); m->setGroups(Groups); } //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 allGroups = groupMap->getNamesOfGroups(); + util->setGroups(Groups, allGroups); delete util; if (m->control_pressed) { delete groupMap; return 0; } @@ -229,14 +250,14 @@ int RemoveOtusCommand::readListGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick." + label + m->getExtension(listfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + label + "." + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); string GroupOutputDir = outputDir; if (outputDir == "") { GroupOutputDir += m->hasPath(groupfile); } - string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick." + label + m->getExtension(groupfile); + string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + label + "." + getOutputFileNameTag("group", groupfile); ofstream outGroup; m->openOutputFile(outputGroupFileName, outGroup); @@ -406,30 +427,6 @@ int RemoveOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstr } } //********************************************************************************************************************** -void RemoveOtusCommand::readAccnos(){ - try { - Groups.clear(); - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - Groups.push_back(name); - - m->gobble(in); - } - in.close(); - - } - catch(exception& e) { - m->errorOut(e, "RemoveOtusCommand", "readAccnos"); - exit(1); - } -} -//**********************************************************************************************************************