X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=parselistscommand.cpp;h=4e61a58d9e5cb4bc640c544797c87a363580575e;hb=f509429e06e545bde69c97cacc0eb436775bd329;hp=9459294fa49945a00b270c1d98529de0a93c008d;hpb=19fcbbdba99658f5eca244803280f9ee7f9f6607;p=mothur.git diff --git a/parselistscommand.cpp b/parselistscommand.cpp index 9459294..4e61a58 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -45,6 +45,27 @@ string ParseListCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string ParseListCommand::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 == "list") { outputFileName = "list"; } + 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, "ParseListCommand", "getOutputFileNameTag"); + exit(1); + } +} + //********************************************************************************************************************** ParseListCommand::ParseListCommand(){ try { @@ -175,11 +196,12 @@ int ParseListCommand::execute(){ //fill filehandles with neccessary ofstreams int i; ofstream* temp; - for (i=0; inamesOfGroups.size(); i++) { + vector gGroups = groupMap->getNamesOfGroups(); + for (i=0; inamesOfGroups[i]] = temp; + filehandles[gGroups[i]] = temp; - string filename = fileroot + groupMap->namesOfGroups[i] + ".list"; + string filename = fileroot + gGroups[i] + "." + getOutputFileNameTag("list"); outputNames.push_back(filename); outputTypes["list"].push_back(filename); m->openOutputFile(filename, *temp); } @@ -194,7 +216,8 @@ int ParseListCommand::execute(){ if (m->control_pressed) { delete input; delete list; delete groupMap; - for (i=0; inamesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; } + vector gGroups = groupMap->getNamesOfGroups(); + for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -203,7 +226,7 @@ int ParseListCommand::execute(){ if (m->control_pressed) { delete input; delete list; delete groupMap; - for (i=0; inamesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; } + for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -241,10 +264,10 @@ int ParseListCommand::execute(){ } if (m->control_pressed) { - delete input; delete groupMap; - for (i=0; inamesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; } - for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); - return 0; + delete input; delete groupMap; + for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); + return 0; } //output error messages about any remaining user labels @@ -262,10 +285,10 @@ int ParseListCommand::execute(){ } if (m->control_pressed) { - delete input; delete groupMap; - for (i=0; inamesOfGroups.size(); i++) { (*(filehandles[groupMap->namesOfGroups[i]])).close(); delete filehandles[groupMap->namesOfGroups[i]]; } - for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); - return 0; + delete input; delete groupMap; + for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); + return 0; } //run last label if you need to