X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=secondarystructurecommand.cpp;h=869df029fdd35efa6c3e9a9a22d46c6c4fea6667;hb=5b72d1cf3fa48730e5bb70d59cced1e43e1fe424;hp=ece2de0fee12364effae1b23065ef30903c22485;hpb=a0e9a8a746faf084e31624f80e69e3c9af9822ad;p=mothur.git diff --git a/secondarystructurecommand.cpp b/secondarystructurecommand.cpp index ece2de0..869df02 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -11,49 +11,70 @@ #include "sequence.hpp" //********************************************************************************************************************** -vector AlignCheckCommand::getValidParameters(){ +vector AlignCheckCommand::setParameters(){ try { - string Array[] = {"fasta", "name","map", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pmap("map", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pmap); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + 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, "AlignCheckCommand", "getValidParameters"); + m->errorOut(e, "AlignCheckCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -AlignCheckCommand::AlignCheckCommand(){ +string AlignCheckCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["aligncheck"] = tempOutNames; + string helpString = ""; + helpString += "The align.check command reads a fasta file and map file as well as an optional name file.\n"; + helpString += "It outputs a file containing the secondary structure matches in the .align.check file.\n"; + helpString += "The align.check command parameters are fasta and map, both are required.\n"; + helpString += "The align.check command should be in the following format: align.check(fasta=yourFasta, map=yourMap).\n"; + helpString += "Example align.check(map=silva.ss.map, fasta=amazon.fasta).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "AlignCheckCommand"); + m->errorOut(e, "AlignCheckCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector AlignCheckCommand::getRequiredParameters(){ +string AlignCheckCommand::getOutputFileNameTag(string type, string inputName=""){ try { - string Array[] = {"fasta","map"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string outputFileName = ""; + map >::iterator it; + + //is this a type this command creates + it = outputTypes.find(type); + if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } + else { + if (type == "aligncheck") { outputFileName = "align.check"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; } catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "getRequiredParameters"); + m->errorOut(e, "AlignCheckCommand", "getOutputFileNameTag"); exit(1); } } //********************************************************************************************************************** -vector AlignCheckCommand::getRequiredFiles(){ +AlignCheckCommand::AlignCheckCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["aligncheck"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "getRequiredFiles"); + m->errorOut(e, "AlignCheckCommand", "AlignCheckCommand"); exit(1); } } @@ -66,11 +87,10 @@ AlignCheckCommand::AlignCheckCommand(string option) { //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { - //valid paramters for this command - string Array[] = {"fasta","name","map", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -123,44 +143,36 @@ AlignCheckCommand::AlignCheckCommand(string option) { else if (mapfile == "not found") { mapfile = ""; m->mothurOut("You must provide an map file."); m->mothurOutEndLine(); abort = true; } fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; m->mothurOut("You must provide an fasta file."); m->mothurOutEndLine(); abort = true; } + if (fastafile == "not open") { fastafile = ""; 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; } + }else { m->setFastaFile(fastafile); } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { namefile = ""; abort = true; } else if (namefile == "not found") { namefile = ""; } + else { m->setNameFile(namefile); } //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } - + + if ((namefile == "") && (fastafile != "")){ + vector files; files.push_back(fastafile); + parser.getNameFile(files); + } } } catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "RemoveSeqsCommand"); - exit(1); - } -} -//********************************************************************************************************************** - -void AlignCheckCommand::help(){ - try { - m->mothurOut("The align.check command reads a fasta file and map file.\n"); - m->mothurOut("It outputs a file containing the secondary structure matches in the .align.check file.\n"); - m->mothurOut("The align.check command parameters are fasta and map, both are required.\n"); - m->mothurOut("The align.check command should be in the following format: align.check(fasta=yourFasta, map=yourMap).\n"); - m->mothurOut("Example align.check(map=silva.ss.map, fasta=amazon.fasta).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "help"); + m->errorOut(e, "AlignCheckCommand", "AlignCheckCommand"); exit(1); } } - //********************************************************************************************************************** int AlignCheckCommand::execute(){ @@ -179,7 +191,7 @@ int AlignCheckCommand::execute(){ m->openInputFile(fastafile, in); ofstream out; - string outfile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "align.check"; + string outfile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("aligncheck"); m->openOutputFile(outfile, out); @@ -196,7 +208,7 @@ int AlignCheckCommand::execute(){ int count = 0; while(!in.eof()){ - if (m->control_pressed) { in.close(); out.close(); remove(outfile.c_str()); return 0; } + if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outfile); return 0; } Sequence seq(in); m->gobble(in); if (seq.getName() != "") { @@ -209,7 +221,7 @@ int AlignCheckCommand::execute(){ //make sure this sequence is in the namefile, else error map::iterator it = nameMap.find(seq.getName()); - if (it == nameMap.end()) { cout << "[ERROR]: " << seq.getName() << " is not in your namefile, please correct." << endl; m->control_pressed = true; } + if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + seq.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } else { num = it->second; } } @@ -233,7 +245,7 @@ int AlignCheckCommand::execute(){ in.close(); out.close(); - if (m->control_pressed) { remove(outfile.c_str()); return 0; } + if (m->control_pressed) { m->mothurRemove(outfile); return 0; } sort(pound.begin(), pound.end()); sort(dash.begin(), dash.end()); @@ -251,7 +263,7 @@ int AlignCheckCommand::execute(){ int ptile97_5 = int(size * 0.975); int ptile100 = size - 1; - if (m->control_pressed) { remove(outfile.c_str()); return 0; } + if (m->control_pressed) { m->mothurRemove(outfile); return 0; } m->mothurOutEndLine(); m->mothurOut("\t\tPound\tDash\tPlus\tEqual\tLoop\tTilde\tTotal"); m->mothurOutEndLine();