X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mergefilecommand.cpp;h=643cf287bb9aded0847390aeea1091c12e95dd74;hb=1a968f34ae2d2680eaf189a197d1a21b8dfd6c03;hp=098da009eaeacfab076c9ad0f800f626158f4a15;hpb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6;p=mothur.git diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index 098da00..643cf28 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -9,20 +9,63 @@ #include "mergefilecommand.h" +//********************************************************************************************************************** +vector MergeFileCommand::setParameters(){ + try { + 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", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string MergeFileCommand::getHelpString(){ + try { + 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", "getHelpString"); + exit(1); + } +} +//********************************************************************************************************************** +MergeFileCommand::MergeFileCommand(){ + try { + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["merge"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); + exit(1); + } +} //********************************************************************************************************************** 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(); @@ -34,6 +77,10 @@ MergeFileCommand::MergeFileCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } + //initialize outputTypes + vector tempOutNames; + outputTypes["merge"] = 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 = ""; } @@ -67,7 +114,7 @@ MergeFileCommand::MergeFileCommand(string option) { outputFileName = validParameter.validFile(parameters, "output", false); if (outputFileName == "not found") { m->mothurOut("you must enter an output file name"); m->mothurOutEndLine(); abort=true; } - else if (outputDir != "") { outputFileName = outputDir + m->getSimpleName(outputFileName); } + else if (outputDir != "") { outputFileName = outputDir + m->getSimpleName(outputFileName); } } } @@ -76,44 +123,20 @@ 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); + if (abort == true) { if (calledHelp) { return 0; } return 2; } - char c; - for(int i=0;iopenInputFile(fileNames[i], inputFile); - - while(!inputFile.eof()){ - if (m->control_pressed) { 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(); - } + m->mothurRemove(outputFileName); + for(int i=0;iappendFiles(fileNames[i], outputFileName); } - outputFile.close(); - - if (m->control_pressed) { 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(outputFileName); 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(); return 0; @@ -123,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); - } -} - //**********************************************************************************************************************