X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mergefilecommand.cpp;h=d431dd32ff17dcef5e267b1e93a47c8fc93b324b;hb=8bc3e5b38c2317a1715f53be22fa96455868c281;hp=3342c489d9f54a55abda3bac79b60511402eaf4c;hpb=cd37904452dc95b183ff313ff05720c562902487;p=mothur.git diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index 3342c48..d431dd3 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -9,9 +9,56 @@ #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 { + //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; @@ -21,7 +68,7 @@ MergeFileCommand::MergeFileCommand(string option){ } else { //valid paramters for this command - string Array[] = {"input", "output"}; + string Array[] = {"input", "output","outputdir","inputdir"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -34,36 +81,51 @@ 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") { cout << "you must enter two or more file names" << endl; 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 = ""; } + numInputFiles = fileNames.size(); ifstream testFile; if(numInputFiles == 0){ - cout << "you must enter two or more file names and you entered " << fileNames.size() << " file names" << endl; + 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(m->openInputFile(fileNames[i], testFile)){ abort = true; } testFile.close(); } } outputFileName = validParameter.validFile(parameters, "output", false); - if (outputFileName == "not found") { cout << "you must enter an output file name" << endl; abort=true; } + 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) { - cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the MergeFileCommand class function MergeFileCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } //********************************************************************************************************************** @@ -77,45 +139,52 @@ int MergeFileCommand::execute(){ if (abort == true) { return 0; } ofstream outputFile; - openOutputFile(outputFileName, outputFile); + m->openOutputFile(outputFileName, outputFile); - ifstream inputFile; char c; for(int i=0;iopenInputFile(fileNames[i], inputFile); - while(!inputFile.eof()){ c = inputFile.get(); outputFile << c; } + 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(); } + + 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) { - cout << "Standard Error: " << e.what() << " has occurred in the BinSeqCommand class Function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "MergeFileCommand", "execute"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the BinSeqCommand class function BinSeqCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - } //********************************************************************************************************************** void MergeFileCommand::help(){ try { - cout << "The merge.file command..." << endl; + m->mothurOut("The merge.file command..."); m->mothurOutEndLine(); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the MergeFileCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "MergeFileCommand", "help"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the MergeFileCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - } //**********************************************************************************************************************