From: Sarah Westcott Date: Thu, 13 Dec 2012 21:33:31 +0000 (-0500) Subject: fixed bug in phylo.diversity rooting. added filename patterns and create filename... X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=1a5c2356c1b955c6ec024b2baf9f46377ee7c72e fixed bug in phylo.diversity rooting. added filename patterns and create filename methods to all commands. --- diff --git a/aligncommand.cpp b/aligncommand.cpp index efc8ce4..9d4a609 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -20,21 +20,21 @@ //********************************************************************************************************************** vector AlignCommand::setParameters(){ try { - CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); - CommandParameter pcandidate("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pcandidate); - CommandParameter psearch("search", "Multiple", "kmer-blast-suffix", "kmer", "", "", "",false,false); parameters.push_back(psearch); - CommandParameter pksize("ksize", "Number", "", "8", "", "", "",false,false); parameters.push_back(pksize); - CommandParameter pmatch("match", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pmatch); - CommandParameter palign("align", "Multiple", "needleman-gotoh-blast-noalign", "needleman", "", "", "",false,false); parameters.push_back(palign); - CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pmismatch); - CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "",false,false); parameters.push_back(pgapopen); - CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pgapextend); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pflip("flip", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pflip); - CommandParameter psave("save", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psave); - CommandParameter pthreshold("threshold", "Number", "", "0.50", "", "", "",false,false); parameters.push_back(pthreshold); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(ptemplate); + CommandParameter pcandidate("fasta", "InputTypes", "", "", "none", "none", "none","fasta-alignreport-accnos",false,true,true); parameters.push_back(pcandidate); + CommandParameter psearch("search", "Multiple", "kmer-blast-suffix", "kmer", "", "", "","",false,false,true); parameters.push_back(psearch); + CommandParameter pksize("ksize", "Number", "", "8", "", "", "","",false,false); parameters.push_back(pksize); + CommandParameter pmatch("match", "Number", "", "1.0", "", "", "","",false,false); parameters.push_back(pmatch); + CommandParameter palign("align", "Multiple", "needleman-gotoh-blast-noalign", "needleman", "", "", "","",false,false,true); parameters.push_back(palign); + CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pmismatch); + CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "","",false,false); parameters.push_back(pgapopen); + CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pgapextend); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pflip("flip", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pflip); + CommandParameter psave("save", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psave); + CommandParameter pthreshold("threshold", "Number", "", "0.50", "", "", "","",false,false); parameters.push_back(pthreshold); + 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); } @@ -76,28 +76,22 @@ string AlignCommand::getHelpString(){ } } //********************************************************************************************************************** -string AlignCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string tag = ""; - map >::iterator it; +string AlignCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { tag = "align"; } - else if (type == "alignreport") { tag = "align.report"; } - else if (type == "accnos") { tag = "flip.accnos"; } - else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } - } - return tag; - } - catch(exception& e) { - m->errorOut(e, "AlignCommand", "getOutputFileName"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],align"; } //makes file like: amazon.align + else if (type == "alignreport") { pattern = "[filename],align.report"; } + else if (type == "accnos") { pattern = "[filename],flip.accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "AlignCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** AlignCommand::AlignCommand(){ try { @@ -328,9 +322,11 @@ int AlignCommand::execute(){ m->mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); m->mothurOutEndLine(); if (outputDir == "") { outputDir += m->hasPath(candidateFileNames[s]); } - string alignFileName = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])) + getOutputFileNameTag("fasta"); - string reportFileName = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])) + getOutputFileNameTag("alignreport"); - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])) + getOutputFileNameTag("accnos"); + map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])); + string alignFileName = getOutputFileName("fasta", variables); + string reportFileName = getOutputFileName("alignreport", variables); + string accnosFileName = getOutputFileName("accnos", variables); + bool hasAccnos = true; int numFastaSeqs = 0; diff --git a/aligncommand.h b/aligncommand.h index 5432d00..cfded38 100644 --- a/aligncommand.h +++ b/aligncommand.h @@ -34,8 +34,9 @@ public: vector setParameters(); string getCommandName() { return "align.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "DeSantis TZ, Jr., Hugenholtz P, Keller K, Brodie EL, Larsen N, Piceno YM, Phan R, Andersen GL (2006). NAST: a multiple sequence alignment server for comparative analysis of 16S rRNA genes. Nucleic Acids Res 34: W394-9.\nSchloss PD (2009). A high-throughput DNA sequence aligner for microbial ecology studies. PLoS ONE 4: e8230.\nSchloss PD (2010). The effects of alignment quality, distance calculation method, sequence filtering, and region on the analysis of 16S rRNA gene-based studies. PLoS Comput Biol 6: e1000844.\nhttp://www.mothur.org/wiki/Align.seqs http://www.mothur.org/wiki/Align.seqs"; } string getDescription() { return "align sequences"; } diff --git a/amovacommand.cpp b/amovacommand.cpp index f36027f..a78aafc 100644 --- a/amovacommand.cpp +++ b/amovacommand.cpp @@ -16,13 +16,13 @@ //********************************************************************************************************************** vector AmovaCommand::setParameters(){ try { - CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); - CommandParameter psets("sets", "String", "", "", "", "", "",false,false); parameters.push_back(psets); - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(palpha); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","amova",false,true,true); parameters.push_back(pdesign); + CommandParameter psets("sets", "String", "", "", "", "", "","",false,false); parameters.push_back(psets); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","amova",false,true,true); parameters.push_back(pphylip); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "","",false,false); parameters.push_back(palpha); + 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); } @@ -54,24 +54,19 @@ string AmovaCommand::getHelpString(){ } } //********************************************************************************************************************** -string AmovaCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string tag = ""; - map >::iterator it; +string AmovaCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "amova") { tag = "amova"; } - else { m->mothurOut("[ERROR]: No definition for type " + type + " output file.\n"); } - } - return tag; - } - catch(exception& e) { - m->errorOut(e, "AmovaCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "amova") { pattern = "[filename],amova"; } //makes file like: amazon.align + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "AmovaCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** AmovaCommand::AmovaCommand(){ @@ -241,7 +236,9 @@ int AmovaCommand::execute(){ //create a new filename ofstream AMOVAFile; - string AMOVAFileName = outputDir + m->getRootName(m->getSimpleName(phylipFileName)) + getOutputFileNameTag("amova"); + map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(phylipFileName)); + string AMOVAFileName = getOutputFileName("amova", variables); + m->openOutputFile(AMOVAFileName, AMOVAFile); outputNames.push_back(AMOVAFileName); outputTypes["amova"].push_back(AMOVAFileName); diff --git a/amovacommand.h b/amovacommand.h index 17dbae6..98d19dd 100644 --- a/amovacommand.h +++ b/amovacommand.h @@ -23,9 +23,10 @@ public: vector setParameters(); string getCommandName() { return "amova"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); - string getCitation() { return "Anderson MJ (2001). A new method for non-parametric multivariate analysis of variance. Austral Ecol 26: 32-46.\nhttp://www.mothur.org/wiki/Amova"; } + string getOutputPattern(string); + string getCitation() { return "Anderson MJ (2001). A new method for non-parametric multivariate analysis of variance. Austral Ecol 26: 32-46.\nhttp://www.mothur.org/wiki/Amova"; } string getDescription() { return "analysis of molecular variance"; } int execute(); diff --git a/anosimcommand.cpp b/anosimcommand.cpp index bd4e6b0..2a688f5 100644 --- a/anosimcommand.cpp +++ b/anosimcommand.cpp @@ -14,12 +14,12 @@ //********************************************************************************************************************** vector AnosimCommand::setParameters(){ try { - CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(palpha); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","anosim",false,true,true); parameters.push_back(pdesign); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","anosim",false,true,true); parameters.push_back(pphylip); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "","",false,false); parameters.push_back(palpha); + 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); } @@ -50,24 +50,19 @@ string AnosimCommand::getHelpString(){ } } //********************************************************************************************************************** -string AnosimCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string AnosimCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "anosim") { outputFileName = "anosim"; } - 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, "AnosimCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "anosim") { pattern = "[filename],anosim"; } //makes file like: amazon.align + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "AnosimCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** AnosimCommand::AnosimCommand(){ @@ -207,7 +202,9 @@ int AnosimCommand::execute(){ //create a new filename ofstream ANOSIMFile; - string ANOSIMFileName = outputDir + m->getRootName(m->getSimpleName(phylipFileName)) + getOutputFileNameTag("anosim"); + map variables; variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(phylipFileName)); + string ANOSIMFileName = getOutputFileName("anosim", variables); + m->openOutputFile(ANOSIMFileName, ANOSIMFile); outputNames.push_back(ANOSIMFileName); outputTypes["anosim"].push_back(ANOSIMFileName); m->mothurOut("\ncomparison\tR-value\tP-value\n"); diff --git a/anosimcommand.h b/anosimcommand.h index ff1b683..6e5aba0 100644 --- a/anosimcommand.h +++ b/anosimcommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "anosim"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Clarke, K. R. (1993). Non-parametric multivariate analysis of changes in community structure. _Australian Journal of Ecology_ 18, 117-143.\nhttp://www.mothur.org/wiki/Anosim"; } string getDescription() { return "analysis of similarity"; } diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index ad71d10..7798a4d 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -13,14 +13,14 @@ //********************************************************************************************************************** vector BinSeqCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - 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); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(plist); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + 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); } @@ -51,24 +51,19 @@ string BinSeqCommand::getHelpString(){ } } //********************************************************************************************************************** -string BinSeqCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string BinSeqCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "fasta"; } - 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, "BinSeqCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],[distance],fasta"; } //makes file like: amazon.0.03.fasta + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "BinSeqCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** BinSeqCommand::BinSeqCommand(){ @@ -333,6 +328,13 @@ int BinSeqCommand::execute(){ if (groupfile != "") { delete groupMap; } if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } + + //set align file as new current fastafile + string currentFasta = ""; + itTypes = outputTypes.find("fasta"); + if (itTypes != outputTypes.end()) { + if ((itTypes->second).size() != 0) { currentFasta = (itTypes->second)[0]; m->setFastaFile(currentFasta); } + } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -385,7 +387,11 @@ void BinSeqCommand::readNamesFile() { //return 1 if error, 0 otherwise int BinSeqCommand::process(ListVector* list) { try { - string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + list->getLabel() + "." + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[distance]"] = list->getLabel(); + string outputFileName = getOutputFileName("fasta", variables); + m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); diff --git a/binsequencecommand.h b/binsequencecommand.h index 5bdd401..c93041f 100644 --- a/binsequencecommand.h +++ b/binsequencecommand.h @@ -28,8 +28,9 @@ public: vector setParameters(); string getCommandName() { return "bin.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Bin.seqs"; } string getDescription() { return "maps sequences to otus"; } diff --git a/catchallcommand.cpp b/catchallcommand.cpp index 1cfd415..584f798 100644 --- a/catchallcommand.cpp +++ b/catchallcommand.cpp @@ -12,12 +12,12 @@ //********************************************************************************************************************** vector CatchAllCommand::setParameters(){ try { - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); //can choose shared or sabund not both, so put them in the same chooseOnlyOneGroup - CommandParameter pshared("shared", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none",false,false); parameters.push_back(pshared); - CommandParameter psabund("sabund", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none",false,false); parameters.push_back(psabund); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none","analysis-bestanalysis-models-bubble-summary",false,false,true); parameters.push_back(pshared); + CommandParameter psabund("sabund", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none","analysis-bestanalysis-models-bubble-summary",false,false,true); parameters.push_back(psabund); + 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); } @@ -49,25 +49,24 @@ string CatchAllCommand::getHelpString(){ } } //********************************************************************************************************************** -string CatchAllCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string CatchAllCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "csv") { outputFileName = "csv"; } - else if (type == "summary") { outputFileName = "catchall.summary"; } - 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, "CatchAllCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "analysis") { pattern = "[filename],_Analysis.csv"; } + else if (type == "bestanalysis") { pattern = "[filename],_BestModelsAnalysis.csv"; } + else if (type == "models") { pattern = "[filename],_BestModelsAnalysis.csv"; } + else if (type == "bubble") { pattern = "[filename],_BubblePlot.csv"; } + else if (type == "summary") { pattern = "[filename],catchall.summary"; } + else if (type == "sabund") { pattern = "[filename],[distance],csv"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "CatchAllCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** CatchAllCommand::CatchAllCommand(){ @@ -76,7 +75,10 @@ CatchAllCommand::CatchAllCommand(){ setParameters(); //initialize outputTypes vector tempOutNames; - outputTypes["csv"] = tempOutNames; + outputTypes["analysis"] = tempOutNames; + outputTypes["bestanalysis"] = tempOutNames; + outputTypes["models"] = tempOutNames; + outputTypes["bubble"] = tempOutNames; outputTypes["summary"] = tempOutNames; } catch(exception& e) { @@ -111,8 +113,12 @@ CatchAllCommand::CatchAllCommand(string option) { //initialize outputTypes vector tempOutNames; - outputTypes["csv"] = tempOutNames; - outputTypes["summary"] = tempOutNames; + outputTypes["analysis"] = tempOutNames; + outputTypes["bestanalysis"] = tempOutNames; + outputTypes["models"] = tempOutNames; + outputTypes["bubble"] = tempOutNames; + outputTypes["summary"] = 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); @@ -257,7 +263,9 @@ int CatchAllCommand::execute() { set processedLabels; set userLabels = labels; - string summaryfilename = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])); + string summaryfilename = getOutputFileName("summary", variables); summaryfilename = m->getFullPathName(summaryfilename); if (m->debug) { m->mothurOut("[DEBUG]: Input File = " + inputFileNames[p] + ".\n[DEBUG]: inputdata address = " + toString(&input) + ".\n[DEBUG]: sabund address = " + toString(&sabund) + ".\n"); } @@ -285,10 +293,18 @@ int CatchAllCommand::execute() { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1"; #else - if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); } - catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \"" + outputPath + "\" 1"; - //wrap entire string in "" - catchAllCommand = "\"" + catchAllCommand + "\""; + //removes extra '\\' catchall doesnt like that + vector tempNames; + string tempFilename = filename; + m->splitAtDash(tempFilename, tempNames); + tempFilename = tempNames[0]; + tempNames.clear(); + string tempOutputPath = outputPath; + m->splitAtDash(tempOutputPath, tempNames); + tempOutputPath = tempNames[0]; + if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); } + catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \"" + tempOutputPath + "\" 1"; + catchAllCommand = "\"" + catchAllCommand + "\""; #endif if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); } @@ -304,10 +320,11 @@ int CatchAllCommand::execute() { filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra . if (savedOutputDir == "") { filename = m->getSimpleName(filename); } - outputNames.push_back(filename + "_Analysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_Analysis." + getOutputFileNameTag("csv")); - outputNames.push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv")); - outputNames.push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv")); - outputNames.push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); + variables["[filename]"] = filename; + outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables)); + outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables)); + outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables)); + outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables)); if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); } @@ -339,8 +356,17 @@ int CatchAllCommand::execute() { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1"; #else - if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); } - catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \"" + outputPath + "\" 1"; + //removes extra '\\' catchall doesnt like that + vector tempNames; + string tempFilename = filename; + m->splitAtDash(tempFilename, tempNames); + tempFilename = tempNames[0]; + tempNames.clear(); + string tempOutputPath = outputPath; + m->splitAtDash(tempOutputPath, tempNames); + tempOutputPath = tempNames[0]; + if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); } + catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \"" + tempOutputPath + "\" 1"; catchAllCommand = "\"" + catchAllCommand + "\""; #endif @@ -357,10 +383,11 @@ int CatchAllCommand::execute() { filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra . if (savedOutputDir == "") { filename = m->getSimpleName(filename); } - outputNames.push_back(filename + "_Analysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_Analysis." + getOutputFileNameTag("csv")); - outputNames.push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv")); - outputNames.push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv")); - outputNames.push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); + variables["[filename]"] = filename; + outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables)); + outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables)); + outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables)); + outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables)); if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); } @@ -414,9 +441,18 @@ int CatchAllCommand::execute() { #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) catchAllCommand += catchAllCommandExe + filename + " " + outputPath + " 1"; #else - if (outputPath.length() > 0) { outputPath = outputPath.substr(0, outputPath.length()-1); } - catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \"" + outputPath + "\" 1"; - catchAllCommand = "\"" + catchAllCommand + "\""; + //removes extra '\\' catchall doesnt like that + vector tempNames; + string tempFilename = filename; + m->splitAtDash(tempFilename, tempNames); + tempFilename = tempNames[0]; + tempNames.clear(); + string tempOutputPath = outputPath; + m->splitAtDash(tempOutputPath, tempNames); + tempOutputPath = tempNames[0]; + if (tempOutputPath.length() > 0) { tempOutputPath = tempOutputPath.substr(0, tempOutputPath.length()-1); } + catchAllCommand += catchAllCommandExe + "\"" + tempFilename + "\" \"" + tempOutputPath + "\" 1"; + catchAllCommand = "\"" + catchAllCommand + "\""; #endif if (m->debug) { m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); } @@ -431,10 +467,12 @@ int CatchAllCommand::execute() { filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra . if (savedOutputDir == "") { filename = m->getSimpleName(filename); } - outputNames.push_back(filename + "_Analysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_Analysis." + getOutputFileNameTag("csv")); - outputNames.push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis." + getOutputFileNameTag("csv")); - outputNames.push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BestModelsFits." + getOutputFileNameTag("csv")); - outputNames.push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); outputTypes["csv"].push_back(filename + "_BubblePlot." + getOutputFileNameTag("csv")); if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); } + variables["[filename]"] = filename; + outputNames.push_back(getOutputFileName("analysis", variables)); outputTypes["analysis"].push_back(getOutputFileName("analysis", variables)); + outputNames.push_back(getOutputFileName("bestanalysis", variables)); outputTypes["bestanalysis"].push_back(getOutputFileName("bestanalysis", variables)); + outputNames.push_back(getOutputFileName("models", variables)); outputTypes["models"].push_back(getOutputFileName("models", variables)); + outputNames.push_back(getOutputFileName("bubble", variables)); outputTypes["bubble"].push_back(getOutputFileName("bubble", variables)); + if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); } createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out); @@ -478,7 +516,10 @@ int CatchAllCommand::execute() { //********************************************************************************************************************** string CatchAllCommand::process(SAbundVector* sabund, string file1) { try { - string filename = outputDir + m->getRootName(m->getSimpleName(file1)) + sabund->getLabel() + ".csv"; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(file1)); + variables["[distance]"] = sabund->getLabel(); + string filename = getOutputFileName("sabund", variables); filename = m->getFullPathName(filename); ofstream out; @@ -511,7 +552,9 @@ string CatchAllCommand::combineSummmary(vector& outputNames) { try { ofstream out; - string combineFileName = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile)); + string combineFileName = getOutputFileName("summary", variables); //open combined file m->openOutputFile(combineFileName, out); diff --git a/catchallcommand.h b/catchallcommand.h index 44ed3ef..32be8b6 100644 --- a/catchallcommand.h +++ b/catchallcommand.h @@ -31,8 +31,9 @@ public: vector setParameters(); string getCommandName() { return "catchall"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Bunge J, Woodard L, Bohning D, Foster JA, Connolly S, Allen HK (2012). Estimating population diversity with CatchAll. Bioinformatics 28:1045.\nhttp://www.northeastern.edu/catchall/index.html\nhttp://www.mothur.org/wiki/Catchall"; } string getDescription() { return "estimate number of species"; } diff --git a/chimerabellerophoncommand.cpp b/chimerabellerophoncommand.cpp index 8240011..bb119e4 100644 --- a/chimerabellerophoncommand.cpp +++ b/chimerabellerophoncommand.cpp @@ -13,14 +13,14 @@ //********************************************************************************************************************** vector ChimeraBellerophonCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none","none","none",false,true); parameters.push_back(pfasta); - CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pfilter); - CommandParameter pcorrection("correction", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pcorrection); - CommandParameter pwindow("window", "Number", "", "0", "", "", "",false,false); parameters.push_back(pwindow); - CommandParameter pincrement("increment", "Number", "", "25", "", "", "",false,false); parameters.push_back(pincrement); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none","none","none","chimera-accnos",false,true,true); parameters.push_back(pfasta); + CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pfilter); + CommandParameter pcorrection("correction", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pcorrection); + CommandParameter pwindow("window", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pwindow); + CommandParameter pincrement("increment", "Number", "", "25", "", "", "","",false,false); parameters.push_back(pincrement); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + 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); } @@ -57,25 +57,20 @@ string ChimeraBellerophonCommand::getHelpString(){ } } //********************************************************************************************************************** -string ChimeraBellerophonCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ChimeraBellerophonCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "chimera") { outputFileName = "bellerophon.chimeras"; } - else if (type == "accnos") { outputFileName = "bellerophon.accnos"; } - 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, "ChimeraBellerophonCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "chimera") { pattern = "[filename],bellerophon.chimeras"; } + else if (type == "accnos") { pattern = "[filename],bellerophon.accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ChimeraBellerophonCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ChimeraBellerophonCommand::ChimeraBellerophonCommand(){ @@ -242,9 +237,11 @@ int ChimeraBellerophonCommand::execute(){ chimera = new Bellerophon(fastaFileNames[i], filter, correction, window, increment, processors, outputDir); - if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[i]); }//if user entered a file with a path then preserve it - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + getOutputFileNameTag("chimera"); - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + getOutputFileNameTag("accnos"); + if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[i]); }//if user entered a file with a path then preserve it + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])); + string outputFileName = getOutputFileName("chimera", variables); + string accnosFileName = getOutputFileName("accnos", variables); chimera->getChimeras(); diff --git a/chimerabellerophoncommand.h b/chimerabellerophoncommand.h index 015f2b7..23e555d 100644 --- a/chimerabellerophoncommand.h +++ b/chimerabellerophoncommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "chimera.bellerophon"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Huber T, Faulkner G, Hugenholtz P (2004). Bellerophon: a program to detect chimeric sequences in multiple sequence alignments. Bioinformatics 20: 2317-9. \nhttp://www.mothur.org/wiki/Chimera.bellerophon"; } string getDescription() { return "detect chimeric sequences"; } diff --git a/chimeraccodecommand.cpp b/chimeraccodecommand.cpp index 942635e..7adf828 100644 --- a/chimeraccodecommand.cpp +++ b/chimeraccodecommand.cpp @@ -13,16 +13,16 @@ //********************************************************************************************************************** vector ChimeraCcodeCommand::setParameters(){ try { - CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pfilter); - CommandParameter pwindow("window", "Number", "", "0", "", "", "",false,false); parameters.push_back(pwindow); - CommandParameter pnumwanted("numwanted", "Number", "", "20", "", "", "",false,false); parameters.push_back(pnumwanted); - CommandParameter pmask("mask", "String", "", "", "", "", "",false,false); parameters.push_back(pmask); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter psave("save", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psave); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","chimera-mapinfo-accnos",false,true,true); parameters.push_back(pfasta); + CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pfilter); + CommandParameter pwindow("window", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pwindow); + CommandParameter pnumwanted("numwanted", "Number", "", "20", "", "", "","",false,false); parameters.push_back(pnumwanted); + CommandParameter pmask("mask", "String", "", "", "", "", "","",false,false); parameters.push_back(pmask); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter psave("save", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psave); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -64,26 +64,21 @@ string ChimeraCcodeCommand::getHelpString(){ } } //********************************************************************************************************************** -string ChimeraCcodeCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ChimeraCcodeCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "chimera") { outputFileName = "ccode.chimeras"; } - else if (type == "mapinfo") { outputFileName = "mapinfo"; } - else if (type == "accnos") { outputFileName = "ccode.accnos"; } - 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, "ChimeraCcodeCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "chimera") { pattern = "[filename],[tag],ccode.chimeras-[filename],ccode.chimeras"; } + else if (type == "accnos") { pattern = "[filename],[tag],ccode.accnos-[filename],ccode.accnos"; } + else if (type == "mapinfo") { pattern = "[filename],mapinfo"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCcodeCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ChimeraCcodeCommand::ChimeraCcodeCommand(){ @@ -94,6 +89,7 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(){ outputTypes["chimera"] = tempOutNames; outputTypes["mapinfo"] = tempOutNames; outputTypes["accnos"] = tempOutNames; + } catch(exception& e) { m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand"); @@ -128,6 +124,7 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { outputTypes["chimera"] = tempOutNames; outputTypes["mapinfo"] = tempOutNames; outputTypes["accnos"] = 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); @@ -305,18 +302,13 @@ int ChimeraCcodeCommand::execute(){ if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it string outputFileName, accnosFileName; - if (maskfile != "") { - outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + getOutputFileNameTag("chimera"); - accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + getOutputFileNameTag("accnos"); - }else { - outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("chimera"); - accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("accnos"); - - } - - string mapInfo = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("mapinfo"); - - + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])); + string mapInfo = getOutputFileName("mapinfo", variables); + if (maskfile != "") { variables["[tag]"] = maskfile; } + outputFileName = getOutputFileName("chimera", variables); + accnosFileName = getOutputFileName("accnos", variables); + if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear(); return 0; } #ifdef USE_MPI diff --git a/chimeraccodecommand.h b/chimeraccodecommand.h index 408e2fe..52bf07d 100644 --- a/chimeraccodecommand.h +++ b/chimeraccodecommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "chimera.ccode"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Gonzalez JM, Zimmermann J, Saiz-Jimenez C (2005). Evaluating putative chimeric sequences from PCR-amplified products. Bioinformatics 21: 333-7. \nhttp://www.mothur.org/wiki/Chimera.ccode"; } string getDescription() { return "detect chimeric sequences"; } diff --git a/chimeracheckcommand.cpp b/chimeracheckcommand.cpp index 6a4732c..6caa606 100644 --- a/chimeracheckcommand.cpp +++ b/chimeracheckcommand.cpp @@ -13,16 +13,16 @@ //********************************************************************************************************************** vector ChimeraCheckCommand::setParameters(){ try { - CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); - 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 psvg("svg", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psvg); - CommandParameter pincrement("increment", "Number", "", "10", "", "", "",false,false); parameters.push_back(pincrement); - CommandParameter pksize("ksize", "Number", "", "7", "", "", "",false,false); parameters.push_back(pksize); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter psave("save", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psave); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","chimera",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter psvg("svg", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psvg); + CommandParameter pincrement("increment", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pincrement); + CommandParameter pksize("ksize", "Number", "", "7", "", "", "","",false,false); parameters.push_back(pksize); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter psave("save", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psave); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -65,24 +65,19 @@ string ChimeraCheckCommand::getHelpString(){ } } //********************************************************************************************************************** -string ChimeraCheckCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ChimeraCheckCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "chimera") { outputFileName = "chimeracheck.chimeras"; } - 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, "ChimeraCcodeCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "chimera") { pattern = "[filename],chimeracheck.chimeras"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ChimeraCheckCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ChimeraCheckCommand::ChimeraCheckCommand(){ @@ -362,7 +357,9 @@ int ChimeraCheckCommand::execute(){ if (m->control_pressed) { delete chimera; return 0; } if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[i]); }//if user entered a file with a path then preserve it - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + getOutputFileNameTag("chimera"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])); + string outputFileName = getOutputFileName("chimera", variables); outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName); #ifdef USE_MPI diff --git a/chimeracheckcommand.h b/chimeracheckcommand.h index 61129cd..8981a14 100644 --- a/chimeracheckcommand.h +++ b/chimeracheckcommand.h @@ -27,8 +27,9 @@ public: vector setParameters(); string getCommandName() { return "chimera.check"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "CHIMERA_CHECK version 2.7 written by Niels Larsen (http://wdcm.nig.ac.jp/RDP/docs/chimera_doc.html) \nhttp://www.mothur.org/wiki/Chimera.check"; } string getDescription() { return "detect chimeric sequences"; } diff --git a/chimeraperseuscommand.cpp b/chimeraperseuscommand.cpp index 7ae5d69..e1ad14e 100644 --- a/chimeraperseuscommand.cpp +++ b/chimeraperseuscommand.cpp @@ -15,16 +15,16 @@ //********************************************************************************************************************** vector ChimeraPerseusCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "NameCount", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "NameCount", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter pcutoff("cutoff", "Number", "", "0.5", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter palpha("alpha", "Number", "", "-5.54", "", "", "",false,false); parameters.push_back(palpha); - CommandParameter pbeta("beta", "Number", "", "0.33", "", "", "",false,false); parameters.push_back(pbeta); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","chimera-accnos",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "NameCount", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "NameCount", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter pcutoff("cutoff", "Number", "", "0.5", "", "", "","",false,false); parameters.push_back(pcutoff); + CommandParameter palpha("alpha", "Number", "", "-5.54", "", "", "","",false,false); parameters.push_back(palpha); + CommandParameter pbeta("beta", "Number", "", "0.33", "", "", "","",false,false); parameters.push_back(pbeta); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -62,25 +62,20 @@ string ChimeraPerseusCommand::getHelpString(){ } } //********************************************************************************************************************** -string ChimeraPerseusCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ChimeraPerseusCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "chimera") { outputFileName = "perseus.chimeras"; } - else if (type == "accnos") { outputFileName = "perseus.accnos"; } - 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, "ChimeraPerseusCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "chimera") { pattern = "[filename],perseus.chimeras"; } + else if (type == "accnos") { pattern = "[filename],perseus.accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPerseusCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ChimeraPerseusCommand::ChimeraPerseusCommand(){ @@ -486,9 +481,11 @@ int ChimeraPerseusCommand::execute(){ m->mothurOut("Checking sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine(); int start = time(NULL); - if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("chimera"); - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("accnos"); + if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])); + string outputFileName = getOutputFileName("chimera", variables); + string accnosFileName = getOutputFileName("accnos", variables); //string newFasta = m->getRootName(fastaFileNames[s]) + "temp"; @@ -695,6 +692,7 @@ vector ChimeraPerseusCommand::loadSequences(string group){ it = counts.find(thisGroupsSeqs[i].getName()); if (it == counts.end()) { error = true; m->mothurOut("[ERROR]: " + thisGroupsSeqs[i].getName() + " is in your fasta file and not in your count file, please correct."); m->mothurOutEndLine(); } else { + thisGroupsSeqs[i].setAligned(removeNs(thisGroupsSeqs[i].getUnaligned())); sequences.push_back(seqData(thisGroupsSeqs[i].getName(), thisGroupsSeqs[i].getUnaligned(), it->second)); if (thisGroupsSeqs[i].getUnaligned().length() > alignLength) { alignLength = thisGroupsSeqs[i].getUnaligned().length(); } } @@ -712,6 +710,7 @@ vector ChimeraPerseusCommand::loadSequences(string group){ if (it == nameMap.end()) { error = true; m->mothurOut("[ERROR]: " + thisGroupsSeqs[i].getName() + " is in your fasta file and not in your namefile, please correct."); m->mothurOutEndLine(); } else { int num = m->getNumNames(it->second); + thisGroupsSeqs[i].setAligned(removeNs(thisGroupsSeqs[i].getUnaligned())); sequences.push_back(seqData(thisGroupsSeqs[i].getName(), thisGroupsSeqs[i].getUnaligned(), num)); if (thisGroupsSeqs[i].getUnaligned().length() > alignLength) { alignLength = thisGroupsSeqs[i].getUnaligned().length(); } } @@ -753,6 +752,7 @@ vector ChimeraPerseusCommand::readFiles(string inputFile, string name){ it = nameMap.find(temp.getName()); if (it == nameMap.end()) { error = true; m->mothurOut("[ERROR]: " + temp.getName() + " is in your fasta file and not in your namefile, please correct."); m->mothurOutEndLine(); } else { + temp.setAligned(removeNs(temp.getUnaligned())); sequences.push_back(seqData(temp.getName(), temp.getUnaligned(), it->second)); if (temp.getUnaligned().length() > alignLength) { alignLength = temp.getUnaligned().length(); } } @@ -772,6 +772,20 @@ vector ChimeraPerseusCommand::readFiles(string inputFile, string name){ } } //********************************************************************************************************************** +string ChimeraPerseusCommand::removeNs(string seq){ + try { + string newSeq = ""; + for (int i = 0; i < seq.length(); i++) { + if (seq[i] != 'N') { newSeq += seq[i]; } + } + return newSeq; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPerseusCommand", "removeNs"); + exit(1); + } +} +//********************************************************************************************************************** vector ChimeraPerseusCommand::readFiles(string inputFile, CountTable* ct){ try { //read fasta file and create sequenceData structure - checking for file mismatches @@ -786,6 +800,7 @@ vector ChimeraPerseusCommand::readFiles(string inputFile, CountTable* c int count = ct->getNumSeqs(temp.getName()); if (m->control_pressed) { break; } else { + temp.setAligned(removeNs(temp.getUnaligned())); sequences.push_back(seqData(temp.getName(), temp.getUnaligned(), count)); if (temp.getUnaligned().length() > alignLength) { alignLength = temp.getUnaligned().length(); } } diff --git a/chimeraperseuscommand.h b/chimeraperseuscommand.h index e2855d0..fdece95 100644 --- a/chimeraperseuscommand.h +++ b/chimeraperseuscommand.h @@ -30,8 +30,9 @@ public: vector setParameters(); string getCommandName() { return "chimera.perseus"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Quince C, Lanzen A, Davenport RJ, Turnbaugh PJ (2011). Removing noise from pyrosequenced amplicons. BMC Bioinformatics 12:38.\nEdgar,R.C., Haas,B.J., Clemente,J.C., Quince,C. and Knight,R. (2011), UCHIME improves sensitivity and speed of chimera detection. Bioinformatics 27:2194.\nhttp://www.mothur.org/wiki/Chimera.perseus\n"; } string getDescription() { return "detect chimeric sequences"; } @@ -65,6 +66,7 @@ private: int deconvoluteResults(map&, string, string); int driverGroups(string, string, int, int, vector); int createProcessesGroups(string, string, vector, string, string, string); + string removeNs(string); }; /**************************************************************************************************/ @@ -136,11 +138,11 @@ static DWORD WINAPI MyPerseusThreadFunction(LPVOID lpParam){ int totalSeqs = 0; int numChimeras = 0; - for (int i = pDataArray->start; i < pDataArray->end; i++) { + for (int u = pDataArray->start; u < pDataArray->end; u++) { int start = time(NULL); if (pDataArray->m->control_pressed) { if (pDataArray->hasCount) { delete cparser; } { delete parser; } pDataArray->m->mothurRemove(pDataArray->outputFName); pDataArray->m->mothurRemove(pDataArray->accnos); return 0; } - pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("Checking sequences from group " + pDataArray->groups[i] + "..."); pDataArray->m->mothurOutEndLine(); + pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("Checking sequences from group " + pDataArray->groups[u] + "..."); pDataArray->m->mothurOutEndLine(); //vector sequences = loadSequences(parser, groups[i]); - same function below //////////////////////////////////////////////////////////////////////////////////////// @@ -148,8 +150,8 @@ static DWORD WINAPI MyPerseusThreadFunction(LPVOID lpParam){ int alignLength = 0; vector sequences; if (pDataArray->hasCount) { - vector thisGroupsSeqs = cparser->getSeqs(pDataArray->groups[i]); - map counts = cparser->getCountTable(pDataArray->groups[i]); + vector thisGroupsSeqs = cparser->getSeqs(pDataArray->groups[u]); + map counts = cparser->getCountTable(pDataArray->groups[u]); map::iterator it; for (int i = 0; i < thisGroupsSeqs.size(); i++) { @@ -159,13 +161,18 @@ static DWORD WINAPI MyPerseusThreadFunction(LPVOID lpParam){ it = counts.find(thisGroupsSeqs[i].getName()); if (it == counts.end()) { error = true; pDataArray->m->mothurOut("[ERROR]: " + thisGroupsSeqs[i].getName() + " is in your fasta file and not in your count file, please correct."); pDataArray->m->mothurOutEndLine(); } else { + string newSeq = ""; + string tempSeq = thisGroupsSeqs[i].getUnaligned(); + for (int j = 0; j < tempSeq.length(); j++) { if (tempSeq[j] != 'N') { newSeq += tempSeq[j]; } } + thisGroupsSeqs[i].setAligned(newSeq); + sequences.push_back(seqData(thisGroupsSeqs[i].getName(), thisGroupsSeqs[i].getUnaligned(), it->second)); if (thisGroupsSeqs[i].getUnaligned().length() > alignLength) { alignLength = thisGroupsSeqs[i].getUnaligned().length(); } } } }else{ - vector thisGroupsSeqs = parser->getSeqs(pDataArray->groups[i]); - map nameMap = parser->getNameMap(pDataArray->groups[i]); + vector thisGroupsSeqs = parser->getSeqs(pDataArray->groups[u]); + map nameMap = parser->getNameMap(pDataArray->groups[u]); map::iterator it; for (int i = 0; i < thisGroupsSeqs.size(); i++) { @@ -176,6 +183,11 @@ static DWORD WINAPI MyPerseusThreadFunction(LPVOID lpParam){ if (it == nameMap.end()) { error = true; pDataArray->m->mothurOut("[ERROR]: " + thisGroupsSeqs[i].getName() + " is in your fasta file and not in your namefile, please correct."); pDataArray->m->mothurOutEndLine(); } else { int num = pDataArray->m->getNumNames(it->second); + string newSeq = ""; + string tempSeq = thisGroupsSeqs[i].getUnaligned(); + for (int j = 0; j < tempSeq.length(); j++) { if (tempSeq[j] != 'N') { newSeq += tempSeq[j]; } } + thisGroupsSeqs[i].setAligned(newSeq); + sequences.push_back(seqData(thisGroupsSeqs[i].getName(), thisGroupsSeqs[i].getUnaligned(), num)); if (thisGroupsSeqs[i].getUnaligned().length() > alignLength) { alignLength = thisGroupsSeqs[i].getUnaligned().length(); } } @@ -194,8 +206,8 @@ static DWORD WINAPI MyPerseusThreadFunction(LPVOID lpParam){ //int numSeqs = driver((outputFName + groups[i]), sequences, (accnos+groups[i]), numChimeras); - same function below //////////////////////////////////////////////////////////////////////////////////////// - string chimeraFileName = pDataArray->outputFName+pDataArray->groups[i]; - string accnosFileName = pDataArray->accnos+pDataArray->groups[i]; + string chimeraFileName = pDataArray->outputFName+pDataArray->groups[u]; + string accnosFileName = pDataArray->accnos+pDataArray->groups[u]; vector > correctModel(4); //could be an option in the future to input own model matrix for(int j=0;j<4;j++){ correctModel[j].resize(4); } @@ -339,7 +351,7 @@ static DWORD WINAPI MyPerseusThreadFunction(LPVOID lpParam){ //append files pDataArray->m->appendFiles(chimeraFileName, pDataArray->outputFName); pDataArray->m->mothurRemove(chimeraFileName); pDataArray->m->appendFiles(accnosFileName, pDataArray->accnos); pDataArray->m->mothurRemove(accnosFileName); - pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences from group " + pDataArray->groups[i] + "."); pDataArray->m->mothurOutEndLine(); + pDataArray->m->mothurOutEndLine(); pDataArray->m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences from group " + pDataArray->groups[u] + "."); pDataArray->m->mothurOutEndLine(); if (pDataArray->m->control_pressed) { if (pDataArray->hasCount) { delete cparser; } { delete parser; } pDataArray->m->mothurRemove(pDataArray->outputFName); pDataArray->m->mothurRemove(pDataArray->accnos); return 0; } } diff --git a/chimerapintailcommand.cpp b/chimerapintailcommand.cpp index c5c678e..d2b7399 100644 --- a/chimerapintailcommand.cpp +++ b/chimerapintailcommand.cpp @@ -14,18 +14,18 @@ //********************************************************************************************************************** vector ChimeraPintailCommand::setParameters(){ try { - CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pconservation("conservation", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pconservation); - CommandParameter pquantile("quantile", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pquantile); - CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pfilter); - CommandParameter pwindow("window", "Number", "", "0", "", "", "",false,false); parameters.push_back(pwindow); - CommandParameter pincrement("increment", "Number", "", "25", "", "", "",false,false); parameters.push_back(pincrement); - CommandParameter pmask("mask", "String", "", "", "", "", "",false,false); parameters.push_back(pmask); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter psave("save", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psave); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","chimera-accnos",false,true,true); parameters.push_back(pfasta); + CommandParameter pconservation("conservation", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pconservation); + CommandParameter pquantile("quantile", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pquantile); + CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pfilter); + CommandParameter pwindow("window", "Number", "", "0", "", "", "","","",false,false); parameters.push_back(pwindow); + CommandParameter pincrement("increment", "Number", "", "25", "", "", "","",false,false); parameters.push_back(pincrement); + CommandParameter pmask("mask", "String", "", "", "", "", "","",false,false); parameters.push_back(pmask); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter psave("save", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psave); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -69,25 +69,20 @@ string ChimeraPintailCommand::getHelpString(){ } } //********************************************************************************************************************** -string ChimeraPintailCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ChimeraPintailCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "chimera") { outputFileName = "pintail.chimeras"; } - else if (type == "accnos") { outputFileName = "pintail.accnos"; } - 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, "ChimeraPintailCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "chimera") { pattern = "[filename],[tag],pintail.chimeras-[filename],pintail.chimeras"; } + else if (type == "accnos") { pattern = "[filename],[tag],pintail.accnos-[filename],pintail.accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ChimeraPintailCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ChimeraPintailCommand::ChimeraPintailCommand(){ @@ -97,6 +92,7 @@ ChimeraPintailCommand::ChimeraPintailCommand(){ vector tempOutNames; outputTypes["chimera"] = tempOutNames; outputTypes["accnos"] = tempOutNames; + } catch(exception& e) { m->errorOut(e, "ChimeraPintailCommand", "ChimeraPintailCommand"); @@ -130,6 +126,7 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { vector tempOutNames; outputTypes["chimera"] = tempOutNames; outputTypes["accnos"] = tempOutNames; + //if the user changes the input directory command factory will send this info to us in the output parameter inputDir = validParameter.validFile(parameters, "inputdir", false); @@ -417,13 +414,12 @@ int ChimeraPintailCommand::execute(){ if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it string outputFileName, accnosFileName; - if (maskfile != "") { - outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + m->getSimpleName(m->getRootName(maskfile)) + getOutputFileNameTag("chimera"); - accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + m->getSimpleName(m->getRootName(maskfile)) + getOutputFileNameTag("accnos"); - }else { - outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("chimera"); - accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("accnos"); - } + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])); + if (maskfile != "") { variables["[tag]"] = m->getSimpleName(m->getRootName(maskfile)); } + outputFileName = getOutputFileName("chimera", variables); + accnosFileName = getOutputFileName("accnos", variables); + if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; } diff --git a/chimerapintailcommand.h b/chimerapintailcommand.h index 1f30b7d..fa195e7 100644 --- a/chimerapintailcommand.h +++ b/chimerapintailcommand.h @@ -28,8 +28,9 @@ public: vector setParameters(); string getCommandName() { return "chimera.pintail"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Ashelford KE, Chuzhanova NA, Fry JC, Jones AJ, Weightman AJ (2005). At least 1 in 20 16S rRNA sequence records currently held in public repositories is estimated to contain substantial anomalies. Appl Environ Microbiol 71: 7724-36. \nAshelford KE, Chuzhanova NA, Fry JC, Jones AJ, Weightman AJ (2006). New screening software shows that most recent large 16S rRNA gene clone libraries contain chimeras. Appl Environ Microbiol 72: 5734-41. \nhttp://www.mothur.org/wiki/Chimera.pintail"; } string getDescription() { return "detect chimeric sequences"; } diff --git a/chimeraslayercommand.cpp b/chimeraslayercommand.cpp index bd9bdbf..a29fc82 100644 --- a/chimeraslayercommand.cpp +++ b/chimeraslayercommand.cpp @@ -16,33 +16,33 @@ //********************************************************************************************************************** vector ChimeraSlayerCommand::setParameters(){ try { - CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pwindow("window", "Number", "", "50", "", "", "",false,false); parameters.push_back(pwindow); - CommandParameter pksize("ksize", "Number", "", "7", "", "", "",false,false); parameters.push_back(pksize); - CommandParameter pmatch("match", "Number", "", "5.0", "", "", "",false,false); parameters.push_back(pmatch); - CommandParameter pmismatch("mismatch", "Number", "", "-4.0", "", "", "",false,false); parameters.push_back(pmismatch); - CommandParameter pminsim("minsim", "Number", "", "90", "", "", "",false,false); parameters.push_back(pminsim); - CommandParameter pmincov("mincov", "Number", "", "70", "", "", "",false,false); parameters.push_back(pmincov); - CommandParameter pminsnp("minsnp", "Number", "", "10", "", "", "",false,false); parameters.push_back(pminsnp); - CommandParameter pminbs("minbs", "Number", "", "90", "", "", "",false,false); parameters.push_back(pminbs); - CommandParameter psearch("search", "Multiple", "kmer-blast", "blast", "", "", "",false,false); parameters.push_back(psearch); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter prealign("realign", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(prealign); - CommandParameter ptrim("trim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptrim); - CommandParameter psplit("split", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psplit); - CommandParameter pnumwanted("numwanted", "Number", "", "15", "", "", "",false,false); parameters.push_back(pnumwanted); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pdivergence("divergence", "Number", "", "1.007", "", "", "",false,false); parameters.push_back(pdivergence); - CommandParameter pparents("parents", "Number", "", "3", "", "", "",false,false); parameters.push_back(pparents); - CommandParameter pincrement("increment", "Number", "", "5", "", "", "",false,false); parameters.push_back(pincrement); - CommandParameter pblastlocation("blastlocation", "String", "", "", "", "", "",false,false); parameters.push_back(pblastlocation); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter psave("save", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psave); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","chimera-accnos",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pwindow("window", "Number", "", "50", "", "", "","",false,false); parameters.push_back(pwindow); + CommandParameter pksize("ksize", "Number", "", "7", "", "", "","",false,false); parameters.push_back(pksize); + CommandParameter pmatch("match", "Number", "", "5.0", "", "", "","",false,false); parameters.push_back(pmatch); + CommandParameter pmismatch("mismatch", "Number", "", "-4.0", "", "", "","",false,false); parameters.push_back(pmismatch); + CommandParameter pminsim("minsim", "Number", "", "90", "", "", "","",false,false); parameters.push_back(pminsim); + CommandParameter pmincov("mincov", "Number", "", "70", "", "", "","",false,false); parameters.push_back(pmincov); + CommandParameter pminsnp("minsnp", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pminsnp); + CommandParameter pminbs("minbs", "Number", "", "90", "", "", "","",false,false); parameters.push_back(pminbs); + CommandParameter psearch("search", "Multiple", "kmer-blast", "blast", "", "", "","",false,false); parameters.push_back(psearch); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter prealign("realign", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(prealign); + CommandParameter ptrim("trim", "Boolean", "", "F", "", "", "","fasta",false,false); parameters.push_back(ptrim); + CommandParameter psplit("split", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psplit); + CommandParameter pnumwanted("numwanted", "Number", "", "15", "", "", "","",false,false); parameters.push_back(pnumwanted); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pdivergence("divergence", "Number", "", "1.007", "", "", "","",false,false); parameters.push_back(pdivergence); + CommandParameter pparents("parents", "Number", "", "3", "", "", "","",false,false); parameters.push_back(pparents); + CommandParameter pincrement("increment", "Number", "", "5", "", "", "","",false,false); parameters.push_back(pincrement); + CommandParameter pblastlocation("blastlocation", "String", "", "", "", "", "","",false,false); parameters.push_back(pblastlocation); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter psave("save", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psave); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -101,26 +101,21 @@ string ChimeraSlayerCommand::getHelpString(){ } } //********************************************************************************************************************** -string ChimeraSlayerCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ChimeraSlayerCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "chimera") { outputFileName = "slayer.chimeras"; } - else if (type == "accnos") { outputFileName = "slayer.accnos"; } - else if (type == "fasta") { outputFileName = "slayer.fasta"; } - 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, "ChimeraSlayerCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "chimera") { pattern = "[filename],slayer.chimeras"; } + else if (type == "accnos") { pattern = "[filename],slayer.accnos"; } + else if (type == "fasta") { pattern = "[filename],slayer.fasta"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ChimeraSlayerCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ChimeraSlayerCommand::ChimeraSlayerCommand(){ @@ -666,10 +661,12 @@ int ChimeraSlayerCommand::execute(){ m->mothurOut("Checking sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine(); int start = time(NULL); - if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("chimera"); - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("accnos"); - string trimFastaFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("fasta"); + if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])); + string outputFileName = getOutputFileName("chimera", variables); + string accnosFileName = getOutputFileName("accnos", variables); + string trimFastaFileName = getOutputFileName("fasta", variables); //clears files ofstream out, out1, out2; diff --git a/chimeraslayercommand.h b/chimeraslayercommand.h index 4d53c5c..6149ef5 100644 --- a/chimeraslayercommand.h +++ b/chimeraslayercommand.h @@ -28,8 +28,9 @@ public: vector setParameters(); string getCommandName() { return "chimera.slayer"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Haas BJ, Gevers D, Earl A, Feldgarden M, Ward DV, Giannokous G, Ciulla D, Tabbaa D, Highlander SK, Sodergren E, Methe B, Desantis TZ, Petrosino JF, Knight R, Birren BW (2011). Chimeric 16S rRNA sequence formation and detection in Sanger and 454-pyrosequenced PCR amplicons. Genome Res 21:494.\nhttp://www.mothur.org/wiki/Chimera.slayer"; } string getDescription() { return "detect chimeric sequences"; } diff --git a/chimerauchimecommand.cpp b/chimerauchimecommand.cpp index 6f7ba10..04e1f1d 100644 --- a/chimerauchimecommand.cpp +++ b/chimerauchimecommand.cpp @@ -17,34 +17,34 @@ //********************************************************************************************************************** vector ChimeraUchimeCommand::setParameters(){ try { - CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter pabskew("abskew", "Number", "", "1.9", "", "", "",false,false); parameters.push_back(pabskew); - CommandParameter pchimealns("chimealns", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pchimealns); - CommandParameter pminh("minh", "Number", "", "0.3", "", "", "",false,false); parameters.push_back(pminh); - CommandParameter pmindiv("mindiv", "Number", "", "0.5", "", "", "",false,false); parameters.push_back(pmindiv); - CommandParameter pxn("xn", "Number", "", "8.0", "", "", "",false,false); parameters.push_back(pxn); - CommandParameter pdn("dn", "Number", "", "1.4", "", "", "",false,false); parameters.push_back(pdn); - CommandParameter pxa("xa", "Number", "", "1", "", "", "",false,false); parameters.push_back(pxa); - CommandParameter pchunks("chunks", "Number", "", "4", "", "", "",false,false); parameters.push_back(pchunks); - CommandParameter pminchunk("minchunk", "Number", "", "64", "", "", "",false,false); parameters.push_back(pminchunk); - CommandParameter pidsmoothwindow("idsmoothwindow", "Number", "", "32", "", "", "",false,false); parameters.push_back(pidsmoothwindow); - CommandParameter pdups("dereplicate", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pdups); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","chimera-accnos",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter pabskew("abskew", "Number", "", "1.9", "", "", "","",false,false); parameters.push_back(pabskew); + CommandParameter pchimealns("chimealns", "Boolean", "", "F", "", "", "","alns",false,false); parameters.push_back(pchimealns); + CommandParameter pminh("minh", "Number", "", "0.3", "", "", "","",false,false); parameters.push_back(pminh); + CommandParameter pmindiv("mindiv", "Number", "", "0.5", "", "", "","",false,false); parameters.push_back(pmindiv); + CommandParameter pxn("xn", "Number", "", "8.0", "", "", "","",false,false); parameters.push_back(pxn); + CommandParameter pdn("dn", "Number", "", "1.4", "", "", "","",false,false); parameters.push_back(pdn); + CommandParameter pxa("xa", "Number", "", "1", "", "", "","",false,false); parameters.push_back(pxa); + CommandParameter pchunks("chunks", "Number", "", "4", "", "", "","",false,false); parameters.push_back(pchunks); + CommandParameter pminchunk("minchunk", "Number", "", "64", "", "", "","",false,false); parameters.push_back(pminchunk); + CommandParameter pidsmoothwindow("idsmoothwindow", "Number", "", "32", "", "", "","",false,false); parameters.push_back(pidsmoothwindow); + CommandParameter pdups("dereplicate", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pdups); //CommandParameter pminsmoothid("minsmoothid", "Number", "", "0.95", "", "", "",false,false); parameters.push_back(pminsmoothid); - CommandParameter pmaxp("maxp", "Number", "", "2", "", "", "",false,false); parameters.push_back(pmaxp); - CommandParameter pskipgaps("skipgaps", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pskipgaps); - CommandParameter pskipgaps2("skipgaps2", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pskipgaps2); - CommandParameter pminlen("minlen", "Number", "", "10", "", "", "",false,false); parameters.push_back(pminlen); - CommandParameter pmaxlen("maxlen", "Number", "", "10000", "", "", "",false,false); parameters.push_back(pmaxlen); - CommandParameter pucl("ucl", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pucl); - CommandParameter pqueryfract("queryfract", "Number", "", "0.5", "", "", "",false,false); parameters.push_back(pqueryfract); + CommandParameter pmaxp("maxp", "Number", "", "2", "", "", "","",false,false); parameters.push_back(pmaxp); + CommandParameter pskipgaps("skipgaps", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pskipgaps); + CommandParameter pskipgaps2("skipgaps2", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pskipgaps2); + CommandParameter pminlen("minlen", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pminlen); + CommandParameter pmaxlen("maxlen", "Number", "", "10000", "", "", "","",false,false); parameters.push_back(pmaxlen); + CommandParameter pucl("ucl", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pucl); + CommandParameter pqueryfract("queryfract", "Number", "", "0.5", "", "", "","",false,false); parameters.push_back(pqueryfract); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -103,26 +103,21 @@ string ChimeraUchimeCommand::getHelpString(){ } } //********************************************************************************************************************** -string ChimeraUchimeCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ChimeraUchimeCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "chimera") { outputFileName = "uchime.chimeras"; } - else if (type == "accnos") { outputFileName = "uchime.accnos"; } - else if (type == "alns") { outputFileName = "uchime.alns"; } - 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, "ChimeraUchimeCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "chimera") { pattern = "[filename],uchime.chimeras"; } + else if (type == "accnos") { pattern = "[filename],uchime.accnos"; } + else if (type == "alns") { pattern = "[filename],uchime.alns"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ChimeraUchimeCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ChimeraUchimeCommand::ChimeraUchimeCommand(){ @@ -642,9 +637,11 @@ int ChimeraUchimeCommand::execute(){ int start = time(NULL); string nameFile = ""; if (outputDir == "") { outputDir = m->hasPath(fastaFileNames[s]); }//if user entered a file with a path then preserve it - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("chimera"); - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("accnos"); - string alnsFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("alns"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])); + string outputFileName = getOutputFileName("chimera", variables); + string accnosFileName = getOutputFileName("accnos", variables); + string alnsFileName = getOutputFileName("alns", variables); string newFasta = m->getRootName(fastaFileNames[s]) + "temp"; //you provided a groupfile diff --git a/chimerauchimecommand.h b/chimerauchimecommand.h index f0c30d0..735c97d 100644 --- a/chimerauchimecommand.h +++ b/chimerauchimecommand.h @@ -28,8 +28,9 @@ public: vector setParameters(); string getCommandName() { return "chimera.uchime"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "uchime by Robert C. Edgar\nhttp://drive5.com/uchime\nThis code was donated to the public domain.\nEdgar,R.C., Haas,B.J., Clemente,J.C., Quince,C. and Knight,R. (2011), UCHIME improves sensitivity and speed of chimera detection. Bioinformatics 27:2194.\nhttp://www.mothur.org/wiki/Chimera.uchime\n"; } string getDescription() { return "detect chimeric sequences"; } diff --git a/chopseqscommand.cpp b/chopseqscommand.cpp index 1761efc..0cce69f 100644 --- a/chopseqscommand.cpp +++ b/chopseqscommand.cpp @@ -13,14 +13,14 @@ //********************************************************************************************************************** vector ChopSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pnumbases("numbases", "Number", "", "0", "", "", "",false,true); parameters.push_back(pnumbases); - CommandParameter pcountgaps("countgaps", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pcountgaps); - CommandParameter pshort("short", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pshort); - CommandParameter pkeep("keep", "Multiple", "front-back", "front", "", "", "",false,false); parameters.push_back(pkeep); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pnumbases("numbases", "Number", "", "0", "", "", "","",false,true,true); parameters.push_back(pnumbases); + CommandParameter pcountgaps("countgaps", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pcountgaps); + CommandParameter pshort("short", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pshort); + CommandParameter pkeep("keep", "Multiple", "front-back", "front", "", "", "","",false,false); parameters.push_back(pkeep); + 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); } @@ -54,25 +54,20 @@ string ChopSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string ChopSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ChopSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "chop.fasta"; } - else if (type == "accnos") { outputFileName = "chop.accnos"; } - 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, "ChopSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],chop.fasta"; } + else if (type == "accnos") { pattern = "[filename],chop.accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ChopSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ChopSeqsCommand::ChopSeqsCommand(){ @@ -173,9 +168,10 @@ int ChopSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta"); - string outputFileNameAccnos = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("accnos"); - + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string outputFileName = getOutputFileName("fasta", variables); + string outputFileNameAccnos = getOutputFileName("accnos", variables); vector positions; vector lines; diff --git a/chopseqscommand.h b/chopseqscommand.h index fa3f559..cd2b2fe 100644 --- a/chopseqscommand.h +++ b/chopseqscommand.h @@ -25,8 +25,9 @@ class ChopSeqsCommand : public Command { vector setParameters(); string getCommandName() { return "chop.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Chops.seqs"; } string getDescription() { return "trim sequence length"; } diff --git a/classifyotucommand.cpp b/classifyotucommand.cpp index 0ada1c8..47b1841 100644 --- a/classifyotucommand.cpp +++ b/classifyotucommand.cpp @@ -15,19 +15,19 @@ //********************************************************************************************************************** vector ClassifyOtuCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptaxonomy); - CommandParameter preftaxonomy("reftaxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(preftaxonomy); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter ppersample("persample", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ppersample); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pbasis("basis", "Multiple", "otu-sequence", "otu", "", "", "",false,false); parameters.push_back(pbasis); - CommandParameter pcutoff("cutoff", "Number", "", "51", "", "", "",false,true); parameters.push_back(pcutoff); - CommandParameter pprobs("probs", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pprobs); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","constaxonomy",false,true,true); parameters.push_back(ptaxonomy); + CommandParameter preftaxonomy("reftaxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(preftaxonomy); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter ppersample("persample", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(ppersample); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pbasis("basis", "Multiple", "otu-sequence", "otu", "", "", "","",false,false); parameters.push_back(pbasis); + CommandParameter pcutoff("cutoff", "Number", "", "51", "", "", "","",false,true); parameters.push_back(pcutoff); + CommandParameter pprobs("probs", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pprobs); + 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); } @@ -67,25 +67,20 @@ string ClassifyOtuCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClassifyOtuCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ClassifyOtuCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "constaxonomy") { outputFileName = "cons.taxonomy"; } - else if (type == "taxsummary") { outputFileName = "cons.tax.summary"; } - 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, "ClassifyOtuCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "constaxonomy") { pattern = "[filename],[distance],cons.taxonomy"; } + else if (type == "taxsummary") { pattern = "[filename],[distance],cons.tax.summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClassifyOtuCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ClassifyOtuCommand::ClassifyOtuCommand(){ @@ -532,12 +527,15 @@ int ClassifyOtuCommand::process(ListVector* processList) { if (outputDir == "") { outputDir += m->hasPath(listfile); } ofstream out; - string outputFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." +getOutputFileNameTag("constaxonomy"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[distance]"] = processList->getLabel(); + string outputFile = getOutputFileName("constaxonomy", variables); m->openOutputFile(outputFile, out); outputNames.push_back(outputFile); outputTypes["constaxonomy"].push_back(outputFile); ofstream outSum; - string outputSumFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." +getOutputFileNameTag("taxsummary"); + string outputSumFile = getOutputFileName("taxsummary", variables); m->openOutputFile(outputSumFile, outSum); outputNames.push_back(outputSumFile); outputTypes["taxsummary"].push_back(outputSumFile); @@ -560,14 +558,15 @@ int ClassifyOtuCommand::process(ListVector* processList) { for (int i = 0; i < groups.size(); i++) { groupIndex[groups[i]] = i; ofstream* temp = new ofstream(); - string outputFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." + groups[i] + "." +getOutputFileNameTag("constaxonomy"); + variables["[distance]"] = processList->getLabel() + "." + groups[i]; + string outputFile = getOutputFileName("constaxonomy", variables); m->openOutputFile(outputFile, *temp); (*temp) << "OTU\tSize\tTaxonomy" << endl; outs.push_back(temp); outputNames.push_back(outputFile); outputTypes["constaxonomy"].push_back(outputFile); ofstream* tempSum = new ofstream(); - string outputSumFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." + groups[i] + "." +getOutputFileNameTag("taxsummary"); + string outputSumFile = getOutputFileName("taxsummary", variables); m->openOutputFile(outputSumFile, *tempSum); outSums.push_back(tempSum); outputNames.push_back(outputSumFile); outputTypes["taxsummary"].push_back(outputSumFile); diff --git a/classifyotucommand.h b/classifyotucommand.h index c08a29b..c0a8220 100644 --- a/classifyotucommand.h +++ b/classifyotucommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "classify.otu"; } string getCommandCategory() { return "Phylotype Analysis"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Westcott SL (2011). Assessing and improving methods used in OTU-based approaches for 16S rRNA gene sequence analysis. Appl Environ Microbiol 77:3219.\nhttp://www.mothur.org/wiki/Classify.otu"; } string getDescription() { return "find the concensus taxonomy for each OTU"; } diff --git a/classifyseqscommand.cpp b/classifyseqscommand.cpp index 0012cd2..89668d9 100644 --- a/classifyseqscommand.cpp +++ b/classifyseqscommand.cpp @@ -14,30 +14,29 @@ //********************************************************************************************************************** vector ClassifySeqsCommand::setParameters(){ try { - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptaxonomy); - CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(ptaxonomy); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","taxonomy",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); - CommandParameter psearch("search", "Multiple", "kmer-blast-suffix-distance-align", "kmer", "", "", "",false,false); parameters.push_back(psearch); - CommandParameter pksize("ksize", "Number", "", "8", "", "", "",false,false); parameters.push_back(pksize); - CommandParameter pmethod("method", "Multiple", "wang-knn-zap", "wang", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pmatch("match", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pmatch); - CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pmismatch); - CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "",false,false); parameters.push_back(pgapopen); - CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pgapextend); - //CommandParameter pflip("flip", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pflip); - CommandParameter pcutoff("cutoff", "Number", "", "0", "", "", "",false,true); parameters.push_back(pcutoff); - CommandParameter pprobs("probs", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pprobs); - CommandParameter piters("iters", "Number", "", "100", "", "", "",false,true); parameters.push_back(piters); - CommandParameter psave("save", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psave); - CommandParameter pshortcuts("shortcuts", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pshortcuts); - CommandParameter pnumwanted("numwanted", "Number", "", "10", "", "", "",false,true); parameters.push_back(pnumwanted); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter psearch("search", "Multiple", "kmer-blast-suffix-distance-align", "kmer", "", "", "","",false,false); parameters.push_back(psearch); + CommandParameter pksize("ksize", "Number", "", "8", "", "", "","",false,false); parameters.push_back(pksize); + CommandParameter pmethod("method", "Multiple", "wang-knn-zap", "wang", "", "", "","",false,false); parameters.push_back(pmethod); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pmatch("match", "Number", "", "1.0", "", "", "","",false,false); parameters.push_back(pmatch); + CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pmismatch); + CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "","",false,false); parameters.push_back(pgapopen); + CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pgapextend); + CommandParameter pcutoff("cutoff", "Number", "", "0", "", "", "","",false,true); parameters.push_back(pcutoff); + CommandParameter pprobs("probs", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pprobs); + CommandParameter piters("iters", "Number", "", "100", "", "", "","",false,true); parameters.push_back(piters); + CommandParameter psave("save", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psave); + CommandParameter pshortcuts("shortcuts", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pshortcuts); + CommandParameter pnumwanted("numwanted", "Number", "", "10", "", "", "","",false,true); parameters.push_back(pnumwanted); + 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); } @@ -89,27 +88,22 @@ string ClassifySeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClassifySeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ClassifySeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "taxonomy") { outputFileName = "taxonomy"; } - else if (type == "accnos") { outputFileName = "flip.accnos"; } - else if (type == "taxsummary") { outputFileName = "tax.summary"; } - else if (type == "matchdist") { outputFileName = "match.dist"; } - 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, "ClassifySeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "taxonomy") { pattern = "[filename],[tag],[tag2],taxonomy"; } + else if (type == "taxsummary") { pattern = "[filename],[tag],[tag2],tax.summary"; } + else if (type == "accnos") { pattern = "[filename],[tag],[tag2],flip.accnos"; } + else if (type == "matchdist") { pattern = "[filename],[tag],[tag2],match.dist"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClassifySeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ClassifySeqsCommand::ClassifySeqsCommand(){ @@ -181,23 +175,7 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["taxonomy"] = inputDir + it->second; } } - - it = parameters.find("group"); - //user has given a template file - if(it != parameters.end()){ - path = m->hasPath(it->second); - //if the user has not given a path then, add inputdir. else leave path alone. - if (path == "") { parameters["group"] = inputDir + it->second; } - } - - it = parameters.find("count"); - //user has given a template file - if(it != parameters.end()){ - path = m->hasPath(it->second); - //if the user has not given a path then, add inputdir. else leave path alone. - if (path == "") { parameters["count"] = inputDir + it->second; } - } - } + } fastaFileName = validParameter.validFile(parameters, "fasta", false); if (fastaFileName == "not found") { @@ -436,49 +414,68 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { //go through files and make sure they are good, if not, then disregard them for (int i = 0; i < groupfileNames.size(); i++) { - if (inputDir != "") { - string path = m->hasPath(groupfileNames[i]); - //if the user has not given a path then, add inputdir. else leave path alone. - if (path == "") { groupfileNames[i] = inputDir + groupfileNames[i]; } - } - int ableToOpen; - ifstream in; - ableToOpen = m->openInputFile(groupfileNames[i], in, "noerror"); - - //if you can't open it, try default location - if (ableToOpen == 1) { - if (m->getDefaultPath() != "") { //default path is set - string tryPath = m->getDefaultPath() + m->getSimpleName(groupfileNames[i]); - m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); - ifstream in2; - ableToOpen = m->openInputFile(tryPath, in2, "noerror"); - in2.close(); - groupfileNames[i] = tryPath; + bool ignore = false; + if (groupfileNames[i] == "current") { + groupfileNames[i] = m->getGroupFile(); + if (groupfileNames[i] != "") { m->mothurOut("Using " + groupfileNames[i] + " as input file for the group parameter where you had given current."); m->mothurOutEndLine(); } + else { + m->mothurOut("You have no current group file, ignoring current."); m->mothurOutEndLine(); ignore=true; + //erase from file list + groupfileNames.erase(groupfileNames.begin()+i); + i--; } } - if (ableToOpen == 1) { - if (m->getOutputDir() != "") { //default path is set - string tryPath = m->getOutputDir() + m->getSimpleName(groupfileNames[i]); - m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); - ifstream in2; - ableToOpen = m->openInputFile(tryPath, in2, "noerror"); - in2.close(); - groupfileNames[i] = tryPath; + if (!ignore) { + + if (inputDir != "") { + string path = m->hasPath(groupfileNames[i]); + cout << path << '\t' << inputDir << endl; + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { groupfileNames[i] = inputDir + groupfileNames[i]; } + } + + int ableToOpen; + + ifstream in; + ableToOpen = m->openInputFile(groupfileNames[i], in, "noerror"); + + //if you can't open it, try default location + if (ableToOpen == 1) { + if (m->getDefaultPath() != "") { //default path is set + string tryPath = m->getDefaultPath() + m->getSimpleName(groupfileNames[i]); + m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); + groupfileNames[i] = tryPath; + } + } + + if (ableToOpen == 1) { + if (m->getOutputDir() != "") { //default path is set + string tryPath = m->getOutputDir() + m->getSimpleName(groupfileNames[i]); + m->mothurOut("Unable to open " + groupfileNames[i] + ". Trying output directory " + tryPath); m->mothurOutEndLine(); + ifstream in2; + ableToOpen = m->openInputFile(tryPath, in2, "noerror"); + in2.close(); + groupfileNames[i] = tryPath; + } + } + + in.close(); + + if (ableToOpen == 1) { + m->mothurOut("Unable to open " + groupfileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); + //erase from file list + groupfileNames.erase(groupfileNames.begin()+i); + i--; + }else { + m->setGroupFile(groupfileNames[i]); } } - in.close(); - - if (ableToOpen == 1) { - m->mothurOut("Unable to open " + groupfileNames[i] + ". It will be disregarded."); m->mothurOutEndLine(); groupfileNames[i] = ""; - //erase from file list - groupfileNames.erase(groupfileNames.begin()+i); - i--; - }else { - m->setGroupFile(groupfileNames[i]); - } } } @@ -644,16 +641,20 @@ int ClassifySeqsCommand::execute(){ else if (foundDot && (baseTName[i] == '.')) { break; } else if (!foundDot && (baseTName[i] == '.')) { foundDot = true; } } - if (RippedTaxName != "") { RippedTaxName += "."; } + //if (RippedTaxName != "") { RippedTaxName += "."; } if (outputDir == "") { outputDir += m->hasPath(fastaFileNames[s]); } - string newTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + outputMethodTag + getOutputFileNameTag("taxonomy"); - string newaccnosFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + outputMethodTag +getOutputFileNameTag("accnos"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])); + variables["[tag]"] = RippedTaxName; + variables["[tag2]"] = outputMethodTag; + string newTaxonomyFile = getOutputFileName("taxonomy", variables); + string newaccnosFile = getOutputFileName("accnos", variables); string tempTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "taxonomy.temp"; - string taxSummary = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + outputMethodTag + getOutputFileNameTag("taxsummary"); + string taxSummary = getOutputFileName("taxsummary", variables); if ((method == "knn") && (search == "distance")) { - string DistName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("matchdist"); + string DistName = getOutputFileName("matchdist", variables); classify->setDistName(DistName); outputNames.push_back(DistName); outputTypes["matchdist"].push_back(DistName); } diff --git a/classifyseqscommand.h b/classifyseqscommand.h index 87d4f51..a3328d8 100644 --- a/classifyseqscommand.h +++ b/classifyseqscommand.h @@ -43,8 +43,9 @@ public: vector setParameters(); string getCommandName() { return "classify.seqs"; } string getCommandCategory() { return "Phylotype Analysis"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Wang Q, Garrity GM, Tiedje JM, Cole JR (2007). Naive Bayesian classifier for rapid assignment of rRNA sequences into the new bacterial taxonomy. Appl Environ Microbiol 73: 5261-7. [ for Bayesian classifier ] \nAltschul SF, Madden TL, Schaffer AA, Zhang J, Zhang Z, Miller W, Lipman DJ (1997). Gapped BLAST and PSI-BLAST: a new generation of protein database search programs. Nucleic Acids Res 25: 3389-402. [ for BLAST ] \nDeSantis TZ, Hugenholtz P, Larsen N, Rojas M, Brodie EL, Keller K, Huber T, Dalevi D, Hu P, Andersen GL (2006). Greengenes, a chimera-checked 16S rRNA gene database and workbench compatible with ARB. Appl Environ Microbiol 72: 5069-72. [ for kmer ] \nhttp://www.mothur.org/wiki/Classify.seqs"; } string getDescription() { return "classify sequences"; } diff --git a/classifysharedcommand.cpp b/classifysharedcommand.cpp index f964937..2dc963b 100755 --- a/classifysharedcommand.cpp +++ b/classifysharedcommand.cpp @@ -15,16 +15,16 @@ vector ClassifySharedCommand::setParameters(){ try { //CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); - CommandParameter potupersplit("otupersplit", "Multiple", "log2-squareroot", "log2", "", "", "",false,false); parameters.push_back(potupersplit); - CommandParameter psplitcriteria("splitcriteria", "Multiple", "gainratio-infogain", "gainratio", "", "", "",false,false); parameters.push_back(psplitcriteria); - CommandParameter pnumtrees("numtrees", "Number", "", "100", "", "", "",false,false); parameters.push_back(pnumtrees); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","summary",false,true,true); parameters.push_back(pshared); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pdesign); + CommandParameter potupersplit("otupersplit", "Multiple", "log2-squareroot", "log2", "", "", "","",false,false); parameters.push_back(potupersplit); + CommandParameter psplitcriteria("splitcriteria", "Multiple", "gainratio-infogain", "gainratio", "", "", "","",false,false); parameters.push_back(psplitcriteria); + CommandParameter pnumtrees("numtrees", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pnumtrees); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - 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); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -53,24 +53,19 @@ string ClassifySharedCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClassifySharedCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string tag = ""; - map >::iterator it; +string ClassifySharedCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "summary") { tag = "summary"; } - else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } - } - return tag; - } - catch(exception& e) { - m->errorOut(e, "ClassifySharedCommand", "getOutputFileName"); - exit(1); - } + if (type == "summary") { pattern = "[filename],[distance],summary"; } //makes file like: amazon.0.03.fasta + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClassifySharedCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -348,7 +343,10 @@ void ClassifySharedCommand::processSharedAndDesignData(vectorgetRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[distance]"] = lookup[0]->getLabel(); + string filename = getOutputFileName("summary", variables); outputNames.push_back(filename); outputTypes["summary"].push_back(filename); randomForest.calcForrestVariableImportance(filename); diff --git a/classifysharedcommand.h b/classifysharedcommand.h index 93c6286..fe06374 100755 --- a/classifysharedcommand.h +++ b/classifysharedcommand.h @@ -21,8 +21,9 @@ public: vector setParameters(); string getCommandName() { return "classify.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); - string getHelpString(); + + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Classify.shared\n"; } string getDescription() { return "description"; } int execute(); diff --git a/classifytreecommand.cpp b/classifytreecommand.cpp index 69da8e0..f1f1ffd 100644 --- a/classifytreecommand.cpp +++ b/classifytreecommand.cpp @@ -13,14 +13,14 @@ //********************************************************************************************************************** vector ClassifyTreeCommand::setParameters(){ try { - CommandParameter ptree("tree", "InputTypes", "", "", "", "", "none",false,true); parameters.push_back(ptree); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "", "", "none",false,true); parameters.push_back(ptaxonomy); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pcutoff("cutoff", "Number", "", "51", "", "", "",false,true); parameters.push_back(pcutoff); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptree("tree", "InputTypes", "", "", "", "", "none","tree-summary",false,true,true); parameters.push_back(ptree); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "", "", "none","",false,true,true); parameters.push_back(ptaxonomy); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pcutoff("cutoff", "Number", "", "51", "", "", "","",false,true); parameters.push_back(pcutoff); + 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); } @@ -52,25 +52,20 @@ string ClassifyTreeCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClassifyTreeCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ClassifyTreeCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "tree") { outputFileName = "taxonomy.tre"; } - else if (type == "summary") { outputFileName = "taxonomy.summary"; } - 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, "ClassifyTreeCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "summary") { pattern = "[filename],taxonomy.summary"; } //makes file like: amazon.0.03.fasta + else if (type == "tree") { pattern = "[filename],taxonomy.tre"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClassifyTreeCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ClassifyTreeCommand::ClassifyTreeCommand(){ @@ -286,7 +281,9 @@ int ClassifyTreeCommand::getClassifications(Tree*& T){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(treefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(treefile)); + string outputFileName = getOutputFileName("summary", variables); outputNames.push_back(outputFileName); outputTypes["summary"].push_back(outputFileName); ofstream out; @@ -300,7 +297,8 @@ int ClassifyTreeCommand::getClassifications(Tree*& T){ string treeOutputDir = outputDir; if (outputDir == "") { treeOutputDir += m->hasPath(treefile); } - string outputTreeFileName = treeOutputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("tree"); + variables["[filename]"] = treeOutputDir + m->getRootName(m->getSimpleName(treefile)); + string outputTreeFileName = getOutputFileName("tree", variables); //create a map from tree node index to names of descendants, save time later map > > nodeToDescendants; //node# -> (groupName -> groupMembers) diff --git a/classifytreecommand.h b/classifytreecommand.h index dd972b6..ef180ba 100644 --- a/classifytreecommand.h +++ b/classifytreecommand.h @@ -23,8 +23,9 @@ public: vector setParameters(); string getCommandName() { return "classify.tree"; } string getCommandCategory() { return "Phylotype Analysis"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Classify.tree"; } string getDescription() { return "Find the consensus taxonomy for the descendant of each tree node"; } diff --git a/clearcutcommand.cpp b/clearcutcommand.cpp index 55fbe0a..1b0a532 100644 --- a/clearcutcommand.cpp +++ b/clearcutcommand.cpp @@ -19,26 +19,26 @@ extern "C" { //********************************************************************************************************************** vector ClearcutCommand::setParameters(){ try { - CommandParameter pphylip("phylip", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none",false,false); parameters.push_back(pphylip); - CommandParameter pfasta("fasta", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none",false,false); parameters.push_back(pfasta); - CommandParameter pverbose("verbose", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pverbose); - CommandParameter pquiet("quiet", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pquiet); - CommandParameter pversion("version", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pversion); - CommandParameter pseed("seed", "String", "", "", "*", "", "",false,false); parameters.push_back(pseed); - CommandParameter pnorandom("norandom", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pnorandom); - CommandParameter pshuffle("shuffle", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pshuffle); - CommandParameter pneighbor("neighbor", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pneighbor); - CommandParameter pexpblen("expblen", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pexpblen); - CommandParameter pexpdist("expdist", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pexpdist); - CommandParameter pDNA("DNA", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pDNA); - CommandParameter pprotein("protein", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pprotein); - CommandParameter pjukes("jukes", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pjukes); - CommandParameter pkimura("kimura", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pkimura); - CommandParameter pstdout("stdout", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pstdout); - CommandParameter pntrees("ntrees", "Number", "", "1", "", "", "",false,false); parameters.push_back(pntrees); - CommandParameter pmatrixout("matrixout", "String", "", "", "", "", "",false,false); parameters.push_back(pmatrixout); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pphylip("phylip", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none","tree",false,false,true); parameters.push_back(pphylip); + CommandParameter pfasta("fasta", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none","tree",false,false,true); parameters.push_back(pfasta); + CommandParameter pverbose("verbose", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pverbose); + CommandParameter pquiet("quiet", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pquiet); + CommandParameter pversion("version", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pversion); + CommandParameter pseed("seed", "String", "", "", "*", "", "","",false,false); parameters.push_back(pseed); + CommandParameter pnorandom("norandom", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pnorandom); + CommandParameter pshuffle("shuffle", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pshuffle); + CommandParameter pneighbor("neighbor", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pneighbor); + CommandParameter pexpblen("expblen", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pexpblen); + CommandParameter pexpdist("expdist", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pexpdist); + CommandParameter pDNA("DNA", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pDNA); + CommandParameter pprotein("protein", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pprotein); + CommandParameter pjukes("jukes", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pjukes); + CommandParameter pkimura("kimura", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pkimura); + CommandParameter pstdout("stdout", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pstdout); + CommandParameter pntrees("ntrees", "Number", "", "1", "", "", "","",false,false); parameters.push_back(pntrees); + CommandParameter pmatrixout("matrixout", "String", "", "", "", "", "","",false,false); parameters.push_back(pmatrixout); + 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); } @@ -87,25 +87,20 @@ string ClearcutCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClearcutCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ClearcutCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "tree") { outputFileName = "tre"; } - else if (type == "matrixout") { outputFileName = ""; } - 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, "ClearcutCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "matrixout") { pattern = "[filename],"; } + else if (type == "tree") { pattern = "[filename],tre"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClearcutCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ClearcutCommand::ClearcutCommand(){ @@ -264,7 +259,9 @@ int ClearcutCommand::execute() { if (abort == true) { if (calledHelp) { return 0; } return 2; } //prepare filename - string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + getOutputFileNameTag("tree"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFile)); + string outputName = getOutputFileName("tree", variables); outputNames.push_back(outputName); outputTypes["tree"].push_back(outputName); vector cPara; diff --git a/clearcutcommand.h b/clearcutcommand.h index 8f3773e..817c4a3 100644 --- a/clearcutcommand.h +++ b/clearcutcommand.h @@ -30,8 +30,9 @@ public: vector setParameters(); string getCommandName() { return "clearcut"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Sheneman L, Evans J, Foster JA (2006). Clearcut: a fast implementation of relaxed neighbor joining. Bioinformatics 22: 2823-4. \nhttp://www.mothur.org/wiki/Clearcut"; } string getDescription() { return "create a tree from a fasta or phylip file"; } diff --git a/clearmemorycommand.cpp b/clearmemorycommand.cpp index e1f3972..abdc555 100644 --- a/clearmemorycommand.cpp +++ b/clearmemorycommand.cpp @@ -22,25 +22,6 @@ vector ClearMemoryCommand::setParameters(){ } } //********************************************************************************************************************** -string ClearMemoryCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - 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 { - m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; - } - return outputFileName; - } - catch(exception& e) { - m->errorOut(e, "ClearMemoryCommand", "getOutputFileNameTag"); - exit(1); - } -} -//********************************************************************************************************************** string ClearMemoryCommand::getHelpString(){ try { string helpString = ""; diff --git a/clearmemorycommand.h b/clearmemorycommand.h index 1208315..765f41d 100644 --- a/clearmemorycommand.h +++ b/clearmemorycommand.h @@ -21,8 +21,9 @@ public: vector setParameters(); string getCommandName() { return "clear.memory"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string) { return ""; } string getCitation() { return "http://www.mothur.org/wiki/Clear.memory"; } string getDescription() { return "remove saved references from memory"; } diff --git a/clustercommand.cpp b/clustercommand.cpp index b46e1fb..93e29fd 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -17,19 +17,19 @@ //********************************************************************************************************************** vector ClusterCommand::setParameters(){ try { - CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn); - CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); - CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pshowabund); - CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptiming); - CommandParameter psim("sim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psim); - CommandParameter phard("hard", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(phard); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none","list",false,false,true); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName","rabund-sabund",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName","list",false,false,true); parameters.push_back(pcolumn); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "","",false,false,true); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "","",false,false,true); parameters.push_back(pmethod); + CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pshowabund); + CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(ptiming); + CommandParameter psim("sim", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psim); + CommandParameter phard("hard", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(phard); + 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); } @@ -56,26 +56,21 @@ string ClusterCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClusterCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ClusterCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "list") { outputFileName = "list"; } - else if (type == "rabund") { outputFileName = "rabund"; } - else if (type == "sabund") { outputFileName = "sabund"; } - 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, "ClusterCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "list") { pattern = "[filename],[clustertag],list-[filename],[clustertag],[tag2],list"; } + else if (type == "rabund") { pattern = "[filename],[clustertag],rabund"; } + else if (type == "sabund") { pattern = "[filename],[clustertag],sabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClusterCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ClusterCommand::ClusterCommand(){ @@ -339,11 +334,13 @@ int ClusterCommand::execute(){ if (outputDir == "") { outputDir += m->hasPath(distfile); } fileroot = outputDir + m->getRootName(m->getSimpleName(distfile)); - string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); - string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); - string listFileName = fileroot+ tag + "."; - if (countfile != "") { listFileName += "unique_"; } - listFileName += getOutputFileNameTag("list"); + map variables; + variables["[filename]"] = fileroot; + if (countfile != "") { variables["[tag2]"] = "unique_list"; } + variables["[clustertag]"] = tag; + string sabundFileName = getOutputFileName("sabund", variables); + string rabundFileName = getOutputFileName("rabund", variables); + string listFileName = getOutputFileName("list", variables); if (countfile == "") { m->openOutputFile(sabundFileName, sabundFile); diff --git a/clustercommand.h b/clustercommand.h index a5b792e..96b7c08 100644 --- a/clustercommand.h +++ b/clustercommand.h @@ -35,8 +35,9 @@ public: vector setParameters(); string getCommandName() { return "cluster"; } string getCommandCategory() { return "Clustering"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Westcott SL (2011). Assessing and improving methods used in OTU-based approaches for 16S rRNA gene sequence analysis. Appl Environ Microbiol 77:3219.\nSchloss PD, Handelsman J (2005). Introducing DOTUR, a computer program for defining operational taxonomic units and estimating species richness. Appl Environ Microbiol 71: 1501-6.\nhttp://www.mothur.org/wiki/Cluster"; } string getDescription() { return "cluster your sequences into OTUs using a distance matrix"; } diff --git a/clusterdoturcommand.cpp b/clusterdoturcommand.cpp index 2515b5c..4463896 100644 --- a/clusterdoturcommand.cpp +++ b/clusterdoturcommand.cpp @@ -13,16 +13,16 @@ //********************************************************************************************************************** vector ClusterDoturCommand::setParameters(){ try { - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); - CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); - CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter phard("hard", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(phard); - CommandParameter psim("sim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psim); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","list",false,true,true); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","rabund-sabund",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "","",false,false,true); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "","",false,false); parameters.push_back(pmethod); + CommandParameter phard("hard", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(phard); + CommandParameter psim("sim", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psim); + 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); } @@ -50,26 +50,21 @@ string ClusterDoturCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClusterDoturCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ClusterDoturCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "list") { outputFileName = "list"; } - else if (type == "rabund") { outputFileName = "rabund"; } - else if (type == "sabund") { outputFileName = "sabund"; } - 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, "ClusterDoturCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "list") { pattern = "[filename],[clustertag],list-[filename],[clustertag],[tag2],list"; } + else if (type == "rabund") { pattern = "[filename],[clustertag],rabund"; } + else if (type == "sabund") { pattern = "[filename],[clustertag],sabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClusterDoturCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ClusterDoturCommand::ClusterDoturCommand(){ @@ -247,11 +242,13 @@ int ClusterDoturCommand::execute(){ if (outputDir == "") { outputDir += m->hasPath(phylipfile); } fileroot = outputDir + m->getRootName(m->getSimpleName(phylipfile)); - string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); - string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); - string listFileName = fileroot+ tag + "."; - if (countfile != "") { listFileName += "unique_"; } - listFileName += getOutputFileNameTag("list"); + map variables; + variables["[filename]"] = fileroot; + if (countfile != "") { variables["[tag2]"] = "unique_list"; } + variables["[clustertag]"] = tag; + string sabundFileName = getOutputFileName("sabund", variables); + string rabundFileName = getOutputFileName("rabund", variables); + string listFileName = getOutputFileName("list", variables); if (countfile == "") { m->openOutputFile(sabundFileName, sabundFile); diff --git a/clusterdoturcommand.h b/clusterdoturcommand.h index dd61a35..ccfe03b 100644 --- a/clusterdoturcommand.h +++ b/clusterdoturcommand.h @@ -27,8 +27,9 @@ public: vector setParameters(); string getCommandName() { return "cluster.classic"; } string getCommandCategory() { return "Clustering"; } - string getOutputFileNameTag(string, string); - string getHelpString(); + + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Westcott SL (2011). Assessing and improving methods used in OTU-based approaches for 16S rRNA gene sequence analysis. Appl Environ Microbiol 77:3219.\nSchloss PD, Handelsman J (2005). Introducing DOTUR, a computer program for defining operational taxonomic units and estimating species richness. Appl Environ Microbiol 71: 1501-6.\nhttp://www.mothur.org/wiki/Cluster.classic\n";} string getDescription() { return "cluster your sequences into OTUs using DOTUR’s method"; } diff --git a/clusterfragmentscommand.cpp b/clusterfragmentscommand.cpp index f785c50..ef199cc 100644 --- a/clusterfragmentscommand.cpp +++ b/clusterfragmentscommand.cpp @@ -28,13 +28,13 @@ inline bool comparePriority(seqRNode first, seqRNode second) { //********************************************************************************************************************** vector ClusterFragmentsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pdiffs("diffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pdiffs); - CommandParameter ppercent("percent", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppercent); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta-name",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pdiffs("diffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pdiffs); + CommandParameter ppercent("percent", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ppercent); + 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); } @@ -68,28 +68,22 @@ string ClusterFragmentsCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClusterFragmentsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ClusterFragmentsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "fragclust.fasta"; } - else if (type == "name") { outputFileName = "fragclust.names"; } - else if (type == "count") { outputFileName = "fragclust.count_table"; } - 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, "ClusterFragmentsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],fragclust.fasta"; } + else if (type == "name") { pattern = "[filename],fragclust.names"; } + else if (type == "count") { pattern = "[filename],fragclust.count_table"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClusterFragmentsCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** ClusterFragmentsCommand::ClusterFragmentsCommand(){ try { @@ -275,10 +269,11 @@ int ClusterFragmentsCommand::execute(){ string fileroot = outputDir + m->getRootName(m->getSimpleName(fastafile)); - - string newFastaFile = fileroot + getOutputFileNameTag("fasta"); - string newNamesFile = fileroot + getOutputFileNameTag("name"); - if (countfile != "") { newNamesFile = fileroot + getOutputFileNameTag("count"); } + map variables; + variables["[filename]"] = fileroot; + string newFastaFile = getOutputFileName("fasta", variables); + string newNamesFile = getOutputFileName("name", variables); + if (countfile != "") { newNamesFile = getOutputFileName("count", variables); } if (m->control_pressed) { return 0; } diff --git a/clusterfragmentscommand.h b/clusterfragmentscommand.h index e3d861a..ee25fb3 100644 --- a/clusterfragmentscommand.h +++ b/clusterfragmentscommand.h @@ -38,8 +38,9 @@ public: vector setParameters(); string getCommandName() { return "cluster.fragments"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Cluster.fragments"; } string getDescription() { return "creates a namesfile with sequences that are a fragment of a larger sequence"; } diff --git a/clustersplitcommand.cpp b/clustersplitcommand.cpp index 277e4a2..ac5e755 100644 --- a/clustersplitcommand.cpp +++ b/clustersplitcommand.cpp @@ -13,26 +13,26 @@ //********************************************************************************************************************** vector ClusterSplitCommand::setParameters(){ try { - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "FastaTaxName",false,false); parameters.push_back(ptaxonomy); - CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnFasta", "PhylipColumnFasta", "none",false,false); parameters.push_back(pphylip); - CommandParameter pfasta("fasta", "InputTypes", "", "", "PhylipColumnFasta", "PhylipColumnFasta", "FastaTaxName",false,false); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName-FastaTaxName",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount", "none", "",false,false); parameters.push_back(pcount); - CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnFasta", "PhylipColumnFasta", "ColumnName",false,false); parameters.push_back(pcolumn); - CommandParameter ptaxlevel("taxlevel", "Number", "", "3", "", "", "",false,false); parameters.push_back(ptaxlevel); - CommandParameter psplitmethod("splitmethod", "Multiple", "classify-fasta-distance", "distance", "", "", "",false,false); parameters.push_back(psplitmethod); - CommandParameter plarge("large", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(plarge); - CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pshowabund); - CommandParameter pcluster("cluster", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pcluster); - CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptiming); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pcutoff("cutoff", "Number", "", "0.25", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); - CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter phard("hard", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(phard); - CommandParameter pclassic("classic", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pclassic); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "FastaTaxName","",false,false,true); parameters.push_back(ptaxonomy); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnFasta", "PhylipColumnFasta", "none","list",false,false,true); parameters.push_back(pphylip); + CommandParameter pfasta("fasta", "InputTypes", "", "", "PhylipColumnFasta", "PhylipColumnFasta", "FastaTaxName","list",false,false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName-FastaTaxName","rabund-sabund",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount", "none", "","",false,false,true); parameters.push_back(pcount); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnFasta", "PhylipColumnFasta", "ColumnName","list",false,false,true); parameters.push_back(pcolumn); + CommandParameter ptaxlevel("taxlevel", "Number", "", "3", "", "", "","",false,false,true); parameters.push_back(ptaxlevel); + CommandParameter psplitmethod("splitmethod", "Multiple", "classify-fasta-distance", "distance", "", "", "","",false,false,true); parameters.push_back(psplitmethod); + CommandParameter plarge("large", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(plarge); + CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pshowabund); + CommandParameter pcluster("cluster", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pcluster); + CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(ptiming); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pcutoff("cutoff", "Number", "", "0.25", "", "", "","",false,false,true); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "","",false,false); parameters.push_back(pmethod); + CommandParameter phard("hard", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(phard); + CommandParameter pclassic("classic", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pclassic); + 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); } @@ -81,27 +81,22 @@ string ClusterSplitCommand::getHelpString(){ } } //********************************************************************************************************************** -string ClusterSplitCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ClusterSplitCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "list") { outputFileName = "list"; } - else if (type == "rabund") { outputFileName = "rabund"; } - else if (type == "sabund") { outputFileName = "sabund"; } - else if (type == "column") { outputFileName = "dist"; } - 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, "ClusterSplitCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "list") { pattern = "[filename],[clustertag],list-[filename],[clustertag],[tag2],list"; } + else if (type == "rabund") { pattern = "[filename],[clustertag],rabund"; } + else if (type == "sabund") { pattern = "[filename],[clustertag],sabund"; } + else if (type == "column") { pattern = "[filename],dist"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ClusterSplitCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ClusterSplitCommand::ClusterSplitCommand(){ @@ -821,11 +816,13 @@ int ClusterSplitCommand::mergeLists(vector listNames, map us if (outputDir == "") { outputDir += m->hasPath(distfile); } fileroot = outputDir + m->getRootName(m->getSimpleName(distfile)); - string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); - string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); - string listFileName = fileroot+ tag + "."; - if (countfile != "") { listFileName += "unique_"; } - listFileName += getOutputFileNameTag("list"); + map variables; + variables["[filename]"] = fileroot; + if (countfile != "") { variables["[tag2]"] = "unique_list"; } + variables["[clustertag]"] = tag; + string sabundFileName = getOutputFileName("sabund", variables); + string rabundFileName = getOutputFileName("rabund", variables); + string listFileName = getOutputFileName("list", variables); if (countfile == "") { m->openOutputFile(sabundFileName, outSabund); @@ -1440,7 +1437,9 @@ int ClusterSplitCommand::createMergedDistanceFile(vector< map > string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir = m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("column"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + string outputFileName = getOutputFileName("column", variables); m->mothurRemove(outputFileName); diff --git a/clustersplitcommand.h b/clustersplitcommand.h index d88a934..e1f17b1 100644 --- a/clustersplitcommand.h +++ b/clustersplitcommand.h @@ -35,8 +35,9 @@ public: vector setParameters(); string getCommandName() { return "cluster.split"; } string getCommandCategory() { return "Clustering"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Westcott SL (2011). Assessing and improving methods used in OTU-based approaches for 16S rRNA gene sequence analysis. Appl Environ Microbiol 77:3219. \nhttp://www.mothur.org/wiki/Cluster.split"; } string getDescription() { return "splits your sequences by distance or taxonomy then clusters into OTUs"; } diff --git a/collectcommand.cpp b/collectcommand.cpp index 73de2a4..de92e49 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -38,17 +38,17 @@ //********************************************************************************************************************** vector CollectCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); - CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); - CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); - CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); - CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-npshannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap-geometric-qstat-logseries-bergerparker-bstick-goodscoverage-efron-boneh-solow-shen", "sobs-chao-ace-jack-shannon-npshannon-simpson", "", "", "",true,false); parameters.push_back(pcalc); - CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund); - CommandParameter psize("size", "Number", "", "0", "", "", "",false,false); parameters.push_back(psize); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false,true); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false,true); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false,true); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pfreq); + CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-npshannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap-geometric-qstat-logseries-bergerparker-bstick-goodscoverage-efron-boneh-solow-shen", "sobs-chao-ace-jack-shannon-npshannon-simpson", "", "", "","",true,false,true); parameters.push_back(pcalc); + CommandParameter pabund("abund", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pabund); + CommandParameter psize("size", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psize); + 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); } @@ -81,48 +81,43 @@ string CollectCommand::getHelpString(){ } } //********************************************************************************************************************** -string CollectCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string CollectCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "sobs") { outputFileName = "sobs"; } - else if (type == "chao") { outputFileName = "chao"; } - else if (type == "nseqs") { outputFileName = "nseqs"; } - else if (type == "coverage") { outputFileName = "coverage"; } - else if (type == "ace") { outputFileName = "ace"; } - else if (type == "jack") { outputFileName = "jack"; } - else if (type == "shannon") { outputFileName = "shannon"; } - else if (type == "shannoneven") { outputFileName = "shannoneven"; } - else if (type == "npshannon") { outputFileName = "npshannon"; } - else if (type == "heip") { outputFileName = "heip"; } - else if (type == "smithwilson") { outputFileName = "smithwilson"; } - else if (type == "simpson") { outputFileName = "simpson"; } - else if (type == "simpsoneven") { outputFileName = "simpsoneven"; } - else if (type == "invsimpson") { outputFileName = "invsimpson"; } - else if (type == "bootstrap") { outputFileName = "bootstrap"; } - else if (type == "geometric") { outputFileName = "geometric"; } - else if (type == "qstat") { outputFileName = "qstat"; } - else if (type == "logseries") { outputFileName = "logseries"; } - else if (type == "bergerparker") { outputFileName = "bergerparker"; } - else if (type == "bstick") { outputFileName = "bstick"; } - else if (type == "goodscoverage") { outputFileName = "goodscoverage"; } - else if (type == "efron") { outputFileName = "efron"; } - else if (type == "boneh") { outputFileName = "boneh"; } - else if (type == "solow") { outputFileName = "solow"; } - else if (type == "shen") { outputFileName = "shen"; } - 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, "CollectCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "sobs") { pattern = "[filename],sobs"; } + else if (type == "chao") { pattern = "[filename],chao"; } + else if (type == "nseqs") { pattern = "[filename],nseqs"; } + else if (type == "coverage") { pattern = "[filename],coverage"; } + else if (type == "ace") { pattern = "[filename],ace"; } + else if (type == "jack") { pattern = "[filename],jack"; } + else if (type == "shannon") { pattern = "[filename],shannon"; } + else if (type == "shannoneven") { pattern = "[filename],shannoneven"; } + else if (type == "npshannon") { pattern = "[filename],npshannon"; } + else if (type == "heip") { pattern = "[filename],heip"; } + else if (type == "smithwilson") { pattern = "[filename],smithwilson"; } + else if (type == "simpson") { pattern = "[filename],simpson"; } + else if (type == "simpsoneven") { pattern = "[filename],simpsoneven"; } + else if (type == "invsimpson") { pattern = "[filename],invsimpson"; } + else if (type == "bootstrap") { pattern = "[filename],bootstrap"; } + else if (type == "geometric") { pattern = "[filename],geometric"; } + else if (type == "qstat") { pattern = "[filename],qstat"; } + else if (type == "logseries") { pattern = "[filename],logseries"; } + else if (type == "bergerparker") { pattern = "[filename],bergerparker"; } + else if (type == "bstick") { pattern = "[filename],bstick"; } + else if (type == "goodscoverage") { pattern = "[filename],goodscoverage"; } + else if (type == "efron") { pattern = "[filename],efron"; } + else if (type == "boneh") { pattern = "[filename],boneh"; } + else if (type == "solow") { pattern = "[filename],solow"; } + else if (type == "shen") { pattern = "[filename],shen"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "CollectCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** CollectCommand::CollectCommand(){ @@ -355,6 +350,8 @@ int CollectCommand::execute(){ if (outputDir == "") { outputDir += m->hasPath(inputFileNames[p]); } string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])); + map variables; + variables["[filename]"] = fileNameRoot; //globaldata->inputFileName = inputFileNames[p]; if (inputFileNames.size() > 1) { @@ -366,80 +363,80 @@ int CollectCommand::execute(){ for (int i=0; i CollectSharedCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); - CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "",true,false); parameters.push_back(pcalc); - CommandParameter pall("all", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pall); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pfreq); + CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "","",true,false,true); parameters.push_back(pcalc); + CommandParameter pall("all", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pall); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -98,63 +98,59 @@ string CollectSharedCommand::getHelpString(){ } } //********************************************************************************************************************** -string CollectSharedCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string CollectSharedCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "sharedchao") { outputFileName = "shared.chao"; } - else if (type == "sharedsobs") { outputFileName = "shared.sobs"; } - else if (type == "sharedace") { outputFileName = "shared.ace"; } - else if (type == "jabund") { outputFileName = "jabund"; } - else if (type == "sorabund") { outputFileName = "sorabund"; } - else if (type == "jclass") { outputFileName = "jclass"; } - else if (type == "sorclass") { outputFileName = "sorclass"; } - else if (type == "jest") { outputFileName = "jest"; } - else if (type == "sorest") { outputFileName = "sorest"; } - else if (type == "thetayc") { outputFileName = "thetayc"; } - else if (type == "thetan") { outputFileName = "thetan"; } - else if (type == "kstest") { outputFileName = "kstest"; } - else if (type == "whittaker") { outputFileName = "whittaker"; } - else if (type == "sharednseqs") { outputFileName = "shared.nseqs"; } - else if (type == "ochiai") { outputFileName = "ochiai"; } - else if (type == "anderberg") { outputFileName = "anderberg"; } - else if (type == "kulczynski") { outputFileName = "kulczynski"; } - else if (type == "kulczynskicody") { outputFileName = "kulczynskicody"; } - else if (type == "lennon") { outputFileName = "lennon"; } - else if (type == "morisitahorn") { outputFileName = "morisitahorn"; } - else if (type == "braycurtis") { outputFileName = "braycurtis"; } - else if (type == "odum") { outputFileName = "odum"; } - else if (type == "canberra") { outputFileName = "canberra"; } - else if (type == "structeuclidean") { outputFileName = "structeuclidean"; } - else if (type == "structchord") { outputFileName = "structchord"; } - else if (type == "hellinger") { outputFileName = "hellinger"; } - else if (type == "manhattan") { outputFileName = "manhattan"; } - else if (type == "structpearson") { outputFileName = "structpearson"; } - else if (type == "soergel") { outputFileName = "soergel"; } - else if (type == "spearman") { outputFileName = "spearman"; } - else if (type == "structkulczynski") { outputFileName = "structkulczynski";} - else if (type == "structchi2") { outputFileName = "structchi2"; } - else if (type == "speciesprofile") { outputFileName = "speciesprofile"; } - else if (type == "hamming") { outputFileName = "hamming"; } - else if (type == "gower") { outputFileName = "gower"; } - else if (type == "memchi2") { outputFileName = "memchi2"; } - else if (type == "memchord") { outputFileName = "memchord"; } - else if (type == "memeuclidean") { outputFileName = "memeuclidean"; } - else if (type == "mempearson") { outputFileName = "mempearson"; } - 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, "CollectSharedCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "sharedchao") { pattern = "[filename],shared.chao"; } + else if (type == "sharedsobs") { pattern = "[filename],shared.sobs"; } + else if (type == "sharedace") { pattern = "[filename],shared.ace"; } + else if (type == "jabund") { pattern = "[filename],jabund"; } + else if (type == "sorabund") { pattern = "[filename],sorabund"; } + else if (type == "jclass") { pattern = "[filename],jclass"; } + else if (type == "sorclass") { pattern = "[filename],sorclass"; } + else if (type == "jest") { pattern = "[filename],jest"; } + else if (type == "sorest") { pattern = "[filename],sorest"; } + else if (type == "thetayc") { pattern = "[filename],thetayc"; } + else if (type == "thetan") { pattern = "[filename],thetan"; } + else if (type == "kstest") { pattern = "[filename],kstest"; } + else if (type == "whittaker") { pattern = "[filename],whittaker"; } + else if (type == "sharednseqs") { pattern = "[filename],shared.nseqs"; } + else if (type == "ochiai") { pattern = "[filename],ochiai"; } + else if (type == "anderberg") { pattern = "[filename],anderberg"; } + else if (type == "kulczynski") { pattern = "[filename],kulczynski"; } + else if (type == "kulczynskicody") { pattern = "[filename],kulczynskicody"; } + else if (type == "lennon") { pattern = "[filename],lennon"; } + else if (type == "morisitahorn") { pattern = "[filename],morisitahorn"; } + else if (type == "braycurtis") { pattern = "[filename],braycurtis"; } + else if (type == "odum") { pattern = "[filename],odum"; } + else if (type == "canberra") { pattern = "[filename],canberra"; } + else if (type == "structeuclidean") { pattern = "[filename],structeuclidean"; } + else if (type == "structchord") { pattern = "[filename],structchord"; } + else if (type == "hellinger") { pattern = "[filename],hellinger"; } + else if (type == "manhattan") { pattern = "[filename],manhattan"; } + else if (type == "structpearson") { pattern = "[filename],structpearson"; } + else if (type == "soergel") { pattern = "[filename],soergel"; } + else if (type == "spearman") { pattern = "[filename],spearman"; } + else if (type == "structkulczynski") { pattern = "[filename],structkulczynski";} + else if (type == "structchi2") { pattern = "[filename],structchi2"; } + else if (type == "speciesprofile") { pattern = "[filename],speciesprofile"; } + else if (type == "hamming") { pattern = "[filename],hamming"; } + else if (type == "gower") { pattern = "[filename],gower"; } + else if (type == "memchi2") { pattern = "[filename],memchi2"; } + else if (type == "memchord") { pattern = "[filename],memchord"; } + else if (type == "memeuclidean") { pattern = "[filename],memeuclidean"; } + else if (type == "mempearson") { pattern = "[filename],mempearson"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "CollectSharedCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** CollectSharedCommand::CollectSharedCommand(){ try { @@ -340,128 +336,130 @@ CollectSharedCommand::CollectSharedCommand(string option) { if (abort == false) { string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - + map variables; + variables["[filename]"] = fileNameRoot; + ValidCalculators validCalculator; for (int i=0; i setParameters(); string getCommandName() { return "collect.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Handelsman J (2006). Introducing SONS, A tool that compares the membership of microbial communities. Appl Environ Microbiol 72: 6773-9. \nhttp://www.mothur.org/wiki/Collect.shared"; } string getDescription() { return "generates collector's curves for calculators, which describe the similarity between communities or their shared richness"; } diff --git a/command.hpp b/command.hpp index f5e0904..2ba35ab 100644 --- a/command.hpp +++ b/command.hpp @@ -33,7 +33,69 @@ class Command { virtual string getDescription() = 0; virtual map > getOutputFiles() { return outputTypes; } - virtual string getOutputFileNameTag(string, string) = 0; //we may not know the complete filename, because some commands use info from the file to create the output file name (ie label). but we do the ending tag which should be enough to find the output file name from a list. Allows for optional passing of the inputFileName for the commands that require its extension. + string getOutputFileName(string type, map variableParts) { //uses the pattern to create an output filename for a given type and input file name. + try { + string filename = ""; + 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 { + + string patternTemp = getOutputPattern(type); + vector patterns; + m->splitAtDash(patternTemp, patterns); + + //find pattern to use based on number of variables passed in + string pattern = ""; + bool foundPattern = false; + for (int i = 0; i < patterns.size(); i++) { + int numVariables = 0; + for (int j = 0; j < patterns[i].length(); j++) { if (patterns[i][j] == '[') { numVariables++; } } + + if (numVariables == variableParts.size()) { pattern = patterns[i]; foundPattern = true; break; } + } + + if (!foundPattern) { m->mothurOut("[ERROR]: Not enough variable pieces for " + type + ".\n"); m->control_pressed = true; } + + if (pattern != "") { + int numVariables = 0; + for (int i = 0; i < pattern.length(); i++) { if (pattern[i] == '[') { numVariables++; } } + + vector pieces; + m->splitAtComma(pattern, pieces); + + + for (int i = 0; i < pieces.size(); i++) { + if (pieces[i][0] == '[') { + map::iterator it = variableParts.find(pieces[i]); + if (it == variableParts.end()) { + m->mothurOut("[ERROR]: Did not provide variable for " + pieces[i] + ".\n"); m->control_pressed = true; + }else { + if (it->second != "") { + if (it->first != "[filename]") { filename += it->second + "."; } + else { filename += it->second; } + } + } + }else { + filename += pieces[i] + "."; + } + } + if (filename.length() > 0) { //rip off last "." + filename = filename.substr(0, filename.length()-1); + } + } + } + return filename; + } + catch(exception& e) { + m->errorOut(e, "command", "getOutputFileName"); + exit(1); + } + } + + virtual string getOutputPattern(string) = 0; //pass in type, returns something like: [filename],align or [filename],[distance],subsample.shared strings in [] means its a variable. This is used by the gui to predict output file names. use variable keywords: [filename], [distance], [group], [extension], [tag] virtual vector setParameters() = 0; //to fill parameters virtual vector getParameters() { return parameters; } diff --git a/commandparameter.h b/commandparameter.h index 9dda0a1..3c622c6 100644 --- a/commandparameter.h +++ b/commandparameter.h @@ -20,9 +20,11 @@ class CommandParameter { public: - CommandParameter() { name = ""; type = ""; options = ""; optionsDefault = ""; chooseOnlyOneGroup = ""; chooseAtLeastOneGroup = ""; linkedGroup = ""; multipleSelectionAllowed = false; required = false; } - CommandParameter(string n, string t, string o, string d, string only, string atLeast, string linked, bool m, bool r) : name(n), type(t), options(o), optionsDefault(d), - chooseOnlyOneGroup(only), chooseAtLeastOneGroup(atLeast), linkedGroup(linked), multipleSelectionAllowed(m), required(r) {} + CommandParameter() { name = ""; type = ""; options = ""; optionsDefault = ""; chooseOnlyOneGroup = ""; chooseAtLeastOneGroup = ""; linkedGroup = ""; multipleSelectionAllowed = false; required = false; important = false; outputTypes = ""; } + CommandParameter(string n, string t, string o, string d, string only, string atLeast, string linked, string opt, bool m, bool r, bool i) : name(n), type(t), options(o), optionsDefault(d), + chooseOnlyOneGroup(only), chooseAtLeastOneGroup(atLeast), linkedGroup(linked), outputTypes(opt),multipleSelectionAllowed(m), required(r), important(i) {} + CommandParameter(string n, string t, string o, string d, string only, string atLeast, string linked, string opt, bool m, bool r) : name(n), type(t), options(o), optionsDefault(d), + chooseOnlyOneGroup(only), chooseAtLeastOneGroup(atLeast), linkedGroup(linked), outputTypes(opt), multipleSelectionAllowed(m), required(r) { important = false; } ~CommandParameter() {} string name; //something like fasta, processors, method @@ -37,11 +39,14 @@ class CommandParameter { string chooseAtLeastOneGroup; //for file inputs: if a command has several options for input files and you want to make sure one is choosen then put them in a group //for instance in the read.dist command you must provide a phylip or column file so set chooseAtLeastOneGroup for both parameters to something like "DistanceFileGroup" string linkedGroup; //for file inputs: if a command has a file option were if you provide one you must provide another you can put them in a group - //for instance in the read.dist command if you provide a column file you must provide a name file so set linkedGroup for both parameters to something like "ColumnNameGroup" + //for instance in the cluster command if you provide a column file you must provide a name file so set linkedGroup for both parameters to something like "ColumnNameGroup" bool multipleSelectionAllowed; //for "Multiple" type to say whether you can select multiple options, for instance for calc parameter set to true, but for method set to false bool required; //is this parameter required - + + bool important; //is this parameter important. The gui will put "important" parameters first in the option panel. + + string outputTypes; //types on files created by the command if this parameter is given. ie. get.seqs command fasta parameter makes a fasta file. can be multiple values split by dashes. private: }; diff --git a/consensusseqscommand.cpp b/consensusseqscommand.cpp index 4134a52..f0fc6bf 100644 --- a/consensusseqscommand.cpp +++ b/consensusseqscommand.cpp @@ -14,14 +14,14 @@ //********************************************************************************************************************** vector ConsensusSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plist); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pcutoff("cutoff", "Number", "", "100", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta-name",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","fasta-name",false,false,true); parameters.push_back(plist); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pcutoff("cutoff", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pcutoff); + 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); } @@ -55,29 +55,23 @@ string ConsensusSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string ConsensusSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ConsensusSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "cons.fasta"; } - else if (type == "name") { outputFileName = "cons.names"; } - else if (type == "count") { outputFileName = "cons.count_table"; } - else if (type == "summary") { outputFileName = "cons.summary"; } - 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, "ConsensusSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],cons.fasta-[filename],[tag],cons.fasta"; } + else if (type == "name") { pattern = "[filename],cons.names-[filename],[tag],cons.names"; } + else if (type == "count") { pattern = "[filename],cons.count_table-[filename],[tag],cons.count_table"; } + else if (type == "summary") { pattern = "[filename],cons.summary-[filename],[tag],cons.summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ConsensusSeqsCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** ConsensusSeqsCommand::ConsensusSeqsCommand(){ try { @@ -238,7 +232,9 @@ int ConsensusSeqsCommand::execute(){ if (listfile == "") { ofstream outSummary; - string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string outputSummaryFile = getOutputFileName("summary", variables); m->openOutputFile(outputSummaryFile, outSummary); outSummary.setf(ios::fixed, ios::floatfield); outSummary.setf(ios::showpoint); outputNames.push_back(outputSummaryFile); outputTypes["summary"].push_back(outputSummaryFile); @@ -246,7 +242,7 @@ int ConsensusSeqsCommand::execute(){ outSummary << "PositioninAlignment\tA\tT\tG\tC\tGap\tNumberofSeqs\tConsensusBase" << endl; ofstream outFasta; - string outputFastaFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta"); + string outputFastaFile = getOutputFileName("fasta", variables); m->openOutputFile(outputFastaFile, outFasta); outputNames.push_back(outputFastaFile); outputTypes["fasta"].push_back(outputFastaFile); @@ -415,18 +411,21 @@ int ConsensusSeqsCommand::processList(ListVector*& list){ try{ ofstream outSummary; - string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[tag]"] = list->getLabel(); + string outputSummaryFile = getOutputFileName("summary", variables); m->openOutputFile(outputSummaryFile, outSummary); outSummary.setf(ios::fixed, ios::floatfield); outSummary.setf(ios::showpoint); outputNames.push_back(outputSummaryFile); outputTypes["summary"].push_back(outputSummaryFile); ofstream outName; - string outputNameFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + getOutputFileNameTag("name"); + string outputNameFile = getOutputFileName("name",variables); m->openOutputFile(outputNameFile, outName); outputNames.push_back(outputNameFile); outputTypes["name"].push_back(outputNameFile); ofstream outFasta; - string outputFastaFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + getOutputFileNameTag("fasta"); + string outputFastaFile = getOutputFileName("fasta",variables); m->openOutputFile(outputFastaFile, outFasta); outputNames.push_back(outputFastaFile); outputTypes["fasta"].push_back(outputFastaFile); diff --git a/consensusseqscommand.h b/consensusseqscommand.h index e0c9715..a69ddbf 100644 --- a/consensusseqscommand.h +++ b/consensusseqscommand.h @@ -24,8 +24,9 @@ public: vector setParameters(); string getCommandName() { return "consensus.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Consensus.seqs"; } string getDescription() { return "create a consensus sequence for each OTU or for a fasta file"; } diff --git a/cooccurrencecommand.cpp b/cooccurrencecommand.cpp index ef8c9ed..78be06f 100644 --- a/cooccurrencecommand.cpp +++ b/cooccurrencecommand.cpp @@ -12,14 +12,14 @@ //********************************************************************************************************************** vector CooccurrenceCommand::setParameters() { try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter pmetric("metric", "Multiple", "cscore-checker-combo-vratio", "cscore", "", "", "",false,false); parameters.push_back(pmetric); - CommandParameter pmatrix("matrixmodel", "Multiple", "sim1-sim2-sim3-sim4-sim5-sim6-sim7-sim8-sim9", "sim2", "", "", "",false,false); parameters.push_back(pmatrix); - CommandParameter pruns("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(pruns); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","summary",false,true,true); parameters.push_back(pshared); + CommandParameter pmetric("metric", "Multiple", "cscore-checker-combo-vratio", "cscore", "", "", "","",false,false); parameters.push_back(pmetric); + CommandParameter pmatrix("matrixmodel", "Multiple", "sim1-sim2-sim3-sim4-sim5-sim6-sim7-sim8-sim9", "sim2", "", "", "","",false,false); parameters.push_back(pmatrix); + CommandParameter pruns("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(pruns); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -51,24 +51,19 @@ string CooccurrenceCommand::getHelpString(){ } } //********************************************************************************************************************** -string CooccurrenceCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string CooccurrenceCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "summary") { outputFileName = "cooccurence.summary"; } - 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, "CooccurrenceCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "summary") { pattern = "[filename],cooccurence.summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "CooccurrenceCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** CooccurrenceCommand::CooccurrenceCommand(){ @@ -196,7 +191,9 @@ int CooccurrenceCommand::execute(){ set userLabels = labels; ofstream out; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + string outputFileName = getOutputFileName("summary", variables); m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["summary"].push_back(outputFileName); out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); diff --git a/cooccurrencecommand.h b/cooccurrencecommand.h index 0820919..758a9ff 100644 --- a/cooccurrencecommand.h +++ b/cooccurrencecommand.h @@ -28,8 +28,9 @@ public: vector setParameters(); string getCommandName() { return "Cooccurrence"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Ulrich W & Gotelli NJ (2010). Null model analysis of species associations using abundance data. Ecology 91:3384.\nhttp://www.mothur.org/wiki/Cooccurrence"; } string getDescription() { return "calculates four metrics and tests their significance to assess whether presence-absence patterns are different than what one would expect by chance."; } diff --git a/corraxescommand.cpp b/corraxescommand.cpp index c4454a5..853c174 100644 --- a/corraxescommand.cpp +++ b/corraxescommand.cpp @@ -14,16 +14,16 @@ //********************************************************************************************************************** vector CorrAxesCommand::setParameters(){ try { - CommandParameter paxes("axes", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paxes); - CommandParameter pshared("shared", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none",false,false); parameters.push_back(pshared); - CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none",false,false); parameters.push_back(prelabund); - CommandParameter pmetadata("metadata", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none",false,false); parameters.push_back(pmetadata); - CommandParameter pnumaxes("numaxes", "Number", "", "3", "", "", "",false,false); parameters.push_back(pnumaxes); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pmethod("method", "Multiple", "pearson-spearman-kendall", "pearson", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter paxes("axes", "InputTypes", "", "", "none", "none", "none","corraxes",false,true,true); parameters.push_back(paxes); + CommandParameter pshared("shared", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none","",false,false,true); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none","",false,false,true); parameters.push_back(prelabund); + CommandParameter pmetadata("metadata", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none","",false,false); parameters.push_back(pmetadata); + CommandParameter pnumaxes("numaxes", "Number", "", "3", "", "", "","",false,false); parameters.push_back(pnumaxes); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter pmethod("method", "Multiple", "pearson-spearman-kendall", "pearson", "", "", "","",false,false); parameters.push_back(pmethod); + 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); } @@ -56,25 +56,21 @@ string CorrAxesCommand::getHelpString(){ } } //********************************************************************************************************************** -string CorrAxesCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string CorrAxesCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "corraxes") { outputFileName = "corr.axes"; } - 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, "CorrAxesCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "corraxes") { pattern = "[filename],[tag],corr.axes"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "CorrAxesCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** CorrAxesCommand::CorrAxesCommand(){ try { @@ -285,8 +281,10 @@ int CorrAxesCommand::execute(){ /*************************************************************************************/ // calc the r values // /************************************************************************************/ - - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + method + "." + getOutputFileNameTag("corraxes"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); + variables["[tag]"] = method; + string outputFileName = getOutputFileName("corraxes", variables); outputNames.push_back(outputFileName); outputTypes["corraxes"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/corraxescommand.h b/corraxescommand.h index 067228f..a91a240 100644 --- a/corraxescommand.h +++ b/corraxescommand.h @@ -24,8 +24,9 @@ public: vector setParameters(); string getCommandName() { return "corr.axes"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "McCune B, Grace JB, Urban DL (2002). Analysis of ecological communities. MjM Software Design: Gleneden Beach, OR. \nLegendre P, Legendre L (1998). Numerical Ecology. Elsevier: New York. \nhttp://www.mothur.org/wiki/Corr.axes"; } string getDescription() { return "calculate the correlation coefficient for each column in a shared/relabund file to the axes displayed in a pcoa file"; } diff --git a/countgroupscommand.cpp b/countgroupscommand.cpp index 716dc90..215c2e5 100644 --- a/countgroupscommand.cpp +++ b/countgroupscommand.cpp @@ -14,13 +14,13 @@ //********************************************************************************************************************** vector CountGroupsCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "sharedGroup", "sharedGroup", "none",false,false); parameters.push_back(pshared); - CommandParameter pgroup("group", "InputTypes", "", "", "sharedGroup", "sharedGroup", "none",false,false); parameters.push_back(pgroup); - CommandParameter pcount("count", "InputTypes", "", "", "sharedGroup", "sharedGroup", "none",false,false); parameters.push_back(pcount); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "sharedGroup", "sharedGroup", "none","",false,false,true); parameters.push_back(pshared); + CommandParameter pgroup("group", "InputTypes", "", "", "sharedGroup", "sharedGroup", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pcount("count", "InputTypes", "", "", "sharedGroup", "sharedGroup", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } diff --git a/countgroupscommand.h b/countgroupscommand.h index d27a7f8..1ab83c8 100644 --- a/countgroupscommand.h +++ b/countgroupscommand.h @@ -23,8 +23,8 @@ public: vector setParameters(); string getCommandName() { return "count.groups"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); + string getOutputPattern(string){ return ""; } string getCitation() { return "http://www.mothur.org/wiki/Count.groups"; } string getDescription() { return "counts the number of sequences in each group"; } diff --git a/countseqscommand.cpp b/countseqscommand.cpp index e4aa253..3bafbcd 100644 --- a/countseqscommand.cpp +++ b/countseqscommand.cpp @@ -15,12 +15,12 @@ //********************************************************************************************************************** vector CountSeqsCommand::setParameters(){ try { - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pname); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter plarge("large", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(plarge); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","count",false,true,true); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter plarge("large", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(plarge); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -50,24 +50,19 @@ string CountSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string CountSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string CountSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "counttable") { outputFileName = "count_table"; } - 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, "CountSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "count") { pattern = "[filename],count_table"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "CountSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** CountSeqsCommand::CountSeqsCommand(){ @@ -75,7 +70,7 @@ CountSeqsCommand::CountSeqsCommand(){ abort = true; calledHelp = true; setParameters(); vector tempOutNames; - outputTypes["counttable"] = tempOutNames; + outputTypes["count"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "CountSeqsCommand", "CountSeqsCommand"); @@ -107,7 +102,7 @@ CountSeqsCommand::CountSeqsCommand(string option) { //initialize outputTypes vector tempOutNames; - outputTypes["counttable"] = tempOutNames; + outputTypes["count"] = tempOutNames; //if the user changes the input directory command factory will send this info to us in the output parameter @@ -171,7 +166,9 @@ int CountSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("counttable"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(namefile)); + string outputFileName = getOutputFileName("count", variables); int total = 0; if (!large) { total = processSmall(outputFileName); } @@ -180,7 +177,7 @@ int CountSeqsCommand::execute(){ if (m->control_pressed) { m->mothurRemove(outputFileName); return 0; } //set rabund file as new current rabundfile - itTypes = outputTypes.find("counttable"); + itTypes = outputTypes.find("count"); if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { string current = (itTypes->second)[0]; m->setCountTableFile(current); } } @@ -205,8 +202,8 @@ int CountSeqsCommand::execute(){ int CountSeqsCommand::processSmall(string outputFileName){ try { ofstream out; - m->openOutputFile(outputFileName, out); outputTypes["counttable"].push_back(outputFileName); - outputNames.push_back(outputFileName); outputTypes["counttable"].push_back(outputFileName); + m->openOutputFile(outputFileName, out); outputTypes["count"].push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["count"].push_back(outputFileName); out << "Representative_Sequence\ttotal\t"; GroupMap* groupMap; @@ -299,7 +296,7 @@ int CountSeqsCommand::processLarge(string outputFileName){ for (set::iterator it = namesOfGroups.begin(); it != namesOfGroups.end(); it++) { initial[(*it)] = 0; } ofstream out; m->openOutputFile(outputFileName, out); - outputNames.push_back(outputFileName); outputTypes["counttable"].push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["count"].push_back(outputFileName); out << "Representative_Sequence\ttotal\t"; if (groupfile == "") { out << endl; } diff --git a/countseqscommand.h b/countseqscommand.h index 555d6a7..b4170a8 100644 --- a/countseqscommand.h +++ b/countseqscommand.h @@ -23,8 +23,9 @@ public: vector setParameters(); string getCommandName() { return "count.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Count.seqs"; } string getDescription() { return "counts the number of sequences represented by each unique sequence in a namesfile"; } diff --git a/createdatabasecommand.cpp b/createdatabasecommand.cpp index 4331c29..5121139 100644 --- a/createdatabasecommand.cpp +++ b/createdatabasecommand.cpp @@ -12,15 +12,15 @@ //********************************************************************************************************************** vector CreateDatabaseCommand::setParameters(){ try { - CommandParameter pfasta("repfasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("repname", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pname); - CommandParameter pcontaxonomy("contaxonomy", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pcontaxonomy); - CommandParameter plist("list", "InputTypes", "", "", "ListShared", "ListShared", "none",false,false); parameters.push_back(plist); - CommandParameter pshared("shared", "InputTypes", "", "", "ListShared", "ListShared", "none",false,false); parameters.push_back(pshared); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); - 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); + CommandParameter pfasta("repfasta", "InputTypes", "", "", "none", "none", "none","database",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("repname", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pname); + CommandParameter pcontaxonomy("contaxonomy", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pcontaxonomy); + CommandParameter plist("list", "InputTypes", "", "", "ListShared", "ListShared", "none","",false,false,true); parameters.push_back(plist); + CommandParameter pshared("shared", "InputTypes", "", "", "ListShared", "ListShared", "none","",false,false,true); parameters.push_back(pshared); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pgroup); + 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); } @@ -55,26 +55,20 @@ string CreateDatabaseCommand::getHelpString(){ } } //********************************************************************************************************************** -string CreateDatabaseCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string CreateDatabaseCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "database") { outputFileName = "database"; } - 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, "CreateDatabaseCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "database") { pattern = "[filename],database"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "CreateDatabaseCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** CreateDatabaseCommand::CreateDatabaseCommand(){ try { @@ -281,9 +275,10 @@ int CreateDatabaseCommand::execute(){ if (m->control_pressed) { return 0; } - string outputFileName = ""; - if (listfile != "") { outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("database"); } - else { outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("database"); } + map variables; + if (listfile != "") { variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); } + else { variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); } + string outputFileName = getOutputFileName("database", variables); outputNames.push_back(outputFileName); outputTypes["database"].push_back(outputFileName); ofstream out; diff --git a/createdatabasecommand.h b/createdatabasecommand.h index 741feba..ca47b7a 100644 --- a/createdatabasecommand.h +++ b/createdatabasecommand.h @@ -22,8 +22,9 @@ public: vector setParameters(); string getCommandName() { return "create.database"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Create.database"; } string getDescription() { return "creates database file that includes, abundances across groups, representative sequences, and taxonomy for each OTU"; } diff --git a/deconvolutecommand.cpp b/deconvolutecommand.cpp index 90a40ce..f33a140 100644 --- a/deconvolutecommand.cpp +++ b/deconvolutecommand.cpp @@ -13,11 +13,11 @@ //********************************************************************************************************************** vector DeconvoluteCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta-name",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","count",false,false,true); parameters.push_back(pcount); + 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); } @@ -46,27 +46,23 @@ string DeconvoluteCommand::getHelpString(){ } } //********************************************************************************************************************** -string DeconvoluteCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string DeconvoluteCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "unique" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "names"; } - else if (type == "count") { outputFileName = "count_table"; } - 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, "DeconvoluteCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],unique,[extension]"; } + else if (type == "name") { pattern = "[filename],names-[filename],[tag],names"; } + else if (type == "count") { pattern = "[filename],count_table-[filename],[tag],count_table"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "DeconvoluteCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** DeconvoluteCommand::DeconvoluteCommand(){ try { @@ -192,20 +188,27 @@ int DeconvoluteCommand::execute() { if (abort == true) { if (calledHelp) { return 0; } return 2; } //prepare filenames and open files - string outNameFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + getOutputFileNameTag("name"); - string outCountFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + getOutputFileNameTag("count"); - string outFastaFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + getOutputFileNameTag("fasta", inFastaName); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inFastaName)); + string outNameFile = getOutputFileName("name", variables); + string outCountFile = getOutputFileName("count", variables); + variables["[extension]"] = m->getExtension(inFastaName); + string outFastaFile = getOutputFileName("fasta", variables); map nameMap; map::iterator itNames; if (oldNameMapFName != "") { m->readNames(oldNameMapFName, nameMap); - if (oldNameMapFName == outNameFile){ outNameFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + "unique." + getOutputFileNameTag("name"); } + if (oldNameMapFName == outNameFile){ + variables["[tag]"] = "unique"; + outNameFile = getOutputFileName("name", variables); } } CountTable ct; if (countfile != "") { ct.readTable(countfile); - if (countfile == outCountFile){ outCountFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + "unique." + getOutputFileNameTag("count"); } + if (countfile == outCountFile){ + variables["[tag]"] = "unique"; + outCountFile = getOutputFileName("count", variables); } } if (m->control_pressed) { return 0; } diff --git a/deconvolutecommand.h b/deconvolutecommand.h index 673ffc9..e514bda 100644 --- a/deconvolutecommand.h +++ b/deconvolutecommand.h @@ -27,8 +27,9 @@ public: vector setParameters(); string getCommandName() { return "unique.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Unique.seqs"; } string getDescription() { return "creates a fasta containing the unique sequences as well as a namesfile with the names each sequence represents"; } diff --git a/degapseqscommand.cpp b/degapseqscommand.cpp index 095eef3..8687194 100644 --- a/degapseqscommand.cpp +++ b/degapseqscommand.cpp @@ -13,9 +13,9 @@ //********************************************************************************************************************** vector DegapSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + 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); } @@ -46,24 +46,19 @@ string DegapSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string DegapSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string DegapSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "ng.fasta"; } - 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, "DegapSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],ng.fasta"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "DegapSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** DegapSeqsCommand::DegapSeqsCommand(){ @@ -213,7 +208,9 @@ int DegapSeqsCommand::execute(){ ofstream outFASTA; string tempOutputDir = outputDir; if (outputDir == "") { tempOutputDir = m->hasPath(fastaFileNames[s]); } - string degapFile = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])); + string degapFile = getOutputFileName("fasta", variables); m->openOutputFile(degapFile, outFASTA); while(!inFASTA.eof()){ diff --git a/degapseqscommand.h b/degapseqscommand.h index c6adac2..3b03c9b 100644 --- a/degapseqscommand.h +++ b/degapseqscommand.h @@ -22,8 +22,9 @@ public: vector setParameters(); string getCommandName() { return "degap.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Degap.seqs"; } string getDescription() { return "removes gap characters from sequences"; } diff --git a/deuniqueseqscommand.cpp b/deuniqueseqscommand.cpp index 918079c..f72a7c9 100644 --- a/deuniqueseqscommand.cpp +++ b/deuniqueseqscommand.cpp @@ -13,10 +13,10 @@ //********************************************************************************************************************** vector DeUniqueSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pname); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,true,true); 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); } @@ -45,24 +45,19 @@ string DeUniqueSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string DeUniqueSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string DeUniqueSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "redundant.fasta"; } - 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, "DeUniqueSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],redundant.fasta"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "DeUniqueSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** DeUniqueSeqsCommand::DeUniqueSeqsCommand(){ @@ -167,11 +162,11 @@ int DeUniqueSeqsCommand::execute() { ofstream out; string outFastaFile = m->getRootName(m->getSimpleName(fastaFile)); int pos = outFastaFile.find("unique"); - if (pos != string::npos) { - outFastaFile = outputDir + outFastaFile.substr(0, pos) + getOutputFileNameTag("fasta"); - }else{ - outFastaFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + getOutputFileNameTag("fasta"); - } + if (pos != string::npos) { outFastaFile = outputDir + outFastaFile.substr(0, pos); } + else { outFastaFile = outputDir + outFastaFile; } + map variables; + variables["[filename]"] = outFastaFile; + outFastaFile = getOutputFileName("fasta", variables); m->openOutputFile(outFastaFile, out); readNamesFile(); diff --git a/deuniqueseqscommand.h b/deuniqueseqscommand.h index 5310b83..a6d467a 100644 --- a/deuniqueseqscommand.h +++ b/deuniqueseqscommand.h @@ -23,8 +23,9 @@ public: vector setParameters(); string getCommandName() { return "deunique.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Deunique.seqs"; } string getDescription() { return "reverse of the unique.seqs command, and creates a fasta file from a fasta and name file"; } diff --git a/deuniquetreecommand.cpp b/deuniquetreecommand.cpp index d334f8f..703e75f 100644 --- a/deuniquetreecommand.cpp +++ b/deuniquetreecommand.cpp @@ -13,10 +13,10 @@ //********************************************************************************************************************** vector DeuniqueTreeCommand::setParameters(){ try { - CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); - 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); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","tree",false,true,true); parameters.push_back(ptree); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,true,true); 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); } @@ -43,24 +43,19 @@ string DeuniqueTreeCommand::getHelpString(){ } } //********************************************************************************************************************** -string DeuniqueTreeCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string DeuniqueTreeCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "tree") { outputFileName = "deunique.tre"; } - 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, "DeuniqueTreeCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "tree") { pattern = "[filename],deunique.tre"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "DeuniqueTreeCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** DeuniqueTreeCommand::DeuniqueTreeCommand(){ @@ -166,7 +161,9 @@ int DeuniqueTreeCommand::execute() { delete reader; //print new Tree - string outputFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("tree"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile)); + string outputFile = getOutputFileName("tree", variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); ofstream out; m->openOutputFile(outputFile, out); diff --git a/deuniquetreecommand.h b/deuniquetreecommand.h index afb25a4..849b3d7 100644 --- a/deuniquetreecommand.h +++ b/deuniquetreecommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "deunique.tree"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Deunique.tree"; } string getDescription() { return "add the redundant sequence names back into a tree of unique sequences"; } diff --git a/distancecommand.cpp b/distancecommand.cpp index 2a4398b..73a38bf 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -12,17 +12,17 @@ //********************************************************************************************************************** vector DistanceCommand::setParameters(){ try { - CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "OldFastaColumn",false,false); parameters.push_back(pcolumn); - CommandParameter poldfasta("oldfasta", "InputTypes", "", "", "none", "none", "OldFastaColumn",false,false); parameters.push_back(poldfasta); - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter poutput("output", "Multiple", "column-lt-square-phylip", "column", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter pcalc("calc", "Multiple", "nogaps-eachgap-onegap", "onegap", "", "", "",false,false); parameters.push_back(pcalc); - CommandParameter pcountends("countends", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pcountends); - CommandParameter pcompress("compress", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pcompress); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pcutoff("cutoff", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "OldFastaColumn","column",false,false); parameters.push_back(pcolumn); + CommandParameter poldfasta("oldfasta", "InputTypes", "", "", "none", "none", "OldFastaColumn","",false,false); parameters.push_back(poldfasta); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","phylip-column",false,true, true); parameters.push_back(pfasta); + CommandParameter poutput("output", "Multiple", "column-lt-square-phylip", "column", "", "", "","phylip-column",false,false, true); parameters.push_back(poutput); + CommandParameter pcalc("calc", "Multiple", "nogaps-eachgap-onegap", "onegap", "", "", "","",false,false); parameters.push_back(pcalc); + CommandParameter pcountends("countends", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pcountends); + CommandParameter pcompress("compress", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pcompress); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false, true); parameters.push_back(pprocessors); + CommandParameter pcutoff("cutoff", "Number", "", "1.0", "", "", "","",false,false, true); parameters.push_back(pcutoff); + 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); } @@ -59,25 +59,20 @@ string DistanceCommand::getHelpString(){ } } //********************************************************************************************************************** -string DistanceCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string DistanceCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "phylip") { outputFileName = "dist"; } - else if (type == "column") { outputFileName = "dist"; } - 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, "DistanceCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "phylip") { pattern = "[filename],[outputtag],dist"; } + else if (type == "column") { pattern = "[filename],dist"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "DistanceCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** DistanceCommand::DistanceCommand(){ @@ -249,14 +244,17 @@ int DistanceCommand::execute(){ if (!alignDB.sameLength()) { m->mothurOut("[ERROR]: your sequences are not the same length, aborting."); m->mothurOutEndLine(); return 0; } string outputFile; - + + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); if (output == "lt") { //does the user want lower triangle phylip formatted file - outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "phylip." + getOutputFileNameTag("phylip"); + variables["[outputtag]"] = "phylip"; + outputFile = getOutputFileName("phylip", variables); m->mothurRemove(outputFile); outputTypes["phylip"].push_back(outputFile); //output numSeqs to phylip formatted dist file }else if (output == "column") { //user wants column format - outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("column"); + outputFile = getOutputFileName("column", variables); outputTypes["column"].push_back(outputFile); //so we don't accidentally overwrite @@ -267,7 +265,8 @@ int DistanceCommand::execute(){ m->mothurRemove(outputFile); }else { //assume square - outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "square." + getOutputFileNameTag("phylip"); + variables["[outputtag]"] = "square"; + outputFile = getOutputFileName("phylip", variables); m->mothurRemove(outputFile); outputTypes["phylip"].push_back(outputFile); } diff --git a/distancecommand.h b/distancecommand.h index 9dea351..ddce044 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -178,8 +178,9 @@ public: vector setParameters(); string getCommandName() { return "dist.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD (2010). The effects of alignment quality, distance calculation method, sequence filtering, and region on the analysis of 16S rRNA gene-based studies. PLoS Comput Biol 6: e1000844. \nhttp://www.mothur.org/wiki/Dist.seqs"; } string getDescription() { return "calculate the pairwaise distances between aligned sequences"; } diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index 7a8fbc8..f6ca479 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -14,14 +14,14 @@ //********************************************************************************************************************** vector FilterSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter phard("hard", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(phard); - CommandParameter ptrump("trump", "String", "", "*", "", "", "",false,false); parameters.push_back(ptrump); - CommandParameter psoft("soft", "Number", "", "0", "", "", "",false,false); parameters.push_back(psoft); - CommandParameter pvertical("vertical", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pvertical); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta-filter",false,true, true); parameters.push_back(pfasta); + CommandParameter phard("hard", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(phard); + CommandParameter ptrump("trump", "String", "", "*", "", "", "","",false,false, true); parameters.push_back(ptrump); + CommandParameter psoft("soft", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psoft); + CommandParameter pvertical("vertical", "Boolean", "", "T", "", "", "","",false,false, true); parameters.push_back(pvertical); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false, true); parameters.push_back(pprocessors); + 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); } @@ -57,25 +57,20 @@ string FilterSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string FilterSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string FilterSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "filter.fasta"; } - else if (type == "filter") { outputFileName = "filter"; } - 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, "FilterSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],filter.fasta"; } + else if (type == "filter") { pattern = "[filename],filter"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "FilterSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** FilterSeqsCommand::FilterSeqsCommand(){ @@ -298,9 +293,10 @@ int FilterSeqsCommand::execute() { ofstream outFilter; //prevent giantic file name - string filterFile; - if (fastafileNames.size() > 3) { filterFile = outputDir + "merge." + getOutputFileNameTag("filter"); } - else { filterFile = outputDir + filterFileName + "." + getOutputFileNameTag("filter"); } + map variables; + variables["[filename]"] = outputDir + filterFileName + "."; + if (fastafileNames.size() > 3) { variables["[filename]"] = outputDir + "merge."; } + string filterFile = getOutputFileName("filter", variables); m->openOutputFile(filterFile, outFilter); outFilter << filter << endl; @@ -363,7 +359,9 @@ int FilterSeqsCommand::filterSequences() { for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); - string filteredFasta = outputDir + m->getRootName(m->getSimpleName(fastafileNames[s])) + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafileNames[s])); + string filteredFasta = getOutputFileName("fasta", variables); #ifdef USE_MPI int pid, numSeqsPerProcessor, num; int tag = 2001; diff --git a/filterseqscommand.h b/filterseqscommand.h index b232237..fc6bcb2 100644 --- a/filterseqscommand.h +++ b/filterseqscommand.h @@ -24,8 +24,9 @@ public: vector setParameters(); string getCommandName() { return "filter.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Filter.seqs"; } string getDescription() { return "removes columns from alignments based on a criteria defined by the user"; } diff --git a/getcommandinfocommand.cpp b/getcommandinfocommand.cpp index 03c6b17..b61236d 100644 --- a/getcommandinfocommand.cpp +++ b/getcommandinfocommand.cpp @@ -12,9 +12,9 @@ //********************************************************************************************************************** vector GetCommandInfoCommand::setParameters(){ try { - CommandParameter poutput("output", "String", "", "", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter poutput("output", "String", "", "", "", "", "","",false,false); parameters.push_back(poutput); + 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); } @@ -127,13 +127,17 @@ int GetCommandInfoCommand::execute(){ map > thisOutputTypes = thisCommand->getOutputFiles(); map >::iterator itTypes; - if (thisOutputTypes.size() == 0) { out << "outputTypes=none" << endl; } + if (thisOutputTypes.size() == 0) { out << "outputTypesNames=0" << endl; } else { - string types = ""; - for (itTypes = thisOutputTypes.begin(); itTypes != thisOutputTypes.end(); itTypes++) { types += itTypes->first + "-"; } + //string types = ""; + //for (itTypes = thisOutputTypes.begin(); itTypes != thisOutputTypes.end(); itTypes++) { types += itTypes->first + "-"; } //rip off last - - types = types.substr(0, types.length()-1); - out << "outputTypes=" << types << endl; + //types = types.substr(0, types.length()-1); + out << "outputTypesNames=" << thisOutputTypes.size() << endl; + + for (itTypes = thisOutputTypes.begin(); itTypes != thisOutputTypes.end(); itTypes++) { + out << itTypes->first << "=" << thisCommand->getOutputPattern(itTypes->first) << endl; + } } vector booleans; vector numbers; vector multiples; vector Strings; @@ -212,34 +216,54 @@ int GetCommandInfoCommand::getInfo(vector para, vector for (int i = 0; i < para.size(); i++) { if ((para[i].name == "inputdir") || (para[i].name == "outputdir")) {} //ignore else { + string important = "|F"; + if (para[i].important || para[i].required) { important = "|T"; } + + string outputType = "|none"; + if (para[i].outputTypes != "") { outputType = "|" + para[i].outputTypes; } + if (para[i].type == "Boolean") { - string temp = para[i].name + "=" + para[i].optionsDefault; + string temp = para[i].name + "=" + para[i].optionsDefault + important + outputType; booleans.push_back(temp); }else if (para[i].type == "Multiple") { string multAllowed = "F"; if (para[i].multipleSelectionAllowed) { multAllowed = "T"; } - string temp = para[i].name + "=" + para[i].options + "|" + para[i].optionsDefault + "|" + multAllowed; + string temp = para[i].name + "=" + para[i].options + "|" + para[i].optionsDefault + "|" + multAllowed + important + outputType; multiples.push_back(temp); }else if (para[i].type == "Number") { - string temp = para[i].name + "=" + para[i].optionsDefault; + string temp = para[i].name + "=" + para[i].optionsDefault + important + outputType; numbers.push_back(temp); }else if (para[i].type == "String") { - string temp = para[i].name + "=" + para[i].optionsDefault; + string temp = para[i].name + "=" + para[i].optionsDefault + important + outputType; strings.push_back(temp); }else if (para[i].type == "InputTypes") { string required = "F"; if (para[i].required) { required = "T"; } - string temp = required + "|" + para[i].chooseOnlyOneGroup + "|" + para[i].chooseAtLeastOneGroup + "|" + para[i].linkedGroup; + string temp = required + important + "|" + para[i].chooseOnlyOneGroup + "|" + para[i].chooseAtLeastOneGroup + "|" + para[i].linkedGroup + outputType; inputTypes[para[i].name] = temp; //add choose only one groups - groups[para[i].chooseOnlyOneGroup].insert(para[i].name); - + vector tempGroups; + m->splitAtDash(para[i].chooseOnlyOneGroup, tempGroups); + for (int l = 0; l < tempGroups.size(); l++) { + groups[tempGroups[l]].insert(para[i].name); + } + tempGroups.clear(); + //add at least one group names - groups[para[i].chooseAtLeastOneGroup].insert(para[i].name); + m->splitAtDash(para[i].chooseAtLeastOneGroup, tempGroups); + for (int l = 0; l < tempGroups.size(); l++) { + groups[tempGroups[l]].insert(para[i].name); + } + tempGroups.clear(); + //add at linked group names - groups[para[i].linkedGroup].insert(para[i].name); + m->splitAtDash(para[i].linkedGroup, tempGroups); + for (int l = 0; l < tempGroups.size(); l++) { + groups[tempGroups[l]].insert(para[i].name); + } + tempGroups.clear(); }else { m->mothurOut("[ERROR]: " + para[i].type + " is an unknown parameter type, please correct."); m->mothurOutEndLine(); } } diff --git a/getcommandinfocommand.h b/getcommandinfocommand.h index b72c236..46ff78b 100644 --- a/getcommandinfocommand.h +++ b/getcommandinfocommand.h @@ -27,8 +27,8 @@ public: vector setParameters(); string getCommandName() { return "get.commandinfo"; } string getCommandCategory() { return "Hidden"; } - string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); + string getOutputPattern(string) { return ""; } string getCitation() { return "no citation"; } string getDescription() { return "get.commandinfo"; } diff --git a/getcoremicrobiomecommand.cpp b/getcoremicrobiomecommand.cpp index 3cc77be..5fbb781 100644 --- a/getcoremicrobiomecommand.cpp +++ b/getcoremicrobiomecommand.cpp @@ -12,15 +12,15 @@ //********************************************************************************************************************** vector GetCoreMicroBiomeCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(pshared); - CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(prelabund); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter poutput("output", "Multiple", "fraction-count", "fraction", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter pabund("abundance", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pabund); - CommandParameter psamples("samples", "Number", "", "-1", "", "", "",false,false); parameters.push_back(psamples); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "SharedRel", "SharedRel", "none","coremicrobiom",false,false, true); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRel", "SharedRel", "none","coremicrobiom",false,false, true); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter poutput("output", "Multiple", "fraction-count", "fraction", "", "", "","",false,false); parameters.push_back(poutput); + CommandParameter pabund("abundance", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pabund); + CommandParameter psamples("samples", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(psamples); + 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); } @@ -52,26 +52,20 @@ string GetCoreMicroBiomeCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetCoreMicroBiomeCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetCoreMicroBiomeCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "coremicrobiome") { outputFileName = "core.microbiome"; } - 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, "GetCoreMicroBiomeCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "coremicrobiome") { pattern = "[filename],[tag],core.microbiome"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetCoreMicroBiomeCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** GetCoreMicroBiomeCommand::GetCoreMicroBiomeCommand(){ try { @@ -307,8 +301,10 @@ int GetCoreMicroBiomeCommand::execute(){ int GetCoreMicroBiomeCommand::createTable(vector& lookup){ try { - - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("coremicrobiome"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); + variables["[tag]"] = lookup[0]->getLabel(); + string outputFileName = getOutputFileName("coremicrobiome", variables); outputNames.push_back(outputFileName); outputTypes["coremicrobiome"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/getcoremicrobiomecommand.h b/getcoremicrobiomecommand.h index 469214c..80def83 100644 --- a/getcoremicrobiomecommand.h +++ b/getcoremicrobiomecommand.h @@ -26,8 +26,9 @@ public: string getCommandName() { return "get.coremicrobiome"; } string getCommandCategory() { return "OTU-Based Approaches"; } //commmand category choices: Sequence Processing, OTU-Based Approaches, Hypothesis Testing, Phylotype Analysis, General, Clustering and Hidden - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.coremicrobiome"; } string getDescription() { return "determines the fraction of OTUs that are found in varying numbers of samples for different minimum relative abundances"; } diff --git a/getcurrentcommand.cpp b/getcurrentcommand.cpp index 86046b6..f73b560 100644 --- a/getcurrentcommand.cpp +++ b/getcurrentcommand.cpp @@ -12,9 +12,9 @@ //********************************************************************************************************************** vector GetCurrentCommand::setParameters(){ try { - CommandParameter pclear("clear", "String", "", "", "", "", "",false,false); parameters.push_back(pclear); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pclear("clear", "String", "", "", "", "", "","",false,false); parameters.push_back(pclear); + 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); } diff --git a/getcurrentcommand.h b/getcurrentcommand.h index f10e6d4..2d8dbb1 100644 --- a/getcurrentcommand.h +++ b/getcurrentcommand.h @@ -22,8 +22,8 @@ class GetCurrentCommand : public Command { vector setParameters(); string getCommandName() { return "get.current"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); + string getOutputPattern(string) { return ""; } string getCitation() { return "http://www.mothur.org/wiki/Get.current"; } string getDescription() { return "get current files saved by mothur"; } diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index b92924c..529ed93 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -13,9 +13,9 @@ //********************************************************************************************************************** vector GetgroupCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none","",false,true, true); parameters.push_back(pshared); + 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); } diff --git a/getgroupcommand.h b/getgroupcommand.h index 7924d7b..fb438df 100644 --- a/getgroupcommand.h +++ b/getgroupcommand.h @@ -21,8 +21,8 @@ public: vector setParameters(); string getCommandName() { return "get.group"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); + string getOutputPattern(string) { return ""; } string getCitation() { return "http://www.mothur.org/wiki/Get.group"; } string getDescription() { return "outputs group names"; } diff --git a/getgroupscommand.cpp b/getgroupscommand.cpp index 69f4403..e4f7450 100644 --- a/getgroupscommand.cpp +++ b/getgroupscommand.cpp @@ -16,18 +16,18 @@ //********************************************************************************************************************** vector GetGroupsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "FNGLT",false,false); parameters.push_back(pfasta); - CommandParameter pshared("shared", "InputTypes", "", "", "none", "sharedGroup", "none",false,false); parameters.push_back(pshared); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "sharedGroup", "FNGLT",false,false); parameters.push_back(pgroup); - CommandParameter pdesign("design", "InputTypes", "", "", "none", "sharedGroup", "FNGLT",false,false); parameters.push_back(pdesign); - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "FNGLT",false,false); parameters.push_back(plist); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "FNGLT",false,false); parameters.push_back(ptaxonomy); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "FNGLT","fasta",false,false, true); parameters.push_back(pfasta); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "sharedGroup", "none","shared",false,false, true); parameters.push_back(pshared); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","name",false,false, true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false, true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "sharedGroup", "FNGLT","group",false,false, true); parameters.push_back(pgroup); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "sharedGroup", "FNGLT","design",false,false, true); parameters.push_back(pdesign); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "FNGLT","list",false,false, true); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "FNGLT","taxonomy",false,false, true); parameters.push_back(ptaxonomy); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -59,33 +59,27 @@ string GetGroupsCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetGroupsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetGroupsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "taxonomy") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "pick.count_table"; } - else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "shared") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "design") { outputFileName = "pick" + m->getExtension(inputName); } - 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, "GetGroupsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],pick,[extension]"; } + else if (type == "taxonomy") { pattern = "[filename],pick,[extension]"; } + else if (type == "name") { pattern = "[filename],pick,[extension]"; } + else if (type == "group") { pattern = "[filename],pick,[extension]"; } + else if (type == "count") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "shared") { pattern = "[filename],[tag],pick,[extension]"; } + else if (type == "design") { pattern = "[filename],pick,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetGroupsCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** GetGroupsCommand::GetGroupsCommand(){ try { @@ -467,7 +461,10 @@ int GetGroupsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[extension]"] = m->getExtension(fastafile); + string outputFileName = getOutputFileName("fasta", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -530,12 +527,17 @@ int GetGroupsCommand::readShared(){ InputData input(sharedfile, "sharedfile"); vector lookup = input.getSharedRAbundVectors(); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[extension]"] = m->getExtension(sharedfile); bool wroteSomething = false; while(lookup[0] != NULL) { - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("shared", sharedfile); + variables["[tag]"] = lookup[0]->getLabel(); + string outputFileName = getOutputFileName("shared", variables); + ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); @@ -580,7 +582,10 @@ int GetGroupsCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -673,7 +678,10 @@ int GetGroupsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outputFileName = getOutputFileName("name", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -754,7 +762,10 @@ int GetGroupsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputFileName = getOutputFileName("group", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -801,7 +812,10 @@ int GetGroupsCommand::readCount(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outputFileName = getOutputFileName("count", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -877,7 +891,10 @@ int GetGroupsCommand::readDesign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(designfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + getOutputFileNameTag("design", designfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(designfile)); + variables["[extension]"] = m->getExtension(designfile); + string outputFileName = getOutputFileName("design", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -927,7 +944,11 @@ int GetGroupsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)); + variables["[extension]"] = m->getExtension(taxfile); + string outputFileName = getOutputFileName("taxonomy", variables); + ofstream out; m->openOutputFile(outputFileName, out); diff --git a/getgroupscommand.h b/getgroupscommand.h index 6bb6088..f67c365 100644 --- a/getgroupscommand.h +++ b/getgroupscommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "get.groups"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.groups"; } string getDescription() { return "gets sequences from a list, fasta, name, group, shared, design or taxonomy file from a given group or set of groups"; } diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp index 8535db3..03bf7ad 100644 --- a/getlabelcommand.cpp +++ b/getlabelcommand.cpp @@ -13,11 +13,11 @@ //********************************************************************************************************************** vector GetlabelCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); - CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); - CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false, true); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false, true); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false, true); parameters.push_back(psabund); + 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); } diff --git a/getlabelcommand.h b/getlabelcommand.h index 7a4d9b5..26ec655 100644 --- a/getlabelcommand.h +++ b/getlabelcommand.h @@ -24,8 +24,8 @@ public: vector setParameters(); string getCommandName() { return "get.label"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); + string getOutputPattern(string) { return ""; } string getCitation() { return "http://www.mothur.org/wiki/Get.label"; } string getDescription() { return "outputs labels"; } diff --git a/getlineagecommand.cpp b/getlineagecommand.cpp index 99359bd..438aa38 100644 --- a/getlineagecommand.cpp +++ b/getlineagecommand.cpp @@ -15,17 +15,17 @@ //********************************************************************************************************************** vector GetLineageCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none",false,false); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(ptaxonomy); - CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport); - CommandParameter ptaxon("taxon", "String", "", "", "", "", "",false,true); parameters.push_back(ptaxon); - CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none","fasta",false,false, true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none","name",false,false, true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none","count",false,false, true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none","group",false,false, true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none","list",false,false, true); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none","taxonomy",false,true, true); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none","alignreport",false,false); parameters.push_back(palignreport); + CommandParameter ptaxon("taxon", "String", "", "", "", "", "","",false,true, true); parameters.push_back(ptaxon); + CommandParameter pdups("dups", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pdups); + 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); } @@ -60,30 +60,25 @@ string GetLineageCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetLineageCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetLineageCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "taxonomy") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "pick.count_table"; } - else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "alignreport") { outputFileName = "pick.align.report"; } - 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, "GetLineageCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],pick,[extension]"; } + else if (type == "taxonomy") { pattern = "[filename],pick,[extension]"; } + else if (type == "name") { pattern = "[filename],pick,[extension]"; } + else if (type == "group") { pattern = "[filename],pick,[extension]"; } + else if (type == "count") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "alignreport") { pattern = "[filename],pick.align.report"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetLineageCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** GetLineageCommand::GetLineageCommand(){ @@ -362,7 +357,10 @@ int GetLineageCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[extension]"] = m->getExtension(fastafile); + string outputFileName = getOutputFileName("fasta", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -409,7 +407,10 @@ int GetLineageCommand::readCount(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outputFileName = getOutputFileName("count", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -463,7 +464,10 @@ int GetLineageCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -535,7 +539,10 @@ int GetLineageCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outputFileName = getOutputFileName("name", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -621,7 +628,10 @@ int GetLineageCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputFileName = getOutputFileName("group", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -668,7 +678,10 @@ int GetLineageCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)); + variables["[extension]"] = m->getExtension(taxfile); + string outputFileName = getOutputFileName("taxonomy", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -867,7 +880,11 @@ int GetLineageCommand::readAlign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)); + variables["[extension]"] = m->getExtension(alignfile); + string outputFileName = getOutputFileName("alignreport", variables); + ofstream out; m->openOutputFile(outputFileName, out); diff --git a/getlineagecommand.h b/getlineagecommand.h index 99bc0fa..68f974f 100644 --- a/getlineagecommand.h +++ b/getlineagecommand.h @@ -23,8 +23,9 @@ class GetLineageCommand : public Command { vector setParameters(); string getCommandName() { return "get.lineage"; } string getCommandCategory() { return "Phylotype Analysis"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.lineage"; } string getDescription() { return "gets sequences from a list, fasta, name, group, alignreport or taxonomy file from a given taxonomy or set of taxonomies"; } diff --git a/getlistcountcommand.cpp b/getlistcountcommand.cpp index b7c4f17..a4d7b83 100644 --- a/getlistcountcommand.cpp +++ b/getlistcountcommand.cpp @@ -12,11 +12,11 @@ //********************************************************************************************************************** vector GetListCountCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter parasort("sort", "Multiple", "name-otu", "otu", "", "", "",false,false); parameters.push_back(parasort); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","otu",false,true, true); parameters.push_back(plist); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter parasort("sort", "Multiple", "name-otu", "otu", "", "", "","",false,false); parameters.push_back(parasort); + 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); } @@ -49,24 +49,19 @@ string GetListCountCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetListCountCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetListCountCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "otu") { outputFileName = "otu"; } - 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, "GetListCountCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "otu") { pattern = "[filename],[tag],otu"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetListCountCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** GetListCountCommand::GetListCountCommand(){ @@ -254,7 +249,11 @@ void GetListCountCommand::process(ListVector* list) { try { string binnames; if (outputDir == "") { outputDir += m->hasPath(listfile); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + list->getLabel() + "." +getOutputFileNameTag("otu"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[tag]"] = list->getLabel(); + string outputFileName = getOutputFileName("otu", variables); + m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["otu"].push_back(outputFileName); diff --git a/getlistcountcommand.h b/getlistcountcommand.h index 629e9b9..c264556 100644 --- a/getlistcountcommand.h +++ b/getlistcountcommand.h @@ -28,8 +28,9 @@ public: string getCitation() { return "http://www.mothur.org/wiki/Get.otulist"; } string getDescription() { return "lists each OTU number and the sequence contained in that OTU"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); int execute(); void help() { m->mothurOut(getHelpString()); } diff --git a/getotulabelscommand.cpp b/getotulabelscommand.cpp index 7dc0b41..0f042c0 100644 --- a/getotulabelscommand.cpp +++ b/getotulabelscommand.cpp @@ -11,12 +11,12 @@ //********************************************************************************************************************** vector GetOtuLabelsCommand::setParameters(){ try { - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos); - CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pconstaxonomy); - CommandParameter potucorr("otucorr", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(potucorr); - CommandParameter pcorraxes("corraxes", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pcorraxes); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,true, true); parameters.push_back(paccnos); + CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "FNGLT", "none","constaxonomy",false,false, true); parameters.push_back(pconstaxonomy); + CommandParameter potucorr("otucorr", "InputTypes", "", "", "none", "FNGLT", "none","otucorr",false,false, true); parameters.push_back(potucorr); + CommandParameter pcorraxes("corraxes", "InputTypes", "", "", "none", "FNGLT", "none","corraxes",false,false, true); parameters.push_back(pcorraxes); + 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); } @@ -46,27 +46,23 @@ string GetOtuLabelsCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetOtuLabelsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetOtuLabelsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "constaxonomy") { outputFileName = "pick.taxonomy"; } - else if (type == "otucorr") { outputFileName = "pick.corr"; } - else if (type == "corraxes") { outputFileName = "pick.axes"; } - 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, "GetOtuLabelsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "constaxonomy") { pattern = "[filename],pick,[extension]"; } + else if (type == "otucorr") { pattern = "[filename],pick,[extension]"; } + else if (type == "corraxes") { pattern = "[filename],pick,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetOtuLabelsCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** GetOtuLabelsCommand::GetOtuLabelsCommand(){ try { @@ -226,7 +222,11 @@ int GetOtuLabelsCommand::readClassifyOtu(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(constaxonomyfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + getOutputFileNameTag("constaxonomy"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)); + variables["[extension]"] = m->getExtension(constaxonomyfile); + string outputFileName = getOutputFileName("constaxonomy", variables); + ofstream out; m->openOutputFile(outputFileName, out); @@ -277,7 +277,11 @@ int GetOtuLabelsCommand::readOtuAssociation(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(otucorrfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + getOutputFileNameTag("otucorr"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)); + variables["[extension]"] = m->getExtension(otucorrfile); + string outputFileName = getOutputFileName("otucorr", variables); + ofstream out; m->openOutputFile(outputFileName, out); @@ -328,7 +332,11 @@ int GetOtuLabelsCommand::readCorrAxes(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(corraxesfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + getOutputFileNameTag("corraxes"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)); + variables["[extension]"] = m->getExtension(corraxesfile); + string outputFileName = getOutputFileName("corraxes", variables); + ofstream out; m->openOutputFile(outputFileName, out); diff --git a/getotulabelscommand.h b/getotulabelscommand.h index 8cfe8b9..8ce0300 100644 --- a/getotulabelscommand.h +++ b/getotulabelscommand.h @@ -23,8 +23,9 @@ public: vector setParameters(); string getCommandName() { return "get.otulabels"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.otulabels"; } string getDescription() { return "Can be used with output from classify.otu, otu.association, or corr.axes to select specific otus."; } diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 1d26b47..b8de5a6 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -39,22 +39,22 @@ inline bool compareGroup(repStruct left, repStruct right){ //********************************************************************************************************************** vector GetOTURepCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pfasta); - CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "ColumnName",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); - CommandParameter pweighted("weighted", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pweighted); - CommandParameter psorted("sorted", "Multiple", "none-name-bin-size-group", "none", "", "", "",false,false); parameters.push_back(psorted); - CommandParameter plarge("large", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(plarge); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","name",false,true, true); parameters.push_back(plist); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,false, true); parameters.push_back(pfasta); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none","",false,false, true); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName","",false,false, true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "ColumnName","count",false,false, true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false, true); parameters.push_back(pgroup); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName","",false,false, true); parameters.push_back(pcolumn); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision); + CommandParameter pweighted("weighted", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pweighted); + CommandParameter psorted("sorted", "Multiple", "none-name-bin-size-group", "none", "", "", "","",false,false); parameters.push_back(psorted); + CommandParameter plarge("large", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(plarge); + 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); } @@ -96,26 +96,21 @@ string GetOTURepCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetOTURepCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetOTURepCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "rep.fasta"; } - else if (type == "name") { outputFileName = "rep.names"; } - else if (type == "count") { outputFileName = "rep.count_table"; } - 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, "GetOTURepCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],[tag],rep.fasta-[filename],[tag],[group],rep.fasta"; } + else if (type == "name") { pattern = "[filename],[tag],rep.names-[filename],[tag],[group],rep.names"; } + else if (type == "count") { pattern = "[filename],[tag],rep.count_table-[filename],[tag],[group],rep.count_table"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetOTURepCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** GetOTURepCommand::GetOTURepCommand(){ @@ -861,13 +856,16 @@ int GetOTURepCommand::process(ListVector* processList) { string outputNamesFile; map filehandles; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + if (Groups.size() == 0) { //you don't want to use groups - outputNamesFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "."; + variables["[tag]"] = processList->getLabel(); if (countfile == "") { - outputNamesFile += getOutputFileNameTag("name"); + outputNamesFile = getOutputFileName("name", variables); outputNames.push_back(outputNamesFile); outputTypes["name"].push_back(outputNamesFile); }else { - outputNamesFile += getOutputFileNameTag("count"); + outputNamesFile = getOutputFileName("count", variables); outputNames.push_back(outputNamesFile); outputTypes["count"].push_back(outputNamesFile); } outputNameFiles[outputNamesFile] = processList->getLabel(); @@ -877,13 +875,15 @@ int GetOTURepCommand::process(ListVector* processList) { ofstream* temp; for (int i=0; igetLabel(); + variables["[group]"] = Groups[i]; filehandles[Groups[i]] = temp; outputNamesFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." + Groups[i] + "."; if (countfile == "") { - outputNamesFile += getOutputFileNameTag("name"); + outputNamesFile = getOutputFileName("name", variables); outputNames.push_back(outputNamesFile); outputTypes["name"].push_back(outputNamesFile); }else { - outputNamesFile += getOutputFileNameTag("count"); + outputNamesFile = getOutputFileName("count", variables); outputNames.push_back(outputNamesFile); outputTypes["count"].push_back(outputNamesFile); } @@ -978,7 +978,10 @@ int GetOTURepCommand::processFastaNames(string filename, string label) { //create output file if (outputDir == "") { outputDir += m->hasPath(listfile); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + label + "." + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[tag]"] = label; + string outputFileName = getOutputFileName("fasta",variables); m->openOutputFile(outputFileName, out); vector reps; outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); diff --git a/getoturepcommand.h b/getoturepcommand.h index 3906329..a1bf3f0 100644 --- a/getoturepcommand.h +++ b/getoturepcommand.h @@ -43,8 +43,9 @@ public: vector setParameters(); string getCommandName() { return "get.oturep"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.oturep"; } string getDescription() { return "gets a representative sequence for each OTU"; } diff --git a/getotuscommand.cpp b/getotuscommand.cpp index 8d20e63..335ebc4 100644 --- a/getotuscommand.cpp +++ b/getotuscommand.cpp @@ -15,13 +15,13 @@ //********************************************************************************************************************** vector GetOtusCommand::setParameters(){ try { - CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - 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); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","group",false,true, true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","list",false,true, true); parameters.push_back(plist); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -54,25 +54,20 @@ string GetOtusCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetOtusCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetOtusCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "group") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } - 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, "GetOtusCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "group") { pattern = "[filename],[tag],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],[tag],pick,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetOtusCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** GetOtusCommand::GetOtusCommand(){ @@ -251,14 +246,20 @@ int GetOtusCommand::readListGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + label + "." + getOutputFileNameTag("list", listfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[tag]"] = label; + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); ofstream out; m->openOutputFile(outputFileName, out); string GroupOutputDir = outputDir; if (outputDir == "") { GroupOutputDir += m->hasPath(groupfile); } - string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + label + "." + getOutputFileNameTag("group", groupfile); + variables["[filename]"] = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputGroupFileName = getOutputFileName("group", variables); ofstream outGroup; m->openOutputFile(outputGroupFileName, outGroup); diff --git a/getotuscommand.h b/getotuscommand.h index 4eff4b6..c71ab06 100644 --- a/getotuscommand.h +++ b/getotuscommand.h @@ -27,8 +27,9 @@ public: vector setParameters(); string getCommandName() { return "get.otus"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.otus"; } string getDescription() { return "outputs a new list file containing the otus containing sequences from the groups specified"; } diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index 3534293..d5f5a8b 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -12,12 +12,12 @@ //********************************************************************************************************************** vector GetRAbundCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); - CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); - CommandParameter psorted("sorted", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(psorted); - 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); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","rabund",false,false, true); parameters.push_back(plist); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","rabund",false,false, true); parameters.push_back(psabund); + CommandParameter psorted("sorted", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(psorted); + 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); } @@ -48,25 +48,21 @@ string GetRAbundCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetRAbundCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetRAbundCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "rabund") { outputFileName = "rabund"; } - 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, "GetRAbundCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "rabund") { pattern = "[filename],rabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetRAbundCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** GetRAbundCommand::GetRAbundCommand(){ try { @@ -192,7 +188,9 @@ int GetRAbundCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("rabund"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); + filename = getOutputFileName("rabund", variables); m->openOutputFile(filename, out); input = new InputData(inputfile, format); diff --git a/getrabundcommand.h b/getrabundcommand.h index 7e93630..dcf8c68 100644 --- a/getrabundcommand.h +++ b/getrabundcommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "get.rabund"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.rabund"; } string getDescription() { return "creates a rabund file"; } diff --git a/getrelabundcommand.cpp b/getrelabundcommand.cpp index 7c623fb..f36f1ba 100644 --- a/getrelabundcommand.cpp +++ b/getrelabundcommand.cpp @@ -12,12 +12,12 @@ //********************************************************************************************************************** vector GetRelAbundCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pscale("scale", "Multiple", "totalgroup-totalotu-averagegroup-averageotu", "totalgroup", "", "", "",false,false); parameters.push_back(pscale); - 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); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","relabund",false,true, true); parameters.push_back(pshared); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter pscale("scale", "Multiple", "totalgroup-totalotu-averagegroup-averageotu", "totalgroup", "", "", "","",false,false); parameters.push_back(pscale); + 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); } @@ -49,24 +49,19 @@ string GetRelAbundCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetRelAbundCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetRelAbundCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "relabund") { outputFileName = "relabund" ; } - 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, "GetRelAbundCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "relabund") { pattern = "[filename],relabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetRelAbundCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** GetRelAbundCommand::GetRelAbundCommand(){ @@ -174,7 +169,9 @@ int GetRelAbundCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("relabund"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + string outputFileName = getOutputFileName("relabund", variables); ofstream out; m->openOutputFile(outputFileName, out); out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); diff --git a/getrelabundcommand.h b/getrelabundcommand.h index c5b50e6..dcb4cf7 100644 --- a/getrelabundcommand.h +++ b/getrelabundcommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "get.relabund"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.relabund"; } string getDescription() { return "calculates the relative abundance of each OTU in a sample"; } diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index 5069249..237506e 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -12,11 +12,11 @@ //********************************************************************************************************************** vector GetSAbundCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); - CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); - 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); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","sabund",false,false, true); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","sabund",false,false, true); parameters.push_back(prabund); + 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); } @@ -46,24 +46,19 @@ string GetSAbundCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetSAbundCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetSAbundCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "sabund") { outputFileName = "sabund"; } - 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, "GetSAbundCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "sabund") { pattern = "[filename],sabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetRAbundCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** GetSAbundCommand::GetSAbundCommand(){ @@ -185,7 +180,9 @@ int GetSAbundCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("sabund"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); + filename = getOutputFileName("sabund", variables); m->openOutputFile(filename, out); input = new InputData(inputfile, format); diff --git a/getsabundcommand.h b/getsabundcommand.h index 4c967b5..685f039 100644 --- a/getsabundcommand.h +++ b/getsabundcommand.h @@ -24,8 +24,9 @@ public: vector setParameters(); string getCommandName() { return "get.sabund"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.sabund"; } string getDescription() { return "creates a sabund file"; } diff --git a/getseqscommand.cpp b/getseqscommand.cpp index 6b16111..779ea91 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -15,19 +15,19 @@ //********************************************************************************************************************** vector GetSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none",false,false); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); - CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pqfile); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos); - CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter paccnos2("accnos2", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos2); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none","fasta",false,false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none","group",false,false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none","list",false,false,true); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none","taxonomy",false,false,true); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none","alignreport",false,false); parameters.push_back(palignreport); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none","qfile",false,false); parameters.push_back(pqfile); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(paccnos); + CommandParameter pdups("dups", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pdups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter paccnos2("accnos2", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos2); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -79,32 +79,27 @@ GetSeqsCommand::GetSeqsCommand(){ } } //********************************************************************************************************************** -string GetSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "taxonomy") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "pick.count_table"; } - else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "qfile") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "accnosreport"){ outputFileName = "accnos.report"; } - else if (type == "alignreport") { outputFileName = "pick.align.report"; } - 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, "GetSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],pick,[extension]"; } + else if (type == "taxonomy") { pattern = "[filename],pick,[extension]"; } + else if (type == "name") { pattern = "[filename],pick,[extension]"; } + else if (type == "group") { pattern = "[filename],pick,[extension]"; } + else if (type == "count") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "qfile") { pattern = "[filename],pick,[extension]"; } + else if (type == "accnosreport") { pattern = "[filename],pick.accnos.report"; } + else if (type == "alignreport") { pattern = "[filename],pick.align.report"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** GetSeqsCommand::GetSeqsCommand(string option) { @@ -409,7 +404,10 @@ int GetSeqsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[extension]"] = m->getExtension(fastafile); + string outputFileName = getOutputFileName("fasta", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -465,7 +463,10 @@ int GetSeqsCommand::readQual(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)); + variables["[extension]"] = m->getExtension(qualfile); + string outputFileName = getOutputFileName("qfile", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -537,7 +538,10 @@ int GetSeqsCommand::readCount(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outputFileName = getOutputFileName("count", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -595,7 +599,10 @@ int GetSeqsCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -671,7 +678,10 @@ int GetSeqsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outputFileName = getOutputFileName("name", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -771,7 +781,10 @@ int GetSeqsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputFileName = getOutputFileName("group", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -827,7 +840,10 @@ int GetSeqsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)); + variables["[extension]"] = m->getExtension(taxfile); + string outputFileName = getOutputFileName("taxonomy", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -881,7 +897,9 @@ int GetSeqsCommand::readAlign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)); + string outputFileName = getOutputFileName("alignreport", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -1047,7 +1065,10 @@ int GetSeqsCommand::compareAccnos(){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(accnosfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(accnosfile)) + getOutputFileNameTag("accnosreport"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(accnosfile)); + string outputFileName = getOutputFileName("accnosreport", variables); + ofstream out; m->openOutputFile(outputFileName, out); diff --git a/getseqscommand.h b/getseqscommand.h index 60e471e..42070e5 100644 --- a/getseqscommand.h +++ b/getseqscommand.h @@ -23,8 +23,9 @@ class GetSeqsCommand : public Command { vector setParameters(); string getCommandName() { return "get.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.seqs"; } string getDescription() { return "gets sequences from a list, fasta, name, group, alignreport, quality or taxonomy file"; } diff --git a/getsharedotucommand.cpp b/getsharedotucommand.cpp index 1b69a25..5ae8da5 100644 --- a/getsharedotucommand.cpp +++ b/getsharedotucommand.cpp @@ -13,15 +13,15 @@ //********************************************************************************************************************** vector GetSharedOTUCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(plist); - CommandParameter poutput("output", "Multiple", "accnos-default", "default", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter punique("unique", "String", "", "", "", "", "",false,false); parameters.push_back(punique); - CommandParameter pshared("shared", "String", "", "", "", "", "",false,false); parameters.push_back(pshared); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none","fasta",false,false); parameters.push_back(pfasta); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none","sharedseq",false,true,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none","sharedseq",false,true,true); parameters.push_back(plist); + CommandParameter poutput("output", "Multiple", "accnos-default", "default", "", "", "","",false,false); parameters.push_back(poutput); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter punique("unique", "String", "", "", "", "", "","",false,false,true); parameters.push_back(punique); + CommandParameter pshared("shared", "String", "", "", "", "", "","",false,false,true); parameters.push_back(pshared); + 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); } @@ -59,28 +59,22 @@ string GetSharedOTUCommand::getHelpString(){ } } //********************************************************************************************************************** -string GetSharedOTUCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string GetSharedOTUCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "fasta") { pattern = "[filename],[distance],[group],shared.fasta"; } + else if (type == "accnos") { pattern = "[filename],[distance],[group],accnos"; } + else if (type == "sharedseqs") { pattern = "[filename],[distance],[group],shared.seqs"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } - //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 == "fasta") { outputFileName = "shared.fasta"; } - else if (type == "accnos") { outputFileName = "accnos"; } - else if (type == "sharedseqs") { outputFileName = "shared.seqs"; } - 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, "GetSharedOTUCommand", "getOutputFileNameTag"); - exit(1); - } + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetSharedOTUCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** GetSharedOTUCommand::GetSharedOTUCommand(){ try { @@ -394,11 +388,13 @@ int GetSharedOTUCommand::process(ListVector* shared) { string outputFileNames; if (outputDir == "") { outputDir += m->hasPath(listfile); } - if (output != "accnos") { - outputFileNames = outputDir + m->getRootName(m->getSimpleName(listfile)) + shared->getLabel() + userGroups + "." + getOutputFileNameTag("sharedseqs"); - }else { - outputFileNames = outputDir + m->getRootName(m->getSimpleName(listfile)) + shared->getLabel() + userGroups + "." + getOutputFileNameTag("accnos"); - } + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[distance]"] = shared->getLabel(); + variables["[group]"] = userGroups; + if (output != "accnos") { outputFileNames = getOutputFileName("sharedseqs", variables); } + else { outputFileNames = getOutputFileName("accnos", variables); } + m->openOutputFile(outputFileNames, outNames); bool wroteSomething = false; @@ -491,7 +487,8 @@ int GetSharedOTUCommand::process(ListVector* shared) { //if fasta file provided output new fasta file if ((fastafile != "") && wroteSomething) { if (outputDir == "") { outputDir += m->hasPath(fastafile); } - string outputFileFasta = outputDir + m->getRootName(m->getSimpleName(fastafile)) + shared->getLabel() + userGroups + "." + getOutputFileNameTag("fasta"); + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string outputFileFasta = getOutputFileName("fasta", variables); ofstream outFasta; m->openOutputFile(outputFileFasta, outFasta); outputNames.push_back(outputFileFasta); outputTypes["fasta"].push_back(outputFileFasta); diff --git a/getsharedotucommand.h b/getsharedotucommand.h index e2026d7..583c2e0 100644 --- a/getsharedotucommand.h +++ b/getsharedotucommand.h @@ -28,8 +28,9 @@ class GetSharedOTUCommand : public Command { string getCommandName() { return "get.sharedseqs"; } string getCommandCategory() { return "OTU-Based Approaches"; } string getRequiredCommand() { return "none"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.sharedseqs"; } string getDescription() { return "identifies sequences that are either unique or shared by specific groups"; } diff --git a/hclustercommand.cpp b/hclustercommand.cpp index cf35cd9..b991ccd 100644 --- a/hclustercommand.cpp +++ b/hclustercommand.cpp @@ -12,18 +12,18 @@ //********************************************************************************************************************** vector HClusterCommand::setParameters(){ try { - CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname); - CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn); - CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); - CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter phard("hard", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(phard); - CommandParameter psorted("sorted", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psorted); - CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pshowabund); - CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptiming); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none","list-rabund-sabund",false,false,true); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName","",false,false,true); parameters.push_back(pname); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName","list-rabund-sabund",false,false,true); parameters.push_back(pcolumn); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "","",false,false,true); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "","",false,false); parameters.push_back(pmethod); + CommandParameter phard("hard", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(phard); + CommandParameter psorted("sorted", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psorted); + CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pshowabund); + CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(ptiming); + 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); } @@ -52,27 +52,23 @@ string HClusterCommand::getHelpString(){ } } //********************************************************************************************************************** -string HClusterCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string HClusterCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "list") { outputFileName = "list"; } - else if (type == "rabund") { outputFileName = "rabund"; } - else if (type == "sabund") { outputFileName = "sabund"; } - 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, "HClusterCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "list") { pattern = "[filename],[clustertag],list"; } + else if (type == "rabund") { pattern = "[filename],[clustertag],rabund"; } + else if (type == "sabund") { pattern = "[filename],[clustertag],sabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "HClusterCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** HClusterCommand::HClusterCommand(){ try { @@ -240,10 +236,14 @@ HClusterCommand::HClusterCommand(string option) { else if (method == "nearest") { tag = "nn"; } else if (method == "weighted") { tag = "wn"; } else { tag = "an"; } + + map variables; + variables["[filename]"] = fileroot; + variables["[clustertag]"] = tag; - string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); - string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); - string listFileName = fileroot+ tag + "." + getOutputFileNameTag("list"); + string sabundFileName = getOutputFileName("sabund",variables); + string rabundFileName = getOutputFileName("rabund",variables); + string listFileName = getOutputFileName("list", variables); m->openOutputFile(sabundFileName, sabundFile); m->openOutputFile(rabundFileName, rabundFile); diff --git a/hclustercommand.h b/hclustercommand.h index 6bf559a..d107407 100644 --- a/hclustercommand.h +++ b/hclustercommand.h @@ -38,8 +38,9 @@ public: vector setParameters(); string getCommandName() { return "hcluster"; } string getCommandCategory() { return "Clustering"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Sun Y, Cai Y, Liu L, Yu F, Farrell ML, Mckendree W, Farmerie W (2009). ESPRIT: estimating species richness using large collections of 16S rRNA pyrosequences. Nucleic Acids Res 37: e76. \nhttp://www.mothur.org/wiki/Hcluster"; } string getDescription() { return "cluster your sequences into OTUs using a distance matrix"; } diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index 441eaf8..e07ae22 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -12,19 +12,19 @@ //********************************************************************************************************************** vector HeatMapCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); - CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); - CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); - CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); - CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prelabund); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pscale("scale", "Multiple", "log10-log2-linear", "log10", "", "", "",false,false); parameters.push_back(pscale); - CommandParameter psorted("sorted", "Multiple", "none-shared-topotu-topgroup", "shared", "", "", "",false,false); parameters.push_back(psorted); - CommandParameter pnumotu("numotu", "Number", "", "0", "", "", "",false,false); parameters.push_back(pnumotu); - CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "",false,false); parameters.push_back(pfontsize); - 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); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false,true); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false,true); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter pscale("scale", "Multiple", "log10-log2-linear", "log10", "", "", "","",false,false); parameters.push_back(pscale); + CommandParameter psorted("sorted", "Multiple", "none-shared-topotu-topgroup", "shared", "", "", "","",false,false); parameters.push_back(psorted); + CommandParameter pnumotu("numotu", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pnumotu); + CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "","",false,false); parameters.push_back(pfontsize); + 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); } @@ -62,25 +62,19 @@ string HeatMapCommand::getHelpString(){ } //********************************************************************************************************************** - -string HeatMapCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string HeatMapCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "svg") { outputFileName = "svg"; } - 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, "HeatMapCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "svg") { pattern = "[filename],svg"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "HeatMapCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** diff --git a/heatmapcommand.h b/heatmapcommand.h index 58eaa36..fc5165e 100644 --- a/heatmapcommand.h +++ b/heatmapcommand.h @@ -28,8 +28,9 @@ public: vector setParameters(); string getCommandName() { return "heatmap.bin"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Heatmap.bin"; } string getDescription() { return "generate a heatmap where the color represents the relative abundanceof an OTU"; } diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp index 8a4a12b..98739b6 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -23,17 +23,17 @@ //********************************************************************************************************************** vector HeatMapSimCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pshared); - CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pphylip); - CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName",false,false); parameters.push_back(pcolumn); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pcalc("calc", "Multiple", "jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-morisitahorn-braycurtis", "jest-thetayc", "", "", "",true,false); parameters.push_back(pcalc); - CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "",false,false); parameters.push_back(pfontsize); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none","svg",false,false,true); parameters.push_back(pshared); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none","svg",false,false); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","",false,false); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","",false,false); parameters.push_back(pcount); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName","svg",false,false); parameters.push_back(pcolumn); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pcalc("calc", "Multiple", "jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-morisitahorn-braycurtis", "jest-thetayc", "", "", "","",true,false); parameters.push_back(pcalc); + CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "","",false,false); parameters.push_back(pfontsize); + 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); } @@ -73,27 +73,20 @@ string HeatMapSimCommand::getHelpString(){ } } //********************************************************************************************************************** - -string HeatMapSimCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string HeatMapSimCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "svg") { outputFileName = "svg"; } - 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, "HeatMapSimCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "svg") { pattern = "[filename],svg"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "HeatMapCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** HeatMapSimCommand::HeatMapSimCommand(){ try { diff --git a/heatmapsimcommand.h b/heatmapsimcommand.h index 2c3a470..f421fdc 100644 --- a/heatmapsimcommand.h +++ b/heatmapsimcommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "heatmap.sim"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Heatmap.sim"; } string getDescription() { return "generate a heatmap indicating the pairwise distance between multiple samples using a variety of calculators"; } diff --git a/helpcommand.h b/helpcommand.h index 31dbd2b..aedb7b5 100644 --- a/helpcommand.h +++ b/helpcommand.h @@ -25,7 +25,7 @@ public: string getCommandName() { return "help"; } string getCommandCategory() { return "Hidden"; } string getHelpString() { return "For more information about a specific command type 'commandName(help)' i.e. 'cluster(help)'"; } - string getOutputFileNameTag(string, string) { return ""; } + string getOutputPattern(string) { return ""; } string getCitation() { return "no citation"; } string getDescription() { return "help"; } diff --git a/homovacommand.cpp b/homovacommand.cpp index 6496cea..49b8b64 100644 --- a/homovacommand.cpp +++ b/homovacommand.cpp @@ -15,13 +15,13 @@ //********************************************************************************************************************** vector HomovaCommand::setParameters(){ try { - CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); - CommandParameter psets("sets", "String", "", "", "", "", "",false,false); parameters.push_back(psets); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(palpha); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","homova",false,true,true); parameters.push_back(pdesign); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","homova",false,true,true); parameters.push_back(pphylip); + CommandParameter psets("sets", "String", "", "", "", "", "","",false,false); parameters.push_back(psets); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "","",false,false); parameters.push_back(palpha); + 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); } @@ -53,24 +53,19 @@ string HomovaCommand::getHelpString(){ } } //********************************************************************************************************************** -string HomovaCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string HomovaCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "homova") { outputFileName = "homova"; } - 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, "HomovaCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "homova") { pattern = "[filename],homova"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "HomovaCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** HomovaCommand::HomovaCommand(){ @@ -242,7 +237,9 @@ int HomovaCommand::execute(){ //create a new filename ofstream HOMOVAFile; - string HOMOVAFileName = outputDir + m->getRootName(m->getSimpleName(phylipFileName)) + getOutputFileNameTag("homova"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(phylipFileName)); + string HOMOVAFileName = getOutputFileName("homova", variables); m->openOutputFile(HOMOVAFileName, HOMOVAFile); outputNames.push_back(HOMOVAFileName); outputTypes["homova"].push_back(HOMOVAFileName); diff --git a/homovacommand.h b/homovacommand.h index 9398627..22741e9 100644 --- a/homovacommand.h +++ b/homovacommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "homova"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Stewart CN, Excoffier L (1996). Assessing population genetic structure and variability with RAPD data: Application to Vaccinium macrocarpon (American Cranberry). J Evol Biol 9: 153-71. \nhttp://www.mothur.org/wiki/Homova"; } string getDescription() { return "homova"; } diff --git a/indicatorcommand.cpp b/indicatorcommand.cpp index 3c461d7..b92c58b 100644 --- a/indicatorcommand.cpp +++ b/indicatorcommand.cpp @@ -14,16 +14,16 @@ //********************************************************************************************************************** vector IndicatorCommand::setParameters(){ try { - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pdesign("design", "InputTypes", "", "", "TreeDesign", "TreeDesign", "none",false,false); parameters.push_back(pdesign); - CommandParameter pshared("shared", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(pshared); - CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(prelabund); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter ptree("tree", "InputTypes", "", "", "TreeDesign", "TreeDesign", "none",false,false); parameters.push_back(ptree); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pdesign("design", "InputTypes", "", "", "TreeDesign", "TreeDesign", "none","summary",false,false,true); parameters.push_back(pdesign); + CommandParameter pshared("shared", "InputTypes", "", "", "SharedRel", "SharedRel", "none","summary",false,false,true); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRel", "SharedRel", "none","summary",false,false); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter ptree("tree", "InputTypes", "", "", "TreeDesign", "TreeDesign", "none","tree-summary",false,false,true); parameters.push_back(ptree); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false); parameters.push_back(pprocessors); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -58,25 +58,20 @@ string IndicatorCommand::getHelpString(){ } } //********************************************************************************************************************** -string IndicatorCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string IndicatorCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "tree") { outputFileName = "indicator.tre"; } - else if (type == "summary") { outputFileName = "indicator.summary"; } - 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, "IndicatorCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "tree") { pattern = "[filename],indicator.tre"; } + else if (type == "summary") { pattern = "[filename],indicator.summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "IndicatorCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** IndicatorCommand::IndicatorCommand(){ @@ -410,7 +405,9 @@ int IndicatorCommand::GetIndicatorSpecies(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(inputFileName); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(inputFileName)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(inputFileName)); + string outputFileName = getOutputFileName("summary", variables); outputNames.push_back(outputFileName); outputTypes["summary"].push_back(outputFileName); ofstream out; @@ -526,7 +523,9 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(inputFileName); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(inputFileName)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(inputFileName)); + string outputFileName = getOutputFileName("summary",variables); outputNames.push_back(outputFileName); outputTypes["summary"].push_back(outputFileName); ofstream out; @@ -546,7 +545,8 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ string treeOutputDir = outputDir; if (outputDir == "") { treeOutputDir += m->hasPath(treefile); } - string outputTreeFileName = treeOutputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("tree"); + variables["[filename]"] = treeOutputDir + m->getRootName(m->getSimpleName(treefile)); + string outputTreeFileName = getOutputFileName("tree", variables); //create a map from tree node index to names of descendants, save time later to know which sharedRabund you need diff --git a/indicatorcommand.h b/indicatorcommand.h index b058af3..1f46081 100644 --- a/indicatorcommand.h +++ b/indicatorcommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "indicator"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Dufrene M, Legendre P (1997). Species assemblages and indicator species: The need for a flexible asymmetrical approach. Ecol Monogr 67: 345-66.\n McCune B, Grace JB, Urban DL (2002). Analysis of ecological communities. MjM Software Design: Gleneden Beach, OR. \nLegendre P, Legendre L (1998). Numerical Ecology. Elsevier: New York. \nhttp://www.mothur.org/wiki/Indicator"; } string getDescription() { return "calculate the indicator value for each OTU"; } diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp index 7f8cd9b..46f1a53 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -23,16 +23,16 @@ //********************************************************************************************************************** vector LibShuffCommand::setParameters(){ try { - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter piters("iters", "Number", "", "10000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pstep("step", "Number", "", "0.01", "", "", "",false,false); parameters.push_back(pstep); - CommandParameter pcutoff("cutoff", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pform("form", "Multiple", "discrete-integral", "integral", "", "", "",false,false); parameters.push_back(pform); - CommandParameter psim("sim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psim); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","coverage-libshuffsummary",false,true,true); parameters.push_back(pphylip); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter piters("iters", "Number", "", "10000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pstep("step", "Number", "", "0.01", "", "", "","",false,false); parameters.push_back(pstep); + CommandParameter pcutoff("cutoff", "Number", "", "1.0", "", "", "","",false,false); parameters.push_back(pcutoff); + CommandParameter pform("form", "Multiple", "discrete-integral", "integral", "", "", "","",false,false); parameters.push_back(pform); + CommandParameter psim("sim", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psim); + 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); } @@ -65,25 +65,20 @@ string LibShuffCommand::getHelpString(){ } } //********************************************************************************************************************** -string LibShuffCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string LibShuffCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "coverage") { outputFileName = "libshuff.coverage"; } - else if (type == "libshuffsummary") { outputFileName = "libshuff.summary"; } - 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, "LibShuffCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "coverage") { pattern = "[filename],libshuff.coverage"; } + else if (type == "libshuffsummary") { pattern = "[filename],libshuff.summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** LibShuffCommand::LibShuffCommand(){ @@ -362,7 +357,9 @@ int LibShuffCommand::printCoverageFile() { try { ofstream outCov; - summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("coverage"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(phylipfile)); + summaryFile = getOutputFileName("coverage", variables); m->openOutputFile(summaryFile, outCov); outputNames.push_back(summaryFile); outputTypes["coverage"].push_back(summaryFile); outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint); @@ -458,7 +455,9 @@ int LibShuffCommand::printSummaryFile() { try { ofstream outSum; - summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("libshuffsummary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(phylipfile)); + summaryFile = getOutputFileName("libshuffsummary",variables); m->openOutputFile(summaryFile, outSum); outputNames.push_back(summaryFile); outputTypes["libshuffsummary"].push_back(summaryFile); diff --git a/libshuffcommand.h b/libshuffcommand.h index 81ae17a..9148576 100644 --- a/libshuffcommand.h +++ b/libshuffcommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "libshuff"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Singleton DR, Furlong MA, Rathbun SL, Whitman WB (2001). Quantitative comparisons of 16S rRNA gene sequence libraries from environmental samples. Appl Environ Microbiol 67: 4374-6. \nSchloss PD, Larget BR, Handelsman J (2004). Integration of microbial ecology and statistics: a test to compare gene libraries. Appl Environ Microbiol 70: 5485-92. \nhttp://www.mothur.org/wiki/Libshuff"; } string getDescription() { return "a generic test that describes whether two or more communities have the same structure using the Cramer-von Mises test statistic"; } diff --git a/listotulabelscommand.cpp b/listotulabelscommand.cpp index 4a12197..e50196b 100644 --- a/listotulabelscommand.cpp +++ b/listotulabelscommand.cpp @@ -12,13 +12,13 @@ //********************************************************************************************************************** vector ListOtuLabelsCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(pshared); - CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(prelabund); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pshared("shared", "InputTypes", "", "", "SharedRel", "SharedRel", "none","otulabels",false,false,true); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRel", "SharedRel", "none","otulabels",false,false); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); //every command must have inputdir and outputdir. This allows mothur users to redirect input and output files. - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + 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); } @@ -47,26 +47,20 @@ string ListOtuLabelsCommand::getHelpString(){ } } //********************************************************************************************************************** -string ListOtuLabelsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ListOtuLabelsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "otulabels") { outputFileName = "otulabels"; } - 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, "ListOtuLabelsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "otulabels") { pattern = "[filename],[distance],otulabels"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ListOtuLabelsCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** ListOtuLabelsCommand::ListOtuLabelsCommand(){ try { @@ -365,7 +359,10 @@ int ListOtuLabelsCommand::execute(){ int ListOtuLabelsCommand::createList(vector& lookup){ try { - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("otulabels"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); + variables["[distance]"] = lookup[0]->getLabel(); + string outputFileName = getOutputFileName("otulabels",variables); outputNames.push_back(outputFileName); outputTypes["otulabels"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); @@ -386,8 +383,10 @@ int ListOtuLabelsCommand::createList(vector& lookup){ int ListOtuLabelsCommand::createList(vector& lookup){ try { - - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("otulabels"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); + variables["[distance]"] = lookup[0]->getLabel(); + string outputFileName = getOutputFileName("otulabels",variables); outputNames.push_back(outputFileName); outputTypes["accnos"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/listotulabelscommand.h b/listotulabelscommand.h index 1b10331..b1150a8 100644 --- a/listotulabelscommand.h +++ b/listotulabelscommand.h @@ -25,8 +25,9 @@ public: string getCommandName() { return "list.otulabels"; } string getCommandCategory() { return "OTU-Based Approaches"; } //commmand category choices: Sequence Processing, OTU-Based Approaches, Hypothesis Testing, Phylotype Analysis, General, Clustering and Hidden - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/List.otulabels"; } string getDescription() { return "lists otu labels from shared or relabund file. Can be used by get.otulabels with output from classify.otu, otu.association, or corr.axes to select specific otus."; } diff --git a/listseqscommand.cpp b/listseqscommand.cpp index 4bc33a3..8a1effe 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -16,15 +16,15 @@ //********************************************************************************************************************** vector ListSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(plist); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); - CommandParameter palignreport("alignreport", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(palignreport); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false,true); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "FNGLT", "FNGLT", "none","accnos",false,false); parameters.push_back(palignreport); + 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); } @@ -52,24 +52,19 @@ string ListSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string ListSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ListSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "accnos") { outputFileName = "accnos"; } - 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, "ListSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "accnos") { pattern = "[filename],accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ListSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ListSeqsCommand::ListSeqsCommand(){ @@ -249,7 +244,9 @@ int ListSeqsCommand::execute(){ if (outputDir == "") { outputDir += m->hasPath(inputFileName); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + getOutputFileNameTag("accnos"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); + string outputFileName = getOutputFileName("accnos", variables); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/listseqscommand.h b/listseqscommand.h index 8e4cce3..b8a79c0 100644 --- a/listseqscommand.h +++ b/listseqscommand.h @@ -23,8 +23,9 @@ class ListSeqsCommand : public Command { vector setParameters(); string getCommandName() { return "list.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/List.seqs"; } string getDescription() { return "lists sequences from a list, fasta, name, group, alignreport or taxonomy file"; } diff --git a/loadlogfilecommand.cpp b/loadlogfilecommand.cpp index 66eb7b6..63c249c 100644 --- a/loadlogfilecommand.cpp +++ b/loadlogfilecommand.cpp @@ -14,9 +14,9 @@ //********************************************************************************************************************** vector LoadLogfileCommand::setParameters(){ try { - CommandParameter plogfile("logfile", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plogfile); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plogfile("logfile", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(plogfile); + 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); } @@ -141,14 +141,14 @@ int LoadLogfileCommand::execute(){ //look for "mothur >" int pos = line.find("mothur > "); //command line int pos2 = line.find("Output File "); //indicates command completed and we can update the current file - int pos3 = line.find("*****************"); + int pos3 = line.find("/*****************"); //skipping over parts where a command runs another command if (pos3 != string::npos) { while (!in.eof()) { if (m->control_pressed) { break; } line = m->getline(in); m->gobble(in); - int posTemp = line.find("*****************"); + int posTemp = line.find("/*****************"); if (posTemp != string::npos) { break; } } } @@ -184,6 +184,7 @@ int LoadLogfileCommand::execute(){ Command* command = cFactory->getCommand(commandName); map > thisOutputTypes = command->getOutputFiles(); + for (map >::iterator it = thisOutputTypes.begin(); it != thisOutputTypes.end(); it++) { if (currentTypes.count((it->first)) != 0) { //do we save this type //if yes whats its tag @@ -191,25 +192,14 @@ int LoadLogfileCommand::execute(){ string thisTypesCurrentFile = ""; if (itCurrentFiles != currentFiles.end()) { thisTypesCurrentFile = itCurrentFiles->second; } - string tag = command->getOutputFileNameTag(it->first, thisTypesCurrentFile); //pass it "fasta" and the current fasta file name. some commands use the current name to get the extension, the others wont care. - //search for the tag in the list of output files - for (int h = 0; h < theseOutputNames.size(); h++) { - string ending = theseOutputNames[h].substr(theseOutputNames[h].length()-tag.length(), tag.length()); - if (ending == tag) { //if it's there and this is a type we save a current version of, save it - if ((it->first == "column") || (it->first == "phylip")) { //check for format - string RippedName = ""; - bool foundDot = false; - for (int i = theseOutputNames[h].length()-1; i >= 0; i--) { - if (foundDot && (theseOutputNames[h][i] != '.')) { RippedName = theseOutputNames[h][i] + RippedName; } - else if (foundDot && (theseOutputNames[h][i] == '.')) { break; } - else if (!foundDot && (theseOutputNames[h][i] == '.')) { foundDot = true; } - } - if ((RippedName == "phylip") || (RippedName == "lt") || (RippedName == "square")) { currentFiles["phylip"] = theseOutputNames[h]; } - else { currentFiles["column"] = theseOutputNames[h]; } - }else { currentFiles[it->first] = theseOutputNames[h]; } - break; - } - } + //outputfilename pattern for this input type + string pattern = command->getOutputPattern(it->first); + updateCurrent(pattern, it->first, thisTypesCurrentFile, theseOutputNames, currentFiles); + + //cout << "current=\n\n"; + //for (map::iterator itcc = currentFiles.begin(); itcc != currentFiles.end(); itcc++) { + // cout << itcc->first << '\t' << itcc->second << endl; + // } } } } @@ -248,4 +238,51 @@ int LoadLogfileCommand::execute(){ } //********************************************************************************************************************** +int LoadLogfileCommand::updateCurrent(string pattern, string type, string thisTypesCurrentFile, vector filenames, map& currentFiles){ + try { + + vector patterns; m->splitAtChar(pattern, patterns, '-'); + + for (int i = 0; i < patterns.size(); i++) { + + vector peices; m->splitAtChar(patterns[i], peices, ','); + //cout << "patterns i = " << patterns[i] << endl; + if (peices.size() != 0) { + string tag = peices[peices.size()-1]; + //cout << "tag = " << tag << endl; + if (peices[peices.size()-1] == "[extension]") { tag = m->getExtension(thisTypesCurrentFile); } + + //search for the tag in the list of output files + for (int h = 0; h < filenames.size(); h++) { + + if (m->control_pressed) { return 0; } + //cout << "filename h = " << filenames[h]<< endl; + string ending = filenames[h].substr(filenames[h].length()-tag.length(), tag.length()); + if (ending == tag) { //if it's there and this is a type we save a current version of, save it + if ((type == "column") || (type == "phylip")) { //check for format + string RippedName = ""; + bool foundDot = false; + for (int i = filenames[h].length()-1; i >= 0; i--) { + if (foundDot && (filenames[h][i] != '.')) { RippedName = filenames[h][i] + RippedName; } + else if (foundDot && (filenames[h][i] == '.')) { break; } + else if (!foundDot && (filenames[h][i] == '.')) { foundDot = true; } + } + if ((RippedName == "phylip") || (RippedName == "lt") || (RippedName == "square")) { currentFiles["phylip"] = filenames[h]; } + else { currentFiles["column"] = filenames[h]; } + }else { currentFiles[type] = filenames[h]; } + break; + } + } + } + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "LoadLogfileCommand", "updateCurrent"); + exit(1); + } +} +//********************************************************************************************************************** + diff --git a/loadlogfilecommand.h b/loadlogfilecommand.h index 0fd82a8..ab8cacd 100644 --- a/loadlogfilecommand.h +++ b/loadlogfilecommand.h @@ -23,8 +23,8 @@ public: vector setParameters(); string getCommandName() { return "load.logfile"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); + string getOutputPattern(string) { return ""; } string getCitation() { return "http://www.mothur.org/wiki/Load.logfile"; } string getDescription() { return "extracts current files from a logfile"; } @@ -35,6 +35,8 @@ private: bool abort; string outputDir, logfile; vector outputNames; + + int updateCurrent(string pattern, string type, string, vector outputNames, map& currentFiles); }; /**************************************************************************************************/ diff --git a/makebiomcommand.cpp b/makebiomcommand.cpp index 6385ade..a19e2e3 100644 --- a/makebiomcommand.cpp +++ b/makebiomcommand.cpp @@ -92,14 +92,14 @@ //********************************************************************************************************************** vector MakeBiomCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter pcontaxonomy("contaxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pcontaxonomy); - CommandParameter pmetadata("metadata", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pmetadata); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - 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); - CommandParameter pmatrixtype("matrixtype", "Multiple", "sparse-dense", "sparse", "", "", "",false,false); parameters.push_back(pmatrixtype); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","biom",false,true,true); parameters.push_back(pshared); + CommandParameter pcontaxonomy("contaxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcontaxonomy); + CommandParameter pmetadata("metadata", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pmetadata); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); + CommandParameter pmatrixtype("matrixtype", "Multiple", "sparse-dense", "sparse", "", "", "","",false,false); parameters.push_back(pmatrixtype); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -133,24 +133,19 @@ string MakeBiomCommand::getHelpString(){ } } //********************************************************************************************************************** -string MakeBiomCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MakeBiomCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "biom") { outputFileName = "biom"; } - 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, "MakeBiomCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "biom") { pattern = "[filename],[distance],biom"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MakeBiomCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -388,8 +383,10 @@ int MakeBiomCommand::execute(){ //********************************************************************************************************************** int MakeBiomCommand::getBiom(vector& lookup){ try { - - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("biom"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[distance]"] = lookup[0]->getLabel(); + string outputFileName = getOutputFileName("biom",variables); ofstream out; m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["biom"].push_back(outputFileName); diff --git a/makebiomcommand.h b/makebiomcommand.h index ee9bd1c..7ea381f 100644 --- a/makebiomcommand.h +++ b/makebiomcommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "make.biom"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://biom-format.org/documentation/biom_format.html, http://www.mothur.org/wiki/Make.biom"; } string getDescription() { return "creates a biom file"; } diff --git a/makecontigscommand.cpp b/makecontigscommand.cpp index f2f6449..bf55165 100644 --- a/makecontigscommand.cpp +++ b/makecontigscommand.cpp @@ -11,25 +11,25 @@ //********************************************************************************************************************** vector MakeContigsCommand::setParameters(){ try { - CommandParameter pfasta("ffastq", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter prfasta("rfastq", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(prfasta); - CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos); - CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppdiffs); - CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pbdiffs); + CommandParameter pfasta("ffastq", "InputTypes", "", "", "none", "none", "none","fasta-qfile",false,true,true); parameters.push_back(pfasta); + CommandParameter prfasta("rfastq", "InputTypes", "", "", "none", "none", "none","fasta-qfile",false,true,true); parameters.push_back(prfasta); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","group",false,false,true); parameters.push_back(poligos); + CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(ppdiffs); + CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(pbdiffs); // CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pldiffs); // CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(psdiffs); - CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ptdiffs); + CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ptdiffs); - CommandParameter palign("align", "Multiple", "needleman-gotoh", "needleman", "", "", "",false,false); parameters.push_back(palign); - CommandParameter pallfiles("allfiles", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pallfiles); - CommandParameter pmatch("match", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pmatch); - CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pmismatch); - CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "",false,false); parameters.push_back(pgapopen); - CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pgapextend); - CommandParameter pthreshold("threshold", "Number", "", "40", "", "", "",false,false); parameters.push_back(pthreshold); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter palign("align", "Multiple", "needleman-gotoh", "needleman", "", "", "","",false,false); parameters.push_back(palign); + CommandParameter pallfiles("allfiles", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pallfiles); + CommandParameter pmatch("match", "Number", "", "1.0", "", "", "","",false,false); parameters.push_back(pmatch); + CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pmismatch); + CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "","",false,false); parameters.push_back(pgapopen); + CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pgapextend); + CommandParameter pthreshold("threshold", "Number", "", "40", "", "", "","",false,false); parameters.push_back(pthreshold); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + 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); } @@ -72,27 +72,22 @@ string MakeContigsCommand::getHelpString(){ } } //********************************************************************************************************************** -string MakeContigsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MakeContigsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "contigs.fasta"; } - else if (type == "qfile") { outputFileName = "contigs.qual"; } - else if (type == "group") { outputFileName = "groups"; } - else if (type == "mismatch") { outputFileName = "contigs.mismatch"; } - 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, "MakeContigsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],[tag],contigs.fasta"; } + else if (type == "qfile") { pattern = "[filename],[tag],contigs.qual"; } + else if (type == "group") { pattern = "[filename],[tag],groups"; } + else if (type == "mismatch") { pattern = "[filename],[tag],contigs.mismatch"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MakeContigsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** MakeContigsCommand::MakeContigsCommand(){ @@ -220,13 +215,15 @@ MakeContigsCommand::MakeContigsCommand(string option) { temp = validParameter.validFile(parameters, "pdiffs", false); if (temp == "not found") { temp = "0"; } m->mothurConvert(temp, pdiffs); - // temp = validParameter.validFile(parameters, "ldiffs", false); if (temp == "not found") { temp = "0"; } + // temp = validParameter.validFile(parameters, "ldiffs", false); if (temp == "not found") { temp = "0"; } // m->mothurConvert(temp, ldiffs); + ldiffs = 0; // temp = validParameter.validFile(parameters, "sdiffs", false); if (temp == "not found") { temp = "0"; } -// m->mothurConvert(temp, sdiffs); + // m->mothurConvert(temp, sdiffs); + sdiffs = 0; - temp = validParameter.validFile(parameters, "tdiffs", false); if (temp == "not found") { int tempTotal = pdiffs + bdiffs + ldiffs + sdiffs; temp = toString(tempTotal); } + temp = validParameter.validFile(parameters, "tdiffs", false); if (temp == "not found") { int tempTotal = pdiffs + bdiffs; temp = toString(tempTotal); } m->mothurConvert(temp, tdiffs); if(tdiffs == 0){ tdiffs = bdiffs + pdiffs; } //+ ldiffs + sdiffs; @@ -265,20 +262,26 @@ int MakeContigsCommand::execute(){ vector > qualFileNames; createGroup = false; string outputGroupFileName; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(ffastqfile)); + variables["[tag]"] = ""; if(oligosfile != ""){ createGroup = getOligos(fastaFileNames, qualFileNames); if (createGroup) { - outputGroupFileName = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + getOutputFileNameTag("group"); + outputGroupFileName = getOutputFileName("group",variables); outputNames.push_back(outputGroupFileName); outputTypes["group"].push_back(outputGroupFileName); } } - string outFastaFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + "trim." + getOutputFileNameTag("fasta"); - string outQualFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + "trim." + getOutputFileNameTag("qfile"); - string outScrapFastaFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + "scrap." + getOutputFileNameTag("fasta"); - string outScrapQualFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + "scrap." + getOutputFileNameTag("qfile"); + variables["[tag]"] = "trim"; + string outFastaFile = getOutputFileName("fasta",variables); + string outQualFile = getOutputFileName("qfile",variables); + variables["[tag]"] = "scrap"; + string outScrapFastaFile = getOutputFileName("fasta",variables); + string outScrapQualFile = getOutputFileName("qfile",variables); - string outMisMatchFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + getOutputFileNameTag("mismatch"); + variables["[tag]"] = ""; + string outMisMatchFile = getOutputFileName("mismatch",variables); outputNames.push_back(outFastaFile); outputTypes["fasta"].push_back(outFastaFile); outputNames.push_back(outQualFile); outputTypes["qfile"].push_back(outQualFile); outputNames.push_back(outScrapFastaFile); outputTypes["fasta"].push_back(outScrapFastaFile); @@ -330,7 +333,7 @@ int MakeContigsCommand::execute(){ ofstream out; string thisGroupName = outputDir + m->getRootName(m->getSimpleName(it->first)); - thisGroupName += getOutputFileNameTag("group"); outputNames.push_back(thisGroupName); outputTypes["group"].push_back(thisGroupName); + thisGroupName += getOutputFileName("group",variables); outputNames.push_back(thisGroupName); outputTypes["group"].push_back(thisGroupName); m->openOutputFile(thisGroupName, out); while (!in.eof()){ diff --git a/makecontigscommand.h b/makecontigscommand.h index 86a8450..d641ec9 100644 --- a/makecontigscommand.h +++ b/makecontigscommand.h @@ -49,8 +49,9 @@ public: string getCommandName() { return "make.contigs"; } string getCommandCategory() { return "Sequence Processing"; } //commmand category choices: Sequence Processing, OTU-Based Approaches, Hypothesis Testing, Phylotype Analysis, General, Clustering and Hidden - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Make.contigs"; } string getDescription() { return "description"; } diff --git a/makefastqcommand.cpp b/makefastqcommand.cpp index c6dcf2c..6712196 100644 --- a/makefastqcommand.cpp +++ b/makefastqcommand.cpp @@ -14,10 +14,11 @@ //********************************************************************************************************************** vector MakeFastQCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pqfile); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fastq",false,true,true); parameters.push_back(pfasta); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none","fastq",false,true,true); parameters.push_back(pqfile); + CommandParameter pformat("format", "Multiple", "sanger-illumina", "sanger", "", "", "","",false,false); parameters.push_back(pformat); + 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); } @@ -32,9 +33,9 @@ vector MakeFastQCommand::setParameters(){ string MakeFastQCommand::getHelpString(){ try { string helpString = ""; - helpString += "The make.fastq command read a fasta and quality file and creates a fastq file.\n"; - helpString += "The make.fastq command parameters are fasta and qfile, both are required.\n"; - helpString += "You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"; + helpString += "The make.fastq command reads a fasta and quality file and creates a fastq file.\n"; + helpString += "The make.fastq command parameters are fasta, qfile and format. fasta and qfile are required.\n"; + helpString += "The format parameter is used to indicate whether your sequences are sanger or illumina, default=sanger.\n"; helpString += "The make.fastq command should be in the following format: make.fastq(qfile=yourQualityFile, fasta=yourFasta).\n"; helpString += "Example make.fastq(fasta=amazon.fasta, qfile=amazon.qual).\n"; helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"; @@ -46,24 +47,19 @@ string MakeFastQCommand::getHelpString(){ } } //********************************************************************************************************************** -string MakeFastQCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MakeFastQCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fastq") { outputFileName = "fastq"; } - 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, "MakeFastQCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fastq") { pattern = "[filename],fastq"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MakeFastQCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** MakeFastQCommand::MakeFastQCommand(){ @@ -148,6 +144,14 @@ MakeFastQCommand::MakeFastQCommand(string option) { //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 = m->hasPath(fastafile); } + + format = validParameter.validFile(parameters, "format", false); if (format == "not found"){ format = "sanger"; } + + if ((format != "sanger") && (format != "illumina") && (format != "solexa")) { + m->mothurOut(format + " is not a valid format. Your format choices are sanger, solexa and illumina, aborting." ); m->mothurOutEndLine(); + abort=true; + } + } @@ -164,8 +168,9 @@ int MakeFastQCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - - string outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fastq"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string outputFile = getOutputFileName("fastq",variables); outputNames.push_back(outputFile); outputTypes["fastq"].push_back(outputFile); ofstream out; @@ -176,7 +181,7 @@ int MakeFastQCommand::execute(){ ifstream fFile; m->openInputFile(fastafile, fFile); - + while (!fFile.eof() && !qFile.eof()) { if (m->control_pressed) { break; } @@ -221,9 +226,10 @@ string MakeFastQCommand::convertQual(vector qual) { try { string qualScores; - int controlChar = int('@'); - - for (int i = 0; i < qual.size(); i++) { + for (int i = 0; i < qual.size(); i++) { + int controlChar = int('!'); + if (format == "illumina") { controlChar = int('@'); } + int temp = qual[i] + controlChar; char qualChar = (char) temp; diff --git a/makefastqcommand.h b/makefastqcommand.h index 9119ebd..e3e0b70 100644 --- a/makefastqcommand.h +++ b/makefastqcommand.h @@ -24,8 +24,9 @@ public: vector setParameters(); string getCommandName() { return "make.fastq"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Make.fastq"; } string getDescription() { return "creates a fastq file from a fasta and quality file"; } @@ -36,7 +37,7 @@ public: private: - string fastafile, qualfile, outputDir; + string fastafile, qualfile, outputDir, format; bool abort; vector outputNames; diff --git a/makegroupcommand.cpp b/makegroupcommand.cpp index a3aca93..68b1e84 100644 --- a/makegroupcommand.cpp +++ b/makegroupcommand.cpp @@ -14,11 +14,11 @@ //********************************************************************************************************************** vector MakeGroupCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter poutput("output", "String", "", "", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","group",false,true,true); parameters.push_back(pfasta); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false,true); parameters.push_back(pgroups); + CommandParameter poutput("output", "String", "", "", "", "", "","",false,false); parameters.push_back(poutput); + 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); } @@ -48,24 +48,19 @@ string MakeGroupCommand::getHelpString(){ } } //********************************************************************************************************************** -string MakeGroupCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MakeGroupCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "group") { outputFileName = "groups"; } - 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, "MakeGroupCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "group") { pattern = "[filename],groups"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MakeGroupCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** MakeGroupCommand::MakeGroupCommand(){ @@ -185,8 +180,10 @@ MakeGroupCommand::MakeGroupCommand(string option) { } //prevent giantic file name - if (fastaFileNames.size() > 3) { filename = outputDir + "merge." + getOutputFileNameTag("group"); } - else { filename += getOutputFileNameTag("group"); } + map variables; + variables["[filename]"] = filename; + if (fastaFileNames.size() > 3) { variables["[filename]"] = outputDir + "merge"; } + filename = getOutputFileName("group",variables); //make sure there is at least one valid file left if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; } diff --git a/makegroupcommand.h b/makegroupcommand.h index b8521d7..f86c707 100644 --- a/makegroupcommand.h +++ b/makegroupcommand.h @@ -22,8 +22,9 @@ public: vector setParameters(); string getCommandName() { return "make.group"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Make.group"; } string getDescription() { return "creates a group file"; } diff --git a/mantelcommand.cpp b/mantelcommand.cpp index f3259e6..b9e4df9 100644 --- a/mantelcommand.cpp +++ b/mantelcommand.cpp @@ -14,12 +14,12 @@ //********************************************************************************************************************** vector MantelCommand::setParameters(){ try { - CommandParameter pphylip1("phylip1", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip1); - CommandParameter pphylip2("phylip2", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip2); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pmethod("method", "Multiple", "pearson-spearman-kendall", "pearson", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pphylip1("phylip1", "InputTypes", "", "", "none", "none", "none","mantel",false,true,true); parameters.push_back(pphylip1); + CommandParameter pphylip2("phylip2", "InputTypes", "", "", "none", "none", "none","mantel",false,true,true); parameters.push_back(pphylip2); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pmethod("method", "Multiple", "pearson-spearman-kendall", "pearson", "", "", "","",false,false); parameters.push_back(pmethod); + 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); } @@ -50,24 +50,19 @@ string MantelCommand::getHelpString(){ } } //********************************************************************************************************************** -string MantelCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MantelCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "mantel") { outputFileName = "mantel"; } - 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, "MantelCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "mantel") { pattern = "[filename],mantel"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MantelCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** MantelCommand::MantelCommand(){ @@ -226,7 +221,9 @@ int MantelCommand::execute(){ if (m->control_pressed) { return 0; } - string outputFile = outputDir + m->getRootName(m->getSimpleName(phylipfile1)) + getOutputFileNameTag("mantel"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(phylipfile1)); + string outputFile = getOutputFileName("mantel",variables); outputNames.push_back(outputFile); outputTypes["mantel"].push_back(outputFile); ofstream out; diff --git a/mantelcommand.h b/mantelcommand.h index 644d9b2..33fa3ea 100644 --- a/mantelcommand.h +++ b/mantelcommand.h @@ -22,8 +22,9 @@ public: vector setParameters(); string getCommandName() { return "mantel"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "McCune B, Grace JB, Urban DL (2002). Analysis of ecological communities. MjM Software Design: Gleneden Beach, OR. \nLegendre P, Legendre L (1998). Numerical Ecology. Elsevier: New York. \nhttp://www.mothur.org/wiki/Mantel"; } string getDescription() { return "Mantel’s test for correlation between matrices"; } diff --git a/matrixoutputcommand.cpp b/matrixoutputcommand.cpp index ccd4f53..b7e1dae 100644 --- a/matrixoutputcommand.cpp +++ b/matrixoutputcommand.cpp @@ -13,17 +13,17 @@ //********************************************************************************************************************** vector MatrixOutputCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter psubsample("subsample", "String", "", "", "", "", "",false,false); parameters.push_back(psubsample); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pcalc("calc", "Multiple", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-whittaker-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-hamming-structchi2-gower-memchi2-memchord-memeuclidean-mempearson", "jclass-thetayc", "", "", "",true,false); parameters.push_back(pcalc); - CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter pmode("mode", "Multiple", "average-median", "average", "", "", "",false,false); parameters.push_back(pmode); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","phylip",false,true,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter psubsample("subsample", "String", "", "", "", "", "","",false,false); parameters.push_back(psubsample); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter pcalc("calc", "Multiple", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-whittaker-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-hamming-structchi2-gower-memchi2-memchord-memeuclidean-mempearson", "jclass-thetayc", "", "", "","",true,false,true); parameters.push_back(pcalc); + CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "","",false,false); parameters.push_back(poutput); + CommandParameter pmode("mode", "Multiple", "average-median", "average", "", "", "","",false,false); parameters.push_back(pmode); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + 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); } @@ -61,24 +61,19 @@ string MatrixOutputCommand::getHelpString(){ } } //********************************************************************************************************************** -string MatrixOutputCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MatrixOutputCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "phylip") { outputFileName = "dist"; } - 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, "MatrixOutputCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "phylip") { pattern = "[filename],[calc],[distance],[outputtag],dist-[filename],[calc],[distance],[outputtag],[tag2],dist"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MatrixOutputCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** MatrixOutputCommand::MatrixOutputCommand(){ @@ -486,8 +481,12 @@ int MatrixOutputCommand::process(vector thisLookup){ try { vector< vector< vector > > calcDistsTotals; //each iter, one for each calc, then each groupCombos dists. this will be used to make .dist files vector< vector > calcDists; calcDists.resize(matrixCalculators.size()); - + for (int thisIter = 0; thisIter < iters+1; thisIter++) { + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[tag2]"] = ""; vector thisItersLookup = thisLookup; @@ -673,7 +672,9 @@ int MatrixOutputCommand::process(vector thisLookup){ matrix[column][row] = dist; } - string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + "." + getOutputFileNameTag("phylip"); + variables["[outputtag]"] = output; + variables["[calc]"] = matrixCalculators[i]->getName(); + string distFileName = getOutputFileName("phylip",variables); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outDist; @@ -777,8 +778,14 @@ int MatrixOutputCommand::process(vector thisLookup){ stdmatrix[row][column] = stdDist; stdmatrix[column][row] = stdDist; } - - string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".ave." + getOutputFileNameTag("phylip"); + + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[outputtag]"] = output; + variables["[tag2]"] = "ave"; + variables["[calc]"] = matrixCalculators[i]->getName(); + string distFileName = getOutputFileName("phylip",variables); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outAve; m->openOutputFile(distFileName, outAve); @@ -788,7 +795,8 @@ int MatrixOutputCommand::process(vector thisLookup){ outAve.close(); - distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".std." + getOutputFileNameTag("phylip"); + variables["[tag2]"] = "std"; + distFileName = outputDir + getOutputFileName("phylip",variables); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outSTD; m->openOutputFile(distFileName, outSTD); diff --git a/matrixoutputcommand.h b/matrixoutputcommand.h index ff05ef7..8a04c96 100644 --- a/matrixoutputcommand.h +++ b/matrixoutputcommand.h @@ -73,8 +73,9 @@ public: vector setParameters(); string getCommandName() { return "dist.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Dist.shared"; } string getDescription() { return "generate a distance matrix that describes the dissimilarity among multiple groups"; } diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index f68bbbe..643cf28 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -12,10 +12,10 @@ //********************************************************************************************************************** vector MergeFileCommand::setParameters(){ try { - CommandParameter pinput("input", "String", "", "", "", "", "",false,true); parameters.push_back(pinput); - CommandParameter poutput("output", "String", "", "", "", "", "",false,true); parameters.push_back(poutput); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pinput("input", "String", "", "", "", "", "","",false,true,true); parameters.push_back(pinput); + CommandParameter poutput("output", "String", "", "", "", "", "","",false,true,true); parameters.push_back(poutput); + 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); } diff --git a/mergefilecommand.h b/mergefilecommand.h index 9cb999b..d7b0aff 100644 --- a/mergefilecommand.h +++ b/mergefilecommand.h @@ -22,8 +22,8 @@ public: vector setParameters(); string getCommandName() { return "merge.files"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); + string getOutputPattern(string){ return ""; } string getCitation() { return "http://www.mothur.org/wiki/Merge.files"; } string getDescription() { return "appends files creating one file"; } diff --git a/mergegroupscommand.cpp b/mergegroupscommand.cpp index 5a67220..bfd1b84 100644 --- a/mergegroupscommand.cpp +++ b/mergegroupscommand.cpp @@ -13,13 +13,13 @@ //********************************************************************************************************************** vector MergeGroupsCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "sharedGroup", "none",false,false); parameters.push_back(pshared); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "sharedGroup", "none",false,false); parameters.push_back(pgroup); - CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "sharedGroup", "none","shared",false,false,true); parameters.push_back(pshared); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "sharedGroup", "none","group",false,false,true); parameters.push_back(pgroup); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pdesign); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -52,26 +52,22 @@ string MergeGroupsCommand::getHelpString(){ exit(1); } } + //********************************************************************************************************************** -string MergeGroupsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MergeGroupsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "shared") { outputFileName = "merge" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "merge" + m->getExtension(inputName); } - 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, "MergeGroupsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "shared") { pattern = "[filename],merge,[extension]"; } + else if (type == "group") { pattern = "[filename],merge,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MergeGroupsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** MergeGroupsCommand::MergeGroupsCommand(){ @@ -305,7 +301,10 @@ int MergeGroupsCommand::processSharedFile(GroupMap*& designMap){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("shared", sharedfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[extension]"] = m->getExtension(sharedfile); + string outputFileName = getOutputFileName("shared", variables); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -408,7 +407,10 @@ int MergeGroupsCommand::processGroupFile(GroupMap*& designMap){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputFileName = getOutputFileName("group", variables); outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; diff --git a/mergegroupscommand.h b/mergegroupscommand.h index 4db3447..3e3d337 100644 --- a/mergegroupscommand.h +++ b/mergegroupscommand.h @@ -24,8 +24,9 @@ public: vector setParameters(); string getCommandName() { return "merge.groups"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Merge.groups"; } string getDescription() { return "reads shared file and a design file and merges the groups in the shared file that are in the same grouping in the design file"; } diff --git a/metastatscommand.cpp b/metastatscommand.cpp index b5b01e7..3eaee96 100644 --- a/metastatscommand.cpp +++ b/metastatscommand.cpp @@ -14,16 +14,16 @@ //********************************************************************************************************************** vector MetaStatsCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pthreshold("threshold", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(pthreshold); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter psets("sets", "String", "", "", "", "", "",false,false); parameters.push_back(psets); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","metastats",false,true,true); parameters.push_back(pshared); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pdesign); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pthreshold("threshold", "Number", "", "0.05", "", "", "","",false,false); parameters.push_back(pthreshold); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter psets("sets", "String", "", "", "", "", "","",false,false); parameters.push_back(psets); + 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); } @@ -61,26 +61,20 @@ string MetaStatsCommand::getHelpString(){ } } //********************************************************************************************************************** -string MetaStatsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MetaStatsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "metastats") { outputFileName = "metastats"; } - 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, "MetaStatsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "metastats") { pattern = "[filename],[distance],[groups],metastats"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MetaStatsCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** MetaStatsCommand::MetaStatsCommand(){ try { @@ -470,7 +464,11 @@ int MetaStatsCommand::driver(int start, int num, vector& th string setB = namesOfGroupCombos[c][1]; //get filename - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + thisLookUp[0]->getLabel() + "." + setA + "-" + setB + "." + getOutputFileNameTag("metastats"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[distance]"] = thisLookUp[0]->getLabel(); + variables["[group]"] = setA + "-" + setB; + string outputFileName = getOutputFileName("metastats",variables); outputNames.push_back(outputFileName); outputTypes["metastats"].push_back(outputFileName); //int nameLength = outputFileName.length(); //char * output = new char[nameLength]; diff --git a/metastatscommand.h b/metastatscommand.h index 377adf1..7884130 100644 --- a/metastatscommand.h +++ b/metastatscommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "metastats"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "White JR, Nagarajan N, Pop M (2009). Statistical methods for detecting differentially abundant features in clinical metagenomic samples. PLoS Comput Biol 5: e1000352. \nhttp://www.mothur.org/wiki/Metastats"; } string getDescription() { return "detects differentially abundant features in clinical metagenomic samples"; } diff --git a/mgclustercommand.cpp b/mgclustercommand.cpp index 1861aa5..b9c9d1e 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -12,20 +12,20 @@ //********************************************************************************************************************** vector MGClusterCommand::setParameters(){ try { - CommandParameter pblast("blast", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pblast); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter plength("length", "Number", "", "5", "", "", "",false,false); parameters.push_back(plength); - CommandParameter ppenalty("penalty", "Number", "", "0.10", "", "", "",false,false); parameters.push_back(ppenalty); - CommandParameter pcutoff("cutoff", "Number", "", "0.70", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); - CommandParameter pmethod("method", "Multiple", "furthest-nearest-average", "average", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter phard("hard", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(phard); - CommandParameter pmin("min", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pmin); - CommandParameter pmerge("merge", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pmerge); - CommandParameter phcluster("hcluster", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(phcluster); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pblast("blast", "InputTypes", "", "", "none", "none", "none","list",false,true,true); parameters.push_back(pblast); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName","rabund-sabund",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter plength("length", "Number", "", "5", "", "", "","",false,false); parameters.push_back(plength); + CommandParameter ppenalty("penalty", "Number", "", "0.10", "", "", "","",false,false); parameters.push_back(ppenalty); + CommandParameter pcutoff("cutoff", "Number", "", "0.70", "", "", "","",false,false,true); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average", "average", "", "", "","",false,false); parameters.push_back(pmethod); + CommandParameter phard("hard", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(phard); + CommandParameter pmin("min", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pmin); + CommandParameter pmerge("merge", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pmerge); + CommandParameter phcluster("hcluster", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(phcluster); + 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); } @@ -62,28 +62,23 @@ string MGClusterCommand::getHelpString(){ } } //********************************************************************************************************************** -string MGClusterCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string MGClusterCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "list") { outputFileName = "list"; } - else if (type == "rabund") { outputFileName = "rabund"; } - else if (type == "sabund") { outputFileName = "sabund"; } - 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, "MGClusterCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "list") { pattern = "[filename],[clustertag],list-[filename],[clustertag],[tag2],list"; } + else if (type == "rabund") { pattern = "[filename],[clustertag],rabund"; } + else if (type == "sabund") { pattern = "[filename],[clustertag],sabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "MGClusterCommand", "getOutputPattern"); + exit(1); + } } -//********************************************************************************************************************** +//******************************************************************************************************************* MGClusterCommand::MGClusterCommand(){ try { abort = true; calledHelp = true; @@ -274,11 +269,13 @@ int MGClusterCommand::execute(){ else if (method == "nearest") { tag = "nn"; } else { tag = "an"; } - string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); - string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); - string listFileName = fileroot+ tag + "."; - if (countfile != "") { listFileName += "unique_"; } - listFileName += getOutputFileNameTag("list"); + map variables; + variables["[filename]"] = fileroot; + if (countfile != "") { variables["[tag2]"] = "unique_list"; } + variables["[clustertag]"] = tag; + string sabundFileName = getOutputFileName("sabund", variables); + string rabundFileName = getOutputFileName("rabund", variables); + string listFileName = getOutputFileName("list", variables); if (countfile == "") { m->openOutputFile(sabundFileName, sabundFile); diff --git a/mgclustercommand.h b/mgclustercommand.h index b5b295f..008bd22 100644 --- a/mgclustercommand.h +++ b/mgclustercommand.h @@ -31,8 +31,9 @@ public: vector setParameters(); string getCommandName() { return "mgcluster"; } string getCommandCategory() { return "Clustering"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Handelsman J (2008). A statistical toolbox for metagenomics. BMC Bioinformatics 9: 34. \nhttp://www.mothur.org/wiki/Mgcluster"; } string getDescription() { return "cluster your sequences into OTUs using a blast file"; } diff --git a/newcommandtemplate.cpp b/newcommandtemplate.cpp index 085039e..b2426f5 100644 --- a/newcommandtemplate.cpp +++ b/newcommandtemplate.cpp @@ -13,30 +13,30 @@ vector NewCommand::setParameters(){ try { //eaxamples of each type of parameter. more info on the types of parameters can be found in commandparameter.h - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false); parameters.push_back(pprocessors); //files that have dependancies - CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname); - CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none","outputType",false,false); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName","outputType",false,false); parameters.push_back(pname); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName","outputType",false,false); parameters.push_back(pcolumn); //files that do not have dependancies - fasta is set to not be required whereas shared is set to be required - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pfasta); - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","outputType",false,false); parameters.push_back(pfasta); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","outputType",false,true); parameters.push_back(pshared); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); //choose more than one multiple options - CommandParameter pcalc("calc", "Multiple", "jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-morisitahorn-braycurtis", "jest-thetayc", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter pcalc("calc", "Multiple", "jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-morisitahorn-braycurtis", "jest-thetayc", "", "", "","",true,false); parameters.push_back(pcalc); //choose only one multiple options - CommandParameter pdistance("distance", "Multiple", "column-lt-square", "column", "", "", "",false,false); parameters.push_back(pdistance); + CommandParameter pdistance("distance", "Multiple", "column-lt-square", "column", "", "", "","",false,false); parameters.push_back(pdistance); - CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptiming); + CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(ptiming); //every command must have inputdir and outputdir. This allows mothur users to redirect input and output files. - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + 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); } @@ -64,26 +64,21 @@ string NewCommand::getHelpString(){ } } //********************************************************************************************************************** -string NewCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string tag = ""; - map >::iterator it; +string NewCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fileType1") { tag = "tag1"; } - else if (type == "fileType2") { tag = "tag2"; } - else if (type == "fileType3") { tag = "tag3"; } - else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } - } - return tag; - } - catch(exception& e) { - m->errorOut(e, "NewCommand", "getOutputFileName"); - exit(1); - } + if (type == "fileType1") { pattern = "[filename],tag1"; } + else if (type == "fileType2") { pattern = "[filename],tag2"; } + else if (type == "fileType3") { pattern = "[filename],tag3"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "NewCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** NewCommand::NewCommand(){ diff --git a/newcommandtemplate.h b/newcommandtemplate.h index ae57bd8..8d11731 100644 --- a/newcommandtemplate.h +++ b/newcommandtemplate.h @@ -35,9 +35,10 @@ public: vector setParameters(); string getCommandName() { return "newCommandNameToBeSeenByUser"; } string getCommandCategory() { return "commandCategory"; } - string getOutputFileNameTag(string, string); + + string getOutputPattern(string); //commmand category choices: Sequence Processing, OTU-Based Approaches, Hypothesis Testing, Phylotype Analysis, General, Clustering and Hidden - string getHelpString(); + string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/newCommandNameToBeSeenByUser"; } string getDescription() { return "brief description"; } diff --git a/nmdscommand.cpp b/nmdscommand.cpp index 900f50b..a90ed29 100644 --- a/nmdscommand.cpp +++ b/nmdscommand.cpp @@ -13,15 +13,15 @@ //********************************************************************************************************************** vector NMDSCommand::setParameters(){ try { - CommandParameter paxes("axes", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paxes); - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); - CommandParameter pmaxdim("maxdim", "Number", "", "2", "", "", "",false,false); parameters.push_back(pmaxdim); - CommandParameter pmindim("mindim", "Number", "", "2", "", "", "",false,false); parameters.push_back(pmindim); - CommandParameter piters("iters", "Number", "", "10", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pmaxiters("maxiters", "Number", "", "500", "", "", "",false,false); parameters.push_back(pmaxiters); - CommandParameter pepsilon("epsilon", "Number", "", "0.000000000001", "", "", "",false,false); parameters.push_back(pepsilon); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter paxes("axes", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(paxes); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","nmds-stress",false,true,true); parameters.push_back(pphylip); + CommandParameter pmaxdim("maxdim", "Number", "", "2", "", "", "","",false,false); parameters.push_back(pmaxdim); + CommandParameter pmindim("mindim", "Number", "", "2", "", "", "","",false,false); parameters.push_back(pmindim); + CommandParameter piters("iters", "Number", "", "10", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pmaxiters("maxiters", "Number", "", "500", "", "", "","",false,false); parameters.push_back(pmaxiters); + CommandParameter pepsilon("epsilon", "Number", "", "0.000000000001", "", "", "","",false,false); parameters.push_back(pepsilon); + 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); } @@ -55,27 +55,23 @@ string NMDSCommand::getHelpString(){ } } //********************************************************************************************************************** -string NMDSCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string NMDSCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "nmds") { outputFileName = "nmds.axes"; } - else if (type == "stress") { outputFileName = "nmds.stress"; } - else if (type == "iters") { outputFileName = "nmds.iters"; } - 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, "NMDSCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "nmds") { pattern = "[filename],nmds.axes"; } + else if (type == "stress") { pattern = "[filename],nmds.stress"; } + else if (type == "iters") { pattern = "[filename],nmds.iters"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "NMDSCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** NMDSCommand::NMDSCommand(){ try { @@ -208,8 +204,10 @@ int NMDSCommand::execute(){ vector< vector > axes; if (axesfile != "") { axes = readAxes(names); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("iters"); - string stressFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("stress"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(phylipfile)); + string outputFileName = getOutputFileName("iters",variables); + string stressFileName = getOutputFileName("stress",variables); outputNames.push_back(outputFileName); outputTypes["iters"].push_back(outputFileName); outputNames.push_back(stressFileName); outputTypes["stress"].push_back(stressFileName); @@ -278,7 +276,7 @@ int NMDSCommand::execute(){ out.close(); out2.close(); //output best config - string BestFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("nmds"); + string BestFileName = getOutputFileName("nmds",variables); outputNames.push_back(BestFileName); outputTypes["nmds"].push_back(BestFileName); m->mothurOut("\nNumber of dimensions:\t" + toString(bestDim) + "\n"); diff --git a/nmdscommand.h b/nmdscommand.h index 90364ad..92b6948 100644 --- a/nmdscommand.h +++ b/nmdscommand.h @@ -37,8 +37,9 @@ public: vector setParameters(); string getCommandName() { return "nmds"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Borg, Groenen (1997). Non-metric multidimensional scaling function using the majorization algorithm, in Modern Multidimensional Scaling. Ed. T.F. Cox and M.A.A. Cox. Chapman and Hall. \nhttp://www.mothur.org/wiki/Nmds"; } string getDescription() { return "nmds"; } diff --git a/nocommands.h b/nocommands.h index a5855dc..8c1d722 100644 --- a/nocommands.h +++ b/nocommands.h @@ -25,7 +25,7 @@ public: string getCommandName() { return "NoCommand"; } string getCommandCategory() { return "Hidden"; } string getHelpString() { return "No Command"; } - string getOutputFileNameTag(string, string) { return ""; } + string getOutputPattern(string) { return ""; } string getCitation() { return "no citation"; } string getDescription() { return "no description"; } diff --git a/normalizesharedcommand.cpp b/normalizesharedcommand.cpp index e41cfd9..acd8208 100644 --- a/normalizesharedcommand.cpp +++ b/normalizesharedcommand.cpp @@ -12,15 +12,15 @@ //********************************************************************************************************************** vector NormalizeSharedCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); - CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prelabund); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pmethod("method", "Multiple", "totalgroup-zscore", "totalgroup", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter pnorm("norm", "Number", "", "0", "", "", "",false,false); parameters.push_back(pnorm); - CommandParameter pmakerelabund("makerelabund", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pmakerelabund); - 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); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","shared",false,false,true); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none","shared",false,false,true); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter pmethod("method", "Multiple", "totalgroup-zscore", "totalgroup", "", "", "","",false,false,true); parameters.push_back(pmethod); + CommandParameter pnorm("norm", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pnorm); + CommandParameter pmakerelabund("makerelabund", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pmakerelabund); + 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); } @@ -53,26 +53,20 @@ string NormalizeSharedCommand::getHelpString(){ exit(1); } } - //********************************************************************************************************************** -string NormalizeSharedCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string NormalizeSharedCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "shared") { outputFileName = "norm.shared"; } - 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, "NormalizeSharedCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "shared") { pattern = "[filename],[distance],norm.shared"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "NormalizeSharedCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** NormalizeSharedCommand::NormalizeSharedCommand(){ @@ -468,7 +462,11 @@ int NormalizeSharedCommand::normalize(vector& thisLookUp){ if (pickedGroups) { eliminateZeroOTUS(thisLookUp); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + "." + getOutputFileNameTag("shared"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); + variables["[distance]"] = thisLookUp[0]->getLabel(); + string outputFileName = getOutputFileName("shared",variables); + ofstream out; m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName); @@ -559,7 +557,10 @@ int NormalizeSharedCommand::normalize(vector& thisLook //save mothurOut's binLabels to restore for next label vector saveBinLabels = m->currentBinLabels; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + "." + getOutputFileNameTag("shared"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); + variables["[distance]"] = thisLookUp[0]->getLabel(); + string outputFileName = getOutputFileName("shared",variables); ofstream out; m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName); diff --git a/normalizesharedcommand.h b/normalizesharedcommand.h index 2feb40d..53bcd6b 100644 --- a/normalizesharedcommand.h +++ b/normalizesharedcommand.h @@ -24,8 +24,9 @@ public: vector setParameters(); string getCommandName() { return "normalize.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Normalize.shared"; } string getDescription() { return "normalize samples in a shared or relabund file"; } diff --git a/otuassociationcommand.cpp b/otuassociationcommand.cpp index 968d767..23cac29 100644 --- a/otuassociationcommand.cpp +++ b/otuassociationcommand.cpp @@ -13,15 +13,15 @@ //********************************************************************************************************************** vector OTUAssociationCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none",false,false); parameters.push_back(pshared); - CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none",false,false); parameters.push_back(prelabund); - CommandParameter pmetadata("metadata", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none",false,false); parameters.push_back(pmetadata); - CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pmethod("method", "Multiple", "pearson-spearman-kendall", "pearson", "", "", "",false,false); parameters.push_back(pmethod); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none","otucorr",false,false,true); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none","otucorr",false,false); parameters.push_back(prelabund); + CommandParameter pmetadata("metadata", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pmetadata); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "","",false,false,true); parameters.push_back(pcutoff); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter pmethod("method", "Multiple", "pearson-spearman-kendall", "pearson", "", "", "","",false,false,true); parameters.push_back(pmethod); + 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); } @@ -55,24 +55,19 @@ string OTUAssociationCommand::getHelpString(){ } } //********************************************************************************************************************** -string OTUAssociationCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string OTUAssociationCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "otucorr") { outputFileName = "otu.corr"; } - 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, "OTUAssociationCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "otucorr") { pattern = "[filename],[distance],[tag],otu.corr"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "OTUAssociationCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** OTUAssociationCommand::OTUAssociationCommand(){ @@ -331,8 +326,11 @@ int OTUAssociationCommand::processShared(){ //********************************************************************************************************************** int OTUAssociationCommand::process(vector& lookup){ try { - - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + method + "." + getOutputFileNameTag("otucorr"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); + variables["[distance]"] = lookup[0]->getLabel(); + variables["[tag]"] = method; + string outputFileName = getOutputFileName("otucorr",variables); outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); ofstream out; @@ -492,7 +490,11 @@ int OTUAssociationCommand::processRelabund(){ int OTUAssociationCommand::process(vector& lookup){ try { - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + method + "." + getOutputFileNameTag("otucorr"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileName)); + variables["[distance]"] = lookup[0]->getLabel(); + variables["[tag]"] = method; + string outputFileName = getOutputFileName("otucorr",variables); outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); ofstream out; diff --git a/otuassociationcommand.h b/otuassociationcommand.h index 7f7664b..e9cdb2a 100644 --- a/otuassociationcommand.h +++ b/otuassociationcommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "otu.association"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Otu.association"; } string getDescription() { return "calculate the correlation coefficient for the otus in a shared/relabund file"; } diff --git a/otuhierarchycommand.cpp b/otuhierarchycommand.cpp index 091bf9b..dc026de 100644 --- a/otuhierarchycommand.cpp +++ b/otuhierarchycommand.cpp @@ -12,11 +12,11 @@ //********************************************************************************************************************** vector OtuHierarchyCommand::setParameters(){ try { - CommandParameter poutput("output", "Multiple", "name-number", "name", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); 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); + CommandParameter poutput("output", "Multiple", "name-number", "name", "", "", "","",false,false); parameters.push_back(poutput); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","otuheirarchy",false,true,true); 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); } @@ -47,24 +47,19 @@ string OtuHierarchyCommand::getHelpString(){ } } //********************************************************************************************************************** -string OtuHierarchyCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string OtuHierarchyCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "otuheirarchy") { outputFileName = "otu.hierarchy"; } - 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, "OtuHierarchyCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "otuheirarchy") { pattern = "[filename],[distance1],[tag],[distance2],otu.hierarchy"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "OtuHierarchyCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** OtuHierarchyCommand::OtuHierarchyCommand(){ @@ -199,7 +194,12 @@ int OtuHierarchyCommand::execute(){ } ofstream out; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(listFile)) + lists[0].getLabel() + "-" + lists[1].getLabel() + "." + getOutputFileNameTag("otuheirarchy"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listFile)); + variables["[distance1]"] = lists[0].getLabel(); + variables["[tag]"] = "-"; + variables["[distance2]"] = lists[1].getLabel(); + string outputFileName = getOutputFileName("otuheirarchy",variables); m->openOutputFile(outputFileName, out); //go through each bin in "big" otu and output the bins in "little" otu which created it diff --git a/otuhierarchycommand.h b/otuhierarchycommand.h index ad6da0c..cd106ec 100644 --- a/otuhierarchycommand.h +++ b/otuhierarchycommand.h @@ -24,8 +24,9 @@ public: vector setParameters(); string getCommandName() { return "otu.hierarchy"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Otu.hierarchy"; } string getDescription() { return "relates OTUs at different distances"; } diff --git a/pairwiseseqscommand.cpp b/pairwiseseqscommand.cpp index dd82431..0f86028 100644 --- a/pairwiseseqscommand.cpp +++ b/pairwiseseqscommand.cpp @@ -12,20 +12,20 @@ //********************************************************************************************************************** vector PairwiseSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter palign("align", "Multiple", "needleman-gotoh-blast-noalign", "needleman", "", "", "",false,false); parameters.push_back(palign); - CommandParameter pmatch("match", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pmatch); - CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pmismatch); - CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "",false,false); parameters.push_back(pgapopen); - CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pgapextend); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter poutput("output", "Multiple", "column-lt-square-phylip", "column", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter pcalc("calc", "Multiple", "nogaps-eachgap-onegap", "onegap", "", "", "",false,false); parameters.push_back(pcalc); - CommandParameter pcountends("countends", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pcountends); - CommandParameter pcompress("compress", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pcompress); - CommandParameter pcutoff("cutoff", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","phylip-column",false,true,true); parameters.push_back(pfasta); + CommandParameter palign("align", "Multiple", "needleman-gotoh-blast-noalign", "needleman", "", "", "","",false,false); parameters.push_back(palign); + CommandParameter pmatch("match", "Number", "", "1.0", "", "", "","",false,false); parameters.push_back(pmatch); + CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pmismatch); + CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "","",false,false); parameters.push_back(pgapopen); + CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "","",false,false); parameters.push_back(pgapextend); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter poutput("output", "Multiple", "column-lt-square-phylip", "column", "", "", "","phylip-column",false,false,true); parameters.push_back(poutput); + CommandParameter pcalc("calc", "Multiple", "nogaps-eachgap-onegap", "onegap", "", "", "","",false,false); parameters.push_back(pcalc); + CommandParameter pcountends("countends", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pcountends); + CommandParameter pcompress("compress", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pcompress); + CommandParameter pcutoff("cutoff", "Number", "", "1.0", "", "", "","",false,false,true); parameters.push_back(pcutoff); + 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); } @@ -65,25 +65,20 @@ string PairwiseSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string PairwiseSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string PairwiseSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "phylip") { outputFileName = "dist"; } - else if (type == "column") { outputFileName = "dist"; } - 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, "PairwiseSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "phylip") { pattern = "[filename],[outputtag],dist"; } + else if (type == "column") { pattern = "[filename],dist"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "PairwiseSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** PairwiseSeqsCommand::PairwiseSeqsCommand(){ @@ -291,16 +286,20 @@ int PairwiseSeqsCommand::execute(){ int numSeqs = alignDB.getNumSeqs(); int startTime = time(NULL); string outputFile = ""; - + + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])); if (output == "lt") { //does the user want lower triangle phylip formatted file - outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "phylip." + getOutputFileNameTag("phylip"); + variables["[outputtag]"] = "phylip"; + outputFile = getOutputFileName("phylip", variables); m->mothurRemove(outputFile); outputTypes["phylip"].push_back(outputFile); }else if (output == "column") { //user wants column format - outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("column"); + outputFile = getOutputFileName("column", variables); outputTypes["column"].push_back(outputFile); m->mothurRemove(outputFile); }else { //assume square - outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "square." + getOutputFileNameTag("phylip"); + variables["[outputtag]"] = "square"; + outputFile = getOutputFileName("phylip", variables); m->mothurRemove(outputFile); outputTypes["phylip"].push_back(outputFile); } diff --git a/pairwiseseqscommand.h b/pairwiseseqscommand.h index 0e749d5..33fcfca 100644 --- a/pairwiseseqscommand.h +++ b/pairwiseseqscommand.h @@ -40,8 +40,9 @@ public: vector setParameters(); string getCommandName() { return "pairwise.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Needleman SB, Wunsch CD (1970). A general method applicable to the search for similarities in the amino acid sequence of two proteins. J Mol Biol 48: 443-53. [ for needleman ]\nGotoh O (1982). An improved algorithm for matching biological sequences. J Mol Biol 162: 705-8. [ for gotoh ] \nhttp://www.mothur.org/wiki/Pairwise.seqs"; } string getDescription() { return "calculates pairwise distances from an unaligned fasta file"; } diff --git a/parsefastaqcommand.cpp b/parsefastaqcommand.cpp index ba23ae3..63ed314 100644 --- a/parsefastaqcommand.cpp +++ b/parsefastaqcommand.cpp @@ -13,12 +13,12 @@ //********************************************************************************************************************** vector ParseFastaQCommand::setParameters(){ try { - CommandParameter pfastq("fastq", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfastq); - CommandParameter pfasta("fasta", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pfasta); - CommandParameter pqual("qfile", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pqual); - CommandParameter pformat("format", "Multiple", "sanger-illumina-solexa", "sanger", "", "", "",false,false); parameters.push_back(pformat); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfastq("fastq", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pfastq); + CommandParameter pfasta("fasta", "Boolean", "", "T", "", "", "","fasta",false,false); parameters.push_back(pfasta); + CommandParameter pqual("qfile", "Boolean", "", "T", "", "", "","qfile",false,false); parameters.push_back(pqual); + CommandParameter pformat("format", "Multiple", "sanger-illumina-solexa", "sanger", "", "", "","",false,false,true); parameters.push_back(pformat); + 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); } @@ -49,27 +49,21 @@ string ParseFastaQCommand::getHelpString(){ } } //********************************************************************************************************************** -string ParseFastaQCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ParseFastaQCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "fasta"; } - else if (type == "qfile") { outputFileName = "qual"; } - 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, "ParseFastaQCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],fasta"; } + else if (type == "qfile") { pattern = "[filename],qual"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ParseFastaQCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** ParseFastaQCommand::ParseFastaQCommand(){ try { @@ -163,8 +157,10 @@ int ParseFastaQCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //open Output Files - string fastaFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + getOutputFileNameTag("fasta"); - string qualFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + getOutputFileNameTag("qfile"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaQFile)); + string fastaFile = getOutputFileName("fasta",variables); + string qualFile = getOutputFileName("qfile",variables); ofstream outFasta, outQual; if (fasta) { m->openOutputFile(fastaFile, outFasta); outputNames.push_back(fastaFile); outputTypes["fasta"].push_back(fastaFile); } @@ -261,9 +257,9 @@ vector ParseFastaQCommand::convertQual(string qual) { temp -= 64; //char '@' }else if (format == "solexa") { temp = int(convertTable[temp]); //convert to sanger - temp -= 33; //char '!' + temp -= int('!'); //char '!' }else { - temp -= 33; //char '!' + temp -= int('!'); //char '!' } qualScores.push_back(temp); } diff --git a/parsefastaqcommand.h b/parsefastaqcommand.h index 96fcb7d..b4d90e5 100644 --- a/parsefastaqcommand.h +++ b/parsefastaqcommand.h @@ -23,8 +23,9 @@ public: vector setParameters(); string getCommandName() { return "parse.fastq"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Parse.fastq"; } string getDescription() { return "reads a fastq file and creates a fasta and quality file"; } diff --git a/parselistscommand.cpp b/parselistscommand.cpp index 4e61a58..61cb245 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -12,11 +12,11 @@ //********************************************************************************************************************** vector ParseListCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); - 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); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","list",false,true,true); parameters.push_back(plist); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pgroup); + 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); } @@ -46,26 +46,20 @@ string ParseListCommand::getHelpString(){ } } //********************************************************************************************************************** -string ParseListCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ParseListCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "list") { outputFileName = "list"; } - 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, "ParseListCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "list") { pattern = "[filename],[group],list"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ParseListCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** ParseListCommand::ParseListCommand(){ try { @@ -191,7 +185,8 @@ int ParseListCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //set fileroot - string fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); //fill filehandles with neccessary ofstreams int i; @@ -201,7 +196,8 @@ int ParseListCommand::execute(){ temp = new ofstream; filehandles[gGroups[i]] = temp; - string filename = fileroot + gGroups[i] + "." + getOutputFileNameTag("list"); + variables["[group]"] = gGroups[i]; + string filename = getOutputFileName("list",variables); outputNames.push_back(filename); outputTypes["list"].push_back(filename); m->openOutputFile(filename, *temp); } diff --git a/parselistscommand.h b/parselistscommand.h index 1faeaeb..b366d28 100644 --- a/parselistscommand.h +++ b/parselistscommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "parse.list"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Parse.list"; } string getDescription() { return "parses a list file by group"; } diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index eabbb59..64d2498 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -13,16 +13,16 @@ //********************************************************************************************************************** vector ParsimonyCommand::setParameters(){ try { - CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter prandom("random", "String", "", "", "", "", "",false,false); parameters.push_back(prandom); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","parsimony-psummary",false,true,true); parameters.push_back(ptree); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter prandom("random", "String", "", "", "", "", "","",false,false); parameters.push_back(prandom); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + 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); } @@ -54,27 +54,21 @@ string ParsimonyCommand::getHelpString(){ } } //********************************************************************************************************************** -string ParsimonyCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ParsimonyCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "parsimony") { outputFileName = "parsimony"; } - else if (type == "psummary") { outputFileName = "psummary"; } - 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, "ParsimonyCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "parsimony") { pattern = "[filename],parsimony"; } + else if (type == "psummary") { pattern = "[filename],psummary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ParsimonyCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** ParsimonyCommand::ParsimonyCommand(){ try { @@ -252,11 +246,14 @@ int ParsimonyCommand::execute() { delete reader; if(outputDir == "") { outputDir += m->hasPath(treefile); } - output = new ColumnFile(outputDir + m->getSimpleName(treefile) + "." + getOutputFileNameTag("parsimony"), itersString); - outputNames.push_back(outputDir + m->getSimpleName(treefile) + "." + getOutputFileNameTag("parsimony")); - outputTypes["parsimony"].push_back(outputDir + m->getSimpleName(treefile) + "." + getOutputFileNameTag("parsimony")); + map variables; + variables["[filename]"] = outputDir + m->getSimpleName(treefile) + "."; + + output = new ColumnFile(getOutputFileName("parsimony",variables), itersString); + outputNames.push_back(getOutputFileName("parsimony",variables)); + outputTypes["parsimony"].push_back(getOutputFileName("parsimony",variables)); - sumFile = outputDir + m->getSimpleName(treefile) + "." + getOutputFileNameTag("psummary"); + sumFile = getOutputFileName("psummary",variables); m->openOutputFile(sumFile, outSum); outputNames.push_back(sumFile); outputTypes["psummary"].push_back(sumFile); @@ -579,7 +576,7 @@ void ParsimonyCommand::getUserInput() { //set tmaps namesOfSeqs for (int j = 0; j < num; j++) { - groupMap[toString(count)] = i; + groupMap[toString(count)] = toString(i); nameMap.insert(toString(count)); count++; } @@ -591,6 +588,7 @@ void ParsimonyCommand::getUserInput() { getline(cin, s); m->Treenames = ct->getNamesOfSeqs(); + m->runParse = false; } catch(exception& e) { m->errorOut(e, "ParsimonyCommand", "getUserInput"); diff --git a/parsimonycommand.h b/parsimonycommand.h index 38a7505..7f7ad89 100644 --- a/parsimonycommand.h +++ b/parsimonycommand.h @@ -28,8 +28,9 @@ public: vector setParameters(); string getCommandName() { return "parsimony"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Slatkin M, Maddison WP (1989). A cladistic measure of gene flow inferred from the phylogenies of alleles. Genetics 123: 603-13. \nSlatkin M, Maddison WP (1990). Detecting isolation by distance using phylogenies of genes. Genetics 126: 249-60. \nMartin AP (2002). Phylogenetic approaches for describing and comparing the diversity of microbial communities. Appl Environ Microbiol 68: 3673-82. \nSchloss PD, Handelsman J (2006). Introducing TreeClimber, a test to compare microbial community structure. Appl Environ Microbiol 72: 2379-84.\nhttp://www.mothur.org/wiki/Parsimony"; } string getDescription() { return "generic test that describes whether two or more communities have the same structure"; } diff --git a/pcacommand.cpp b/pcacommand.cpp index 2cb37bd..7103adb 100644 --- a/pcacommand.cpp +++ b/pcacommand.cpp @@ -13,13 +13,13 @@ //********************************************************************************************************************** vector PCACommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); - CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prelabund); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pmetric("metric", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pmetric); - 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); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","pca-loadings",false,false,true); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none","pca-loadings",false,false,true); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter pmetric("metric", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pmetric); + 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); } @@ -49,25 +49,20 @@ string PCACommand::getHelpString(){ } } //********************************************************************************************************************** -string PCACommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string PCACommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "pca") { outputFileName = "pca.axes"; } - else if (type == "loadings") { outputFileName = "pca.loadings"; } - 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, "PCACommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "pca") { pattern = "[filename],[distance],pca.axes"; } + else if (type == "loadings") { pattern = "[filename],[distance],pca.loadings"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "PCACommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -386,8 +381,8 @@ int PCACommand::process(vector& lookupFloat){ if (m->control_pressed) { return 0; } string fbase = outputDir + m->getRootName(m->getSimpleName(inputFile)); - string outputFileName = fbase + lookupFloat[0]->getLabel(); - output(outputFileName, m->getGroups(), X, d); + //string outputFileName = fbase + lookupFloat[0]->getLabel(); + output(fbase, lookupFloat[0]->getLabel(), m->getGroups(), X, d); if (metric) { @@ -416,7 +411,7 @@ int PCACommand::process(vector& lookupFloat){ } /*********************************************************************************************************************************/ -void PCACommand::output(string fnameRoot, vector name_list, vector >& G, vector d) { +void PCACommand::output(string fbase, string label, vector name_list, vector >& G, vector d) { try { int numEigenValues = d.size(); @@ -426,18 +421,23 @@ void PCACommand::output(string fnameRoot, vector name_list, vectoropenOutputFile((fnameRoot+"."+getOutputFileNameTag("pca")), pcaData); + map variables; + variables["[filename]"] = fbase; + variables["[distance]"] = label; + string pcaFileName = getOutputFileName("pca",variables); + m->openOutputFile(pcaFileName, pcaData); pcaData.setf(ios::fixed, ios::floatfield); pcaData.setf(ios::showpoint); - outputNames.push_back(fnameRoot+"."+getOutputFileNameTag("pca")); - outputTypes["pca"].push_back(fnameRoot+"."+getOutputFileNameTag("pca")); + outputNames.push_back(pcaFileName); + outputTypes["pca"].push_back(pcaFileName); ofstream pcaLoadings; - m->openOutputFile((fnameRoot+"."+getOutputFileNameTag("loadings")), pcaLoadings); + string loadingsFilename = getOutputFileName("loadings",variables); + m->openOutputFile(loadingsFilename, pcaLoadings); pcaLoadings.setf(ios::fixed, ios::floatfield); pcaLoadings.setf(ios::showpoint); - outputNames.push_back(fnameRoot+"."+getOutputFileNameTag("loadings")); - outputTypes["loadings"].push_back(fnameRoot+"."+getOutputFileNameTag("loadings")); + outputNames.push_back(loadingsFilename); + outputTypes["loadings"].push_back(loadingsFilename); pcaLoadings << "axis\tloading\n"; for(int i=0;i setParameters(); string getCommandName() { return "pca"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "McCune B, Grace JB, Urban DL (2002). Analysis of ecological communities. MjM Software Design: Gleneden Beach, OR. \nLegendre P, Legendre L (1998). Numerical Ecology. Elsevier: New York. \nhttp://www.mothur.org/wiki/Pca"; } string getDescription() { return "pca"; } @@ -44,7 +45,7 @@ private: //vector< vector > createMatrix(vector); int process(vector&); - void output(string, vector, vector >&, vector); + void output(string, string, vector, vector >&, vector); }; diff --git a/pcoacommand.cpp b/pcoacommand.cpp index 354826f..2043a12 100644 --- a/pcoacommand.cpp +++ b/pcoacommand.cpp @@ -15,10 +15,10 @@ //********************************************************************************************************************** vector PCOACommand::setParameters(){ try { - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); - CommandParameter pmetric("metric", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pmetric); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","pcoa-loadings",false,true,true); parameters.push_back(pphylip); + CommandParameter pmetric("metric", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pmetric); + 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); } @@ -45,29 +45,24 @@ string PCOACommand::getHelpString(){ exit(1); } } - //********************************************************************************************************************** -string PCOACommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string PCOACommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "pcoa") { outputFileName = "pcoa.axes"; } - else if (type == "loadings") { outputFileName = "pcoa.loadings"; } - 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, "PCOACommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "pcoa") { pattern = "[filename],pcoa.axes"; } + else if (type == "loadings") { pattern = "[filename],pcoa.loadings"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "PCOACommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** PCOACommand::PCOACommand(){ try { @@ -251,7 +246,9 @@ void PCOACommand::output(string fnameRoot, vector name_list, vector variables; + variables["[filename]"] = fnameRoot; + string pcoaDataFile = getOutputFileName("pcoa",variables); m->openOutputFile(pcoaDataFile, pcaData); pcaData.setf(ios::fixed, ios::floatfield); pcaData.setf(ios::showpoint); @@ -259,7 +256,7 @@ void PCOACommand::output(string fnameRoot, vector name_list, vectoropenOutputFile(loadingsFile, pcaLoadings); pcaLoadings.setf(ios::fixed, ios::floatfield); pcaLoadings.setf(ios::showpoint); diff --git a/pcoacommand.h b/pcoacommand.h index 93feefa..29957f1 100644 --- a/pcoacommand.h +++ b/pcoacommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "pcoa"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "McCune B, Grace JB, Urban DL (2002). Analysis of ecological communities. MjM Software Design: Gleneden Beach, OR. \nLegendre P, Legendre L (1998). Numerical Ecology. Elsevier: New York. \nhttp://www.mothur.org/wiki/Pcoa"; } string getDescription() { return "pcoa"; } diff --git a/pcrseqscommand.h b/pcrseqscommand.h index d35850c..9fc4041 100644 --- a/pcrseqscommand.h +++ b/pcrseqscommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "pcr.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Pcr.seqs"; } string getDescription() { return "pcr.seqs"; } diff --git a/phylodiversitycommand.cpp b/phylodiversitycommand.cpp index b0c11f6..002c577 100644 --- a/phylodiversitycommand.cpp +++ b/phylodiversitycommand.cpp @@ -14,20 +14,20 @@ vector PhyloDiversityCommand::setParameters(){ try { - CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter prarefy("rarefy", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(prarefy); - CommandParameter psummary("summary", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(psummary); - CommandParameter pcollect("collect", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pcollect); - CommandParameter pscale("scale", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pscale); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","phylodiv",false,true,true); parameters.push_back(ptree); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pfreq); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter prarefy("rarefy", "Boolean", "", "F", "", "", "","rarefy",false,false); parameters.push_back(prarefy); + CommandParameter psummary("summary", "Boolean", "", "T", "", "", "","summary",false,false); parameters.push_back(psummary); + CommandParameter pcollect("collect", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pcollect); + CommandParameter pscale("scale", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pscale); + 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); } @@ -63,26 +63,21 @@ string PhyloDiversityCommand::getHelpString(){ } } //********************************************************************************************************************** -string PhyloDiversityCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string PhyloDiversityCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "phylodiv") { outputFileName = "phylodiv"; } - else if (type == "rarefy") { outputFileName = "phylodiv.rarefaction"; } - else if (type == "summary") { outputFileName = "phylodiv.summary"; } - 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, "PhyloDiversityCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "phylodiv") { pattern = "[filename],[tag],phylodiv"; } + else if (type == "rarefy") { pattern = "[filename],[tag],phylodiv.rarefaction"; } + else if (type == "summary") { pattern = "[filename],[tag],phylodiv.summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "PhyloDiversityCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -284,9 +279,12 @@ int PhyloDiversityCommand::execute(){ if (m->control_pressed) { delete ct; for (int j = 0; j < trees.size(); j++) { delete trees[j]; } for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } return 0; } ofstream outSum, outRare, outCollect; - string outSumFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(i+1) + "." + getOutputFileNameTag("summary"); - string outRareFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(i+1) + "." + getOutputFileNameTag("rarefy"); - string outCollectFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(i+1) + "." + getOutputFileNameTag("phylodiv"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile)); + variables["[tag]"] = toString(i+1); + string outSumFile = getOutputFileName("summary",variables); + string outRareFile = getOutputFileName("rarefy",variables); + string outCollectFile = getOutputFileName("phylodiv",variables); if (summary) { m->openOutputFile(outSumFile, outSum); outputNames.push_back(outSumFile); outputTypes["summary"].push_back(outSumFile); } if (rarefy) { m->openOutputFile(outRareFile, outRare); outputNames.push_back(outRareFile); outputTypes["rarefy"].push_back(outRareFile); } @@ -301,6 +299,31 @@ int PhyloDiversityCommand::execute(){ randomLeaf.push_back(j); } } + + /* float sum = 0; + vector sums; sums.resize(m->getGroups().size(), 0); + vector sumsAboveRoot; sumsAboveRoot.resize(m->getGroups().size(), 0); + for (int j = 0; j < trees[i]->getNumNodes(); j++) { + if (trees[i]->tree[j].getBranchLength() < 0) { cout << j << '\t' << trees[i]->tree[j].getName() << '\t' << trees[i]->tree[j].getBranchLength() << endl; } + + sum += abs(trees[i]->tree[j].getBranchLength()); + for (int k = 0; k < m->getGroups().size(); k++) { + map::iterator itGroup = trees[i]->tree[j].pcount.find(m->getGroups()[k]); + if (itGroup != trees[i]->tree[j].pcount.end()) { //this branch belongs to a group we care about + if (j < rootForGroup[m->getGroups()[k]]) { + sums[k] += abs(trees[i]->tree[j].getBranchLength()); + }else { + sumsAboveRoot[k] += abs(trees[i]->tree[j].getBranchLength()); + } + } + } + } + cout << sum << endl; //exit(1); + + for (int k = 0; k < m->getGroups().size(); k++) { + cout << m->getGroups()[k] << "root node = " << rootForGroup[m->getGroups()[k]] << "sum below root = " << sums[k] << "sum above root = " << sumsAboveRoot[k] << endl; + } + exit(1); */ numLeafNodes = randomLeaf.size(); //reset the number of leaf nodes you are using @@ -571,6 +594,7 @@ void PhyloDiversityCommand::printSumData(map< string, vector >& div, ofst else { score = div[mGroups[j]][numSampled] / (float)numIters; } out << setprecision(4) << score << endl; + cout << mGroups[j] << '\t' << numSampled << '\t'<< setprecision(4) << score << endl; } out.close(); @@ -635,7 +659,7 @@ vector PhyloDiversityCommand::calcBranchLength(Tree* t, int leaf, vector< //you are a leaf if(t->tree[index].getBranchLength() != -1){ for (int k = 0; k < groups.size(); k++) { - sums[k] += abs(t->tree[index].getBranchLength()); + sums[k] += abs(t->tree[index].getBranchLength()); } } @@ -686,10 +710,10 @@ map PhyloDiversityCommand::getRootForGroups(Tree* t){ for (int j = 0; j < groups.size(); j++) { - if (done[groups[j]] == false) { //we haven't found the root for this group yet - - done[groups[j]] = true; - roots[groups[j]] = i; //set root to self to start + if (done[groups[j]] == false) { //we haven't found the root for this group yet, initialize it + done[groups[j]] = true; + roots[groups[j]] = i; //set root to self to start + } //while you aren't at root while(t->tree[index].getParent() != -1){ @@ -709,15 +733,17 @@ map PhyloDiversityCommand::getRootForGroups(Tree* t){ if (itGroup != t->tree[rc].pcount.end()) { RpcountSize++; } if ((LpcountSize != 0) && (RpcountSize != 0)) { //possible root - roots[groups[j]] = index; + if (index > roots[groups[j]]) { roots[groups[j]] = index; } }else { ;} index = t->tree[index].getParent(); } - } + //} } } + + return roots; } diff --git a/phylodiversitycommand.h b/phylodiversitycommand.h index ee76f05..ec372ba 100644 --- a/phylodiversitycommand.h +++ b/phylodiversitycommand.h @@ -25,8 +25,9 @@ class PhyloDiversityCommand : public Command { vector setParameters(); string getCommandName() { return "phylo.diversity"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Faith DP (1994). Phylogenetic pattern and the quantification of organismal biodiversity. Philos Trans R Soc Lond B Biol Sci 345: 45-58. \nhttp://www.mothur.org/wiki/Phylo.diversity"; } string getDescription() { return "phylo.diversity"; } diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index eddddfa..fbc7c60 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -16,12 +16,12 @@ //********************************************************************************************************************** vector PhylotypeCommand::setParameters(){ try { - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptaxonomy); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcutoff("cutoff", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pcutoff); - 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); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","list-rabund-sabund",false,true,true); parameters.push_back(ptaxonomy); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcutoff("cutoff", "Number", "", "-1", "", "", "","",false,false,true); parameters.push_back(pcutoff); + 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); } @@ -54,26 +54,21 @@ string PhylotypeCommand::getHelpString(){ } } //********************************************************************************************************************** -string PhylotypeCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string PhylotypeCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "list") { outputFileName = "list"; } - else if (type == "rabund") { outputFileName = "rabund"; } - else if (type == "sabund") { outputFileName = "sabund"; } - 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, "PhylotypeCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "list") { pattern = "[filename],[tag],list"; } + else if (type == "rabund") { pattern = "[filename],[tag],rabund"; } + else if (type == "sabund") { pattern = "[filename],[tag],sabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "PhylotypeCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** PhylotypeCommand::PhylotypeCommand(){ @@ -217,15 +212,17 @@ int PhylotypeCommand::execute(){ if (m->control_pressed) { delete tree; return 0; } string fileroot = outputDir + m->getRootName(m->getSimpleName(taxonomyFileName)); - - ofstream outList; - string outputListFile = fileroot + "tx." + getOutputFileNameTag("list"); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = "tx"; + ofstream outList; + string outputListFile = getOutputFileName("list",variables); m->openOutputFile(outputListFile, outList); ofstream outSabund; - string outputSabundFile = fileroot + "tx." + getOutputFileNameTag("sabund"); + string outputSabundFile = getOutputFileName("sabund",variables); m->openOutputFile(outputSabundFile, outSabund); ofstream outRabund; - string outputRabundFile = fileroot + "tx." + getOutputFileNameTag("rabund"); + string outputRabundFile = getOutputFileName("rabund",variables); m->openOutputFile(outputRabundFile, outRabund); outputNames.push_back(outputListFile); outputTypes["list"].push_back(outputListFile); diff --git a/phylotypecommand.h b/phylotypecommand.h index 0e315ec..7fe10af 100644 --- a/phylotypecommand.h +++ b/phylotypecommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "phylotype"; } string getCommandCategory() { return "Clustering"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Phylotype"; } string getDescription() { return "cluster your sequences into OTUs based on their classifications"; } diff --git a/pipelinepdscommand.cpp b/pipelinepdscommand.cpp index 968ba4f..958201d 100644 --- a/pipelinepdscommand.cpp +++ b/pipelinepdscommand.cpp @@ -14,16 +14,16 @@ //********************************************************************************************************************** vector PipelineCommand::setParameters(){ try { - CommandParameter psff("sff", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(psff); - CommandParameter poligos("oligos", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(poligos); - CommandParameter palign("align", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(palign); - CommandParameter pchimera("chimera", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(pchimera); - CommandParameter pclassify("classify", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(pclassify); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(ptaxonomy); - CommandParameter ppipeline("pipeline", "InputTypes", "", "", "none", "oneRequired", "none",false,false); parameters.push_back(ppipeline); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter psff("sff", "InputTypes", "", "", "none", "oneRequired", "pipe","",false,false,true); parameters.push_back(psff); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "oneRequired", "pipe","",false,false,true); parameters.push_back(poligos); + CommandParameter palign("align", "InputTypes", "", "", "none", "oneRequired", "pipe","",false,false,true); parameters.push_back(palign); + CommandParameter pchimera("chimera", "InputTypes", "", "", "none", "oneRequired", "pipe","",false,false,true); parameters.push_back(pchimera); + CommandParameter pclassify("classify", "InputTypes", "", "", "none", "oneRequired", "pipe","",false,false,true); parameters.push_back(pclassify); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "oneRequired", "pipe","",false,false,true); parameters.push_back(ptaxonomy); + CommandParameter ppipeline("pipeline", "InputTypes", "", "", "none", "oneRequired", "none","",false,false,true); parameters.push_back(ppipeline); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + 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); } diff --git a/pipelinepdscommand.h b/pipelinepdscommand.h index 4697f40..22386bc 100644 --- a/pipelinepdscommand.h +++ b/pipelinepdscommand.h @@ -26,8 +26,8 @@ public: vector setParameters(); string getCommandName() { return "pipeline.pds"; } string getCommandCategory() { return "Hidden"; } - string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); + string getOutputPattern(string) { return ""; } string getCitation() { return "Schloss PD, Gevers D, Westcott SL (2011). Reducing the effects of PCR amplification and sequencing artifacts on 16S rRNA-based studies. PLoS ONE. 6:e27310.\nhttp://www.mothur.org/wiki/Pipeline.pds"; } string getDescription() { return "pat's pipeline"; } diff --git a/prcseqscommand.cpp b/prcseqscommand.cpp index de2cb20..5fc9f98 100644 --- a/prcseqscommand.cpp +++ b/prcseqscommand.cpp @@ -11,21 +11,21 @@ //********************************************************************************************************************** vector PcrSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter poligos("oligos", "InputTypes", "", "", "ecolioligos", "none", "none",false,false); parameters.push_back(poligos); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter ptax("taxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(ptax); - CommandParameter pecoli("ecoli", "InputTypes", "", "", "ecolioligos", "none", "none",false,false); parameters.push_back(pecoli); - CommandParameter pstart("start", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pstart); - CommandParameter pend("end", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pend); - CommandParameter pnomatch("nomatch", "Multiple", "reject-keep", "reject", "", "", "",false,false); parameters.push_back(pnomatch); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pkeepprimer("keepprimer", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pkeepprimer); - CommandParameter pkeepdots("keepdots", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pkeepdots); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter poligos("oligos", "InputTypes", "", "", "ecolioligos", "none", "none","",false,false,true); parameters.push_back(poligos); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","group",false,false,true); parameters.push_back(pgroup); + CommandParameter ptax("taxonomy", "InputTypes", "", "", "none", "none", "none","taxonomy",false,false,true); parameters.push_back(ptax); + CommandParameter pecoli("ecoli", "InputTypes", "", "", "ecolioligos", "none", "none","",false,false); parameters.push_back(pecoli); + CommandParameter pstart("start", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pstart); + CommandParameter pend("end", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pend); + CommandParameter pnomatch("nomatch", "Multiple", "reject-keep", "reject", "", "", "","",false,false); parameters.push_back(pnomatch); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pkeepprimer("keepprimer", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pkeepprimer); + CommandParameter pkeepdots("keepdots", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pkeepdots); + 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); } @@ -58,31 +58,25 @@ string PcrSeqsCommand::getHelpString(){ exit(1); } } - //********************************************************************************************************************** -string PcrSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string PcrSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "pcr.fasta"; } - else if (type == "taxonomy") { outputFileName = "pcr" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "pcr" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "pcr" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "pcr" + m->getExtension(inputName); } - else if (type == "accnos") { outputFileName = "bad.accnos"; } - 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, "PcrSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],pcr,[extension]-[filename],[tag],pcr,[extension]"; } + else if (type == "taxonomy") { pattern = "[filename],pcr,[extension]"; } + else if (type == "name") { pattern = "[filename],pcr,[extension]"; } + else if (type == "group") { pattern = "[filename],pcr,[extension]"; } + else if (type == "count") { pattern = "[filename],pcr,[extension]"; } + else if (type == "accnos") { pattern = "[filename],bad.accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "PcrSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -315,10 +309,13 @@ int PcrSeqsCommand::execute(){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string trimSeqFile = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[extension]"] = m->getExtension(fastafile); + string trimSeqFile = getOutputFileName("fasta",variables); outputNames.push_back(trimSeqFile); outputTypes["fasta"].push_back(trimSeqFile); - - string badSeqFile = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "scrap." + getOutputFileNameTag("fasta"); + variables["[tag]"] = "scrap"; + string badSeqFile = getOutputFileName("fasta",variables); length = 0; @@ -914,7 +911,9 @@ int PcrSeqsCommand::writeAccnos(set badNames){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("accnos"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + string outputFileName = getOutputFileName("accnos",variables); outputNames.push_back(outputFileName); outputTypes["accnos"].push_back(outputFileName); ofstream out; @@ -976,7 +975,10 @@ int PcrSeqsCommand::readName(set& names){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outputFileName = getOutputFileName("name", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -1034,7 +1036,10 @@ int PcrSeqsCommand::readGroup(set names){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputFileName = getOutputFileName("group", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -1081,7 +1086,11 @@ int PcrSeqsCommand::readTax(set names){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)); + variables["[extension]"] = m->getExtension(taxfile); + string outputFileName = getOutputFileName("taxonomy", variables); + ofstream out; m->openOutputFile(outputFileName, out); @@ -1128,7 +1137,11 @@ int PcrSeqsCommand::readCount(set badSeqNames){ m->openInputFile(countfile, in); set::iterator it; - string goodCountFile = outputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string goodCountFile = getOutputFileName("count", variables); + outputNames.push_back(goodCountFile); outputTypes["count"].push_back(goodCountFile); ofstream goodCountOut; m->openOutputFile(goodCountFile, goodCountOut); diff --git a/preclustercommand.cpp b/preclustercommand.cpp index dadc918..0c7895c 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -13,14 +13,14 @@ //********************************************************************************************************************** vector PreClusterCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pdiffs("diffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pdiffs); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta-name",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pdiffs("diffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(pdiffs); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + 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); } @@ -54,27 +54,22 @@ string PreClusterCommand::getHelpString(){ } } //********************************************************************************************************************** -string PreClusterCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string PreClusterCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "precluster" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "precluster.names"; } - else if (type == "count") { outputFileName = "precluster.count_table"; } - else if (type == "map") { outputFileName = "precluster.map"; } - 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, "PreClusterCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],precluster,[extension]"; } + else if (type == "name") { pattern = "[filename],precluster.names"; } + else if (type == "count") { pattern = "[filename],precluster.count_table"; } + else if (type == "map") { pattern = "[filename],precluster.map"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "PreClusterCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** PreClusterCommand::PreClusterCommand(){ @@ -239,10 +234,13 @@ int PreClusterCommand::execute(){ int start = time(NULL); string fileroot = outputDir + m->getRootName(m->getSimpleName(fastafile)); - string newFastaFile = fileroot + getOutputFileNameTag("fasta", fastafile); - string newNamesFile = fileroot + getOutputFileNameTag("name"); - string newCountFile = fileroot + getOutputFileNameTag("count"); - string newMapFile = fileroot + getOutputFileNameTag("map"); //add group name if by group + map variables; + variables["[filename]"] = fileroot; + string newNamesFile = getOutputFileName("name",variables); + string newCountFile = getOutputFileName("count",variables); + string newMapFile = getOutputFileName("map",variables); //add group name if by group + variables["[extension]"] = m->getExtension(fastafile); + string newFastaFile = getOutputFileName("fasta", variables); outputNames.push_back(newFastaFile); outputTypes["fasta"].push_back(newFastaFile); if (countfile == "") { outputNames.push_back(newNamesFile); outputTypes["name"].push_back(newNamesFile); } else { outputNames.push_back(newCountFile); outputTypes["count"].push_back(newCountFile); } diff --git a/preclustercommand.h b/preclustercommand.h index e63afa6..0bd56c8 100644 --- a/preclustercommand.h +++ b/preclustercommand.h @@ -48,8 +48,9 @@ public: vector setParameters(); string getCommandName() { return "pre.cluster"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Gevers D, Westcott SL (2011). Reducing the effects of PCR amplification and sequencing artifacts on 16S rRNA-based studies. PLoS ONE. 6:e27310.\nhttp://www.mothur.org/wiki/Pre.cluster"; } string getDescription() { return "implements a pseudo-single linkage algorithm with the goal of removing sequences that are likely due to pyrosequencing errors"; } diff --git a/quitcommand.h b/quitcommand.h index 63d6fd5..9a6ea29 100644 --- a/quitcommand.h +++ b/quitcommand.h @@ -27,7 +27,7 @@ public: string getCommandName() { return "quit"; } string getCommandCategory() { return "Hidden"; } string getHelpString() { return "The quit command will terminate mothur and should be in the following format: quit() or quit. \n"; } - string getOutputFileNameTag(string, string) { return ""; } + string getOutputPattern(string) { return ""; } string getCitation() { return "no citation"; } string getDescription() { return "quit"; } diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index c4a104b..75a87ef 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -28,19 +28,19 @@ //********************************************************************************************************************** vector RareFactCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); - CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); - CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); - CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-npshannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap", "sobs", "", "", "",true,false); parameters.push_back(pcalc); - CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pgroupmode("groupmode", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pgroupmode); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false,true); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","",false,false,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pfreq); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-npshannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap", "sobs", "", "", "","",true,false,true); parameters.push_back(pcalc); + CommandParameter pabund("abund", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pabund); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pgroupmode("groupmode", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pgroupmode); + 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); } @@ -75,39 +75,33 @@ string RareFactCommand::getHelpString(){ } } //********************************************************************************************************************** -string RareFactCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string RareFactCommand::getOutputPattern(string type) { + try { + string pattern = ""; + if (type == "rarefaction") { pattern = "[filename],rarefaction"; } + else if (type == "r_chao") { pattern = "[filename],r_chao"; } + else if (type == "r_ace") { pattern = "[filename],r_ace"; } + else if (type == "r_jack") { pattern = "[filename],r_jack"; } + else if (type == "r_shannon") { pattern = "[filename],r_shannon"; } + else if (type == "r_shannoneven") { pattern = "[filename],r_shannoneven"; } + else if (type == "r_smithwilson") { pattern = "[filename],r_smithwilson"; } + else if (type == "r_npshannon") { pattern = "[filename],r_npshannon"; } + else if (type == "r_simpson") { pattern = "[filename],r_simpson"; } + else if (type == "r_simpsoneven") { pattern = "[filename],r_simpsoneven"; } + else if (type == "r_invsimpson") { pattern = "[filename],r_invsimpson"; } + else if (type == "r_bootstrap") { pattern = "[filename],r_bootstrap"; } + else if (type == "r_coverage") { pattern = "[filename],r_coverage"; } + else if (type == "r_nseqs") { pattern = "[filename],r_nseqs"; } + else if (type == "r_heip") { pattern = "[filename],r_heip"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } - //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 == "rarefaction") { outputFileName = "rarefaction"; } - else if (type == "r_chao") { outputFileName = "r_chao"; } - else if (type == "r_ace") { outputFileName = "r_ace"; } - else if (type == "r_jack") { outputFileName = "r_jack"; } - else if (type == "r_shannon") { outputFileName = "r_shannon"; } - else if (type == "r_shannoneven") { outputFileName = "r_shannoneven"; } - else if (type == "r_smithwilson") { outputFileName = "r_smithwilson"; } - else if (type == "r_npshannon") { outputFileName = "r_npshannon"; } - else if (type == "r_simpson") { outputFileName = "r_simpson"; } - else if (type == "r_simpsoneven") { outputFileName = "r_simpsoneven"; } - else if (type == "r_invsimpson") { outputFileName = "r_invsimpson"; } - else if (type == "r_bootstrap") { outputFileName = "r_bootstrap"; } - else if (type == "r_coverage") { outputFileName = "r_coverage"; } - else if (type == "r_nseqs") { outputFileName = "r_nseqs"; } - 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, "RareFactCommand", "getOutputFileNameTag"); - exit(1); - } + return pattern; + } + catch(exception& e) { + m->errorOut(e, "RareFactCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** RareFactCommand::RareFactCommand(){ try { @@ -334,56 +328,58 @@ int RareFactCommand::execute(){ int i; ValidCalculators validCalculator; + map variables; + variables["[filename]"] = fileNameRoot; for (i=0; i 1) { file2Group[outputNames.size()-1] = groups[p]; } } diff --git a/rarefactcommand.h b/rarefactcommand.h index 9c7e1ed..02fe6e3 100644 --- a/rarefactcommand.h +++ b/rarefactcommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "rarefaction.single"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Magurran AE (2004). Measuring biological diversity. Blackwell Pub.: Malden, Ma. \nhttp://www.mothur.org/wiki/Rarefaction.single"; } string getDescription() { return "generate intra-sample rarefaction curves using a re-sampling without replacement approach"; } diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index 6451041..64b40aa 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -16,20 +16,20 @@ //********************************************************************************************************************** vector RareFactSharedCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pdesign); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pcalc("calc", "Multiple", "sharednseqs-sharedobserved", "sharedobserved", "", "", "",true,false); parameters.push_back(pcalc); - CommandParameter psubsampleiters("subsampleiters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(psubsampleiters); - CommandParameter psubsample("subsample", "String", "", "", "", "", "",false,false); parameters.push_back(psubsample); - CommandParameter pjumble("jumble", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pjumble); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter psets("sets", "String", "", "", "", "", "",false,false); parameters.push_back(psets); - CommandParameter pgroupmode("groupmode", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pgroupmode); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pshared); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pdesign); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pfreq); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pcalc("calc", "Multiple", "sharednseqs-sharedobserved", "sharedobserved", "", "", "","",true,false,true); parameters.push_back(pcalc); + CommandParameter psubsampleiters("subsampleiters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(psubsampleiters); + CommandParameter psubsample("subsample", "String", "", "", "", "", "","",false,false); parameters.push_back(psubsample); + CommandParameter pjumble("jumble", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pjumble); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter psets("sets", "String", "", "", "", "", "","",false,false); parameters.push_back(psets); + CommandParameter pgroupmode("groupmode", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pgroupmode); + 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); } @@ -68,25 +68,20 @@ string RareFactSharedCommand::getHelpString(){ } } //********************************************************************************************************************** -string RareFactSharedCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string RareFactSharedCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "sharedrarefaction") { outputFileName = "shared.rarefaction"; } - else if (type == "sharedr_nseqs") { outputFileName = "shared.r_nseqs"; } - 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, "RareFactSharedCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "sharedrarefaction") { pattern = "[filename],shared.rarefaction"; } + else if (type == "sharedr_nseqs") { pattern = "[filename],shared.r_nseqs"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "RareFactSharedCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** RareFactSharedCommand::RareFactSharedCommand(){ @@ -346,16 +341,18 @@ int RareFactSharedCommand::process(GroupMap& designMap, string thisSet){ if (subset.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); m->control_pressed = true; return 0; } } /******************************************************/ - + + map variables; + variables["[filename]"] = fileNameRoot; ValidCalculators validCalculator; for (int i=0; i& thisLook string thisfileNameRoot = fileNameRoot + toString(thisIter); + map variables; + variables["[filename]"] = thisfileNameRoot; + ValidCalculators validCalculator; for (int i=0; i& thisLook if (!m->control_pressed) { //process results - string outputFile = fileNameRoot + "ave-std." + thisLookup[0]->getLabel() + "." + getOutputFileNameTag(it->first); + map variables; variables["[filename]"] = fileNameRoot + "ave-std." + thisLookup[0]->getLabel() + "."; + + string outputFile = getOutputFileName(it->first,variables); ofstream out; m->openOutputFile(outputFile, out); outputNames.push_back(outputFile); outputTypes[it->first].push_back(outputFile); diff --git a/rarefactsharedcommand.h b/rarefactsharedcommand.h index af73e13..4f08d00 100644 --- a/rarefactsharedcommand.h +++ b/rarefactsharedcommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "rarefaction.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Magurran AE (2004). Measuring biological diversity. Blackwell Pub.: Malden, Ma. \nhttp://www.mothur.org/wiki/Rarefaction.shared"; } string getDescription() { return "generate inter-sample rarefaction curves using a re-sampling without replacement approach"; } diff --git a/readtree.cpp b/readtree.cpp index 71c4bd5..4c9def8 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -378,7 +378,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T, CountTable* ct) { //set group info vector group = ct->getGroups(name); - + //cout << name << endl; //find index in tree of name int n1 = T->getIndex(name); diff --git a/removegroupscommand.cpp b/removegroupscommand.cpp index a29906c..4f4b158 100644 --- a/removegroupscommand.cpp +++ b/removegroupscommand.cpp @@ -16,17 +16,18 @@ //********************************************************************************************************************** vector RemoveGroupsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "FNGLT",false,false); parameters.push_back(pfasta); - CommandParameter pshared("shared", "InputTypes", "", "", "none", "sharedGroup", "none",false,false); parameters.push_back(pshared); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "sharedGroup", "FNGLT",false,false); parameters.push_back(pgroup); CommandParameter pdesign("design", "InputTypes", "", "", "none", "sharedGroup", "FNGLT",false,false); parameters.push_back(pdesign); - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "FNGLT",false,false); parameters.push_back(plist); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "FNGLT",false,false); parameters.push_back(ptaxonomy); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "FNGLT","fasta",false,false,true); parameters.push_back(pfasta); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "sharedGroup", "none","shared",false,false,true); parameters.push_back(pshared); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "sharedGroup", "FNGLT","group",false,false,true); parameters.push_back(pgroup); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "sharedGroup", "FNGLT","design",false,false); parameters.push_back(pdesign); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "FNGLT","list",false,false,true); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "FNGLT","taxonomy",false,false,true); parameters.push_back(ptaxonomy); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -58,31 +59,26 @@ string RemoveGroupsCommand::getHelpString(){ } } //********************************************************************************************************************** -string RemoveGroupsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string RemoveGroupsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "taxonomy") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "pick.count_table"; } - else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "shared") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "design") { outputFileName = "pick" + m->getExtension(inputName); } - 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, "RemoveGroupsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],pick,[extension]"; } + else if (type == "taxonomy") { pattern = "[filename],pick,[extension]"; } + else if (type == "name") { pattern = "[filename],pick,[extension]"; } + else if (type == "group") { pattern = "[filename],pick,[extension]"; } + else if (type == "count") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "shared") { pattern = "[filename],[tag],pick,[extension]"; } + else if (type == "design") { pattern = "[filename],pick,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "RemoveGroupsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** RemoveGroupsCommand::RemoveGroupsCommand(){ @@ -468,7 +464,10 @@ int RemoveGroupsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[extension]"] = m->getExtension(fastafile); + string outputFileName = getOutputFileName("fasta", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -529,6 +528,10 @@ int RemoveGroupsCommand::readShared(){ //that way we can take advantage of the reads in inputdata and sharedRabundVector InputData* tempInput = new InputData(sharedfile, "sharedfile"); vector lookup = tempInput->getSharedRAbundVectors(); + + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[extension]"] = m->getExtension(sharedfile); //save m->Groups vector allGroupsNames = m->getAllGroups(); @@ -560,7 +563,8 @@ int RemoveGroupsCommand::readShared(){ while(lookup[0] != NULL) { - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("shared", sharedfile); + variables["[tag]"] = lookup[0]->getLabel(); + string outputFileName = getOutputFileName("shared", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); @@ -608,7 +612,11 @@ int RemoveGroupsCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); + ofstream out; m->openOutputFile(outputFileName, out); @@ -698,7 +706,10 @@ int RemoveGroupsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outputFileName = getOutputFileName("name", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -778,7 +789,10 @@ int RemoveGroupsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputFileName = getOutputFileName("group", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -824,7 +838,10 @@ int RemoveGroupsCommand::readCount(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outputFileName = getOutputFileName("count", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -905,7 +922,10 @@ int RemoveGroupsCommand::readDesign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(designfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + getOutputFileNameTag("design", designfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(designfile)); + variables["[extension]"] = m->getExtension(designfile); + string outputFileName = getOutputFileName("design", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -953,7 +973,10 @@ int RemoveGroupsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)); + variables["[extension]"] = m->getExtension(taxfile); + string outputFileName = getOutputFileName("taxonomy", variables); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/removegroupscommand.h b/removegroupscommand.h index c36998a..c6e9d64 100644 --- a/removegroupscommand.h +++ b/removegroupscommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "remove.groups"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Remove.groups"; } string getDescription() { return "removes sequences from a list, fasta, name, group, shared, design or taxonomy file from a given group or set of groups"; } diff --git a/removelineagecommand.cpp b/removelineagecommand.cpp index 56b24cd..5b6fc25 100644 --- a/removelineagecommand.cpp +++ b/removelineagecommand.cpp @@ -15,17 +15,17 @@ //********************************************************************************************************************** vector RemoveLineageCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none",false,false); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(ptaxonomy); - CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport); - CommandParameter ptaxon("taxon", "String", "", "", "", "", "",false,true); parameters.push_back(ptaxon); - CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none","fasta",false,false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none","group",false,false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none","list",false,false,true); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none","taxonomy",false,true,true); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none","alignreport",false,false); parameters.push_back(palignreport); + CommandParameter ptaxon("taxon", "String", "", "", "", "", "","",false,true,true); parameters.push_back(ptaxon); + CommandParameter pdups("dups", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pdups); + 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); } @@ -60,31 +60,27 @@ string RemoveLineageCommand::getHelpString(){ } } //********************************************************************************************************************** -string RemoveLineageCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string RemoveLineageCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "taxonomy") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "pick.count_table"; } - else if (type == "alignreport") { outputFileName = "pick.align.report"; } - 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, "RemoveLineageCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],pick,[extension]"; } + else if (type == "taxonomy") { pattern = "[filename],pick,[extension]"; } + else if (type == "name") { pattern = "[filename],pick,[extension]"; } + else if (type == "group") { pattern = "[filename],pick,[extension]"; } + else if (type == "count") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "alignreport") { pattern = "[filename],pick.align.report"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "RemoveLineageCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** RemoveLineageCommand::RemoveLineageCommand(){ try { @@ -365,7 +361,10 @@ int RemoveLineageCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[extension]"] = m->getExtension(fastafile); + string outputFileName = getOutputFileName("fasta", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -410,7 +409,10 @@ int RemoveLineageCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -480,7 +482,10 @@ int RemoveLineageCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outputFileName = getOutputFileName("name", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -556,7 +561,11 @@ int RemoveLineageCommand::readCount(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outputFileName = getOutputFileName("count", variables); + ofstream out; m->openOutputFile(outputFileName, out); @@ -609,7 +618,11 @@ int RemoveLineageCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputFileName = getOutputFileName("group", variables); + ofstream out; m->openOutputFile(outputFileName, out); @@ -651,7 +664,10 @@ int RemoveLineageCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)); + variables["[extension]"] = m->getExtension(taxfile); + string outputFileName = getOutputFileName("taxonomy", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -858,7 +874,10 @@ int RemoveLineageCommand::readAlign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)); + variables["[extension]"] = m->getExtension(alignfile); + string outputFileName = getOutputFileName("alignreport", variables); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/removelineagecommand.h b/removelineagecommand.h index a756d24..f644972 100644 --- a/removelineagecommand.h +++ b/removelineagecommand.h @@ -23,8 +23,9 @@ class RemoveLineageCommand : public Command { vector setParameters(); string getCommandName() { return "remove.lineage"; } string getCommandCategory() { return "Phylotype Analysis"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Remove.lineage"; } string getDescription() { return "removes sequences from a list, fasta, name, group, alignreport or taxonomy file from a given taxonomy or set of taxonomies"; } diff --git a/removeotulabelscommand.cpp b/removeotulabelscommand.cpp index a05e081..5359db8 100644 --- a/removeotulabelscommand.cpp +++ b/removeotulabelscommand.cpp @@ -11,12 +11,12 @@ //********************************************************************************************************************** vector RemoveOtuLabelsCommand::setParameters(){ try { - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos); - CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pconstaxonomy); - CommandParameter potucorr("otucorr", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(potucorr); - CommandParameter pcorraxes("corraxes", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pcorraxes); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(paccnos); + CommandParameter pconstaxonomy("constaxonomy", "InputTypes", "", "", "none", "FNGLT", "none","constaxonomy",false,false); parameters.push_back(pconstaxonomy); + CommandParameter potucorr("otucorr", "InputTypes", "", "", "none", "FNGLT", "none","otucorr",false,false); parameters.push_back(potucorr); + CommandParameter pcorraxes("corraxes", "InputTypes", "", "", "none", "FNGLT", "none","corraxes",false,false); parameters.push_back(pcorraxes); + 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); } @@ -46,26 +46,21 @@ string RemoveOtuLabelsCommand::getHelpString(){ } } //********************************************************************************************************************** -string RemoveOtuLabelsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string RemoveOtuLabelsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "constaxonomy") { outputFileName = "pick.taxonomy"; } - else if (type == "otucorr") { outputFileName = "pick.corr"; } - else if (type == "corraxes") { outputFileName = "pick.axes"; } - 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, "RemoveOtuLabelsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "constaxonomy") { pattern = "[filename],pick,[extension]"; } + else if (type == "otucorr") { pattern = "[filename],pick,[extension]"; } + else if (type == "corraxes") { pattern = "[filename],pick,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "RemoveOtuLabelsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(){ @@ -73,7 +68,7 @@ RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(){ abort = true; calledHelp = true; setParameters(); vector tempOutNames; - outputTypes["contaxonomy"] = tempOutNames; + outputTypes["constaxonomy"] = tempOutNames; outputTypes["otucorr"] = tempOutNames; outputTypes["corraxes"] = tempOutNames; } @@ -226,7 +221,10 @@ int RemoveOtuLabelsCommand::readClassifyOtu(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(constaxonomyfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + getOutputFileNameTag("constaxonomy"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)); + variables["[extension]"] = m->getExtension(constaxonomyfile); + string outputFileName = getOutputFileName("constaxonomy", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -275,7 +273,10 @@ int RemoveOtuLabelsCommand::readOtuAssociation(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(otucorrfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + getOutputFileNameTag("otucorr"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)); + variables["[extension]"] = m->getExtension(otucorrfile); + string outputFileName = getOutputFileName("otucorr", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -325,7 +326,10 @@ int RemoveOtuLabelsCommand::readCorrAxes(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(corraxesfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + getOutputFileNameTag("corraxes"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)); + variables["[extension]"] = m->getExtension(corraxesfile); + string outputFileName = getOutputFileName("corraxes", variables); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/removeotulabelscommand.h b/removeotulabelscommand.h index ea59662..03d2da3 100644 --- a/removeotulabelscommand.h +++ b/removeotulabelscommand.h @@ -23,8 +23,9 @@ public: vector setParameters(); string getCommandName() { return "remove.otulabels"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Get.otulabels"; } string getDescription() { return "Can be used with output from classify.otu, otu.association, or corr.axes to remove specific otus."; } diff --git a/removeotuscommand.cpp b/removeotuscommand.cpp index 54adeb2..16fd8dc 100644 --- a/removeotuscommand.cpp +++ b/removeotuscommand.cpp @@ -14,13 +14,13 @@ //********************************************************************************************************************** vector RemoveOtusCommand::setParameters(){ try { - CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - 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); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","group",false,true,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","list",false,true,true); parameters.push_back(plist); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -53,25 +53,20 @@ string RemoveOtusCommand::getHelpString(){ } } //********************************************************************************************************************** -string RemoveOtusCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string RemoveOtusCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "group") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } - 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, "RemoveOtusCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "group") { pattern = "[filename],[tag],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],[tag],pick,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "RemoveOtusCommand", "getOutputPattern"); + exit(1); + } } ///********************************************************************************************************************** RemoveOtusCommand::RemoveOtusCommand(){ @@ -250,14 +245,20 @@ int RemoveOtusCommand::readListGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + label + "." + getOutputFileNameTag("list", listfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[tag]"] = label; + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); ofstream out; m->openOutputFile(outputFileName, out); string GroupOutputDir = outputDir; if (outputDir == "") { GroupOutputDir += m->hasPath(groupfile); } - string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + label + "." + getOutputFileNameTag("group", groupfile); + variables["[filename]"] = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputGroupFileName = getOutputFileName("group", variables); ofstream outGroup; m->openOutputFile(outputGroupFileName, outGroup); diff --git a/removeotuscommand.h b/removeotuscommand.h index 3a52a39..a7fcf0e 100644 --- a/removeotuscommand.h +++ b/removeotuscommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "remove.otus"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Remove.otus"; } string getDescription() { return "outputs a new list file containing the otus NOT containing sequences from the groups specified"; } diff --git a/removerarecommand.cpp b/removerarecommand.cpp index ded26bb..c069448 100644 --- a/removerarecommand.cpp +++ b/removerarecommand.cpp @@ -16,18 +16,18 @@ //********************************************************************************************************************** vector RemoveRareCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plist); - CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(prabund); - CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psabund); - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pshared); - CommandParameter pcount("count", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pnseqs("nseqs", "Number", "", "0", "", "", "",false,true); parameters.push_back(pnseqs); - CommandParameter pbygroup("bygroup", "Boolean", "", "f", "", "", "",false,true); parameters.push_back(pbygroup); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "none", "atleast", "none","list",false,false,true); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "none", "atleast", "none","rabund",false,false,true); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "none", "atleast", "none","sabund",false,false,true); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "atleast", "none","shared",false,false,true); parameters.push_back(pshared); + CommandParameter pcount("count", "InputTypes", "", "", "CountGroup", "none", "none","count",false,false); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","group",false,false); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pnseqs("nseqs", "Number", "", "0", "", "", "","",false,true,true); parameters.push_back(pnseqs); + CommandParameter pbygroup("bygroup", "Boolean", "", "f", "", "", "","",false,false); parameters.push_back(pbygroup); + 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); } @@ -60,31 +60,25 @@ string RemoveRareCommand::getHelpString(){ } } //********************************************************************************************************************** -string RemoveRareCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string RemoveRareCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "rabund") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "sabund") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "shared") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } - 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, "RemoveRareCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "rabund") { pattern = "[filename],pick,[extension]"; } + else if (type == "sabund") { pattern = "[filename],pick,[extension]"; } + else if (type == "group") { pattern = "[filename],pick,[extension]"; } + else if (type == "count") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "shared") { pattern = "[filename],[tag],pick,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "RemoveRareCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** RemoveRareCommand::RemoveRareCommand(){ try { @@ -352,9 +346,16 @@ int RemoveRareCommand::processList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); - string outputGroupFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); - string outputCountFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputGroupFileName = getOutputFileName("group", variables); + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outputCountFileName = getOutputFileName("count", variables); ofstream out, outGroup; m->openOutputFile(outputFileName, out); @@ -519,7 +520,10 @@ int RemoveRareCommand::processSabund(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sabundfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + getOutputFileNameTag("sabund", sabundfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)); + variables["[extension]"] = m->getExtension(sabundfile); + string outputFileName = getOutputFileName("sabund", variables); outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -618,7 +622,10 @@ int RemoveRareCommand::processRabund(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(rabundfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + getOutputFileNameTag("rabund", rabundfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)); + variables["[extension]"] = m->getExtension(rabundfile); + string outputFileName = getOutputFileName("rabund", variables); outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -725,7 +732,10 @@ int RemoveRareCommand::processShared(){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("shared", sharedfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[extension]"] = m->getExtension(sharedfile); + string outputFileName = getOutputFileName("shared", variables); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; diff --git a/removerarecommand.h b/removerarecommand.h index 7b4c6fb..2cab7be 100644 --- a/removerarecommand.h +++ b/removerarecommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "remove.rare"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Remove.rare"; } string getDescription() { return "removes rare sequences from a sabund, rabund, shared or list and group file"; } diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index 00b94a9..5c02163 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -15,18 +15,18 @@ //********************************************************************************************************************** vector RemoveSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none",false,false); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); - CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pqfile); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos); - CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none","fasta",false,false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none","group",false,false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none","list",false,false,true); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none","taxonomy",false,false,true); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none","alignreport",false,false); parameters.push_back(palignreport); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none","qfile",false,false); parameters.push_back(pqfile); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(paccnos); + CommandParameter pdups("dups", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pdups); + 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); } @@ -56,33 +56,27 @@ string RemoveSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string RemoveSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string RemoveSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "taxonomy") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "qfile") { outputFileName = "pick" + m->getExtension(inputName); } - else if (type == "alignreport") { outputFileName = "pick.align.report"; } - else if (type == "count") { outputFileName = "pick.count_table"; } - 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, "RemoveSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],pick,[extension]"; } + else if (type == "taxonomy") { pattern = "[filename],pick,[extension]"; } + else if (type == "name") { pattern = "[filename],pick,[extension]"; } + else if (type == "group") { pattern = "[filename],pick,[extension]"; } + else if (type == "count") { pattern = "[filename],pick,[extension]"; } + else if (type == "list") { pattern = "[filename],pick,[extension]"; } + else if (type == "qfile") { pattern = "[filename],pick,[extension]"; } + else if (type == "alignreport") { pattern = "[filename],pick.align.report"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "GetSeqsCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** RemoveSeqsCommand::RemoveSeqsCommand(){ try { @@ -390,7 +384,10 @@ int RemoveSeqsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[extension]"] = m->getExtension(fastafile); + string outputFileName = getOutputFileName("fasta", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -445,7 +442,10 @@ int RemoveSeqsCommand::readQual(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)); + variables["[extension]"] = m->getExtension(qualfile); + string outputFileName = getOutputFileName("qfile", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -519,7 +519,10 @@ int RemoveSeqsCommand::readCount(){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outputFileName = getOutputFileName("count", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -576,7 +579,10 @@ int RemoveSeqsCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -654,7 +660,10 @@ int RemoveSeqsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outputFileName = getOutputFileName("name", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -738,7 +747,10 @@ int RemoveSeqsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputFileName = getOutputFileName("group", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -784,7 +796,10 @@ int RemoveSeqsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)); + variables["[extension]"] = m->getExtension(taxfile); + string outputFileName = getOutputFileName("taxonomy", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -836,7 +851,9 @@ int RemoveSeqsCommand::readAlign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)); + string outputFileName = getOutputFileName("alignreport", variables); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/removeseqscommand.h b/removeseqscommand.h index e26e751..1a6365d 100644 --- a/removeseqscommand.h +++ b/removeseqscommand.h @@ -23,8 +23,9 @@ class RemoveSeqsCommand : public Command { vector setParameters(); string getCommandName() { return "remove.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Remove.seqs"; } string getDescription() { return "removes sequences from a list, fasta, name, group, alignreport, quality or taxonomy file"; } diff --git a/reversecommand.cpp b/reversecommand.cpp index 96a216a..a9b2977 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -14,10 +14,10 @@ //********************************************************************************************************************** vector ReverseSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "fastaQual", "none",false,false); parameters.push_back(pfasta); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "fastaQual", "none",false,false); parameters.push_back(pqfile); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "fastaQual", "none","fasta",false,false,true); parameters.push_back(pfasta); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "fastaQual", "none","qfile",false,false,true); parameters.push_back(pqfile); + 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); } @@ -44,25 +44,20 @@ string ReverseSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string ReverseSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ReverseSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "rc" + m->getExtension(inputName); } - else if (type == "qfile") { outputFileName = "rc" + m->getExtension(inputName); } - 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, "ReverseSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],rc,[extension]"; } + else if (type == "qfile") { pattern = "[filename],rc,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ReverseSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** ReverseSeqsCommand::ReverseSeqsCommand(){ @@ -182,7 +177,10 @@ int ReverseSeqsCommand::execute(){ ofstream outFASTA; string tempOutputDir = outputDir; if (outputDir == "") { tempOutputDir += m->hasPath(fastaFileName); } //if user entered a file with a path then preserve it - fastaReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileName)) + getOutputFileNameTag("fasta", fastaFileName); + map variables; + variables["[filename]"] = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileName)); + variables["[extension]"] = m->getExtension(fastaFileName); + fastaReverseFileName = getOutputFileName("fasta", variables); m->openOutputFile(fastaReverseFileName, outFASTA); while(!inFASTA.eof()){ @@ -210,7 +208,10 @@ int ReverseSeqsCommand::execute(){ ofstream outQual; string tempOutputDir = outputDir; if (outputDir == "") { tempOutputDir += m->hasPath(qualFileName); } //if user entered a file with a path then preserve it - string qualReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(qualFileName)) + getOutputFileNameTag("qfile", qualFileName); + map variables; + variables["[filename]"] = tempOutputDir + m->getRootName(m->getSimpleName(qualFileName)); + variables["[extension]"] = m->getExtension(qualFileName); + string qualReverseFileName = getOutputFileName("qfile", variables); m->openOutputFile(qualReverseFileName, outQual); while(!inQual.eof()){ diff --git a/reversecommand.h b/reversecommand.h index 2c7a9e4..f7f729c 100644 --- a/reversecommand.h +++ b/reversecommand.h @@ -21,8 +21,9 @@ public: vector setParameters(); string getCommandName() { return "reverse.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Reverse.seqs"; } string getDescription() { return "outputs a fasta file containing the reverse-complements"; } diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index 2b5ebc1..5a9c0c8 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -13,24 +13,24 @@ //********************************************************************************************************************** vector ScreenSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pqfile); - CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(palignreport); - CommandParameter ptax("taxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(ptax); - CommandParameter pstart("start", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pstart); - CommandParameter pend("end", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pend); - CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxambig); - CommandParameter pmaxhomop("maxhomop", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxhomop); - CommandParameter pminlength("minlength", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pminlength); - CommandParameter pmaxlength("maxlength", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxlength); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pcriteria("criteria", "Number", "", "90", "", "", "",false,false); parameters.push_back(pcriteria); - CommandParameter poptimize("optimize", "Multiple", "none-start-end-maxambig-maxhomop-minlength-maxlength", "none", "", "", "",true,false); parameters.push_back(poptimize); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","group",false,false,true); parameters.push_back(pgroup); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none","qfile",false,false); parameters.push_back(pqfile); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "none", "none","alignreport",false,false); parameters.push_back(palignreport); + CommandParameter ptax("taxonomy", "InputTypes", "", "", "none", "none", "none","taxonomy",false,false); parameters.push_back(ptax); + CommandParameter pstart("start", "Number", "", "-1", "", "", "","",false,false,true); parameters.push_back(pstart); + CommandParameter pend("end", "Number", "", "-1", "", "", "","",false,false,true); parameters.push_back(pend); + CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxambig); + CommandParameter pmaxhomop("maxhomop", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxhomop); + CommandParameter pminlength("minlength", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pminlength); + CommandParameter pmaxlength("maxlength", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxlength); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pcriteria("criteria", "Number", "", "90", "", "", "","",false,false); parameters.push_back(pcriteria); + CommandParameter poptimize("optimize", "Multiple", "none-start-end-maxambig-maxhomop-minlength-maxlength", "none", "", "", "","",true,false); parameters.push_back(poptimize); + 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); } @@ -72,33 +72,27 @@ string ScreenSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string ScreenSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ScreenSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "good" + m->getExtension(inputName); } - else if (type == "taxonomy") { outputFileName = "good" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "good" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "good" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "good" + m->getExtension(inputName); } - else if (type == "accnos") { outputFileName = "bad.accnos"; } - else if (type == "qfile") { outputFileName = "good" + m->getExtension(inputName); } - else if (type == "alignreport") { outputFileName = "good.align.report"; } - 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, "ScreenSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],good,[extension]"; } + else if (type == "taxonomy") { pattern = "[filename],good,[extension]"; } + else if (type == "name") { pattern = "[filename],good,[extension]"; } + else if (type == "group") { pattern = "[filename],good,[extension]"; } + else if (type == "count") { pattern = "[filename],good,[extension]"; } + else if (type == "accnos") { pattern = "[filename],bad.accnos"; } + else if (type == "qfile") { pattern = "[filename],good,[extension]"; } + else if (type == "alignreport") { pattern = "[filename],good.align.report"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** ScreenSeqsCommand::ScreenSeqsCommand(){ try { @@ -367,9 +361,13 @@ int ScreenSeqsCommand::execute(){ } #endif } - - string goodSeqFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); - string badAccnosFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("accnos"); + + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string badAccnosFile = getOutputFileName("accnos",variables); + variables["[extension]"] = m->getExtension(fastafile); + string goodSeqFile = getOutputFileName("fasta", variables); + int numFastaSeqs = 0; set badSeqNames; @@ -579,8 +577,10 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ set badSeqGroups; string seqName, seqList, group; set::iterator it; - - string goodNameFile = outputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string goodNameFile = getOutputFileName("name", variables); outputNames.push_back(goodNameFile); outputTypes["name"].push_back(goodNameFile); ofstream goodNameOut; m->openOutputFile(goodNameFile, goodNameOut); @@ -625,8 +625,10 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ ifstream inputGroups; m->openInputFile(groupfile, inputGroups); - - string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string goodGroupFile = getOutputFileName("group", variables); + outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile); ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); @@ -958,8 +960,10 @@ int ScreenSeqsCommand::screenGroupFile(set badSeqNames){ m->openInputFile(groupfile, inputGroups); string seqName, group; set::iterator it; - - string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string goodGroupFile = getOutputFileName("group", variables); outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile); ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); @@ -1007,8 +1011,11 @@ int ScreenSeqsCommand::screenCountFile(set badSeqNames){ ifstream in; m->openInputFile(countfile, in); set::iterator it; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string goodCountFile = getOutputFileName("count", variables); - string goodCountFile = outputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); outputNames.push_back(goodCountFile); outputTypes["count"].push_back(goodCountFile); ofstream goodCountOut; m->openOutputFile(goodCountFile, goodCountOut); @@ -1073,7 +1080,10 @@ int ScreenSeqsCommand::screenAlignReport(set badSeqNames){ string seqName, group; set::iterator it; - string goodAlignReportFile = outputDir + m->getRootName(m->getSimpleName(alignreport)) + getOutputFileNameTag("alignreport"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(alignreport)); + string goodAlignReportFile = getOutputFileName("alignreport", variables); + outputNames.push_back(goodAlignReportFile); outputTypes["alignreport"].push_back(goodAlignReportFile); ofstream goodAlignReportOut; m->openOutputFile(goodAlignReportFile, goodAlignReportOut); @@ -1136,8 +1146,11 @@ int ScreenSeqsCommand::screenTaxonomy(set badSeqNames){ m->openInputFile(taxonomy, input); string seqName, tax; set::iterator it; - - string goodTaxFile = outputDir + m->getRootName(m->getSimpleName(taxonomy)) + getOutputFileNameTag("taxonomy", taxonomy); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(taxonomy)); + variables["[extension]"] = m->getExtension(taxonomy); + string goodTaxFile = getOutputFileName("taxonomy", variables); + outputNames.push_back(goodTaxFile); outputTypes["taxonomy"].push_back(goodTaxFile); ofstream goodTaxOut; m->openOutputFile(goodTaxFile, goodTaxOut); @@ -1185,8 +1198,11 @@ int ScreenSeqsCommand::screenQual(set badSeqNames){ ifstream in; m->openInputFile(qualfile, in); set::iterator it; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(qualfile)); + variables["[extension]"] = m->getExtension(qualfile); + string goodQualFile = getOutputFileName("qfile", variables); - string goodQualFile = outputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile); outputNames.push_back(goodQualFile); outputTypes["qfile"].push_back(goodQualFile); ofstream goodQual; m->openOutputFile(goodQualFile, goodQual); diff --git a/screenseqscommand.h b/screenseqscommand.h index b0d7c7c..284c9a5 100644 --- a/screenseqscommand.h +++ b/screenseqscommand.h @@ -23,8 +23,9 @@ public: vector setParameters(); string getCommandName() { return "screen.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Screen.seqs"; } string getDescription() { return "enables you to keep sequences that fulfill certain user defined criteria"; } diff --git a/secondarystructurecommand.cpp b/secondarystructurecommand.cpp index 870283c..c1cdb6b 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -14,12 +14,12 @@ //********************************************************************************************************************** vector AlignCheckCommand::setParameters(){ try { - 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", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","aligncheck",false,true,true); parameters.push_back(pfasta); + CommandParameter pmap("map", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pmap); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","",false,false); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","",false,false); parameters.push_back(pcount); + 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); } @@ -48,24 +48,19 @@ string AlignCheckCommand::getHelpString(){ } } //********************************************************************************************************************** -string AlignCheckCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string AlignCheckCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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", "getOutputFileNameTag"); - exit(1); - } + if (type == "aligncheck") { pattern = "[filename],align.check"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "AlignCheckCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** AlignCheckCommand::AlignCheckCommand(){ @@ -215,7 +210,9 @@ int AlignCheckCommand::execute(){ m->openInputFile(fastafile, in); ofstream out; - string outfile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("aligncheck"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string outfile = getOutputFileName("aligncheck",variables); m->openOutputFile(outfile, out); diff --git a/secondarystructurecommand.h b/secondarystructurecommand.h index becafc5..ce97a22 100644 --- a/secondarystructurecommand.h +++ b/secondarystructurecommand.h @@ -39,8 +39,9 @@ class AlignCheckCommand : public Command { vector setParameters(); string getCommandName() { return "align.check"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Align.check"; } string getDescription() { return "calculate the number of potentially misaligned bases in a 16S rRNA gene sequence alignment"; } diff --git a/sensspeccommand.cpp b/sensspeccommand.cpp index 5a1ead5..dfb89b9 100644 --- a/sensspeccommand.cpp +++ b/sensspeccommand.cpp @@ -12,15 +12,15 @@ //********************************************************************************************************************** vector SensSpecCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); - CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); - CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pcolumn); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pcutoff("cutoff", "Number", "", "-1.00", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); - CommandParameter phard("hard", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(phard); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","sensspec",false,true,true); parameters.push_back(plist); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none","",false,false); parameters.push_back(pphylip); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none","",false,false); parameters.push_back(pcolumn); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pcutoff("cutoff", "Number", "", "-1.00", "", "", "","",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision); + CommandParameter phard("hard", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(phard); + 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); } @@ -44,24 +44,19 @@ string SensSpecCommand::getHelpString(){ } } //********************************************************************************************************************** -string SensSpecCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SensSpecCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "sensspec") { outputFileName = "sensspec"; } - 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, "SensSpecCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "sensspec") { pattern = "[filename],sensspec"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SensSpecCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** SensSpecCommand::SensSpecCommand(){ @@ -201,7 +196,9 @@ SensSpecCommand::SensSpecCommand(string option) { else { allLines = 1; } } - sensSpecFileName = outputDir + m->getRootName(m->getSimpleName(listFile)) + getOutputFileNameTag("sensspec"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listFile)); + sensSpecFileName = getOutputFileName("sensspec",variables); } } catch(exception& e) { diff --git a/sensspeccommand.h b/sensspeccommand.h index be5e975..73b74e3 100644 --- a/sensspeccommand.h +++ b/sensspeccommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "sens.spec"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Westcott SL (2011). Assessing and improving methods used in OTU-based approaches for 16S rRNA gene sequence analysis. Appl Environ Microbiol 77:3219.\nhttp://www.mothur.org/wiki/Sens.spec"; } string getDescription() { return "sens.spec"; } diff --git a/seqerrorcommand.cpp b/seqerrorcommand.cpp index 5ec6cf2..87d4524 100644 --- a/seqerrorcommand.cpp +++ b/seqerrorcommand.cpp @@ -17,17 +17,17 @@ //********************************************************************************************************************** vector SeqErrorCommand::setParameters(){ try { - CommandParameter pquery("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pquery); - CommandParameter preference("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(preference); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "QualReport",false,false); parameters.push_back(pqfile); - CommandParameter preport("report", "InputTypes", "", "", "none", "none", "QualReport",false,false); parameters.push_back(preport); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pignorechimeras("ignorechimeras", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pignorechimeras); - CommandParameter pthreshold("threshold", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pthreshold); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter psave("save", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psave); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pquery("fasta", "InputTypes", "", "", "none", "none", "none","errorType",false,true,true); parameters.push_back(pquery); + CommandParameter preference("reference", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(preference); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "QualReport","",false,false); parameters.push_back(pqfile); + CommandParameter preport("report", "InputTypes", "", "", "none", "none", "QualReport","",false,false); parameters.push_back(preport); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pname); + CommandParameter pignorechimeras("ignorechimeras", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pignorechimeras); + CommandParameter pthreshold("threshold", "Number", "", "1.0", "", "", "","",false,false); parameters.push_back(pthreshold); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter psave("save", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(psave); + 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); } @@ -63,34 +63,29 @@ string SeqErrorCommand::getHelpString(){ } } //********************************************************************************************************************** -string SeqErrorCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SeqErrorCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "errorsummary") { outputFileName = "error.summary"; } - else if (type == "errorseq") { outputFileName = "error.seq"; } - else if (type == "errorquality") { outputFileName = "error.quality"; } - else if (type == "errorqualforward") { outputFileName = "error.qual.forward"; } - else if (type == "errorqualreverse") { outputFileName = "error.qual.reverse"; } - else if (type == "errorforward") { outputFileName = "error.seq.forward"; } - else if (type == "errorreverse") { outputFileName = "error.seq.reverse"; } - else if (type == "errorcount") { outputFileName = "error.count"; } - else if (type == "errormatrix") { outputFileName = "error.matrix"; } - else if (type == "errorchimera") { outputFileName = "error.chimera"; } - else if (type == "errorref-query") { outputFileName = "error.ref-query"; } - 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, "SeqErrorCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "errorsummary") { pattern = "[filename],error.summary"; } + else if (type == "errorseq") { pattern = "[filename],error.seq"; } + else if (type == "errorquality") { pattern = "[filename],error.quality"; } + else if (type == "errorqualforward") { pattern = "[filename],error.qual.forward"; } + else if (type == "errorqualreverse") { pattern = "[filename],error.qual.reverse"; } + else if (type == "errorforward") { pattern = "[filename],error.seq.forward"; } + else if (type == "errorreverse") { pattern = "[filename],error.seq.reverse"; } + else if (type == "errorcount") { pattern = "[filename],error.count"; } + else if (type == "errormatrix") { pattern = "[filename],error.matrix"; } + else if (type == "errorchimera") { pattern = "[filename],error.chimera"; } + else if (type == "errorref-query") { pattern = "[filename],error.ref-query"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SeqErrorCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** SeqErrorCommand::SeqErrorCommand(){ @@ -304,13 +299,15 @@ int SeqErrorCommand::execute(){ totalMatches = 0; string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(queryFileName)); - string errorSummaryFileName = fileNameRoot + getOutputFileNameTag("errorsummary"); + map variables; + variables["[filename]"] = fileNameRoot; + string errorSummaryFileName = getOutputFileName("errorsummary",variables); outputNames.push_back(errorSummaryFileName); outputTypes["errorsummary"].push_back(errorSummaryFileName); - string errorSeqFileName = fileNameRoot + getOutputFileNameTag("errorseq"); + string errorSeqFileName = getOutputFileName("errorseq",variables); outputNames.push_back(errorSeqFileName); outputTypes["errorseq"].push_back(errorSeqFileName); - string errorChimeraFileName = fileNameRoot + getOutputFileNameTag("errorchimera"); + string errorChimeraFileName = getOutputFileName("errorchimera",variables); outputNames.push_back(errorChimeraFileName); outputTypes["errorchimera"].push_back(errorChimeraFileName); getReferences(); //read in reference sequences - make sure there's no ambiguous bases @@ -352,7 +349,7 @@ int SeqErrorCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - string errorCountFileName = fileNameRoot + getOutputFileNameTag("errorcount"); + string errorCountFileName = getOutputFileName("errorcount",variables); ofstream errorCountFile; m->openOutputFile(errorCountFileName, errorCountFile); outputNames.push_back(errorCountFileName); outputTypes["errorcount"].push_back(errorCountFileName); @@ -369,7 +366,7 @@ int SeqErrorCommand::execute(){ printSubMatrix(); - string megAlignmentFileName = fileNameRoot + getOutputFileNameTag("errorref-query"); + string megAlignmentFileName = getOutputFileName("errorref-query",variables); ofstream megAlignmentFile; m->openOutputFile(megAlignmentFileName, megAlignmentFile); outputNames.push_back(megAlignmentFileName); outputTypes["errorref-query"].push_back(megAlignmentFileName); @@ -1088,7 +1085,9 @@ void SeqErrorCommand::printErrorData(Compare error, int numParentSeqs, ofstream& void SeqErrorCommand::printSubMatrix(){ try { string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(queryFileName)); - string subMatrixFileName = fileNameRoot + getOutputFileNameTag("errormatrix"); + map variables; + variables["[filename]"] = fileNameRoot; + string subMatrixFileName = getOutputFileName("errormatrix",variables); ofstream subMatrixFile; m->openOutputFile(subMatrixFileName, subMatrixFile); outputNames.push_back(subMatrixFileName); outputTypes["errormatrix"].push_back(subMatrixFileName); @@ -1135,7 +1134,9 @@ void SeqErrorCommand::printSubMatrix(){ void SeqErrorCommand::printErrorFRFile(map > errorForward, map > errorReverse){ try{ string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(queryFileName)); - string errorForwardFileName = fileNameRoot + getOutputFileNameTag("errorforward"); + map variables; + variables["[filename]"] = fileNameRoot; + string errorForwardFileName = getOutputFileName("errorforward",variables); ofstream errorForwardFile; m->openOutputFile(errorForwardFileName, errorForwardFile); outputNames.push_back(errorForwardFileName); outputTypes["errorforward"].push_back(errorForwardFileName); @@ -1153,7 +1154,7 @@ void SeqErrorCommand::printErrorFRFile(map > errorForward, map } errorForwardFile.close(); - string errorReverseFileName = fileNameRoot + getOutputFileNameTag("errorreverse"); + string errorReverseFileName = getOutputFileName("errorreverse",variables); ofstream errorReverseFile; m->openOutputFile(errorReverseFileName, errorReverseFile); outputNames.push_back(errorReverseFileName); outputTypes["errorreverse"].push_back(errorReverseFileName); @@ -1182,7 +1183,9 @@ void SeqErrorCommand::printErrorFRFile(map > errorForward, map void SeqErrorCommand::printErrorQuality(map > qScoreErrorMap){ try{ string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(queryFileName)); - string errorQualityFileName = fileNameRoot + getOutputFileNameTag("errorquality"); + map variables; + variables["[filename]"] = fileNameRoot; + string errorQualityFileName = getOutputFileName("errorquality",variables); ofstream errorQualityFile; m->openOutputFile(errorQualityFileName, errorQualityFile); outputNames.push_back(errorQualityFileName); outputTypes["errorquality"].push_back(errorQualityFileName); @@ -1216,7 +1219,9 @@ void SeqErrorCommand::printQualityFR(vector > qualForwardMap, vector } } string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(queryFileName)); - string qualityForwardFileName = fileNameRoot + getOutputFileNameTag("errorqualforward"); + map variables; + variables["[filename]"] = fileNameRoot; + string qualityForwardFileName = getOutputFileName("errorqualforward",variables); ofstream qualityForwardFile; m->openOutputFile(qualityForwardFileName, qualityForwardFile); outputNames.push_back(qualityForwardFileName); outputTypes["errorqualforward"].push_back(qualityForwardFileName); @@ -1234,7 +1239,7 @@ void SeqErrorCommand::printQualityFR(vector > qualForwardMap, vector qualityForwardFile.close(); - string qualityReverseFileName = fileNameRoot + getOutputFileNameTag("errorqualreverse"); + string qualityReverseFileName = getOutputFileName("errorqualreverse",variables); ofstream qualityReverseFile; m->openOutputFile(qualityReverseFileName, qualityReverseFile); outputNames.push_back(qualityReverseFileName); outputTypes["errorqualreverse"].push_back(qualityReverseFileName); diff --git a/seqerrorcommand.h b/seqerrorcommand.h index fba392d..6c7af2c 100644 --- a/seqerrorcommand.h +++ b/seqerrorcommand.h @@ -24,8 +24,9 @@ public: vector setParameters(); string getCommandName() { return "seq.error"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Gevers D, Westcott SL (2011). Reducing the effects of PCR amplification and sequencing artifacts on 16S rRNA-based studies. PLoS ONE. 6:e27310.\nhttp://www.mothur.org/wiki/Seq.error"; } string getDescription() { return "seq.error"; } diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index fb43503..8f27b8c 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -13,12 +13,12 @@ //********************************************************************************************************************** vector SeqSummaryCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","summary",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + 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); } @@ -48,24 +48,19 @@ string SeqSummaryCommand::getHelpString(){ } } //********************************************************************************************************************** -string SeqSummaryCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SeqSummaryCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "summary") { outputFileName = "summary"; } - 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, "SeqSummaryCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "summary") { pattern = "[filename],summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SeqSummaryCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -193,7 +188,9 @@ int SeqSummaryCommand::execute(){ //set current fasta to fastafile m->setFastaFile(fastafile); - string summaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string summaryFile = getOutputFileName("summary",variables); int numSeqs = 0; diff --git a/seqsummarycommand.h b/seqsummarycommand.h index 3926e25..c4e6131 100644 --- a/seqsummarycommand.h +++ b/seqsummarycommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "summary.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Summary.seqs"; } string getDescription() { return "summarize the quality of sequences in an unaligned or aligned fasta file"; } diff --git a/setcurrentcommand.cpp b/setcurrentcommand.cpp index 27d7b92..9d277f3 100644 --- a/setcurrentcommand.cpp +++ b/setcurrentcommand.cpp @@ -13,32 +13,32 @@ vector SetCurrentCommand::setParameters(){ try { - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pflow("flow", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pflow); - CommandParameter pbiom("biom", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pbiom); - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pphylip); - CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pcolumn); - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plist); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(ptaxonomy); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pqfile); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); - CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(prabund); - CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psabund); - CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pdesign); - CommandParameter porder("order", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(porder); - CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(ptree); - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pshared); - CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pordergroup); - CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter prelabund("relabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(prelabund); - CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psff); - CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos); - CommandParameter pclear("clear", "String", "", "", "", "", "",false,false); parameters.push_back(pclear); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pflow("flow", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pflow); + CommandParameter pbiom("biom", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pbiom); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pphylip); + CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcolumn); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptaxonomy); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pqfile); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos); + CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psabund); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pdesign); + CommandParameter porder("order", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(porder); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(ptree); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pshared); + CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pordergroup); + CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pcount); + CommandParameter prelabund("relabund", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(prelabund); + CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(psff); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(poligos); + CommandParameter pclear("clear", "String", "", "", "", "", "","",false,false); parameters.push_back(pclear); + 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); } diff --git a/setcurrentcommand.h b/setcurrentcommand.h index e741399..190bf77 100644 --- a/setcurrentcommand.h +++ b/setcurrentcommand.h @@ -23,8 +23,9 @@ public: vector setParameters(); string getCommandName() { return "set.current"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string) { return ""; } + string getHelpString(); + string getOutputPattern(string){ return ""; } string getCitation() { return "http://www.mothur.org/wiki/Set.current"; } string getDescription() { return "set current files for mothur"; } diff --git a/setdircommand.cpp b/setdircommand.cpp index ca8c62d..4536d95 100644 --- a/setdircommand.cpp +++ b/setdircommand.cpp @@ -12,12 +12,12 @@ //********************************************************************************************************************** vector SetDirectoryCommand::setParameters(){ try { - CommandParameter ptempdefault("tempdefault", "String", "", "", "", "", "",false,false); parameters.push_back(ptempdefault); - CommandParameter pdebug("debug", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pdebug); - CommandParameter pinput("input", "String", "", "", "", "", "",false,false); parameters.push_back(pinput); - CommandParameter poutput("output", "String", "", "", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptempdefault("tempdefault", "String", "", "", "", "", "","",false,false); parameters.push_back(ptempdefault); + CommandParameter pdebug("debug", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pdebug); + CommandParameter pinput("input", "String", "", "", "", "", "","",false,false,true); parameters.push_back(pinput); + CommandParameter poutput("output", "String", "", "", "", "", "","",false,false,true); parameters.push_back(poutput); + 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); } diff --git a/setdircommand.h b/setdircommand.h index 837a8b5..ab174c2 100644 --- a/setdircommand.h +++ b/setdircommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "set.dir"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string) { return ""; } + string getHelpString(); + string getOutputPattern(string){ return ""; } string getCitation() { return "http://www.mothur.org/wiki/Set.dir"; } string getDescription() { return "set input, output and default directories"; } diff --git a/setlogfilecommand.cpp b/setlogfilecommand.cpp index 576a37c..128c567 100644 --- a/setlogfilecommand.cpp +++ b/setlogfilecommand.cpp @@ -13,10 +13,10 @@ //********************************************************************************************************************** vector SetLogFileCommand::setParameters(){ try { - CommandParameter pappend("append", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pappend); - CommandParameter pname("name", "String", "", "", "", "", "",false,true); parameters.push_back(pname); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pappend("append", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pappend); + CommandParameter pname("name", "String", "", "", "", "", "","",false,true,true); 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); } diff --git a/setlogfilecommand.h b/setlogfilecommand.h index a97c791..0354971 100644 --- a/setlogfilecommand.h +++ b/setlogfilecommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "set.logfile"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string) { return ""; } + string getHelpString(); + string getOutputPattern(string){ return ""; } string getCitation() { return "http://www.mothur.org/wiki/Set.logfile"; } string getDescription() { return "set logfile name"; } diff --git a/sffinfocommand.cpp b/sffinfocommand.cpp index c50255a..a1b7066 100644 --- a/sffinfocommand.cpp +++ b/sffinfocommand.cpp @@ -16,21 +16,21 @@ //********************************************************************************************************************** vector SffInfoCommand::setParameters(){ try { - CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psff); - CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); - CommandParameter psfftxt("sfftxt", "String", "", "", "", "", "",false,false); parameters.push_back(psfftxt); - CommandParameter pflow("flow", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pflow); - CommandParameter ptrim("trim", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(ptrim); - CommandParameter pfasta("fasta", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pfasta); - CommandParameter pqfile("name", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pqfile); - CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppdiffs); - CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pbdiffs); - CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pldiffs); - CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(psdiffs); - CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ptdiffs); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(psff); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(poligos); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos); + CommandParameter psfftxt("sfftxt", "String", "", "", "", "", "","",false,false); parameters.push_back(psfftxt); + CommandParameter pflow("flow", "Boolean", "", "T", "", "", "","flow",false,false); parameters.push_back(pflow); + CommandParameter ptrim("trim", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(ptrim); + CommandParameter pfasta("fasta", "Boolean", "", "T", "", "", "","fasta",false,false); parameters.push_back(pfasta); + CommandParameter pqfile("qfile", "Boolean", "", "T", "", "", "","qfile",false,false); parameters.push_back(pqfile); + CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ppdiffs); + CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pbdiffs); + CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pldiffs); + CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psdiffs); + CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ptdiffs); + 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); } @@ -70,32 +70,26 @@ string SffInfoCommand::getHelpString(){ exit(1); } } + //********************************************************************************************************************** -string SffInfoCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SffInfoCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "fasta"; } - else if (type == "flow") { outputFileName = "flow"; } - else if (type == "sfftxt") { outputFileName = "sff.txt"; } - else if (type == "sff") { outputFileName = "sff"; } - else if (type == "qfile") { outputFileName = "qual"; } - 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, "SffInfoCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],fasta-[filename],[tag],fasta"; } + else if (type == "flow") { pattern = "[filename],flow"; } + else if (type == "sfftxt") { pattern = "[filename],sff.txt"; } + else if (type == "sff") { pattern = "[filename],[group],sff"; } + else if (type == "qfile") { pattern = "[filename],qual-[filename],[tag],qual"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "getOutputPattern"); + exit(1); + } } - - //********************************************************************************************************************** SffInfoCommand::SffInfoCommand(){ try { @@ -504,16 +498,14 @@ int SffInfoCommand::extractSffInfo(string input, string accnos, string oligos){ string rootName = outputDir + m->getRootName(m->getSimpleName(input)); if(rootName.find_last_of(".") == rootName.npos){ rootName += "."; } - string sfftxtFileName = outputDir + m->getRootName(m->getSimpleName(input)) + getOutputFileNameTag("sfftxt"); - string outFlowFileName = outputDir + m->getRootName(m->getSimpleName(input)) + getOutputFileNameTag("flow"); - if (trim) { - outFastaFileName = outputDir + m->getRootName(m->getSimpleName(input)) + getOutputFileNameTag("fasta"); - outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + getOutputFileNameTag("qfile"); - }else{ - outFastaFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw." + getOutputFileNameTag("fasta"); - outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw." + getOutputFileNameTag("qfile"); - } - + map variables; + variables["[filename]"] = rootName; + string sfftxtFileName = getOutputFileName("sfftxt",variables); + string outFlowFileName = getOutputFileName("flow",variables); + if (!trim) { variables["[tag]"] = "raw"; } + outFastaFileName = getOutputFileName("fasta",variables); + outQualFileName = getOutputFileName("qfile",variables); + if (sfftxt) { m->openOutputFile(sfftxtFileName, outSfftxt); outSfftxt.setf(ios::fixed, ios::floatfield); outSfftxt.setf(ios::showpoint); outputNames.push_back(sfftxtFileName); outputTypes["sfftxt"].push_back(sfftxtFileName); } if (fasta) { m->openOutputFile(outFastaFileName, outFasta); outputNames.push_back(outFastaFileName); outputTypes["fasta"].push_back(outFastaFileName); } if (qual) { m->openOutputFile(outQualFileName, outQual); outputNames.push_back(outQualFileName); outputTypes["qfile"].push_back(outQualFileName); } @@ -1396,14 +1388,13 @@ int SffInfoCommand::parseSffTxt() { fileRoot = m->getRootName(fileRoot); } - string outFlowFileName = outputDir + fileRoot + getOutputFileNameTag("flow"); - if (trim) { - outFastaFileName = outputDir + fileRoot + getOutputFileNameTag("fasta"); - outQualFileName = outputDir + fileRoot + getOutputFileNameTag("qfile"); - }else{ - outFastaFileName = outputDir + fileRoot + "raw." + getOutputFileNameTag("fasta"); - outQualFileName = outputDir + fileRoot + "raw." + getOutputFileNameTag("qfile"); - } + map variables; + variables["[filename]"] = fileRoot; + string sfftxtFileName = getOutputFileName("sfftxt",variables); + string outFlowFileName = getOutputFileName("flow",variables); + if (!trim) { variables["[tag]"] = "raw"; } + outFastaFileName = getOutputFileName("fasta",variables); + outQualFileName = getOutputFileName("qfile",variables); if (fasta) { m->openOutputFile(outFastaFileName, outFasta); outputNames.push_back(outFastaFileName); outputTypes["fasta"].push_back(outFastaFileName); } if (qual) { m->openOutputFile(outQualFileName, outQual); outputNames.push_back(outQualFileName); outputTypes["qfile"].push_back(outQualFileName); } @@ -1731,7 +1722,10 @@ bool SffInfoCommand::readOligos(string oligoFile){ } ofstream temp; - string thisFilename = outputDir + m->getRootName(m->getSimpleName(currentFileName)) + comboGroupName + "." + getOutputFileNameTag("sff"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(currentFileName)); + variables["[group]"] = comboGroupName; + string thisFilename = getOutputFileName("sff",variables); if (uniqueNames.count(thisFilename) == 0) { outputNames.push_back(thisFilename); outputTypes["sff"].push_back(thisFilename); @@ -1746,7 +1740,10 @@ bool SffInfoCommand::readOligos(string oligoFile){ numFPrimers = primers.size(); numLinkers = linker.size(); numSpacers = spacer.size(); - noMatchFile = outputDir + m->getRootName(m->getSimpleName(currentFileName)) + "scrap." + getOutputFileNameTag("sff"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(currentFileName)); + variables["[group]"] = "scrap"; + noMatchFile = getOutputFileName("sff",variables); m->mothurRemove(noMatchFile); bool allBlank = true; diff --git a/sffinfocommand.h b/sffinfocommand.h index 4917a27..5ec6e72 100644 --- a/sffinfocommand.h +++ b/sffinfocommand.h @@ -69,8 +69,9 @@ public: vector setParameters(); string getCommandName() { return "sffinfo"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Sffinfo"; } string getDescription() { return "extract sequences reads from a .sff file"; } diff --git a/sffmultiplecommand.cpp b/sffmultiplecommand.cpp index 05bc9aa..91d8b01 100644 --- a/sffmultiplecommand.cpp +++ b/sffmultiplecommand.cpp @@ -13,46 +13,46 @@ //********************************************************************************************************************** vector SffMultipleCommand::setParameters(){ try { - CommandParameter pfile("file", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfile); + CommandParameter pfile("file", "InputTypes", "", "", "none", "none", "none","fasta-name",false,true,true); parameters.push_back(pfile); //sffinfo - CommandParameter ptrim("trim", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(ptrim); + CommandParameter ptrim("trim", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(ptrim); //trim.flows - CommandParameter pmaxhomop("maxhomop", "Number", "", "9", "", "", "",false,false); parameters.push_back(pmaxhomop); - CommandParameter pmaxflows("maxflows", "Number", "", "450", "", "", "",false,false); parameters.push_back(pmaxflows); - CommandParameter pminflows("minflows", "Number", "", "450", "", "", "",false,false); parameters.push_back(pminflows); - CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppdiffs); - CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pbdiffs); - CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pldiffs); - CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(psdiffs); - CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ptdiffs); - CommandParameter psignal("signal", "Number", "", "0.50", "", "", "",false,false); parameters.push_back(psignal); - CommandParameter pnoise("noise", "Number", "", "0.70", "", "", "",false,false); parameters.push_back(pnoise); - CommandParameter porder("order", "String", "", "TACG", "", "", "",false,false); parameters.push_back(porder); + CommandParameter pmaxhomop("maxhomop", "Number", "", "9", "", "", "","",false,false); parameters.push_back(pmaxhomop); + CommandParameter pmaxflows("maxflows", "Number", "", "450", "", "", "","",false,false); parameters.push_back(pmaxflows); + CommandParameter pminflows("minflows", "Number", "", "450", "", "", "","",false,false); parameters.push_back(pminflows); + CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(ppdiffs); + CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(pbdiffs); + CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pldiffs); + CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psdiffs); + CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ptdiffs); + CommandParameter psignal("signal", "Number", "", "0.50", "", "", "","",false,false); parameters.push_back(psignal); + CommandParameter pnoise("noise", "Number", "", "0.70", "", "", "","",false,false); parameters.push_back(pnoise); + CommandParameter porder("order", "String", "", "TACG", "", "", "","",false,false); parameters.push_back(porder); //shhh.flows - CommandParameter plookup("lookup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plookup); - CommandParameter pcutoff("cutoff", "Number", "", "0.01", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pmaxiter("maxiter", "Number", "", "1000", "", "", "",false,false); parameters.push_back(pmaxiter); - CommandParameter plarge("large", "Number", "", "-1", "", "", "",false,false); parameters.push_back(plarge); - CommandParameter psigma("sigma", "Number", "", "60", "", "", "",false,false); parameters.push_back(psigma); - CommandParameter pmindelta("mindelta", "Number", "", "0.000001", "", "", "",false,false); parameters.push_back(pmindelta); + CommandParameter plookup("lookup", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(plookup); + CommandParameter pcutoff("cutoff", "Number", "", "0.01", "", "", "","",false,false); parameters.push_back(pcutoff); + CommandParameter pmaxiter("maxiter", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(pmaxiter); + CommandParameter plarge("large", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(plarge); + CommandParameter psigma("sigma", "Number", "", "60", "", "", "","",false,false); parameters.push_back(psigma); + CommandParameter pmindelta("mindelta", "Number", "", "0.000001", "", "", "","",false,false); parameters.push_back(pmindelta); //trim.seqs parameters - CommandParameter pallfiles("allfiles", "Boolean", "", "t", "", "", "",false,false); parameters.push_back(pallfiles); - CommandParameter pflip("flip", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pflip); - CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxambig); - CommandParameter pminlength("minlength", "Number", "", "0", "", "", "",false,false); parameters.push_back(pminlength); - CommandParameter pmaxlength("maxlength", "Number", "", "0", "", "", "",false,false); parameters.push_back(pmaxlength); - CommandParameter pkeepforward("keepforward", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pkeepforward); - CommandParameter pkeepfirst("keepfirst", "Number", "", "0", "", "", "",false,false); parameters.push_back(pkeepfirst); - CommandParameter premovelast("removelast", "Number", "", "0", "", "", "",false,false); parameters.push_back(premovelast); + CommandParameter pallfiles("allfiles", "Boolean", "", "t", "", "", "","",false,false); parameters.push_back(pallfiles); + CommandParameter pflip("flip", "Boolean", "", "F", "", "", "","",false,false,true); parameters.push_back(pflip); + CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxambig); + CommandParameter pminlength("minlength", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pminlength); + CommandParameter pmaxlength("maxlength", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pmaxlength); + CommandParameter pkeepforward("keepforward", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pkeepforward); + CommandParameter pkeepfirst("keepfirst", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pkeepfirst); + CommandParameter premovelast("removelast", "Number", "", "0", "", "", "","",false,false); parameters.push_back(premovelast); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + 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); } @@ -100,29 +100,22 @@ string SffMultipleCommand::getHelpString(){ } } //********************************************************************************************************************** -string SffMultipleCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SffMultipleCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "fasta"; } - else if (type == "name") { outputFileName = "names"; } - else if (type == "group") { outputFileName = "groups"; } - 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, "SffMultipleCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],fasta"; } + else if (type == "name") { pattern = "[filename],names"; } + else if (type == "group") { pattern = "[filename],groups"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SffMultipleCommand", "getOutputPattern"); + exit(1); + } } - - //********************************************************************************************************************** SffMultipleCommand::SffMultipleCommand(){ try { @@ -132,8 +125,6 @@ SffMultipleCommand::SffMultipleCommand(){ outputTypes["fasta"] = tempOutNames; outputTypes["name"] = tempOutNames; outputTypes["group"] = tempOutNames; - outputTypes["flow"] = tempOutNames; - outputTypes["qfile"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "SffMultipleCommand", "SffMultipleCommand"); @@ -168,8 +159,6 @@ SffMultipleCommand::SffMultipleCommand(string option) { //initialize outputTypes vector tempOutNames; outputTypes["fasta"] = tempOutNames; - outputTypes["flow"] = tempOutNames; - outputTypes["qfile"] = tempOutNames; outputTypes["name"] = tempOutNames; outputTypes["group"] = tempOutNames; @@ -379,9 +368,11 @@ int SffMultipleCommand::execute(){ outputDir = m->hasPath(filename); string fileroot = outputDir + m->getRootName(m->getSimpleName(filename)); - string fasta = fileroot + getOutputFileNameTag("fasta"); - string name = fileroot + getOutputFileNameTag("name"); - string group = fileroot + getOutputFileNameTag("group"); + map variables; + variables["[filename]"] = fileroot; + string fasta = fileroot + getOutputFileName("fasta",variables); + string name = fileroot + getOutputFileName("name",variables); + string group = fileroot + getOutputFileName("group",variables); if (m->control_pressed) { return 0; } diff --git a/sffmultiplecommand.h b/sffmultiplecommand.h index 4ab2c97..ee83d72 100644 --- a/sffmultiplecommand.h +++ b/sffmultiplecommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "sff.multiple"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Sff.multiple"; } string getDescription() { return "run multiple sff files through, sffinfo, trim.flow, shhh.flows and trim.seqs combining the results"; } diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 542f8d3..91ca1a1 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -19,15 +19,15 @@ inline bool compareSharedRabunds(SharedRAbundVector* left, SharedRAbundVector* r //********************************************************************************************************************** vector SharedCommand::setParameters(){ try { - CommandParameter pbiom("biom", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "none",false,false); parameters.push_back(pbiom); - CommandParameter plist("list", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "ListGroup",false,false); parameters.push_back(plist); - CommandParameter pcount("count", "InputTypes", "", "", "", "GroupCount", "",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "GroupCount", "ListGroup",false,false); parameters.push_back(pgroup); + CommandParameter pbiom("biom", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "none","shared",false,false); parameters.push_back(pbiom); + CommandParameter plist("list", "InputTypes", "", "", "BiomListGroup", "BiomListGroup", "ListGroup","shared",false,false,true); parameters.push_back(plist); + CommandParameter pcount("count", "InputTypes", "", "", "none", "GroupCount", "none","",false,false); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "GroupCount", "ListGroup","",false,false,true); parameters.push_back(pgroup); //CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pordergroup); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","group",false,false); parameters.push_back(pgroups); + 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); } @@ -56,28 +56,22 @@ string SharedCommand::getHelpString(){ } } //********************************************************************************************************************** -string SharedCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SharedCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "shared") { outputFileName = "shared"; } - else if (type == "rabund") { outputFileName = "rabund"; } - else if (type == "group") { outputFileName = "groups"; } - 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, "SharedCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "shared") { pattern = "[filename],shared"; } + else if (type == "rabund") { pattern = "[filename],[group],rabund"; } + else if (type == "group") { pattern = "[filename],[group],groups"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SharedCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** SharedCommand::SharedCommand(){ try { @@ -263,8 +257,9 @@ int SharedCommand::execute(){ if (outputDir == "") { outputDir += m->hasPath(filename); } - filename = outputDir + m->getRootName(m->getSimpleName(filename)); - filename = filename + getOutputFileNameTag("shared"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(filename)); + filename = getOutputFileName("shared",variables); outputNames.push_back(filename); outputTypes["shared"].push_back(filename); if (listfile != "") { createSharedFromListGroup(filename); } @@ -795,12 +790,15 @@ int SharedCommand::createSharedFromListGroup(string filename) { //set fileroot fileroot = outputDir + m->getRootName(m->getSimpleName(listfile)); - + map variables; + variables["[filename]"] = fileroot; //clears file before we start to write to it below for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); - outputNames.push_back((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); - outputTypes["rabund"].push_back((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); + variables["[group]"] = Groups[i]; + string rabundFIleName = getOutputFileName("rabund",variables); + m->mothurRemove(rabundFIleName); + outputNames.push_back(rabundFIleName); + outputTypes["rabund"].push_back(rabundFIleName); } string errorOff = "no error"; @@ -817,7 +815,9 @@ int SharedCommand::createSharedFromListGroup(string filename) { delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } + for (int i=0; imothurRemove(rabundFIleName); } return 0; } @@ -849,8 +849,10 @@ int SharedCommand::createSharedFromListGroup(string filename) { groups += (m->getGroups())[i] + "."; } }else { groups = "merge"; } - - string newGroupFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + groups + getOutputFileNameTag("group"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[group]"] = groups; + string newGroupFile = getOutputFileName("group",variables); outputTypes["group"].push_back(newGroupFile); outputNames.push_back(newGroupFile); ofstream outGroups; @@ -876,7 +878,9 @@ int SharedCommand::createSharedFromListGroup(string filename) { delete SharedList; if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } + for (int i=0; imothurRemove(rabundFIleName); } return 0; } @@ -894,7 +898,9 @@ int SharedCommand::createSharedFromListGroup(string filename) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } + for (int i=0; imothurRemove(rabundFIleName); } return 0; } @@ -924,7 +930,9 @@ int SharedCommand::createSharedFromListGroup(string filename) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } + for (int i=0; imothurRemove(rabundFIleName); } return 0; } @@ -970,7 +978,9 @@ int SharedCommand::createSharedFromListGroup(string filename) { if (groupMap != NULL) { delete groupMap; } if (countTable != NULL) { delete countTable; } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } + for (int i=0; imothurRemove(rabundFIleName); } return 0; } @@ -990,7 +1000,9 @@ int SharedCommand::createSharedFromListGroup(string filename) { if (m->control_pressed) { m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } + for (int i=0; imothurRemove(rabundFIleName); } return 0; } @@ -1019,7 +1031,10 @@ void SharedCommand::printSharedData(vector thislookup, ofst Groups.push_back(thislookup[i]->getGroup()); RAbundVector rav = thislookup[i]->getRAbundVector(); - m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + "." + getOutputFileNameTag("rabund"), *(filehandles[thislookup[i]->getGroup()])); + map variables; + variables["[filename]"] = fileroot; + variables["[group]"] = thislookup[i]->getGroup(); + m->openOutputFileAppend(getOutputFileName("rabund",variables), *(filehandles[thislookup[i]->getGroup()])); rav.print(*(filehandles[thislookup[i]->getGroup()])); (*(filehandles[thislookup[i]->getGroup()])).close(); } @@ -1047,7 +1062,10 @@ void SharedCommand::printSharedData(vector thislookup, ofst Groups.push_back((myIt->second)->getGroup()); RAbundVector rav = (myIt->second)->getRAbundVector(); - m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + "." + getOutputFileNameTag("rabund"), *(filehandles[(myIt->second)->getGroup()])); + map variables; + variables["[filename]"] = fileroot; + variables["[group]"] = (myIt->second)->getGroup(); + m->openOutputFileAppend(getOutputFileName("rabund",variables), *(filehandles[(myIt->second)->getGroup()])); rav.print(*(filehandles[(myIt->second)->getGroup()])); (*(filehandles[(myIt->second)->getGroup()])).close(); }else{ diff --git a/sharedcommand.h b/sharedcommand.h index 9d9c194..39ef9a7 100644 --- a/sharedcommand.h +++ b/sharedcommand.h @@ -30,8 +30,9 @@ public: vector setParameters(); string getCommandName() { return "make.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Make.shared"; } string getDescription() { return "make a shared file from a list and group file"; } diff --git a/shhhercommand.cpp b/shhhercommand.cpp index 19ffc89..a859d14 100644 --- a/shhhercommand.cpp +++ b/shhhercommand.cpp @@ -12,18 +12,18 @@ //********************************************************************************************************************** vector ShhherCommand::setParameters(){ try { - CommandParameter pflow("flow", "InputTypes", "", "", "none", "fileflow", "none",false,false); parameters.push_back(pflow); - CommandParameter pfile("file", "InputTypes", "", "", "none", "fileflow", "none",false,false); parameters.push_back(pfile); - CommandParameter plookup("lookup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plookup); - CommandParameter pcutoff("cutoff", "Number", "", "0.01", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pmaxiter("maxiter", "Number", "", "1000", "", "", "",false,false); parameters.push_back(pmaxiter); - CommandParameter plarge("large", "Number", "", "-1", "", "", "",false,false); parameters.push_back(plarge); - CommandParameter psigma("sigma", "Number", "", "60", "", "", "",false,false); parameters.push_back(psigma); - CommandParameter pmindelta("mindelta", "Number", "", "0.000001", "", "", "",false,false); parameters.push_back(pmindelta); - CommandParameter porder("order", "String", "", "", "", "", "",false,false); parameters.push_back(porder); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pflow("flow", "InputTypes", "", "", "none", "fileflow", "none","fasta-name-group-counts-qfile",false,false,true); parameters.push_back(pflow); + CommandParameter pfile("file", "InputTypes", "", "", "none", "fileflow", "none","fasta-name-group-counts-qfile",false,false,true); parameters.push_back(pfile); + CommandParameter plookup("lookup", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(plookup); + CommandParameter pcutoff("cutoff", "Number", "", "0.01", "", "", "","",false,false); parameters.push_back(pcutoff); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pmaxiter("maxiter", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(pmaxiter); + CommandParameter plarge("large", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(plarge); + CommandParameter psigma("sigma", "Number", "", "60", "", "", "","",false,false); parameters.push_back(psigma); + CommandParameter pmindelta("mindelta", "Number", "", "0.000001", "", "", "","",false,false); parameters.push_back(pmindelta); + CommandParameter porder("order", "String", "", "", "", "", "","",false,false); parameters.push_back(porder); + 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); } @@ -47,28 +47,23 @@ string ShhherCommand::getHelpString(){ } } //********************************************************************************************************************** -string ShhherCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - 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 == "fasta") { outputFileName = "shhh.fasta"; } - else if (type == "name") { outputFileName = "shhh.names"; } - else if (type == "group") { outputFileName = "shhh.groups"; } - else if (type == "counts") { outputFileName = "shhh.counts"; } - else if (type == "qfile") { outputFileName = "shhh.qual"; } - 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, "ShhherCommand", "getOutputFileNameTag"); - exit(1); - } +string ShhherCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "fasta") { pattern = "[filename],shhh.fasta"; } + else if (type == "name") { pattern = "[filename],shhh.names"; } + else if (type == "group") { pattern = "[filename],shhh.groups"; } + else if (type == "counts") { pattern = "[filename],shhh.counts"; } + else if (type == "qfile") { pattern = "[filename],shhh.qual"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ShhherCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -801,8 +796,9 @@ string ShhherCommand::createNamesFile(){ for(int i=0;igetRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("name"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(flowFileName)); + string nameFileName = getOutputFileName("name",variables); ofstream nameFile; m->openOutputFile(nameFileName, nameFile); @@ -1651,7 +1647,9 @@ void ShhherCommand::writeQualities(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string qualityFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("qfile"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(flowFileName)); + string qualityFileName = getOutputFileName("qfile",variables); ofstream qualityFile; m->openOutputFile(qualityFileName, qualityFile); @@ -1758,7 +1756,9 @@ void ShhherCommand::writeSequences(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string fastaFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)); + string fastaFileName = getOutputFileName("fasta",variables); ofstream fastaFile; m->openOutputFile(fastaFileName, fastaFile); @@ -1806,7 +1806,9 @@ void ShhherCommand::writeNames(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string nameFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("name"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)); + string nameFileName = getOutputFileName("name",variables); ofstream nameFile; m->openOutputFile(nameFileName, nameFile); @@ -1848,7 +1850,9 @@ void ShhherCommand::writeGroups(){ int pos = fileRoot.find_first_of('.'); string fileGroup = fileRoot; if (pos != string::npos) { fileGroup = fileRoot.substr(pos+1, (fileRoot.length()-1-(pos+1))); } - string groupFileName = thisOutputDir + fileRoot + getOutputFileNameTag("group"); + map variables; + variables["[filename]"] = thisOutputDir + fileRoot; + string groupFileName = getOutputFileName("group",variables); ofstream groupFile; m->openOutputFile(groupFileName, groupFile); @@ -1872,7 +1876,9 @@ void ShhherCommand::writeClusters(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string otuCountsFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) +getOutputFileNameTag("counts"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)); + string otuCountsFileName = getOutputFileName("counts",variables); ofstream otuCountsFile; m->openOutputFile(otuCountsFileName, otuCountsFile); @@ -2323,15 +2329,17 @@ int ShhherCommand::driver(vector filenames, string thisCompositeFASTAFil if ((large) && (g == 0)) { flowFileName = filenames[i]; theseFlowFileNames[0] = filenames[i]; } string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir = m->hasPath(flowFileName); } - string qualityFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("qfile"); - string fastaFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("fasta"); - string nameFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("name"); - string otuCountsFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("counts"); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)); + string qualityFileName = getOutputFileName("qfile",variables); + string fastaFileName = getOutputFileName("fasta",variables); + string nameFileName = getOutputFileName("name",variables); + string otuCountsFileName = getOutputFileName("counts",variables); string fileRoot = m->getRootName(m->getSimpleName(flowFileName)); int pos = fileRoot.find_first_of('.'); string fileGroup = fileRoot; if (pos != string::npos) { fileGroup = fileRoot.substr(pos+1, (fileRoot.length()-1-(pos+1))); } - string groupFileName = thisOutputDir + fileRoot + getOutputFileNameTag("group"); + string groupFileName = getOutputFileName("group",variables); writeQualities(numOTUs, numFlowCells, qualityFileName, otuCounts, nSeqsPerOTU, seqNumber, singleTau, flowDataIntI, uniqueFlowgrams, cumNumSeqs, mapUniqueToSeq, seqNameVector, centroids, aaI); if (m->control_pressed) { break; } @@ -2342,15 +2350,16 @@ int ShhherCommand::driver(vector filenames, string thisCompositeFASTAFil if (large) { if (g > 0) { - m->appendFiles(qualityFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("qfile"))); + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])); + m->appendFiles(qualityFileName, getOutputFileName("qfile",variables)); m->mothurRemove(qualityFileName); - m->appendFiles(fastaFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("fasta"))); + m->appendFiles(fastaFileName, getOutputFileName("fasta",variables)); m->mothurRemove(fastaFileName); - m->appendFiles(nameFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("name"))); + m->appendFiles(nameFileName, getOutputFileName("name",variables)); m->mothurRemove(nameFileName); - m->appendFiles(otuCountsFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("counts"))); + m->appendFiles(otuCountsFileName, getOutputFileName("counts",variables)); m->mothurRemove(otuCountsFileName); - m->appendFiles(groupFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("group"))); + m->appendFiles(groupFileName, getOutputFileName("group",variables)); m->mothurRemove(groupFileName); } m->mothurRemove(theseFlowFileNames[g]); diff --git a/shhhercommand.h b/shhhercommand.h index ef52dcd..3b75724 100644 --- a/shhhercommand.h +++ b/shhhercommand.h @@ -40,8 +40,9 @@ public: vector setParameters(); string getCommandName() { return "shhh.flows"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Gevers D, Westcott SL (2011). Reducing the effects of PCR amplification and sequencing artifacts on 16S rRNA-based studies. PLoS ONE. 6:e27310.\nQuince C, Lanzen A, Davenport RJ, Turnbaugh PJ (2011). Removing noise from pyrosequenced amplicons. BMC Bioinformatics 12:38.\nQuince C, Lanzén A, Curtis TP, Davenport RJ, Hall N, Head IM, Read LF, Sloan WT (2009). Accurate determination of microbial diversity from 454 pyrosequencing data. Nat. Methods 6:639.\nhttp://www.mothur.org/wiki/Shhh.flows"; } string getDescription() { return "shhh.flows"; } diff --git a/shhhseqscommand.cpp b/shhhseqscommand.cpp index 63de2bb..3e3e586 100644 --- a/shhhseqscommand.cpp +++ b/shhhseqscommand.cpp @@ -14,13 +14,13 @@ //********************************************************************************************************************** vector ShhhSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pname); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - CommandParameter psigma("sigma", "Number", "", "0.01", "", "", "",false,false); parameters.push_back(psigma); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta-map",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none","name",false,true,true); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(pgroup); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + CommandParameter psigma("sigma", "Number", "", "0.01", "", "", "","",false,false); parameters.push_back(psigma); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -55,26 +55,21 @@ string ShhhSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string ShhhSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string ShhhSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "shhh_seqs.fasta"; } - else if (type == "name") { outputFileName = "shhh_seqs.names"; } - else if (type == "map") { outputFileName = "shhh_seqs.map"; } - 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, "ShhhSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],shhh_seqs.fasta"; } + else if (type == "name") { pattern = "[filename],shhh_seqs.names"; } + else if (type == "map") { pattern = "[filename],shhh_seqs.map"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ShhhSeqsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -207,10 +202,13 @@ int ShhhSeqsCommand::execute() { if (abort == true) { if (calledHelp) { return 0; } return 2; } - if (outputDir == "") { outputDir = m->hasPath(fastafile); }//if user entered a file with a path then preserve it - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta"); - string nameFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("name"); - string mapFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("map"); + if (outputDir == "") { outputDir = m->hasPath(fastafile); }//if user entered a file with a path then preserve it + + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + string outputFileName = getOutputFileName("fasta",variables); + string nameFileName = getOutputFileName("name",variables); + string mapFileName = getOutputFileName("map",variables); if (groupfile != "") { //Parse sequences by group diff --git a/shhhseqscommand.h b/shhhseqscommand.h index 85be58c..4da1a84 100644 --- a/shhhseqscommand.h +++ b/shhhseqscommand.h @@ -29,8 +29,9 @@ public: vector setParameters(); string getCommandName() { return "shhh.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Schloss PD, Gevers D, Westcott SL (2011). Reducing the effects of PCR amplification and sequencing artifacts on 16S rRNA-based studies. PLoS ONE. 6:e27310.\nQuince C, Lanzen A, Davenport RJ, Turnbaugh PJ (2011). Removing noise from pyrosequenced amplicons. BMC Bioinformatics 12:38.\nhttp://www.mothur.org/wiki/Shhh.seqs"; } string getDescription() { return "shhh.seqs"; } diff --git a/sortseqscommand.cpp b/sortseqscommand.cpp index b0af154..d844452 100644 --- a/sortseqscommand.cpp +++ b/sortseqscommand.cpp @@ -13,17 +13,17 @@ //********************************************************************************************************************** vector SortSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); - CommandParameter pflow("flow", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pflow); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none",false,false); parameters.push_back(pgroup); - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pqfile); - CommandParameter plarge("large", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(plarge); - CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none","fasta",false,false); parameters.push_back(pfasta); + CommandParameter pflow("flow", "InputTypes", "", "", "none", "FNGLT", "none","flow",false,false); parameters.push_back(pflow); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none","name",false,false); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none","count",false,false); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none","group",false,false); parameters.push_back(pgroup); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none","taxonomy",false,false); parameters.push_back(ptaxonomy); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none","qfile",false,false); parameters.push_back(pqfile); + CommandParameter plarge("large", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(plarge); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(paccnos); + 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); } @@ -52,34 +52,27 @@ string SortSeqsCommand::getHelpString(){ exit(1); } } - //********************************************************************************************************************** -string SortSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SortSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "sorted" + m->getExtension(inputName); } - else if (type == "taxonomy") { outputFileName = "sorted" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "sorted" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "sorted" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "sorted" + m->getExtension(inputName); } - else if (type == "flow") { outputFileName = "sorted" + m->getExtension(inputName); } - else if (type == "qfile") { outputFileName = "sorted" + m->getExtension(inputName); } - 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, "SortSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],sorted,[extension]"; } + else if (type == "taxonomy") { pattern = "[filename],sorted,[extension]"; } + else if (type == "name") { pattern = "[filename],sorted,[extension]"; } + else if (type == "group") { pattern = "[filename],sorted,[extension]"; } + else if (type == "count") { pattern = "[filename],sorted,[extension]"; } + else if (type == "flow") { pattern = "[filename],sorted,[extension]"; } + else if (type == "qfile") { pattern = "[filename],sorted,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SortSeqsCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** SortSeqsCommand::SortSeqsCommand(){ try { @@ -358,7 +351,10 @@ int SortSeqsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[extension]"] = m->getExtension(fastafile); + string outputFileName = getOutputFileName("fasta", variables); outputTypes["fasta"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -531,7 +527,10 @@ int SortSeqsCommand::readFlow(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowfile)) + getOutputFileNameTag("flow", flowfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(flowfile)); + variables["[extension]"] = m->getExtension(flowfile); + string outputFileName = getOutputFileName("flow", variables); outputTypes["flow"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -709,7 +708,10 @@ int SortSeqsCommand::readQual(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)); + variables["[extension]"] = m->getExtension(qualfile); + string outputFileName = getOutputFileName("qfile", variables); outputTypes["qfile"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -889,7 +891,10 @@ int SortSeqsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outputFileName = getOutputFileName("name", variables); outputTypes["name"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -965,7 +970,10 @@ int SortSeqsCommand::readCount(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(countfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string outputFileName = getOutputFileName("count", variables); outputTypes["count"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -1047,7 +1055,10 @@ int SortSeqsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string outputFileName = getOutputFileName("group", variables); outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -1123,7 +1134,11 @@ int SortSeqsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)); + variables["[extension]"] = m->getExtension(taxfile); + string outputFileName = getOutputFileName("taxonomy", variables); + outputTypes["taxonomy"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; diff --git a/sortseqscommand.h b/sortseqscommand.h index 4ba8e42..c1de84e 100644 --- a/sortseqscommand.h +++ b/sortseqscommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "sort.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Sort.seqs"; } string getDescription() { return "puts sequences from a fasta, name, group, quality, flow or taxonomy file in the same order"; } diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index 48fada8..2d37e8d 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -13,17 +13,17 @@ //********************************************************************************************************************** vector SplitAbundCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pcutoff("cutoff", "Number", "", "0", "", "", "",false,true); parameters.push_back(pcutoff); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter paccnos("accnos", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(paccnos); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","group",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none","list",false,false,true); parameters.push_back(plist); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pcutoff("cutoff", "Number", "", "0", "", "", "","",false,true); parameters.push_back(pcutoff); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter paccnos("accnos", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(paccnos); + 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); } @@ -58,30 +58,26 @@ string SplitAbundCommand::getHelpString(){ exit(1); } } + //********************************************************************************************************************** -string SplitAbundCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SplitAbundCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "fasta"; } - else if (type == "list") { outputFileName = "list"; } - else if (type == "name") { outputFileName = "names"; } - else if (type == "count") { outputFileName = "count_table"; } - else if (type == "group") { outputFileName = "groups"; } - else if (type == "accnos") { outputFileName = "accnos"; } - 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, "SplitAbundCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],[tag],[tag2],fasta-[filename],[tag],[group],[tag2],fasta"; } + else if (type == "list") { pattern = "[filename],[tag],[tag2],list-[filename],[group],[tag],[tag2],list"; } + else if (type == "name") { pattern = "[filename],[tag],names-[filename],[group],[tag],names"; } + else if (type == "count") { pattern = "[filename],[tag],[tag2],count_table-[filename],[tag],count_table"; } + else if (type == "group") { pattern = "[filename],[tag],[tag2],groups-[filename],[tag],[group],[tag2],groups"; } + else if (type == "accnos") { pattern = "[filename],[tag],[tag2],accnos-[filename],[tag],[group],[tag2],accnos"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** SplitAbundCommand::SplitAbundCommand(){ @@ -471,7 +467,7 @@ int SplitAbundCommand::splitList(ListVector* thisList) { }//end for - string tag = thisList->getLabel() + "."; + string tag = thisList->getLabel(); writeList(thisList, tag, numRareBins); @@ -500,11 +496,16 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "rare." + getOutputFileNameTag("list"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("list",variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["list"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "abund." + getOutputFileNameTag("list"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("list",variables); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["list"].push_back(abund); @@ -548,8 +549,14 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag, int numRareBi temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - string rareGroupFileName = fileroot + Groups[i] +"."+ tag + "rare." + getOutputFileNameTag("list"); - string abundGroupFileName = fileroot + Groups[i] +"."+ tag + "abund." + getOutputFileNameTag("list"); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + variables["[group]"] = Groups[i]; + string rareGroupFileName = getOutputFileName("list",variables); + variables["[tag2]"] = "abund"; + string abundGroupFileName = getOutputFileName("list",variables); m->openOutputFile(rareGroupFileName, *(filehandles[Groups[i]+".rare"])); m->openOutputFile(abundGroupFileName, *(filehandles[Groups[i]+".abund"])); outputNames.push_back(rareGroupFileName); outputTypes["list"].push_back(rareGroupFileName); @@ -759,10 +766,14 @@ int SplitAbundCommand::parseCount(string tag) { //namefile map filehandles; if (Groups.size() == 0) { - string rare = outputDir + m->getRootName(m->getSimpleName(countfile)) + tag + "rare." + getOutputFileNameTag("count"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("count",variables); outputNames.push_back(rare); outputTypes["count"].push_back(rare); - - string abund = outputDir + m->getRootName(m->getSimpleName(countfile)) + tag + "abund." + getOutputFileNameTag("count"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("count",variables); outputNames.push_back(abund); outputTypes["count"].push_back(abund); CountTable rareTable; @@ -846,7 +857,10 @@ int SplitAbundCommand::parseCount(string tag) { //namefile for (it3 = countTableMap.begin(); it3 != countTableMap.end(); it3++) { string fileroot = outputDir + m->getRootName(m->getSimpleName(countfile)); - string filename = fileroot + it3->first + "." + getOutputFileNameTag("count"); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = it3->first; + string filename = getOutputFileName("count",variables); outputNames.push_back(filename); outputTypes["count"].push_back(filename); (it3->second)->printTable(filename); delete it3->second; @@ -871,11 +885,15 @@ int SplitAbundCommand::writeNames() { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare." + getOutputFileNameTag("name"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[tag]"] = "rare"; + string rare = getOutputFileName("name", variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["name"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund." + getOutputFileNameTag("name"); + variables["[tag]"] = "abund"; + string abund = getOutputFileName("name", variables); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["name"].push_back(abund); @@ -906,8 +924,13 @@ int SplitAbundCommand::writeNames() { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - string rareGroupFileName = fileroot + Groups[i] + ".rare." + getOutputFileNameTag("name"); - string abundGroupFileName = fileroot + Groups[i] + ".abund." + getOutputFileNameTag("name"); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = "rare"; + variables["[group]"] = Groups[i]; + string rareGroupFileName = getOutputFileName("name",variables); + variables["[tag]"] = "abund"; + string abundGroupFileName = getOutputFileName("name",variables); m->openOutputFile(rareGroupFileName, *(filehandles[Groups[i]+".rare"])); m->openOutputFile(abundGroupFileName, *(filehandles[Groups[i]+".abund"])); } @@ -945,7 +968,10 @@ int SplitAbundCommand::writeNames() { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + it3->first + "." + getOutputFileNameTag("name")); outputTypes["name"].push_back(fileroot + it3->first + "." + getOutputFileNameTag("name")); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = it3->first; + outputNames.push_back(getOutputFileName("name",variables)); outputTypes["name"].push_back(getOutputFileName("name",variables)); delete it3->second; } } @@ -969,8 +995,11 @@ int SplitAbundCommand::writeAccnos(string tag) { ofstream aout; ofstream rout; - - string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare." + getOutputFileNameTag("accnos"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("accnos",variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["accnos"].push_back(rare); @@ -979,7 +1008,8 @@ int SplitAbundCommand::writeAccnos(string tag) { } rout.close(); - string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund." + getOutputFileNameTag("accnos"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("accnos",variables); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["accnos"].push_back(abund); @@ -1001,8 +1031,14 @@ int SplitAbundCommand::writeAccnos(string tag) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + tag + Groups[i] + ".rare." + getOutputFileNameTag("accnos"), *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + tag + Groups[i] + ".abund." + getOutputFileNameTag("accnos"), *(filehandles[Groups[i]+".abund"])); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + variables["[group]"] = Groups[i]; + m->openOutputFile(getOutputFileName("accnos",variables), *(filehandles[Groups[i]+".rare"])); + variables["[tag2]"] = "abund"; + m->openOutputFile(getOutputFileName("accnos",variables), *(filehandles[Groups[i]+".abund"])); } //write rare @@ -1026,7 +1062,11 @@ int SplitAbundCommand::writeAccnos(string tag) { //close files for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("accnos")); outputTypes["accnos"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("accnos")); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = it3->first; + outputNames.push_back(getOutputFileName("accnos",variables)); outputTypes["accnos"].push_back(getOutputFileName("accnos",variables)); delete it3->second; } } @@ -1049,11 +1089,16 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare." + getOutputFileNameTag("group"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("group",variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["group"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund." + getOutputFileNameTag("group"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("group",variables); ; m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["group"].push_back(abund); @@ -1094,8 +1139,14 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + tag + Groups[i] + ".rare." + getOutputFileNameTag("group"), *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + tag + Groups[i] + ".abund." + getOutputFileNameTag("group"), *(filehandles[Groups[i]+".abund"])); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + variables["[group]"] = Groups[i]; + m->openOutputFile(getOutputFileName("group",variables), *(filehandles[Groups[i]+".rare"])); + variables["[tag2]"] = "abund"; + m->openOutputFile(getOutputFileName("group",variables), *(filehandles[Groups[i]+".abund"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { @@ -1121,7 +1172,11 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("group")); outputTypes["group"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("group")); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = it3->first; + outputNames.push_back(getOutputFileName("group",variables)); outputTypes["group"].push_back(getOutputFileName("group",variables)); delete it3->second; } } @@ -1144,11 +1199,16 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare." + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + string rare = getOutputFileName("fasta",variables); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["fasta"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund." + getOutputFileNameTag("fasta"); + variables["[tag2]"] = "abund"; + string abund = getOutputFileName("fasta",variables); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["fasta"].push_back(abund); @@ -1195,8 +1255,14 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + tag + Groups[i] + ".rare." + getOutputFileNameTag("fasta"), *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + tag + Groups[i] + ".abund." + getOutputFileNameTag("fasta"), *(filehandles[Groups[i]+".abund"])); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = "rare"; + variables["[group]"] = Groups[i]; + m->openOutputFile(getOutputFileName("fasta",variables), *(filehandles[Groups[i]+".rare"])); + variables["[tag2]"] = "abund"; + m->openOutputFile(getOutputFileName("fasta",variables), *(filehandles[Groups[i]+".abund"])); } //open input file @@ -1249,7 +1315,11 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("fasta")); outputTypes["fasta"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("fasta")); + map variables; + variables["[filename]"] = fileroot; + variables["[tag]"] = tag; + variables["[tag2]"] = it3->first; + outputNames.push_back(getOutputFileName("fasta",variables)); outputTypes["fasta"].push_back(getOutputFileName("fasta",variables)); delete it3->second; } } diff --git a/splitabundcommand.h b/splitabundcommand.h index d054264..9929b79 100644 --- a/splitabundcommand.h +++ b/splitabundcommand.h @@ -36,8 +36,9 @@ public: vector setParameters(); string getCommandName() { return "split.abund"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Split.abund"; } string getDescription() { return "split a list, name, group or fasta file based on abundance"; } diff --git a/splitgroupscommand.cpp b/splitgroupscommand.cpp index bc52112..238eda5 100644 --- a/splitgroupscommand.cpp +++ b/splitgroupscommand.cpp @@ -15,13 +15,13 @@ //********************************************************************************************************************** vector SplitGroupCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "CountGroup", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "CountGroup", "none",false,false); parameters.push_back(pgroup); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "CountGroup", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "CountGroup", "none","group",false,false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -53,27 +53,23 @@ string SplitGroupCommand::getHelpString(){ } } //********************************************************************************************************************** -string SplitGroupCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SplitGroupCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "fasta"; } - else if (type == "name") { outputFileName = "names"; } - else if (type == "count") { outputFileName = "count_table"; } - 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, "SplitGroupCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],[group],fasta"; } + else if (type == "name") { pattern = "[filename],[group],names"; } + else if (type == "count") { pattern = "[filename],[group],count_table"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SplitGroupCommand", "getOutputPattern"); + exit(1); + } } + //********************************************************************************************************************** SplitGroupCommand::SplitGroupCommand(){ try { @@ -289,8 +285,13 @@ int SplitGroupCommand::runNameGroup(){ m->mothurOut("Processing group: " + Groups[i]); m->mothurOutEndLine(); - string newFasta = fastafileRoot + Groups[i] + "." + getOutputFileNameTag("fasta"); - string newName = namefileRoot + Groups[i] + "." + getOutputFileNameTag("name"); + map variables; + variables["[filename]"] = fastafileRoot; + variables["[group]"] = Groups[i]; + + string newFasta = getOutputFileName("fasta",variables); + variables["[filename]"] = namefileRoot; + string newName = getOutputFileName("name",variables); parser->getSeqs(Groups[i], newFasta, false); outputNames.push_back(newFasta); outputTypes["fasta"].push_back(newFasta); @@ -334,12 +335,16 @@ int SplitGroupCommand::runCount(){ for (int i=0; igetRootName(m->getSimpleName(fastafile)) + Groups[i] + "." + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[group]"] = Groups[i]; + string newFasta = getOutputFileName("fasta",variables); outputNames.push_back(newFasta); outputTypes["fasta"].push_back(newFasta); m->openOutputFile(newFasta, (*temp)); temp = new ofstream; cfiles[Groups[i]] = temp; - string newCount = outputDir + m->getRootName(m->getSimpleName(countfile)) + Groups[i] + "." + getOutputFileNameTag("count"); + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(countfile)); + string newCount = getOutputFileName("count",variables); m->openOutputFile(newCount, (*temp)); outputNames.push_back(newCount); outputTypes["count"].push_back(newCount); (*temp) << "Representative_Sequence\ttotal\t" << Groups[i] << endl; diff --git a/splitgroupscommand.h b/splitgroupscommand.h index 62e063d..b251fe5 100644 --- a/splitgroupscommand.h +++ b/splitgroupscommand.h @@ -30,8 +30,9 @@ public: vector setParameters(); string getCommandName() { return "split.group"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Split.group"; } string getDescription() { return "split a name or fasta file by group"; } diff --git a/splitmatrix.cpp b/splitmatrix.cpp index aea99ef..a5ae3cb 100644 --- a/splitmatrix.cpp +++ b/splitmatrix.cpp @@ -191,8 +191,12 @@ int SplitMatrix::createDistanceFilesFromTax(map& seqGroup, int numG else { options = "fasta=" + (fastafile + "." + toString(i) + ".temp") + ", processors=" + toString(processors) + ", cutoff=" + toString(distCutoff); } if (outputDir != "") { options += ", outputdir=" + outputDir; } + m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + Command* command = new DistanceCommand(options); + m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + command->execute(); delete command; diff --git a/subsample.cpp b/subsample.cpp index a6b1b2d..392f97b 100644 --- a/subsample.cpp +++ b/subsample.cpp @@ -24,7 +24,7 @@ Tree* SubSample::getSample(Tree* T, CountTable* ct, CountTable* newCt, int size) for (int i = 0; i < Groups.size(); i++) { if (m->inUsersGroups(Groups[i], m->getGroups())) { if (m->control_pressed) { break; } - cout << Groups[i] << endl; + int thisSize = ct->getGroupCount(Groups[i]); if (thisSize >= size) { diff --git a/subsamplecommand.cpp b/subsamplecommand.cpp index e1793f4..cfc7b1d 100644 --- a/subsamplecommand.cpp +++ b/subsamplecommand.cpp @@ -15,20 +15,20 @@ //********************************************************************************************************************** vector SubSampleCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(pfasta); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter plist("list", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(plist); - CommandParameter pshared("shared", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(pshared); - CommandParameter prabund("rabund", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(prabund); - CommandParameter psabund("sabund", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(psabund); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter psize("size", "Number", "", "0", "", "", "",false,false); parameters.push_back(psize); - CommandParameter ppersample("persample", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ppersample); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FLSSR", "none","fasta",false,false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","group",false,false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FLSSR", "none","list",false,false,true); parameters.push_back(plist); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "FLSSR", "none","shared",false,false,true); parameters.push_back(pshared); + CommandParameter prabund("rabund", "InputTypes", "", "", "none", "FLSSR", "none","rabund",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "none", "FLSSR", "none","sabund",false,false); parameters.push_back(psabund); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter psize("size", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(psize); + CommandParameter ppersample("persample", "Boolean", "", "F", "", "", "","",false,false,true); parameters.push_back(ppersample); + 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); } @@ -65,33 +65,27 @@ string SubSampleCommand::getHelpString(){ } } //********************************************************************************************************************** -string SubSampleCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SubSampleCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "fasta") { outputFileName = "subsample" + m->getExtension(inputName); } - else if (type == "sabund") { outputFileName = "subsample" + m->getExtension(inputName); } - else if (type == "name") { outputFileName = "subsample" + m->getExtension(inputName); } - else if (type == "count") { outputFileName = "subsample" + m->getExtension(inputName); } - else if (type == "group") { outputFileName = "subsample" + m->getExtension(inputName); } - else if (type == "list") { outputFileName = "subsample" + m->getExtension(inputName); } - else if (type == "rabund") { outputFileName = "subsample" + m->getExtension(inputName); } - else if (type == "shared") { outputFileName = "subsample" + m->getExtension(inputName); } - 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, "SubSampleCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "fasta") { pattern = "[filename],subsample,[extension]"; } + else if (type == "sabund") { pattern = "[filename],subsample,[extension]"; } + else if (type == "name") { pattern = "[filename],subsample,[extension]"; } + else if (type == "group") { pattern = "[filename],subsample,[extension]"; } + else if (type == "count") { pattern = "[filename],subsample,[extension]"; } + else if (type == "list") { pattern = "[filename],subsample,[extension]"; } + else if (type == "shared") { pattern = "[filename],[distance],subsample,[extension]"; } + else if (type == "rabund") { pattern = "[filename],subsample,[extension]"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SubSampleCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** SubSampleCommand::SubSampleCommand(){ try { @@ -545,7 +539,10 @@ int SubSampleCommand::getSubSampleFasta() { string countOutputDir = outputDir; if (outputDir == "") { countOutputDir += m->hasPath(countfile); } - string countOutputFileName = countOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = countOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string countOutputFileName = getOutputFileName("count", variables); outputTypes["count"].push_back(countOutputFileName); outputNames.push_back(countOutputFileName); sampledCt.printTable(countOutputFileName); } @@ -579,7 +576,10 @@ int SubSampleCommand::getSubSampleFasta() { string countOutputDir = outputDir; if (outputDir == "") { countOutputDir += m->hasPath(countfile); } - string countOutputFileName = countOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = countOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string countOutputFileName = getOutputFileName("count", variables); outputTypes["count"].push_back(countOutputFileName); outputNames.push_back(countOutputFileName); sampledCt.printTable(countOutputFileName); } @@ -589,7 +589,10 @@ int SubSampleCommand::getSubSampleFasta() { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)); + variables["[extension]"] = m->getExtension(fastafile); + string outputFileName = getOutputFileName("fasta", variables); ofstream out; m->openOutputFile(outputFileName, out); @@ -636,8 +639,10 @@ int SubSampleCommand::getSubSampleFasta() { if (namefile != "") { m->mothurOut("Deconvoluting subsampled fasta file... "); m->mothurOutEndLine(); - - string outputNameFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(namefile)); + variables["[extension]"] = m->getExtension(namefile); + string outputNameFileName = getOutputFileName("name", variables); //use unique.seqs to create new name and fastafile string inputString = "fasta=" + outputFileName; m->mothurOut("/******************************************/"); m->mothurOutEndLine(); @@ -669,7 +674,10 @@ int SubSampleCommand::getSubSampleFasta() { string groupOutputDir = outputDir; if (outputDir == "") { groupOutputDir += m->hasPath(groupfile); } - string groupOutputFileName = groupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + map variables; + variables["[filename]"] = groupOutputDir + m->getRootName(m->getSimpleName(groupfile)); + variables["[extension]"] = m->getExtension(groupfile); + string groupOutputFileName = getOutputFileName("group", variables); ofstream outGroup; m->openOutputFile(groupOutputFileName, outGroup); @@ -891,7 +899,11 @@ int SubSampleCommand::processShared(vector& thislookup) { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + thislookup[0]->getLabel() + "." +getOutputFileNameTag("shared", sharedfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[extension]"] = m->getExtension(sharedfile); + variables["[distance]"] = thislookup[0]->getLabel(); + string outputFileName = getOutputFileName("shared", variables); SubSample sample; vector subsampledLabels = sample.getSample(thislookup, size); @@ -929,7 +941,10 @@ int SubSampleCommand::getSubSampleList() { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(listfile)); + variables["[extension]"] = m->getExtension(listfile); + string outputFileName = getOutputFileName("list", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); @@ -1113,7 +1128,10 @@ int SubSampleCommand::getSubSampleList() { string countOutputDir = outputDir; if (outputDir == "") { countOutputDir += m->hasPath(countfile); } - string countOutputFileName = countOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile); + map variables; + variables["[filename]"] = countOutputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[extension]"] = m->getExtension(countfile); + string countOutputFileName = getOutputFileName("count", variables); outputTypes["count"].push_back(countOutputFileName); outputNames.push_back(countOutputFileName); sampledCt.printTable(countOutputFileName); } @@ -1260,7 +1278,10 @@ int SubSampleCommand::getSubSampleRabund() { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(rabundfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + getOutputFileNameTag("rabund", rabundfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)); + variables["[extension]"] = m->getExtension(rabundfile); + string outputFileName = getOutputFileName("rabund", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName); @@ -1414,7 +1435,10 @@ int SubSampleCommand::getSubSampleSabund() { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sabundfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + getOutputFileNameTag("sabund", sabundfile); + map variables; + variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)); + variables["[extension]"] = m->getExtension(sabundfile); + string outputFileName = getOutputFileName("sabund", variables); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName); diff --git a/subsamplecommand.h b/subsamplecommand.h index 7116909..7bafd9b 100644 --- a/subsamplecommand.h +++ b/subsamplecommand.h @@ -29,8 +29,9 @@ public: vector setParameters(); string getCommandName() { return "sub.sample"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Sub.sample"; } string getDescription() { return "get a sampling of sequences from a list, shared, rabund, sabund or fasta file"; } diff --git a/summarycommand.cpp b/summarycommand.cpp index 7a167a6..43202e5 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -38,19 +38,19 @@ //********************************************************************************************************************** vector SummaryCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); - CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); - CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); - CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); - CommandParameter psubsample("subsample", "String", "", "", "", "", "",false,false); parameters.push_back(psubsample); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-npshannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap-geometric-qstat-logseries-bergerparker-bstick-goodscoverage-efron-boneh-solow-shen", "sobs-chao-ace-jack-shannon-npshannon-simpson", "", "", "",true,false); parameters.push_back(pcalc); - CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund); - CommandParameter psize("size", "Number", "", "0", "", "", "",false,false); parameters.push_back(psize); - CommandParameter pgroupmode("groupmode", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pgroupmode); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","summary",false,false,true); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","summary",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","summary",false,false); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","summary",false,false,true); parameters.push_back(pshared); + CommandParameter psubsample("subsample", "String", "", "", "", "", "","",false,false); parameters.push_back(psubsample); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-npshannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap-geometric-qstat-logseries-bergerparker-bstick-goodscoverage-efron-boneh-solow-shen", "sobs-chao-ace-jack-shannon-npshannon-simpson", "", "", "","",true,false,true); parameters.push_back(pcalc); + CommandParameter pabund("abund", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pabund); + CommandParameter psize("size", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psize); + CommandParameter pgroupmode("groupmode", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pgroupmode); + 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); } @@ -85,24 +85,19 @@ string SummaryCommand::getHelpString(){ } } //********************************************************************************************************************** -string SummaryCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SummaryCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "summary") { outputFileName = "summary"; } - 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, "SummaryCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "summary") { pattern = "[filename],summary-[filename],[tag],summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SummaryCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** SummaryCommand::SummaryCommand(){ @@ -273,7 +268,7 @@ SummaryCommand::SummaryCommand(string option) { else { subsample = false; subsampleSize = -1; } } - if (subsample == false) { iters = 1; } + if (subsample == false) { iters = 0; } else { //if you did not set a samplesize and are not using a sharedfile if ((subsampleSize == -1) && (format != "sharedfile")) { m->mothurOut("[ERROR]: If you want to subsample with a list, rabund or sabund file, you must provide the sample size. You can do this by setting subsample=yourSampleSize.\n"); abort=true; } @@ -307,8 +302,11 @@ int SummaryCommand::execute(){ numLines = 0; numCols = 0; - string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + getOutputFileNameTag("summary"); - string fileNameAve = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "ave-std." + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])); + string fileNameRoot = getOutputFileName("summary",variables); + variables["[tag]"] = "ave-std"; + string fileNameAve = getOutputFileName("summary",variables); outputNames.push_back(fileNameRoot); outputTypes["summary"].push_back(fileNameRoot); if (inputFileNames.size() > 1) { diff --git a/summarycommand.h b/summarycommand.h index 4936dd8..3c84207 100644 --- a/summarycommand.h +++ b/summarycommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "summary.single"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Summary.single"; } string getDescription() { return "generate summary file that has the calculator value for each line in the OTU data"; } diff --git a/summaryqualcommand.cpp b/summaryqualcommand.cpp index 48852a7..ae5b652 100644 --- a/summaryqualcommand.cpp +++ b/summaryqualcommand.cpp @@ -13,12 +13,12 @@ //********************************************************************************************************************** vector SummaryQualCommand::setParameters(){ try { - CommandParameter pqual("qfile", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pqual); - CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pqual("qfile", "InputTypes", "", "", "none", "none", "none","summary",false,true,true); parameters.push_back(pqual); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + 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); } @@ -48,24 +48,19 @@ string SummaryQualCommand::getHelpString(){ } } //********************************************************************************************************************** -string SummaryQualCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SummaryQualCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "summary") { outputFileName = "qual.summary"; } - 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, "SummaryQualCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "summary") { pattern = "[filename],qual.summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SummaryQualCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** SummaryQualCommand::SummaryQualCommand(){ @@ -233,7 +228,9 @@ int SummaryQualCommand::execute(){ if (m->control_pressed) { return 0; } //print summary file - string summaryFile = outputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(qualfile)); + string summaryFile = getOutputFileName("summary",variables); printQual(summaryFile, position, averageQ, scores); if (m->control_pressed) { m->mothurRemove(summaryFile); return 0; } diff --git a/summaryqualcommand.h b/summaryqualcommand.h index ac65938..49583b0 100644 --- a/summaryqualcommand.h +++ b/summaryqualcommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "summary.qual"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Summary.qual"; } string getDescription() { return "summarize the quality of a set of sequences"; } diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 6147832..85eb448 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -13,18 +13,18 @@ //********************************************************************************************************************** vector SummarySharedCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter psubsample("subsample", "String", "", "", "", "", "",false,false); parameters.push_back(psubsample); - CommandParameter pdistance("distance", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pdistance); - CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "",true,false); parameters.push_back(pcalc); - CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter pall("all", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pall); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","summary",false,true,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter psubsample("subsample", "String", "", "", "", "", "","phylip",false,false); parameters.push_back(psubsample); + CommandParameter pdistance("distance", "Boolean", "", "F", "", "", "","phylip",false,false); parameters.push_back(pdistance); + CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "","",true,false,true); parameters.push_back(pcalc); + CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "","",false,false); parameters.push_back(poutput); + CommandParameter pall("all", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pall); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + 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); } @@ -64,25 +64,20 @@ string SummarySharedCommand::getHelpString(){ } } //********************************************************************************************************************** -string SummarySharedCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SummarySharedCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "summary") { outputFileName = "shared.summary"; } - else if (type == "phylip") { outputFileName = "dist"; } - 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, "SummarySharedCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "summary") { pattern = "[filename],summary-[filename],[tag],summary"; } + else if (type == "phylip") { pattern = "[filename],[calc],[distance],[outputtag],[tag2],dist"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SummarySharedCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** SummarySharedCommand::SummarySharedCommand(){ @@ -205,7 +200,7 @@ SummarySharedCommand::SummarySharedCommand(string option) { else { subsample = false; } } - if (subsample == false) { iters = 1; } + if (subsample == false) { iters = 0; } temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } m->setProcessors(temp); @@ -317,7 +312,9 @@ int SummarySharedCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } ofstream outputFileHandle, outAll; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + string outputFileName = getOutputFileName("summary",variables); //if the users entered no valid calculators don't execute command if (sumCalculators.size() == 0) { return 0; } @@ -348,7 +345,8 @@ int SummarySharedCommand::execute(){ outputFileHandle.close(); //create file and put column headers for multiple groups file - string outAllFileName = ((m->getRootName(sharedfile)) + "multiple." + getOutputFileNameTag("summary")); + variables["[tag]"]= "multiple"; + string outAllFileName = getOutputFileName("summary",variables); if (mult == true) { m->openOutputFile(outAllFileName, outAll); outputNames.push_back(outAllFileName); @@ -786,7 +784,12 @@ int SummarySharedCommand::process(vector thisLookup, string matrix[column][row] = dist; } - string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + "." + getOutputFileNameTag("phylip"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[calc]"] = sumCalculators[i]->getName(); + variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[outputtag]"] = output; + string distFileName = getOutputFileName("phylip",variables); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outDist; m->openOutputFile(distFileName, outDist); @@ -879,7 +882,13 @@ int SummarySharedCommand::process(vector thisLookup, string stdmatrix[column][row] = stdDist; } - string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".ave." + getOutputFileNameTag("phylip"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + variables["[calc]"] = sumCalculators[i]->getName(); + variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[outputtag]"] = output; + variables["[tag2]"] = "ave"; + string distFileName = getOutputFileName("phylip",variables); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outAve; m->openOutputFile(distFileName, outAve); @@ -889,7 +898,8 @@ int SummarySharedCommand::process(vector thisLookup, string outAve.close(); - distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".std." + getOutputFileNameTag("phylip"); + variables["[tag2]"] = "std"; + distFileName = getOutputFileName("phylip",variables); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outSTD; m->openOutputFile(distFileName, outSTD); diff --git a/summarysharedcommand.h b/summarysharedcommand.h index 7c6a4b2..f486d52 100644 --- a/summarysharedcommand.h +++ b/summarysharedcommand.h @@ -67,8 +67,9 @@ public: vector setParameters(); string getCommandName() { return "summary.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Summary.shared"; } string getDescription() { return "generate a summary file containing calculator values for each line in the OTU data and for all possible comparisons between groups"; } diff --git a/summarytaxcommand.cpp b/summarytaxcommand.cpp index d33b4f0..c76f175 100644 --- a/summarytaxcommand.cpp +++ b/summarytaxcommand.cpp @@ -13,13 +13,13 @@ //********************************************************************************************************************** vector SummaryTaxCommand::setParameters(){ try { - CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptaxonomy); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter preftaxonomy("reftaxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(preftaxonomy); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none","summary",false,true,true); parameters.push_back(ptaxonomy); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter preftaxonomy("reftaxonomy", "InputTypes", "", "", "none", "none", "none","",false,false); parameters.push_back(preftaxonomy); + 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); } @@ -51,24 +51,19 @@ string SummaryTaxCommand::getHelpString(){ } } //********************************************************************************************************************** -string SummaryTaxCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string SummaryTaxCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "summary") { outputFileName = "tax.summary"; } - 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, "SummaryTaxCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "summary") { pattern = "[filename],tax.summary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "SummaryTaxCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** SummaryTaxCommand::SummaryTaxCommand(){ @@ -283,7 +278,9 @@ int SummaryTaxCommand::execute(){ //print summary file ofstream outTaxTree; - string summaryFile = outputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("summary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(taxfile)); + string summaryFile = getOutputFileName("summary",variables); m->openOutputFile(summaryFile, outTaxTree); taxaSum->print(outTaxTree); outTaxTree.close(); diff --git a/summarytaxcommand.h b/summarytaxcommand.h index e8033e2..5f61d13 100644 --- a/summarytaxcommand.h +++ b/summarytaxcommand.h @@ -24,8 +24,9 @@ class SummaryTaxCommand : public Command { vector setParameters(); string getCommandName() { return "summary.tax"; } string getCommandCategory() { return "Phylotype Analysis"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Summary.tax"; } string getDescription() { return "summarize the taxonomies of a set of sequences"; } diff --git a/systemcommand.cpp b/systemcommand.cpp index c07deff..b5b4945 100644 --- a/systemcommand.cpp +++ b/systemcommand.cpp @@ -12,7 +12,7 @@ //********************************************************************************************************************** vector SystemCommand::setParameters(){ try { - CommandParameter pcommand("command", "String", "", "", "", "", "",false,false); parameters.push_back(pcommand); + CommandParameter pcommand("command", "String", "", "", "", "", "","",false,false); parameters.push_back(pcommand); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } diff --git a/systemcommand.h b/systemcommand.h index 6dc09ef..27adf7c 100644 --- a/systemcommand.h +++ b/systemcommand.h @@ -24,8 +24,8 @@ class SystemCommand : public Command { vector setParameters(); string getCommandName() { return "system"; } string getCommandCategory() { return "General"; } - string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); + string getOutputPattern(string){ return ""; } string getCitation() { return "http://www.mothur.org/wiki/System"; } string getDescription() { return "execute system commands from within mothur"; } diff --git a/tree.cpp b/tree.cpp index 0bd98e0..6b799f4 100644 --- a/tree.cpp +++ b/tree.cpp @@ -1344,7 +1344,7 @@ int Tree::readTreeString(ifstream& filehandle) { c = filehandle.get(); //k = c; //cout << k << endl; - while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) { + while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) { name += c; c = filehandle.get(); //k = c; @@ -1352,7 +1352,9 @@ int Tree::readTreeString(ifstream& filehandle) { } //cout << "name = " << name << endl; - m->Treenames.push_back(name); + if (name != "\r" ) { + m->Treenames.push_back(name); } //cout << m->Treenames.size() << '\t' << name << endl; + filehandle.putback(c); //k = c; //cout << " after putback" << k << endl; diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index 8ee11d3..90d336d 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -14,23 +14,23 @@ //********************************************************************************************************************** vector TreeGroupCommand::setParameters(){ try { - CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pshared); - CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pphylip); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount", "none", "countcolumn",false,false); parameters.push_back(pcount); - CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName-countcolumn",false,false); parameters.push_back(pcolumn); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter psubsample("subsample", "String", "", "", "", "", "",false,false); parameters.push_back(psubsample); - CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); - CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter pcalc("calc", "Multiple", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-whittaker-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-hamming-structchi2-gower-memchi2-memchord-memeuclidean-mempearson", "jclass-thetayc", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none","tree",false,false,true); parameters.push_back(pshared); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none","tree",false,false); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "ColumnName","",false,false); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount", "none", "countcolumn","",false,false); parameters.push_back(pcount); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName-countcolumn","tree",false,false); parameters.push_back(pcolumn); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter psubsample("subsample", "String", "", "", "", "", "","",false,false); parameters.push_back(psubsample); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pprecision); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter pcalc("calc", "Multiple", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-whittaker-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-hamming-structchi2-gower-memchi2-memchord-memeuclidean-mempearson", "jclass-thetayc", "", "", "","",true,false,true); parameters.push_back(pcalc); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); //CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + 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); } @@ -71,24 +71,19 @@ string TreeGroupCommand::getHelpString(){ } } //********************************************************************************************************************** -string TreeGroupCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string TreeGroupCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "tree") { outputFileName = "tre"; } - 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, "TreeGroupCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "tree") { pattern = "[filename],[calc],[distance],[tag],tre-[filename],tre"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "TreeGroupCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** TreeGroupCommand::TreeGroupCommand(){ @@ -504,7 +499,9 @@ int TreeGroupCommand::execute(){ if (m->control_pressed) { return 0; } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("tree"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); + string outputFile = getOutputFileName("tree",variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); Tree* newTree = createTree(matrix); @@ -961,7 +958,12 @@ int TreeGroupCommand::process(vector thisLookup) { } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".ave." + getOutputFileNameTag("tree"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); + variables["[calc]"] = treeCalculators[i]->getName(); + variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[tag]"] = "ave"; + string outputFile = getOutputFileName("tree",variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); //creates tree from similarity matrix and write out file @@ -974,7 +976,13 @@ int TreeGroupCommand::process(vector thisLookup) { if (m->control_pressed) { break; } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".all." + getOutputFileNameTag("tree"); + //create a new filename + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); + variables["[calc]"] = treeCalculators[i]->getName(); + variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[tag]"] = "all"; + string outputFile = getOutputFileName("tree",variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); ofstream outAll; @@ -1015,7 +1023,8 @@ int TreeGroupCommand::process(vector thisLookup) { Tree* conTree = consensus.getTree(trees); //create a new filename - string conFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".cons." + getOutputFileNameTag("tree"); + variables["[tag]"] = "cons"; + string conFile = getOutputFileName("tree",variables); outputNames.push_back(conFile); outputTypes["tree"].push_back(conFile); ofstream outTree; m->openOutputFile(conFile, outTree); @@ -1043,7 +1052,12 @@ int TreeGroupCommand::process(vector thisLookup) { } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + getOutputFileNameTag("tree"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile)); + variables["[calc]"] = treeCalculators[i]->getName(); + variables["[distance]"] = thisLookup[0]->getLabel(); + variables["[tag]"] = ""; + string outputFile = getOutputFileName("tree",variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); //creates tree from similarity matrix and write out file diff --git a/treegroupscommand.h b/treegroupscommand.h index b29670a..979612f 100644 --- a/treegroupscommand.h +++ b/treegroupscommand.h @@ -78,8 +78,9 @@ public: vector setParameters(); string getCommandName() { return "tree.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Tree.shared"; } string getDescription() { return "generate a tree file that describes the dissimilarity among groups"; } diff --git a/trimflowscommand.cpp b/trimflowscommand.cpp index 296a6fe..cc49755 100644 --- a/trimflowscommand.cpp +++ b/trimflowscommand.cpp @@ -14,24 +14,24 @@ //********************************************************************************************************************** vector TrimFlowsCommand::setParameters(){ try { - CommandParameter pflow("flow", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pflow); - CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos); - CommandParameter pmaxhomop("maxhomop", "Number", "", "9", "", "", "",false,false); parameters.push_back(pmaxhomop); - CommandParameter pmaxflows("maxflows", "Number", "", "450", "", "", "",false,false); parameters.push_back(pmaxflows); - CommandParameter pminflows("minflows", "Number", "", "450", "", "", "",false,false); parameters.push_back(pminflows); - CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppdiffs); - CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pbdiffs); - CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pldiffs); - CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(psdiffs); - CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ptdiffs); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter psignal("signal", "Number", "", "0.50", "", "", "",false,false); parameters.push_back(psignal); - CommandParameter pnoise("noise", "Number", "", "0.70", "", "", "",false,false); parameters.push_back(pnoise); - CommandParameter pallfiles("allfiles", "Boolean", "", "t", "", "", "",false,false); parameters.push_back(pallfiles); - CommandParameter porder("order", "String", "", "TACG", "", "", "",false,false); parameters.push_back(porder); - CommandParameter pfasta("fasta", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pfasta); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pflow("flow", "InputTypes", "", "", "none", "none", "none","flow",false,true,true); parameters.push_back(pflow); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(poligos); + CommandParameter pmaxhomop("maxhomop", "Number", "", "9", "", "", "","",false,false); parameters.push_back(pmaxhomop); + CommandParameter pmaxflows("maxflows", "Number", "", "450", "", "", "","",false,false); parameters.push_back(pmaxflows); + CommandParameter pminflows("minflows", "Number", "", "450", "", "", "","",false,false); parameters.push_back(pminflows); + CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(ppdiffs); + CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(pbdiffs); + CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pldiffs); + CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psdiffs); + CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ptdiffs); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter psignal("signal", "Number", "", "0.50", "", "", "","",false,false); parameters.push_back(psignal); + CommandParameter pnoise("noise", "Number", "", "0.70", "", "", "","",false,false); parameters.push_back(pnoise); + CommandParameter pallfiles("allfiles", "Boolean", "", "t", "", "", "","",false,false); parameters.push_back(pallfiles); + CommandParameter porder("order", "String", "", "TACG", "", "", "","",false,false); parameters.push_back(porder); + CommandParameter pfasta("fasta", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pfasta); + 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); } @@ -57,26 +57,21 @@ string TrimFlowsCommand::getHelpString(){ } } //********************************************************************************************************************** -string TrimFlowsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string TrimFlowsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "flow") { outputFileName = "flow"; } - else if (type == "fasta") { outputFileName = "flow.fasta"; } - else if (type == "file") { outputFileName = "flow.files"; } - 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, "TrimFlowsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "flow") { pattern = "[filename],[tag],flow"; } + else if (type == "fasta") { pattern = "[filename],flow.fasta"; } + else if (type == "file") { pattern = "[filename],flow.files"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "TrimFlowsCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** @@ -248,16 +243,20 @@ int TrimFlowsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string trimFlowFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "trim." + getOutputFileNameTag("flow"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(flowFileName)); + string fastaFileName = getOutputFileName("fasta",variables); + if(fasta){ outputNames.push_back(fastaFileName); outputTypes["fasta"].push_back(fastaFileName); } + + variables["[tag]"] = "trim"; + string trimFlowFileName = getOutputFileName("flow",variables); outputNames.push_back(trimFlowFileName); outputTypes["flow"].push_back(trimFlowFileName); - string scrapFlowFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "scrap." + getOutputFileNameTag("flow");; + variables["[tag]"] = "scrap"; + string scrapFlowFileName = getOutputFileName("flow",variables); outputNames.push_back(scrapFlowFileName); outputTypes["flow"].push_back(scrapFlowFileName); - string fastaFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("fasta"); - if(fasta){ - outputNames.push_back(fastaFileName); outputTypes["fasta"].push_back(fastaFileName); - } + vector flowFilePos; #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix) @@ -307,7 +306,8 @@ int TrimFlowsCommand::execute(){ if(allFiles){ set namesAlreadyProcessed; - flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("file"); + variables["[tag]"] = ""; + flowFilesFileName = getOutputFileName("file",variables); m->openOutputFile(flowFilesFileName, output); for(int i=0;igetRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("file"); + variables["[tag]"] = ""; + flowFilesFileName = getOutputFileName("file",variables); m->openOutputFile(flowFilesFileName, output); output << m->getFullPathName(trimFlowFileName) << endl; @@ -623,9 +624,13 @@ void TrimFlowsCommand::getOligos(vector >& outFlowFileNames){ string comboGroupName = ""; string fileName = ""; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(flowFileName)); + if(primerName == ""){ comboGroupName = barcodeNameVector[itBar->second]; - fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + comboGroupName + ".flow"; + variables["[tag]"] = comboGroupName; + fileName = getOutputFileName("flow", variables); } else{ if(barcodeName == ""){ @@ -634,7 +639,8 @@ void TrimFlowsCommand::getOligos(vector >& outFlowFileNames){ else{ comboGroupName = barcodeNameVector[itBar->second] + "." + primerNameVector[itPrimer->second]; } - fileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + comboGroupName + ".flow"; + variables["[tag]"] = comboGroupName; + fileName = getOutputFileName("flow", variables); } outFlowFileNames[itBar->second][itPrimer->second] = fileName; diff --git a/trimflowscommand.h b/trimflowscommand.h index b7fbf43..065e6b4 100644 --- a/trimflowscommand.h +++ b/trimflowscommand.h @@ -26,8 +26,9 @@ public: vector setParameters(); string getCommandName() { return "trim.flows"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Trim.flows"; } string getDescription() { return "trim.flows"; } diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index ba368fc..64d9d9e 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -15,35 +15,35 @@ //********************************************************************************************************************** vector TrimSeqsCommand::setParameters(){ try { - CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); - CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos); - CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pqfile); - CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pflip("flip", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pflip); - CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxambig); - CommandParameter pmaxhomop("maxhomop", "Number", "", "0", "", "", "",false,false); parameters.push_back(pmaxhomop); - CommandParameter pminlength("minlength", "Number", "", "0", "", "", "",false,false); parameters.push_back(pminlength); - CommandParameter pmaxlength("maxlength", "Number", "", "0", "", "", "",false,false); parameters.push_back(pmaxlength); - CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppdiffs); - CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pbdiffs); - CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pldiffs); - CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(psdiffs); - CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ptdiffs); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pallfiles("allfiles", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pallfiles); - CommandParameter pkeepforward("keepforward", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pkeepforward); - CommandParameter pqtrim("qtrim", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pqtrim); - CommandParameter pqthreshold("qthreshold", "Number", "", "0", "", "", "",false,false); parameters.push_back(pqthreshold); - CommandParameter pqaverage("qaverage", "Number", "", "0", "", "", "",false,false); parameters.push_back(pqaverage); - CommandParameter prollaverage("rollaverage", "Number", "", "0", "", "", "",false,false); parameters.push_back(prollaverage); - CommandParameter pqwindowaverage("qwindowaverage", "Number", "", "0", "", "", "",false,false); parameters.push_back(pqwindowaverage); - CommandParameter pqstepsize("qstepsize", "Number", "", "1", "", "", "",false,false); parameters.push_back(pqstepsize); - CommandParameter pqwindowsize("qwindowsize", "Number", "", "50", "", "", "",false,false); parameters.push_back(pqwindowsize); - CommandParameter pkeepfirst("keepfirst", "Number", "", "0", "", "", "",false,false); parameters.push_back(pkeepfirst); - CommandParameter premovelast("removelast", "Number", "", "0", "", "", "",false,false); parameters.push_back(premovelast); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none","fasta",false,true,true); parameters.push_back(pfasta); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none","group",false,false,true); parameters.push_back(poligos); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none","qfile",false,false,true); parameters.push_back(pqfile); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","name",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","count",false,false,true); parameters.push_back(pcount); + CommandParameter pflip("flip", "Boolean", "", "F", "", "", "","",false,false,true); parameters.push_back(pflip); + CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "","",false,false); parameters.push_back(pmaxambig); + CommandParameter pmaxhomop("maxhomop", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pmaxhomop); + CommandParameter pminlength("minlength", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pminlength); + CommandParameter pmaxlength("maxlength", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pmaxlength); + CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(ppdiffs); + CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "","",false,false,true); parameters.push_back(pbdiffs); + CommandParameter pldiffs("ldiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pldiffs); + CommandParameter psdiffs("sdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(psdiffs); + CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "","",false,false); parameters.push_back(ptdiffs); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter pallfiles("allfiles", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pallfiles); + CommandParameter pkeepforward("keepforward", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pkeepforward); + CommandParameter pqtrim("qtrim", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(pqtrim); + CommandParameter pqthreshold("qthreshold", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pqthreshold); + CommandParameter pqaverage("qaverage", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pqaverage); + CommandParameter prollaverage("rollaverage", "Number", "", "0", "", "", "","",false,false); parameters.push_back(prollaverage); + CommandParameter pqwindowaverage("qwindowaverage", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pqwindowaverage); + CommandParameter pqstepsize("qstepsize", "Number", "", "1", "", "", "","",false,false); parameters.push_back(pqstepsize); + CommandParameter pqwindowsize("qwindowsize", "Number", "", "50", "", "", "","",false,false); parameters.push_back(pqwindowsize); + CommandParameter pkeepfirst("keepfirst", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pkeepfirst); + CommandParameter premovelast("removelast", "Number", "", "0", "", "", "","",false,false); parameters.push_back(premovelast); + 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); } @@ -101,31 +101,24 @@ string TrimSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** -string TrimSeqsCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string TrimSeqsCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "qfile") { outputFileName = "qual"; } - else if (type == "fasta") { outputFileName = "fasta"; } - else if (type == "group") { outputFileName = "groups"; } - else if (type == "name") { outputFileName = "names"; } - else if (type == "count") { outputFileName = "count_table"; } - 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, "TrimSeqsCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "qfile") { pattern = "[filename],[tag],qual"; } + else if (type == "fasta") { pattern = "[filename],[tag],fasta"; } + else if (type == "group") { pattern = "[filename],groups"; } + else if (type == "name") { pattern = "[filename],[tag],names"; } + else if (type == "count") { pattern = "[filename],count_table"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "TrimSeqsCommand", "getOutputPattern"); + exit(1); + } } - - //********************************************************************************************************************** TrimSeqsCommand::TrimSeqsCommand(){ @@ -382,15 +375,18 @@ int TrimSeqsCommand::execute(){ vector > qualFileNames; vector > nameFileNames; - string trimSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim." + getOutputFileNameTag("fasta"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFile)); + variables["[tag]"] = "trim"; + string trimSeqFile = getOutputFileName("fasta",variables); + string trimQualFile = getOutputFileName("qfile",variables); outputNames.push_back(trimSeqFile); outputTypes["fasta"].push_back(trimSeqFile); - - string scrapSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap." + getOutputFileNameTag("fasta"); + + variables["[tag]"] = "scrap"; + string scrapSeqFile = getOutputFileName("fasta",variables); + string scrapQualFile = getOutputFileName("qfile",variables); outputNames.push_back(scrapSeqFile); outputTypes["fasta"].push_back(scrapSeqFile); - string trimQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim." + getOutputFileNameTag("qfile"); - string scrapQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap." + getOutputFileNameTag("qfile"); - if (qFileName != "") { outputNames.push_back(trimQualFile); outputNames.push_back(scrapQualFile); @@ -398,8 +394,11 @@ int TrimSeqsCommand::execute(){ outputTypes["qfile"].push_back(scrapQualFile); } - string trimNameFile = outputDir + m->getRootName(m->getSimpleName(nameFile)) + "trim." + getOutputFileNameTag("name"); - string scrapNameFile = outputDir + m->getRootName(m->getSimpleName(nameFile)) + "scrap." + getOutputFileNameTag("name"); + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(nameFile)); + variables["[tag]"] = "trim"; + string trimNameFile = getOutputFileName("name",variables); + variables["[tag]"] = "scrap"; + string scrapNameFile = getOutputFileName("name",variables); if (nameFile != "") { m->readNames(nameFile, nameMap); @@ -409,8 +408,11 @@ int TrimSeqsCommand::execute(){ outputTypes["name"].push_back(scrapNameFile); } - string trimCountFile = outputDir + m->getRootName(m->getSimpleName(countfile)) + "trim." + getOutputFileNameTag("count"); - string scrapCountFile = outputDir + m->getRootName(m->getSimpleName(countfile)) + "scrap." + getOutputFileNameTag("count"); + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(countfile)); + variables["[tag]"] = "trim"; + string trimCountFile = getOutputFileName("count",variables); + variables["[tag]"] = "scrap"; + string scrapCountFile = getOutputFileName("count",variables); if (countfile != "") { CountTable ct; @@ -429,7 +431,9 @@ int TrimSeqsCommand::execute(){ if(oligoFile != ""){ createGroup = getOligos(fastaFileNames, qualFileNames, nameFileNames); if ((createGroup) && (countfile == "")){ - outputGroupFileName = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + getOutputFileNameTag("group"); + map myvariables; + myvariables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFile)); + outputGroupFileName = getOutputFileName("group",myvariables); outputNames.push_back(outputGroupFileName); outputTypes["group"].push_back(outputGroupFileName); } } @@ -488,9 +492,11 @@ int TrimSeqsCommand::execute(){ m->openInputFile(it->first, in); ofstream out; - string thisGroupName = outputDir + m->getRootName(m->getSimpleName(it->first)); - if (countfile == "") { thisGroupName += getOutputFileNameTag("group"); outputNames.push_back(thisGroupName); outputTypes["group"].push_back(thisGroupName); } - else { thisGroupName += getOutputFileNameTag("count"); outputNames.push_back(thisGroupName); outputTypes["count"].push_back(thisGroupName); } + map myvariables; + myvariables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(it->first)); + string thisGroupName = ""; + if (countfile == "") { thisGroupName = getOutputFileName("group",variables); outputNames.push_back(thisGroupName); outputTypes["group"].push_back(thisGroupName); } + else { thisGroupName = getOutputFileName("count",variables); outputNames.push_back(thisGroupName); outputTypes["count"].push_back(thisGroupName); } m->openOutputFile(thisGroupName, out); if (countfile != "") { out << "Representative_Sequence\ttotal\t" << it->second << endl; } @@ -1519,7 +1525,10 @@ bool TrimSeqsCommand::getOligos(vector >& fastaFileNames, vector< ofstream temp; - fastaFileName = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + comboGroupName + ".fasta"; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(fastaFile)); + variables["[tag]"] = comboGroupName; + fastaFileName = getOutputFileName("fasta", variables); if (uniqueNames.count(fastaFileName) == 0) { outputNames.push_back(fastaFileName); outputTypes["fasta"].push_back(fastaFileName); @@ -1530,7 +1539,8 @@ bool TrimSeqsCommand::getOligos(vector >& fastaFileNames, vector< m->openOutputFile(fastaFileName, temp); temp.close(); if(qFileName != ""){ - qualFileName = outputDir + m->getRootName(m->getSimpleName(qFileName)) + comboGroupName + ".qual"; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(qFileName)); + qualFileName = getOutputFileName("qfile", variables); if (uniqueNames.count(qualFileName) == 0) { outputNames.push_back(qualFileName); outputTypes["qfile"].push_back(qualFileName); @@ -1541,7 +1551,8 @@ bool TrimSeqsCommand::getOligos(vector >& fastaFileNames, vector< } if(nameFile != ""){ - nameFileName = outputDir + m->getRootName(m->getSimpleName(nameFile)) + comboGroupName + ".names"; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(nameFile)); + nameFileName = getOutputFileName("name", variables); if (uniqueNames.count(nameFileName) == 0) { outputNames.push_back(nameFileName); outputTypes["name"].push_back(nameFileName); diff --git a/trimseqscommand.h b/trimseqscommand.h index 1ffad21..60d29f9 100644 --- a/trimseqscommand.h +++ b/trimseqscommand.h @@ -27,8 +27,9 @@ public: vector setParameters(); string getCommandName() { return "trim.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Trim.seqs"; } string getDescription() { return "provides the preprocessing features needed to screen and sort pyrosequences"; } diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index edc4bbc..5f3cffc 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -15,20 +15,20 @@ //********************************************************************************************************************** vector UnifracUnweightedCommand::setParameters(){ try { - CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter prandom("random", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(prandom); - CommandParameter pdistance("distance", "Multiple", "column-lt-square-phylip", "column", "", "", "",false,false); parameters.push_back(pdistance); - CommandParameter psubsample("subsample", "String", "", "", "", "", "",false,false); parameters.push_back(psubsample); - CommandParameter pconsensus("consensus", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pconsensus); - CommandParameter proot("root", "Boolean", "F", "", "", "", "",false,false); parameters.push_back(proot); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","unweighted-uwsummary",false,true,true); parameters.push_back(ptree); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter prandom("random", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(prandom); + CommandParameter pdistance("distance", "Multiple", "column-lt-square-phylip", "column", "", "", "","phylip-column",false,false); parameters.push_back(pdistance); + CommandParameter psubsample("subsample", "String", "", "", "", "", "","",false,false); parameters.push_back(psubsample); + CommandParameter pconsensus("consensus", "Boolean", "", "F", "", "", "","tree",false,false); parameters.push_back(pconsensus); + CommandParameter proot("root", "Boolean", "F", "", "", "", "","",false,false); parameters.push_back(proot); + 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); } @@ -65,30 +65,23 @@ string UnifracUnweightedCommand::getHelpString(){ } } //********************************************************************************************************************** -string UnifracUnweightedCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - 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 == "unweighted") { outputFileName = "unweighted"; } - else if (type == "uwsummary") { outputFileName = "uwsummary"; } - else if (type == "phylip") { outputFileName = "dist"; } - else if (type == "column") { outputFileName = "dist"; } - else if (type == "tree") { outputFileName = "tre"; } - 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, "UnifracUnweightedCommand", "getOutputFileNameTag"); - exit(1); - } +string UnifracUnweightedCommand::getOutputPattern(string type) { + try { + string pattern = ""; + if (type == "unweighted") { pattern = "[filename],unweighted-[filename],[tag],unweighted"; } + else if (type == "uwsummary") { pattern = "[filename],uwsummary"; } + else if (type == "phylip") { pattern = "[filename],[tag],[tag2],dist"; } + else if (type == "column") { pattern = "[filename],[tag],[tag2],dist"; } + else if (type == "tree") { pattern = "[filename],[tag],[tag2],tre"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "UnifracUnweightedCommand", "getOutputPattern"); + exit(1); + } } - //********************************************************************************************************************** UnifracUnweightedCommand::UnifracUnweightedCommand(){ try { @@ -304,7 +297,9 @@ int UnifracUnweightedCommand::execute() { ct = T[0]->getCountTable(); delete reader; - sumFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("uwsummary"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile)); + sumFile = getOutputFileName("uwsummary",variables); outputNames.push_back(sumFile); outputTypes["uwsummary"].push_back(sumFile); m->openOutputFile(sumFile, outSum); @@ -362,9 +357,11 @@ int UnifracUnweightedCommand::execute() { counter = 0; if (random) { - output = new ColumnFile(outputDir + m->getSimpleName(treefile) + toString(i+1) + "." + getOutputFileNameTag("unweighted"), itersString); - outputNames.push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + "." + getOutputFileNameTag("unweighted")); - outputTypes["unweighted"].push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + "." + getOutputFileNameTag("unweighted")); + variables["[filename]"] = outputDir + m->getSimpleName(treefile); + variables["[tag]"] = toString(i+1); + string unFileName = getOutputFileName("unweighted", variables); + output = new ColumnFile(unFileName, itersString); + outputNames.push_back(unFileName); outputTypes["unweighted"].push_back(unFileName); } @@ -406,9 +403,13 @@ int UnifracUnweightedCommand::execute() { CountTable* newCt = new CountTable(); //uses method of setting groups to doNotIncludeMe + int sampleTime = 0; + if (m->debug) { sampleTime = time(NULL); } SubSample sample; Tree* subSampleTree = sample.getSample(T[i], ct, newCt, subsampleSize); + if (m->debug) { m->mothurOut("[DEBUG]: iter " + toString(thisIter) + " took " + toString(time(NULL) - sampleTime) + " seconds to sample tree.\n"); } + //call new weighted function vector iterData; iterData.resize(numComp,0); Unweighted thisUnweighted(includeRoot); @@ -529,13 +530,18 @@ int UnifracUnweightedCommand::getAverageSTDMatrices(vector< vector >& di } } - string aveFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".unweighted.ave." + getOutputFileNameTag("phylip"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile)); + variables["[tag]"] = toString(treeNum+1); + variables["[tag2]"] = "unweighted.ave"; + string aveFileName = getOutputFileName("phylip",variables); if (outputForm != "column") { outputNames.push_back(aveFileName); outputTypes["phylip"].push_back(aveFileName); } else { outputNames.push_back(aveFileName); outputTypes["column"].push_back(aveFileName); } ofstream out; m->openOutputFile(aveFileName, out); - string stdFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".unweighted.std." + getOutputFileNameTag("phylip"); + variables["[tag2]"] = "unweighted.std"; + string stdFileName = getOutputFileName("phylip",variables); if (outputForm != "column") { outputNames.push_back(stdFileName); outputTypes["phylip"].push_back(stdFileName); } else { outputNames.push_back(stdFileName); outputTypes["column"].push_back(stdFileName); } ofstream outStd; @@ -626,7 +632,11 @@ int UnifracUnweightedCommand::getConsensusTrees(vector< vector >& dists, Tree* conTree = con.getTree(newTrees); //create a new filename - string conFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(treeNum+1) + ".unweighted.cons." + getOutputFileNameTag("tree"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile)); + variables["[tag]"] = toString(treeNum+1); + variables["[tag2]"] = "unweighted.cons"; + string conFile = getOutputFileName("tree",variables); outputNames.push_back(conFile); outputTypes["tree"].push_back(conFile); ofstream outTree; m->openOutputFile(conFile, outTree); @@ -650,7 +660,11 @@ vector UnifracUnweightedCommand::buildTrees(vector< vector >& dis vector trees; //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(treeNum+1) + ".unweighted.all." + getOutputFileNameTag("tree"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile)); + variables["[tag]"] = toString(treeNum+1); + variables["[tag2]"] = "unweighted.all"; + string outputFile = getOutputFileName("tree",variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); ofstream outAll; @@ -816,11 +830,16 @@ void UnifracUnweightedCommand::printUWSummaryFile(int i) { void UnifracUnweightedCommand::createPhylipFile(int i) { try { string phylipFileName; + map variables; + variables["[filename]"] = outputDir + m->getSimpleName(treefile); + variables["[tag]"] = toString(i+1); if ((outputForm == "lt") || (outputForm == "square")) { - phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted.phylip." + getOutputFileNameTag("phylip"); + variables["[tag2]"] = "unweighted.phylip"; + phylipFileName = getOutputFileName("phylip",variables); outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName); }else { //column - phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted.column." + getOutputFileNameTag("column"); + variables["[tag2]"] = "unweighted.column"; + phylipFileName = getOutputFileName("column",variables); outputNames.push_back(phylipFileName); outputTypes["column"].push_back(phylipFileName); } diff --git a/unifracunweightedcommand.h b/unifracunweightedcommand.h index 107083f..3961e53 100644 --- a/unifracunweightedcommand.h +++ b/unifracunweightedcommand.h @@ -27,8 +27,9 @@ class UnifracUnweightedCommand : public Command { vector setParameters(); string getCommandName() { return "unifrac.unweighted"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Lozupone C, Knight R (2005). UniFrac: a new phylogenetic method for comparing microbial communities. Appl Environ Microbiol 71: 8228-35. \nhttp://www.mothur.org/wiki/Unifrac.unweighted"; } string getDescription() { return "generic tests that describes whether two or more communities have the same structure"; } diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index 541131e..47adc9a 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -15,20 +15,20 @@ //********************************************************************************************************************** vector UnifracWeightedCommand::setParameters(){ try { - CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); - CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none",false,false); parameters.push_back(pcount); - CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter psubsample("subsample", "String", "", "", "", "", "",false,false); parameters.push_back(psubsample); - CommandParameter pconsensus("consensus", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pconsensus); - CommandParameter prandom("random", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(prandom); - CommandParameter pdistance("distance", "Multiple", "column-lt-square-phylip", "column", "", "", "",false,false); parameters.push_back(pdistance); - CommandParameter proot("root", "Boolean", "F", "", "", "", "",false,false); parameters.push_back(proot); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","weighted-wsummary",false,true,true); parameters.push_back(ptree); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + CommandParameter psubsample("subsample", "String", "", "", "", "", "","",false,false); parameters.push_back(psubsample); + CommandParameter pconsensus("consensus", "Boolean", "", "F", "", "", "","tree",false,false); parameters.push_back(pconsensus); + CommandParameter prandom("random", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(prandom); + CommandParameter pdistance("distance", "Multiple", "column-lt-square-phylip", "column", "", "", "","phylip-column",false,false); parameters.push_back(pdistance); + CommandParameter proot("root", "Boolean", "F", "", "", "", "","",false,false); parameters.push_back(proot); + 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); } @@ -65,28 +65,22 @@ string UnifracWeightedCommand::getHelpString(){ } } //********************************************************************************************************************** -string UnifracWeightedCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string UnifracWeightedCommand::getOutputPattern(string type) { + try { + string pattern = ""; + if (type == "weighted") { pattern = "[filename],weighted-[filename],[tag],weighted"; } + else if (type == "wsummary") { pattern = "[filename],wsummary"; } + else if (type == "phylip") { pattern = "[filename],[tag],[tag2],dist"; } + else if (type == "column") { pattern = "[filename],[tag],[tag2],dist"; } + else if (type == "tree") { pattern = "[filename],[tag],[tag2],tre"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } - //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 == "weighted") { outputFileName = "weighted"; } - else if (type == "wsummary") { outputFileName = "wsummary"; } - else if (type == "phylip") { outputFileName = "dist"; } - else if (type == "column") { outputFileName = "dist"; } - else if (type == "tree") { outputFileName = "tre"; } - 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, "UnifracWeightedCommand", "getOutputFileNameTag"); - exit(1); - } + return pattern; + } + catch(exception& e) { + m->errorOut(e, "UnifracWeightedCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** UnifracWeightedCommand::UnifracWeightedCommand(){ @@ -296,8 +290,10 @@ int UnifracWeightedCommand::execute() { delete reader; if (m->control_pressed) { delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; } return 0; } - - sumFile = outputDir + m->getSimpleName(treefile) + getOutputFileNameTag("wsummary"); + + map variables; + variables["[filename]"] = outputDir + m->getSimpleName(treefile); + sumFile = getOutputFileName("wsummary",variables); m->openOutputFile(sumFile, outSum); outputNames.push_back(sumFile); outputTypes["wsummary"].push_back(sumFile); @@ -359,9 +355,11 @@ int UnifracWeightedCommand::execute() { vector randomData; randomData.resize(numComp,0); //weighted score info for random trees. data[0] = weightedscore AB, data[1] = weightedscore AC... if (random) { - output = new ColumnFile(outputDir + m->getSimpleName(treefile) + toString(i+1) + "." + getOutputFileNameTag("weighted"), itersString); - outputNames.push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + "." + getOutputFileNameTag("weighted")); - outputTypes["weighted"].push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + "." + getOutputFileNameTag("weighted")); + variables["[filename]"] = outputDir + m->getSimpleName(treefile); + variables["[tag]"] = toString(i+1); + string wFileName = getOutputFileName("weighted", variables); + output = new ColumnFile(wFileName, itersString); + outputNames.push_back(wFileName); outputTypes["wweighted"].push_back(wFileName); } userData = weighted.getValues(T[i], processors, outputDir); //userData[0] = weightedscore @@ -514,13 +512,18 @@ int UnifracWeightedCommand::getAverageSTDMatrices(vector< vector >& dist } } - string aveFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".weighted.ave." + getOutputFileNameTag("phylip"); + map variables; + variables["[filename]"] = outputDir + m->getSimpleName(treefile); + variables["[tag]"] = toString(treeNum+1); + variables["[tag2]"] = "weighted.ave"; + string aveFileName = getOutputFileName("phylip",variables); if (outputForm != "column") { outputNames.push_back(aveFileName); outputTypes["phylip"].push_back(aveFileName); } else { outputNames.push_back(aveFileName); outputTypes["column"].push_back(aveFileName); } ofstream out; m->openOutputFile(aveFileName, out); - string stdFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".weighted.std." + getOutputFileNameTag("phylip"); + variables["[tag2]"] = "weighted.std"; + string stdFileName = getOutputFileName("phylip",variables); if (outputForm != "column") { outputNames.push_back(stdFileName); outputTypes["phylip"].push_back(stdFileName); } else { outputNames.push_back(stdFileName); outputTypes["column"].push_back(stdFileName); } ofstream outStd; @@ -611,7 +614,11 @@ int UnifracWeightedCommand::getConsensusTrees(vector< vector >& dists, i Tree* conTree = con.getTree(newTrees); //create a new filename - string conFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(treeNum+1) + ".weighted.cons." + getOutputFileNameTag("tree"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile)); + variables["[tag]"] = toString(treeNum+1); + variables["[tag2]"] = "weighted.cons"; + string conFile = getOutputFileName("tree",variables); outputNames.push_back(conFile); outputTypes["tree"].push_back(conFile); ofstream outTree; m->openOutputFile(conFile, outTree); @@ -635,7 +642,11 @@ vector UnifracWeightedCommand::buildTrees(vector< vector >& dists vector trees; //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(treeNum+1) + ".weighted.all." + getOutputFileNameTag("tree"); + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(treefile)); + variables["[tag]"] = toString(treeNum+1); + variables["[tag2]"] = "weighted.all"; + string outputFile = getOutputFileName("tree",variables); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); ofstream outAll; @@ -943,14 +954,20 @@ void UnifracWeightedCommand::createPhylipFile() { //for each tree for (int i = 0; i < T.size(); i++) { - string phylipFileName; - if ((outputForm == "lt") || (outputForm == "square")) { - phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted.phylip." + getOutputFileNameTag("phylip"); - outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName); - }else { //column - phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted.column." + getOutputFileNameTag("column"); - outputNames.push_back(phylipFileName); outputTypes["column"].push_back(phylipFileName); - } + string phylipFileName; + map variables; + variables["[filename]"] = outputDir + m->getSimpleName(treefile); + variables["[tag]"] = toString(i+1); + if ((outputForm == "lt") || (outputForm == "square")) { + variables["[tag2]"] = "weighted.phylip"; + phylipFileName = getOutputFileName("phylip",variables); + outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName); + }else { //column + variables["[tag2]"] = "weighted.column"; + phylipFileName = getOutputFileName("column",variables); + outputNames.push_back(phylipFileName); outputTypes["column"].push_back(phylipFileName); + } + ofstream out; m->openOutputFile(phylipFileName, out); diff --git a/unifracweightedcommand.h b/unifracweightedcommand.h index fead41b..1c67c32 100644 --- a/unifracweightedcommand.h +++ b/unifracweightedcommand.h @@ -28,8 +28,9 @@ class UnifracWeightedCommand : public Command { vector setParameters(); string getCommandName() { return "unifrac.weighted"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "Lozupone CA, Hamady M, Kelley ST, Knight R (2007). Quantitative and qualitative beta diversity measures lead to different insights into factors that structure microbial communities. Appl Environ Microbiol 73: 1576-85. \nhttp://www.mothur.org/wiki/Unifrac.weighted"; } string getDescription() { return "generic tests that describes whether two or more communities have the same structure"; } diff --git a/venncommand.cpp b/venncommand.cpp index c918500..9c23495 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -20,17 +20,17 @@ //********************************************************************************************************************** vector VennCommand::setParameters(){ try { - CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); - CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); - CommandParameter pcalc("calc", "String", "", "", "", "", "",false,false); parameters.push_back(pcalc); - CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund); - CommandParameter pnseqs("nseqs", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pnseqs); - CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "",false,false); parameters.push_back(pfontsize); - CommandParameter ppermute("permute", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ppermute); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false,true); parameters.push_back(plist); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false,true); parameters.push_back(pshared); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel); + CommandParameter pcalc("calc", "String", "", "", "", "", "","",false,false); parameters.push_back(pcalc); + CommandParameter pabund("abund", "Number", "", "10", "", "", "","",false,false); parameters.push_back(pabund); + CommandParameter pnseqs("nseqs", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pnseqs); + CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "","",false,false); parameters.push_back(pfontsize); + CommandParameter ppermute("permute", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(ppermute); + 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); } @@ -67,25 +67,19 @@ string VennCommand::getHelpString(){ } } //********************************************************************************************************************** - -string VennCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string VennCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //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 == "svg") { outputFileName = "svg"; } - 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, "VennCommand", "getOutputFileNameTag"); - exit(1); - } + if (type == "svg") { pattern = "[filename],svg"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "VennCommand", "getOutputPattern"); + exit(1); + } } //********************************************************************************************************************** diff --git a/venncommand.h b/venncommand.h index 9f36928..15932ec 100644 --- a/venncommand.h +++ b/venncommand.h @@ -25,8 +25,9 @@ public: vector setParameters(); string getCommandName() { return "venn"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getOutputFileNameTag(string, string); + string getHelpString(); + string getOutputPattern(string); string getCitation() { return "http://www.mothur.org/wiki/Venn"; } string getDescription() { return "generates a Venn diagram from data provided in a shared file"; }