X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=makegroupcommand.cpp;h=fd68b8022c610557402d03a1ab970901939c9126;hb=8bc3e5b38c2317a1715f53be22fa96455868c281;hp=8dd1d67b294517437648f314321324ca8f1baf11;hpb=b4d2979ffc1440ffeac9343cc60ceb80fff0e058;p=mothur.git diff --git a/makegroupcommand.cpp b/makegroupcommand.cpp index 8dd1d67..fd68b80 100644 --- a/makegroupcommand.cpp +++ b/makegroupcommand.cpp @@ -10,6 +10,53 @@ #include "makegroupcommand.h" #include "sequence.hpp" +//********************************************************************************************************************** +vector MakeGroupCommand::getValidParameters(){ + try { + string Array[] = {"fasta", "groups","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MakeGroupCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +MakeGroupCommand::MakeGroupCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["group"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "MakeGroupCommand", "MakeGroupCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector MakeGroupCommand::getRequiredParameters(){ + try { + string Array[] = {"fasta","groups"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MakeGroupCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector MakeGroupCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MakeGroupCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** MakeGroupCommand::MakeGroupCommand(string option) { @@ -36,7 +83,11 @@ MakeGroupCommand::MakeGroupCommand(string option) { for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + + //initialize outputTypes + vector tempOutNames; + outputTypes["group"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } @@ -68,6 +119,16 @@ MakeGroupCommand::MakeGroupCommand(string option) { fastaFileNames[i] = tryPath; } } + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(fastaFileNames[i]); + m->mothurOut("Unable to open " + fastaFileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ableToOpen = m->openInputFile(tryPath, in, "noerror"); + fastaFileNames[i] = tryPath; + } + } in.close(); if (ableToOpen == 1) { @@ -140,7 +201,7 @@ int MakeGroupCommand::execute(){ for (int i = 0; i < fastaFileNames.size(); i++) { - if (m->control_pressed) { out.close(); remove(filename.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); return 0; } ifstream in; m->openInputFile(fastaFileNames[i], in); @@ -149,7 +210,7 @@ int MakeGroupCommand::execute(){ Sequence seq(in, "no align"); m->gobble(in); - if (m->control_pressed) { in.close(); out.close(); remove(filename.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); in.close(); out.close(); remove(filename.c_str()); return 0; } if (seq.getName() != "") { out << seq.getName() << '\t' << groupsNames[i] << endl; } } @@ -159,7 +220,7 @@ int MakeGroupCommand::execute(){ out.close(); m->mothurOutEndLine(); - m->mothurOut("Output File Name: " + filename); m->mothurOutEndLine(); + m->mothurOut("Output File Name: " + filename); m->mothurOutEndLine(); outputNames.push_back(filename); outputTypes["group"].push_back(filename); m->mothurOutEndLine(); return 0;