X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mergefilecommand.cpp;h=643cf287bb9aded0847390aeea1091c12e95dd74;hb=3914b0d6480f67df53b1e838f51c4e6155710434;hp=d431dd32ff17dcef5e267b1e93a47c8fc93b324b;hpb=8bc3e5b38c2317a1715f53be22fa96455868c281;p=mothur.git diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index d431dd3..643cf28 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -10,49 +10,47 @@ #include "mergefilecommand.h" //********************************************************************************************************************** -vector MergeFileCommand::getValidParameters(){ +vector MergeFileCommand::setParameters(){ try { - string Array[] = {"input", "output","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pinput("input", "String", "", "", "", "", "","",false,true,true); parameters.push_back(pinput); + CommandParameter poutput("output", "String", "", "", "", "", "","",false,true,true); parameters.push_back(poutput); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -MergeFileCommand::MergeFileCommand(){ - try { - //initialize outputTypes - vector tempOutNames; - outputTypes["merge"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); + m->errorOut(e, "MergeFileCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector MergeFileCommand::getRequiredParameters(){ +string MergeFileCommand::getHelpString(){ try { - string Array[] = {"input","output"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The merge.file command takes a list of files separated by dashes and merges them into one file."; + helpString += "The merge.file command parameters are input and output."; + helpString += "Example merge.file(input=small.fasta-large.fasta, output=all.fasta)."; + helpString += "Note: No spaces between parameter labels (i.e. output), '=' and parameters (i.e.yourOutputFileName).\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "getRequiredParameters"); + m->errorOut(e, "MergeFileCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector MergeFileCommand::getRequiredFiles(){ +MergeFileCommand::MergeFileCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["merge"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "getRequiredFiles"); + m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); exit(1); } } @@ -60,16 +58,14 @@ vector MergeFileCommand::getRequiredFiles(){ MergeFileCommand::MergeFileCommand(string option) { try { - abort = false; + abort = false; calledHelp = false; if(option == "help") { help(); - abort = true; - } + abort = true; calledHelp = true; + }else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { - //valid paramters for this command - string Array[] = {"input", "output","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -127,43 +123,19 @@ MergeFileCommand::MergeFileCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -MergeFileCommand::~MergeFileCommand() { /* do nothing */ } - //********************************************************************************************************************** int MergeFileCommand::execute(){ try { - if (abort == true) { return 0; } - - ofstream outputFile; - m->openOutputFile(outputFileName, outputFile); - - char c; - for(int i=0;iopenInputFile(fileNames[i], inputFile); - - while(!inputFile.eof()){ - if (m->control_pressed) { outputTypes.clear(); inputFile.close(); outputFile.close(); remove(outputFileName.c_str()); return 0; } - - c = inputFile.get(); - //-1 is eof char - if (int(c) != -1) { outputFile << c; } - } - - inputFile.close(); - } + if (abort == true) { if (calledHelp) { return 0; } return 2; } - outputFile.close(); + m->mothurRemove(outputFileName); + for(int i=0;iappendFiles(fileNames[i], outputFileName); } - if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { m->mothurRemove(outputFileName); return 0; } m->mothurOutEndLine(); - m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["merge"].push_back(outputFileName); m->mothurOutEndLine(); @@ -174,17 +146,4 @@ int MergeFileCommand::execute(){ exit(1); } } - -//********************************************************************************************************************** - -void MergeFileCommand::help(){ - try { - m->mothurOut("The merge.file command..."); m->mothurOutEndLine(); - } - catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "help"); - exit(1); - } -} - //**********************************************************************************************************************