X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=getsabundcommand.cpp;h=3637d2903112154c6af122e1bac68a2a0ab65f1a;hb=d4cd876bd09bfa1bcb137261700eae79f9e41fc0;hp=d9197fe7724b32ca0f6789032a7ea98246bc69a5;hpb=74844a60d80c6dd06e3fb02ee9b928424f9019b0;p=mothur.git diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index d9197fe..3637d29 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -10,7 +10,54 @@ #include "getsabundcommand.h" //********************************************************************************************************************** - +vector GetSAbundCommand::getValidParameters(){ + try { + string Array[] = {"label","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +GetSAbundCommand::GetSAbundCommand(){ + try { + abort = true; + //initialize outputTypes + vector tempOutNames; + outputTypes["sabund"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "GetSAbundCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetSAbundCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector GetSAbundCommand::getRequiredFiles(){ + try { + string Array[] = {"list","rabund"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "GetSAbundCommand", "getRequiredFiles"); + exit(1); + } +} +//********************************************************************************************************************** GetSAbundCommand::GetSAbundCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -36,10 +83,14 @@ GetSAbundCommand::GetSAbundCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["sabund"] = tempOutNames; + //if the user changes the output directory command factory will send this info to us in the output parameter string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it } //make sure the user has already run the read.otu command @@ -50,7 +101,7 @@ GetSAbundCommand::GetSAbundCommand(string option) { label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } @@ -61,8 +112,8 @@ GetSAbundCommand::GetSAbundCommand(string option) { } if (abort == false) { - filename = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "sabund"; - openOutputFile(filename, out); + filename = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "sabund"; + m->openOutputFile(filename, out); } } @@ -115,6 +166,9 @@ int GetSAbundCommand::execute(){ set processedLabels; set userLabels = labels; + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + + while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(order->getLabel()) == 1){ @@ -123,12 +177,14 @@ int GetSAbundCommand::execute(){ *sabund = (order->getSAbundVector()); sabund->print(out); delete sabund; + + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); } - if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = order->getLabel(); delete order; @@ -139,6 +195,8 @@ int GetSAbundCommand::execute(){ *sabund = (order->getSAbundVector()); sabund->print(out); delete sabund; + + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); @@ -177,6 +235,9 @@ int GetSAbundCommand::execute(){ *sabund = (order->getSAbundVector()); sabund->print(out); delete sabund; + + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + delete order; } globaldata->gorder = NULL; @@ -185,7 +246,7 @@ int GetSAbundCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(filename); m->mothurOutEndLine(); + m->mothurOut(filename); m->mothurOutEndLine(); outputNames.push_back(filename); outputTypes["sabund"].push_back(filename); m->mothurOutEndLine(); return 0;