X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mergefilecommand.cpp;h=c7e5b65e06b77107251b9f4164f4f722edaaeeb2;hb=3e2465c16d187247ce3befd29811c2d5dfc15ee8;hp=d5973394e5a097e879bf1526689d137266a417c1;hpb=315e38cf393c82be238da5b32574f225a020d25c;p=mothur.git diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index d597339..c7e5b65 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -9,9 +9,57 @@ #include "mergefilecommand.h" +//********************************************************************************************************************** +vector MergeFileCommand::getValidParameters(){ + try { + string Array[] = {"input", "output","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MergeFileCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +MergeFileCommand::MergeFileCommand(){ + try { + abort = true; + //initialize outputTypes + vector tempOutNames; + outputTypes["merge"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); + exit(1); + } +} +//********************************************************************************************************************** +vector MergeFileCommand::getRequiredParameters(){ + try { + string Array[] = {"input","output"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MergeFileCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector MergeFileCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "MergeFileCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** -MergeFileCommand::MergeFileCommand(string option){ +MergeFileCommand::MergeFileCommand(string option) { try { abort = false; @@ -34,13 +82,17 @@ 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 = ""; } string fileList = validParameter.validFile(parameters, "input", false); - if(fileList == "not found") { mothurOut("you must enter two or more file names"); mothurOutEndLine(); abort=true; } - else{ splitAtDash(fileList, fileNames); } + if(fileList == "not found") { m->mothurOut("you must enter two or more file names"); m->mothurOutEndLine(); abort=true; } + else{ m->splitAtDash(fileList, fileNames); } //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 = ""; } @@ -49,30 +101,30 @@ MergeFileCommand::MergeFileCommand(string option){ numInputFiles = fileNames.size(); ifstream testFile; if(numInputFiles == 0){ - mothurOut("you must enter two or more file names and you entered " + toString(fileNames.size()) + " file names"); mothurOutEndLine(); + m->mothurOut("you must enter two or more file names and you entered " + toString(fileNames.size()) + " file names"); m->mothurOutEndLine(); abort=true; } else{ for(int i=0;ihasPath(fileNames[i]); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { fileNames[i] = inputDir + fileNames[i]; } } - if(openInputFile(fileNames[i], testFile)){ abort = true; } + if(m->openInputFile(fileNames[i], testFile)){ abort = true; } testFile.close(); } } outputFileName = validParameter.validFile(parameters, "output", false); - if (outputFileName == "not found") { mothurOut("you must enter an output file name"); mothurOutEndLine(); abort=true; } - else if (outputDir != "") { outputFileName = outputDir + getSimpleName(outputFileName); } + 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); } } } catch(exception& e) { - errorOut(e, "MergeFileCommand", "MergeFileCommand"); + m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); exit(1); } } @@ -88,24 +140,38 @@ int MergeFileCommand::execute(){ if (abort == true) { return 0; } ofstream outputFile; - openOutputFile(outputFileName, 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; } - while(!inputFile.eof()){ c = inputFile.get(); outputFile << c; } + c = inputFile.get(); + //-1 is eof char + if (int(c) != -1) { outputFile << c; } + } inputFile.close(); } outputFile.close(); + + if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0; } + + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["merge"].push_back(outputFileName); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "MergeFileCommand", "execute"); + m->errorOut(e, "MergeFileCommand", "execute"); exit(1); } } @@ -114,10 +180,10 @@ int MergeFileCommand::execute(){ void MergeFileCommand::help(){ try { - mothurOut("The merge.file command..."); mothurOutEndLine(); + m->mothurOut("The merge.file command..."); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "MergeFileCommand", "help"); + m->errorOut(e, "MergeFileCommand", "help"); exit(1); } }