X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=reversecommand.cpp;h=7a87a99a9720f3f5c8bc04e77bac39d5eabf5ea0;hb=ee1d3ba3f314f05ea50c07c881fa41ce257da77a;hp=9be29152445487dea77a36e62c01812aa617e1ea;hpb=986663e2220f6b043ee83d1699cfa081dc49cbed;p=mothur.git diff --git a/reversecommand.cpp b/reversecommand.cpp index 9be2915..7a87a99 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -13,19 +13,53 @@ //*************************************************************************************************************** -ReverseSeqsCommand::ReverseSeqsCommand(){ +ReverseSeqsCommand::ReverseSeqsCommand(string option){ try { - globaldata = GlobalData::getInstance(); - if(globaldata->getFastaFile() == "") { cout << "you need to at least enter a fasta file name" << endl; } + abort = false; + + //allow user to run help + if(option == "help") { help(); abort = true; } + + else { + //valid paramters for this command + string Array[] = {"fasta"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + OptionParser parser(option); + map parameters = parser.getParameters(); + + ValidParameters validParameter; + + //check to make sure all parameters are valid for command + for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } + } + + //check for required parameters + fasta = validParameter.validFile(parameters, "fasta", true); + if (fasta == "not open") { abort = true; } + else if (fasta == "not found") { fasta = ""; mothurOut("fasta is a required parameter for the reverse.seqs command."); mothurOutEndLine(); abort = true; } + + } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SeqCoordCommand class Function SeqCoordCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "ReverseSeqsCommand", "ReverseSeqsCommand"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SeqCoordCommand class function SeqCoordCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +//********************************************************************************************************************** + +void ReverseSeqsCommand::help(){ + try { + mothurOut("The reverse.seqs command reads a fastafile and ....\n"); + mothurOut("The reverse.seqs command parameter is fasta and it is required.\n"); + mothurOut("The reverse.seqs command should be in the following format: \n"); + mothurOut("reverse.seqs(fasta=yourFastaFile) \n"); + } + catch(exception& e) { + errorOut(e, "ReverseSeqsCommand", "help"); exit(1); - } + } } //*************************************************************************************************************** @@ -38,11 +72,13 @@ ReverseSeqsCommand::~ReverseSeqsCommand(){ /* do nothing */ } int ReverseSeqsCommand::execute(){ try{ + if (abort == true) { return 0; } + ifstream inFASTA; - openInputFile(globaldata->getFastaFile(), inFASTA); + openInputFile(fasta, inFASTA); ofstream outFASTA; - string reverseFile = getRootName(globaldata->getFastaFile()) + "rc" + getExtension(globaldata->getFastaFile()); + string reverseFile = getRootName(fasta) + "rc" + getExtension(fasta); openOutputFile(reverseFile, outFASTA); while(!inFASTA.eof()){ @@ -57,11 +93,7 @@ int ReverseSeqsCommand::execute(){ } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the FilterSeqsCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the FilterSeqsCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + errorOut(e, "ReverseSeqsCommand", "execute"); exit(1); } }