X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=consensusseqscommand.cpp;h=f1c766d3a270fea328c76f05d1c8d4c606c9df27;hb=1d898dc6edaf9e9f287fab53bf1f21fb29757a17;hp=513566f0c4fd75990f781e2b4a482332cfe5ac12;hpb=4de64268dd8f64b82f3c4e804cac72ffcb6fd583;p=mothur.git diff --git a/consensusseqscommand.cpp b/consensusseqscommand.cpp index 513566f..f1c766d 100644 --- a/consensusseqscommand.cpp +++ b/consensusseqscommand.cpp @@ -12,68 +12,73 @@ #include "inputdata.h" //********************************************************************************************************************** -vector ConsensusSeqsCommand::getValidParameters(){ +vector ConsensusSeqsCommand::setParameters(){ try { - string Array[] = {"fasta", "list", "name", "label","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plist); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + 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, "ConsensusSeqsCommand", "getValidParameters"); + m->errorOut(e, "ConsensusSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ConsensusSeqsCommand::ConsensusSeqsCommand(){ +string ConsensusSeqsCommand::getHelpString(){ try { - abort = true; - //initialize outputTypes - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["name"] = tempOutNames; - outputTypes["summary"] = tempOutNames; + string helpString = ""; + helpString += "The consensus.seqs command can be used in 2 ways: create a consensus sequence from a fastafile, or with a listfile create a consensus sequence for each otu. Sequences must be aligned.\n"; + helpString += "The consensus.seqs command parameters are fasta, list, name and label.\n"; + helpString += "The fasta parameter allows you to enter the fasta file containing your sequences, and is required, unless you have a valid current fasta file. \n"; + helpString += "The list parameter allows you to enter a your list file. \n"; + helpString += "The name parameter allows you to enter a names file associated with the fasta file. \n"; + helpString += "The label parameter allows you to select what distance levels you would like output files for, and are separated by dashes.\n"; + helpString += "The consensus.seqs command should be in the following format: \n"; + helpString += "consensus.seqs(fasta=yourFastaFile, list=yourListFile) \n"; + helpString += "Example: consensus.seqs(fasta=abrecovery.align, list=abrecovery.fn.list) \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ConsensusSeqsCommand", "ConsensusSeqsCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector ConsensusSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta", "list"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ConsensusSeqsCommand", "getRequiredParameters"); + m->errorOut(e, "ConsensusSeqsCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector ConsensusSeqsCommand::getRequiredFiles(){ +ConsensusSeqsCommand::ConsensusSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["summary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "DegapSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "ConsensusSeqsCommand", "ConsensusSeqsCommand"); exit(1); } } //*************************************************************************************************************** ConsensusSeqsCommand::ConsensusSeqsCommand(string option) { try { - abort = false; + abort = false; calledHelp = false; allLines = 1; //allow user to run help - if(option == "help") { help(); abort = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","list","name","label", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -127,7 +132,11 @@ ConsensusSeqsCommand::ConsensusSeqsCommand(string option) { //check for parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the consensus.seqs command."); m->mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { abort = true; } @@ -154,37 +163,12 @@ ConsensusSeqsCommand::ConsensusSeqsCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ConsensusSeqsCommand::help(){ - try { - m->mothurOut("The consensus.seqs command can be used in 2 ways: create a consensus sequence from a fastafile, or with a listfile create a consensus sequence for each otu. Sequences must be aligned.\n"); - m->mothurOut("The consensus.seqs command parameters are fasta, list, name and label.\n"); - m->mothurOut("The fasta parameter allows you to enter the fasta file containing your sequences, and is required. \n"); - m->mothurOut("The list parameter allows you to enter a your list file. \n"); - m->mothurOut("The name parameter allows you to enter a names file associated with the fasta file. \n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like output files for, and are separated by dashes.\n"); - m->mothurOut("The consensus.seqs command should be in the following format: \n"); - m->mothurOut("consensus.seqs(fasta=yourFastaFile, list=yourListFile) \n"); - m->mothurOut("Example: consensus.seqs(fasta=abrecovery.align, list=abrecovery.fn.list) \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ConsensusSeqsCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -ConsensusSeqsCommand::~ConsensusSeqsCommand(){ /* do nothing */ } - //*************************************************************************************************************** int ConsensusSeqsCommand::execute(){ try{ - if (abort == true) { return 0; } + if (abort == true) { if (calledHelp) { return 0; } return 2; } readFasta();