X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=parselistscommand.cpp;h=4e61a58d9e5cb4bc640c544797c87a363580575e;hb=159fd324dfecacb6617669246d85c787ae67f630;hp=6e4082e0c139b76435aa073cd1f0c7013b85dca3;hpb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6;p=mothur.git diff --git a/parselistscommand.cpp b/parselistscommand.cpp index 6e4082e..4e61a58 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -37,7 +37,7 @@ string ParseListCommand::getHelpString(){ helpString += "The label parameter is used to read specific labels in your input you want to use.\n"; helpString += "The parse.list command should be used in the following format: parse.list(list=yourListFile, group=yourGroupFile, label=yourLabels).\n"; helpString += "Example: parse.list(list=abrecovery.fn.list, group=abrecovery.groups, label=0.03).\n"; - helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n"; return helpString; } catch(exception& e) { @@ -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 { @@ -66,6 +87,7 @@ ParseListCommand::ParseListCommand(string option) { //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { vector myArray = setParameters(); @@ -122,7 +144,7 @@ ParseListCommand::ParseListCommand(string option) { abort = true; } - } + }else { m->setListFile(listfile); } groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } @@ -136,6 +158,7 @@ ParseListCommand::ParseListCommand(string option) { if (error == 1) { abort = true; } }else { m->mothurOut("No valid current group file. You must provide a group file."); m->mothurOutEndLine(); abort = true; } }else { + m->setGroupFile(groupfile); groupMap = new GroupMap(groupfile); int error = groupMap->readMap(); @@ -173,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); } @@ -192,8 +216,9 @@ 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 (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + vector gGroups = groupMap->getNamesOfGroups(); + for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -201,8 +226,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]]; } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + for (i=0; imothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -239,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++) { remove(outputNames[i].c_str()); } 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 @@ -260,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++) { remove(outputNames[i].c_str()); } 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 @@ -287,7 +312,7 @@ int ParseListCommand::execute(){ delete input; if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; }