X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=screenseqscommand.cpp;h=31b6bb7137579796c3a6652b283858bff435731a;hp=ed71559fba582e8d5a696621ab943a4851579704;hb=0470f6d037aacb3563c3f7010708120a4a67d4e6;hpb=bede5752eaeedb5a7e339439b6ba2f6670bca2b9 diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index ed71559..31b6bb7 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -12,10 +12,74 @@ //*************************************************************************************************************** -ScreenSeqsCommand::ScreenSeqsCommand(){ +ScreenSeqsCommand::ScreenSeqsCommand(string option){ try { globaldata = GlobalData::getInstance(); - if(globaldata->getFastaFile() == "") { cout << "you must provide a fasta formatted file" << endl; } + abort = false; + + //allow user to run help + if(option == "help") { help(); abort = true; } + + else { + //valid paramters for this command + string AlignArray[] = {"fasta", "start", "end", "maxambig", "maxhomop", "minlength", "maxlength", "name", "group"}; + vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + + parser = new OptionParser(); + parser->parse(option, parameters); delete parser; + + ValidParameters* validParameter = new ValidParameters(); + + //check to make sure all parameters are valid for command + for (it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter->isValidParameter(it->first, myArray, it->second) != true) { abort = true; } + } + + //check for required parameters + fastafile = validParameter->validFile(parameters, "fasta", true); + if (fastafile == "not found") { cout << "fasta is a required parameter for the screen.seqs command." << endl; abort = true; } + else if (fastafile == "not open") { abort = true; } + else { globaldata->setFastaFile(fastafile); } + + groupfile = validParameter->validFile(parameters, "group", true); + if (groupfile == "not open") { abort = true; } + else if (groupfile == "not found") { groupfile = ""; } + else { + globaldata->setGroupFile(groupfile); + } + + namefile = validParameter->validFile(parameters, "name", true); + if (namefile == "not open") { abort = true; } + else if (namefile == "not found") { namefile = ""; } + else { + globaldata->setNameFile(namefile); + } + + + //check for optional parameter and set defaults + // ...at some point should added some additional type checking... + string temp; + temp = validParameter->validFile(parameters, "start", false); if (temp == "not found") { temp = "-1"; } + convert(temp, startPos); + + temp = validParameter->validFile(parameters, "end", false); if (temp == "not found") { temp = "-1"; } + convert(temp, endPos); + + temp = validParameter->validFile(parameters, "maxambig", false); if (temp == "not found") { temp = "-1"; } + convert(temp, maxAmbig); + + temp = validParameter->validFile(parameters, "maxhomop", false); if (temp == "not found") { temp = "-1"; } + convert(temp, maxHomoP); + + temp = validParameter->validFile(parameters, "minlength", false); if (temp == "not found") { temp = "-1"; } + convert(temp, minLength); + + temp = validParameter->validFile(parameters, "maxlength", false); if (temp == "not found") { temp = "-1"; } + convert(temp, maxLength); + + delete validParameter; + } + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the ScreenSeqsCommand class Function ScreenSeqsCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -26,6 +90,36 @@ ScreenSeqsCommand::ScreenSeqsCommand(){ exit(1); } } +//********************************************************************************************************************** + +void ScreenSeqsCommand::help(){ + try { + cout << "The screen.seqs command reads a fastafile and creates ....." << "\n"; + cout << "The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, and group." << "\n"; + cout << "The fasta parameter is required." << "\n"; + cout << "The start parameter .... The default is -1." << "\n"; + cout << "The end parameter .... The default is -1." << "\n"; + cout << "The maxambig parameter .... The default is -1." << "\n"; + cout << "The maxhomop parameter .... The default is -1." << "\n"; + cout << "The minlength parameter .... The default is -1." << "\n"; + cout << "The maxlength parameter .... The default is -1." << "\n"; + cout << "The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile." << "\n"; + cout << "The screen.seqs command should be in the following format: " << "\n"; + cout << "screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig, " << "\n"; + cout << "maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength) " << "\n"; + cout << "Example screen.seqs(fasta=abrecovery.fasta, name=abrecovery.names, group=abrecovery.groups, start=..., end=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...)." << "\n"; + cout << "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta)." << "\n" << "\n"; + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ScreenSeqsCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ScreenSeqsCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} //*************************************************************************************************************** @@ -35,21 +129,16 @@ ScreenSeqsCommand::~ScreenSeqsCommand(){ /* do nothing */ } int ScreenSeqsCommand::execute(){ try{ - int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength; - convert(globaldata->getStartPos(), startPos); - convert(globaldata->getEndPos(), endPos); - convert(globaldata->getMaxAmbig(), maxAmbig); - convert(globaldata->getMaxHomoPolymer(), maxHomoP); - convert(globaldata->getMinLength(), minLength); - convert(globaldata->getMaxLength(), maxLength); + if (abort == true) { return 0; } + ifstream inFASTA; - openInputFile(globaldata->getFastaFile(), inFASTA); + openInputFile(fastafile, inFASTA); set badSeqNames; - string goodSeqFile = getRootName(globaldata->getFastaFile()) + "good" + getExtension(globaldata->getFastaFile()); - string badSeqFile = getRootName(globaldata->getFastaFile()) + "bad" + getExtension(globaldata->getFastaFile()); + string goodSeqFile = getRootName(fastafile) + "good" + getExtension(fastafile); + string badSeqFile = getRootName(fastafile) + "bad" + getExtension(fastafile); ofstream goodSeqOut; openOutputFile(goodSeqFile, goodSeqOut); ofstream badSeqOut; openOutputFile(badSeqFile, badSeqOut); @@ -73,10 +162,10 @@ int ScreenSeqsCommand::execute(){ } gobble(inFASTA); } - if(globaldata->getNameFile() != ""){ + if(namefile != ""){ screenNameGroupFile(badSeqNames); } - else if(globaldata->getGroupFile() != ""){ + else if(groupfile != ""){ screenGroupFile(badSeqNames); }