X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getrabundcommand.cpp;h=5f33f3a1fbab70aad5764b20f4e1d8633c8a865b;hb=c7e8c2d15bd7cedcfdf18675cb0ea1a0dcd0e3c0;hp=2f49a3b37181603f88065629ddc73f5194be49d9;hpb=10c8178dc5e3f96ef8e92a986f1eddd13e622173;p=mothur.git diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index 2f49a3b..5f33f3a 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -47,7 +47,26 @@ string GetRAbundCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string GetRAbundCommand::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 == "rabund") { outputFileName = "rabund"; } + 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, "GetRAbundCommand", "getOutputFileNameTag"); + exit(1); + } +} //********************************************************************************************************************** GetRAbundCommand::GetRAbundCommand(){ try { @@ -69,6 +88,7 @@ GetRAbundCommand::GetRAbundCommand(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(); @@ -115,12 +135,12 @@ GetRAbundCommand::GetRAbundCommand(string option) { listfile = validParameter.validFile(parameters, "list", true); if (listfile == "not open") { listfile = ""; abort = true; } else if (listfile == "not found") { listfile = ""; } - else { format = "list"; inputfile = listfile; } + else { format = "list"; inputfile = listfile; m->setListFile(listfile); } sabundfile = validParameter.validFile(parameters, "sabund", true); if (sabundfile == "not open") { sabundfile = ""; abort = true; } else if (sabundfile == "not found") { sabundfile = ""; } - else { format = "sabund"; inputfile = sabundfile; } + else { format = "sabund"; inputfile = sabundfile; m->setSabundFile(sabundfile); } //check for optional parameter and set defaults @@ -172,7 +192,7 @@ int GetRAbundCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "rabund"; + filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("rabund"); m->openOutputFile(filename, out); input = new InputData(inputfile, format); @@ -183,14 +203,14 @@ int GetRAbundCommand::execute(){ set processedLabels; set userLabels = labels; - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete rabund; delete input; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; delete input; return 0; } while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(rabund->getLabel()) == 1){ m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete input; delete rabund; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete input; delete rabund; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } @@ -207,7 +227,7 @@ int GetRAbundCommand::execute(){ m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete input; delete rabund; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete input; delete rabund; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } @@ -245,7 +265,7 @@ int GetRAbundCommand::execute(){ m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete input; delete rabund; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete input; delete rabund; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); }