From: Sarah Westcott Date: Tue, 19 Jun 2012 12:48:32 +0000 (-0400) Subject: added load.logfile command. changed summary.single output for subsample=t. X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=commitdiff_plain;h=49d2b7459c5027557564b21e9487dadafbbbdc96 added load.logfile command. changed summary.single output for subsample=t. --- diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index d98b284..6db66c6 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ A721765713BB9F7D0014DAAE /* referencedb.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A721765613BB9F7D0014DAAE /* referencedb.cpp */; }; A724D2B7153C8628000A826F /* makebiomcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A724D2B6153C8628000A826F /* makebiomcommand.cpp */; }; A727864412E9E28C00F86ABA /* removerarecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A727864312E9E28C00F86ABA /* removerarecommand.cpp */; }; + A73901081588C40900ED2ED6 /* loadlogfilecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A73901071588C40900ED2ED6 /* loadlogfilecommand.cpp */; }; A73DDBBA13C4A0D1006AAE38 /* clearmemorycommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A73DDBB913C4A0D1006AAE38 /* clearmemorycommand.cpp */; }; A73DDC3813C4BF64006AAE38 /* mothurmetastats.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A73DDC3713C4BF64006AAE38 /* mothurmetastats.cpp */; }; A74A9A9F148E881E00AB5E3E /* spline.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A74A9A9E148E881E00AB5E3E /* spline.cpp */; }; @@ -214,11 +215,8 @@ A7E9B92912D37EC400DA6239 /* readblast.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7B012D37EC400DA6239 /* readblast.cpp */; }; A7E9B92A12D37EC400DA6239 /* readcluster.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7B212D37EC400DA6239 /* readcluster.cpp */; }; A7E9B92B12D37EC400DA6239 /* readcolumn.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7B412D37EC400DA6239 /* readcolumn.cpp */; }; - A7E9B92C12D37EC400DA6239 /* readdistcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7B612D37EC400DA6239 /* readdistcommand.cpp */; }; - A7E9B92E12D37EC400DA6239 /* readotucommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7BB12D37EC400DA6239 /* readotucommand.cpp */; }; A7E9B92F12D37EC400DA6239 /* readphylip.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7BD12D37EC400DA6239 /* readphylip.cpp */; }; A7E9B93012D37EC400DA6239 /* readtree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7BF12D37EC400DA6239 /* readtree.cpp */; }; - A7E9B93112D37EC400DA6239 /* readtreecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7C112D37EC400DA6239 /* readtreecommand.cpp */; }; A7E9B93212D37EC400DA6239 /* removegroupscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7C312D37EC400DA6239 /* removegroupscommand.cpp */; }; A7E9B93312D37EC400DA6239 /* removelineagecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7C512D37EC400DA6239 /* removelineagecommand.cpp */; }; A7E9B93412D37EC400DA6239 /* removeotuscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B7C712D37EC400DA6239 /* removeotuscommand.cpp */; }; @@ -391,6 +389,8 @@ A724D2B6153C8628000A826F /* makebiomcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = makebiomcommand.cpp; sourceTree = ""; }; A727864212E9E28C00F86ABA /* removerarecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = removerarecommand.h; sourceTree = ""; }; A727864312E9E28C00F86ABA /* removerarecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = removerarecommand.cpp; sourceTree = ""; }; + A73901051588C3EF00ED2ED6 /* loadlogfilecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = loadlogfilecommand.h; sourceTree = ""; }; + A73901071588C40900ED2ED6 /* loadlogfilecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = loadlogfilecommand.cpp; sourceTree = ""; }; A73DDBB813C4A0D1006AAE38 /* clearmemorycommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = clearmemorycommand.h; sourceTree = ""; }; A73DDBB913C4A0D1006AAE38 /* clearmemorycommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clearmemorycommand.cpp; sourceTree = ""; }; A73DDC3613C4BF64006AAE38 /* mothurmetastats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mothurmetastats.h; sourceTree = ""; }; @@ -797,17 +797,11 @@ A7E9B7B312D37EC400DA6239 /* readcluster.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readcluster.h; sourceTree = ""; }; A7E9B7B412D37EC400DA6239 /* readcolumn.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readcolumn.cpp; sourceTree = ""; }; A7E9B7B512D37EC400DA6239 /* readcolumn.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readcolumn.h; sourceTree = ""; }; - A7E9B7B612D37EC400DA6239 /* readdistcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readdistcommand.cpp; sourceTree = ""; }; - A7E9B7B712D37EC400DA6239 /* readdistcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readdistcommand.h; sourceTree = ""; }; A7E9B7B812D37EC400DA6239 /* readmatrix.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = readmatrix.hpp; sourceTree = ""; }; - A7E9B7BB12D37EC400DA6239 /* readotucommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readotucommand.cpp; sourceTree = ""; }; - A7E9B7BC12D37EC400DA6239 /* readotucommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readotucommand.h; sourceTree = ""; }; A7E9B7BD12D37EC400DA6239 /* readphylip.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readphylip.cpp; sourceTree = ""; }; A7E9B7BE12D37EC400DA6239 /* readphylip.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readphylip.h; sourceTree = ""; }; A7E9B7BF12D37EC400DA6239 /* readtree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readtree.cpp; sourceTree = ""; }; A7E9B7C012D37EC400DA6239 /* readtree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readtree.h; sourceTree = ""; }; - A7E9B7C112D37EC400DA6239 /* readtreecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = readtreecommand.cpp; sourceTree = ""; }; - A7E9B7C212D37EC400DA6239 /* readtreecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readtreecommand.h; sourceTree = ""; }; A7E9B7C312D37EC400DA6239 /* removegroupscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = removegroupscommand.cpp; sourceTree = ""; }; A7E9B7C412D37EC400DA6239 /* removegroupscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = removegroupscommand.h; sourceTree = ""; }; A7E9B7C512D37EC400DA6239 /* removelineagecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = removelineagecommand.cpp; sourceTree = ""; }; @@ -1315,6 +1309,8 @@ A7A067191562946F0095C8C5 /* listotulabelscommand.cpp */, A7E9B73E12D37EC400DA6239 /* listseqscommand.h */, A7E9B73D12D37EC400DA6239 /* listseqscommand.cpp */, + A73901051588C3EF00ED2ED6 /* loadlogfilecommand.h */, + A73901071588C40900ED2ED6 /* loadlogfilecommand.cpp */, A7FA10001302E096003860FE /* mantelcommand.h */, A7FA10011302E096003860FE /* mantelcommand.cpp */, A724D2B4153C8600000A826F /* makebiomcommand.h */, @@ -1373,12 +1369,6 @@ A7E9B7AB12D37EC400DA6239 /* rarefactcommand.cpp */, A7E9B7AF12D37EC400DA6239 /* rarefactsharedcommand.h */, A7E9B7AE12D37EC400DA6239 /* rarefactsharedcommand.cpp */, - A7E9B7B712D37EC400DA6239 /* readdistcommand.h */, - A7E9B7B612D37EC400DA6239 /* readdistcommand.cpp */, - A7E9B7BC12D37EC400DA6239 /* readotucommand.h */, - A7E9B7BB12D37EC400DA6239 /* readotucommand.cpp */, - A7E9B7C212D37EC400DA6239 /* readtreecommand.h */, - A7E9B7C112D37EC400DA6239 /* readtreecommand.cpp */, A7E9B7C412D37EC400DA6239 /* removegroupscommand.h */, A7E9B7C312D37EC400DA6239 /* removegroupscommand.cpp */, A7E9B7C612D37EC400DA6239 /* removelineagecommand.h */, @@ -2030,11 +2020,8 @@ A7E9B92912D37EC400DA6239 /* readblast.cpp in Sources */, A7E9B92A12D37EC400DA6239 /* readcluster.cpp in Sources */, A7E9B92B12D37EC400DA6239 /* readcolumn.cpp in Sources */, - A7E9B92C12D37EC400DA6239 /* readdistcommand.cpp in Sources */, - A7E9B92E12D37EC400DA6239 /* readotucommand.cpp in Sources */, A7E9B92F12D37EC400DA6239 /* readphylip.cpp in Sources */, A7E9B93012D37EC400DA6239 /* readtree.cpp in Sources */, - A7E9B93112D37EC400DA6239 /* readtreecommand.cpp in Sources */, A7E9B93212D37EC400DA6239 /* removegroupscommand.cpp in Sources */, A7E9B93312D37EC400DA6239 /* removelineagecommand.cpp in Sources */, A7E9B93412D37EC400DA6239 /* removeotuscommand.cpp in Sources */, @@ -2192,6 +2179,7 @@ A7A0671F1562AC3E0095C8C5 /* makecontigscommand.cpp in Sources */, A70056E6156A93D000924A2D /* getotulabelscommand.cpp in Sources */, A70056EB156AB6E500924A2D /* removeotulabelscommand.cpp in Sources */, + A73901081588C40900ED2ED6 /* loadlogfilecommand.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/aligncommand.cpp b/aligncommand.cpp index 75466f9..a68fbfc 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -75,6 +75,29 @@ string AlignCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string AlignCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string tag = ""; + 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") { 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); + } +} + //********************************************************************************************************************** AlignCommand::AlignCommand(){ try { @@ -305,9 +328,9 @@ 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])) + "align"; - string reportFileName = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])) + "align.report"; - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(candidateFileNames[s])) + "flip.accnos"; + 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"); bool hasAccnos = true; int numFastaSeqs = 0; diff --git a/aligncommand.h b/aligncommand.h index d4b7e78..5432d00 100644 --- a/aligncommand.h +++ b/aligncommand.h @@ -34,6 +34,7 @@ public: vector setParameters(); string getCommandName() { return "align.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 3ec14bf..c4260fb 100644 --- a/amovacommand.cpp +++ b/amovacommand.cpp @@ -51,6 +51,26 @@ string AmovaCommand::getHelpString(){ } } //********************************************************************************************************************** +string AmovaCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string tag = ""; + 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 == "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); + } +} +//********************************************************************************************************************** AmovaCommand::AmovaCommand(){ try { abort = true; calledHelp = true; @@ -187,7 +207,7 @@ int AmovaCommand::execute(){ //create a new filename ofstream AMOVAFile; - string AMOVAFileName = outputDir + m->getRootName(m->getSimpleName(phylipFileName)) + "amova"; + string AMOVAFileName = outputDir + m->getRootName(m->getSimpleName(phylipFileName)) + getOutputFileNameTag("amova"); m->openOutputFile(AMOVAFileName, AMOVAFile); outputNames.push_back(AMOVAFileName); outputTypes["amova"].push_back(AMOVAFileName); diff --git a/amovacommand.h b/amovacommand.h index 50dc81a..6b3c83a 100644 --- a/amovacommand.h +++ b/amovacommand.h @@ -23,6 +23,7 @@ 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 getDescription() { return "analysis of molecular variance"; } diff --git a/anosimcommand.cpp b/anosimcommand.cpp index 1b6afe3..bd4e6b0 100644 --- a/anosimcommand.cpp +++ b/anosimcommand.cpp @@ -49,7 +49,26 @@ string AnosimCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string AnosimCommand::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 == "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); + } +} //********************************************************************************************************************** AnosimCommand::AnosimCommand(){ try { @@ -188,7 +207,7 @@ int AnosimCommand::execute(){ //create a new filename ofstream ANOSIMFile; - string ANOSIMFileName = outputDir + m->getRootName(m->getSimpleName(phylipFileName)) + "anosim"; + string ANOSIMFileName = outputDir + m->getRootName(m->getSimpleName(phylipFileName)) + getOutputFileNameTag("anosim"); 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 4b65070..ff1b683 100644 --- a/anosimcommand.h +++ b/anosimcommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "anosim"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 2117daf..7569a4b 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -50,6 +50,26 @@ string BinSeqCommand::getHelpString(){ } } //********************************************************************************************************************** +string BinSeqCommand::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 = "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); + } +} +//********************************************************************************************************************** BinSeqCommand::BinSeqCommand(){ try { abort = true; calledHelp = true; @@ -344,8 +364,8 @@ int BinSeqCommand::process(ListVector* list) { try { string binnames, name, sequence; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + list->getLabel() + ".fasta"; - m->openOutputFile(outputFileName, out); + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + list->getLabel() + getOutputFileNameTag("fasta"); + m->openOutputFile(outputFileName, out); //save to output list of output file names outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); diff --git a/binsequencecommand.h b/binsequencecommand.h index 365fb3c..1fb5664 100644 --- a/binsequencecommand.h +++ b/binsequencecommand.h @@ -27,6 +27,7 @@ public: vector setParameters(); string getCommandName() { return "bin.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 329b56a..1cfd415 100644 --- a/catchallcommand.cpp +++ b/catchallcommand.cpp @@ -49,6 +49,27 @@ string CatchAllCommand::getHelpString(){ } } //********************************************************************************************************************** +string CatchAllCommand::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 == "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); + } +} +//********************************************************************************************************************** CatchAllCommand::CatchAllCommand(){ try { abort = true; calledHelp = true; @@ -236,7 +257,7 @@ int CatchAllCommand::execute() { set processedLabels; set userLabels = labels; - string summaryfilename = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "catchall.summary"; + string summaryfilename = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + getOutputFileNameTag("summary"); 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"); } @@ -283,10 +304,10 @@ 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.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv"); - outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv"); - outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv"); - outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv"); + 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"); } @@ -336,10 +357,10 @@ 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.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv"); - outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv"); - outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv"); - outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv"); + 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"); } @@ -410,11 +431,10 @@ 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.csv"); outputTypes["csv"].push_back(filename + "_Analysis.csv"); - outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv"); - outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv"); - outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv"); - if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); } + 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"); } createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out); @@ -491,7 +511,7 @@ string CatchAllCommand::combineSummmary(vector& outputNames) { try { ofstream out; - string combineFileName = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "catchall.summary"; + string combineFileName = savedOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("summary"); //open combined file m->openOutputFile(combineFileName, out); diff --git a/catchallcommand.h b/catchallcommand.h index 238dfb6..d1b8a2a 100644 --- a/catchallcommand.h +++ b/catchallcommand.h @@ -31,6 +31,7 @@ public: vector setParameters(); string getCommandName() { return "catchall"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "Bunge, J. (2011). Estimating the number of species with CatchAll. Forthcoming in Proceedings of the Pacific Symposium on Biocomputing 2011.\nhttp://www.northeastern.edu/catchall/index.html http://www.mothur.org/wiki/Catchall"; } string getDescription() { return "estimate number of species"; } diff --git a/chimerabellerophoncommand.cpp b/chimerabellerophoncommand.cpp index c519f91..8240011 100644 --- a/chimerabellerophoncommand.cpp +++ b/chimerabellerophoncommand.cpp @@ -57,6 +57,27 @@ string ChimeraBellerophonCommand::getHelpString(){ } } //********************************************************************************************************************** +string ChimeraBellerophonCommand::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 == "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); + } +} +//********************************************************************************************************************** ChimeraBellerophonCommand::ChimeraBellerophonCommand(){ try { abort = true; calledHelp = true; @@ -222,8 +243,8 @@ 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])) + "bellerophon.chimeras"; - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + "bellerophon.accnos"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + getOutputFileNameTag("chimera"); + string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + getOutputFileNameTag("accnos"); chimera->getChimeras(); diff --git a/chimerabellerophoncommand.h b/chimerabellerophoncommand.h index b759d5a..015f2b7 100644 --- a/chimerabellerophoncommand.h +++ b/chimerabellerophoncommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "chimera.bellerophon"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 fc98e0f..942635e 100644 --- a/chimeraccodecommand.cpp +++ b/chimeraccodecommand.cpp @@ -64,6 +64,28 @@ string ChimeraCcodeCommand::getHelpString(){ } } //********************************************************************************************************************** +string ChimeraCcodeCommand::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 == "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); + } +} +//********************************************************************************************************************** ChimeraCcodeCommand::ChimeraCcodeCommand(){ try { abort = true; calledHelp = true; @@ -284,14 +306,16 @@ 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 + ".ccode.chimeras"; - accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + maskfile + ".ccode.accnos"; + 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])) + "ccode.chimeras"; - accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ccode.accnos"; + 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])) + "mapinfo"; + string mapInfo = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("mapinfo"); + if (m->control_pressed) { delete chimera; for (int j = 0; j < outputNames.size(); j++) { m->mothurRemove(outputNames[j]); } outputTypes.clear(); return 0; } diff --git a/chimeraccodecommand.h b/chimeraccodecommand.h index 5b8092b..408e2fe 100644 --- a/chimeraccodecommand.h +++ b/chimeraccodecommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "chimera.ccode"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 cc486d3..87f51e7 100644 --- a/chimeracheckcommand.cpp +++ b/chimeracheckcommand.cpp @@ -65,6 +65,26 @@ string ChimeraCheckCommand::getHelpString(){ } } //********************************************************************************************************************** +string ChimeraCheckCommand::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 == "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); + } +} +//********************************************************************************************************************** ChimeraCheckCommand::ChimeraCheckCommand(){ try { abort = true; calledHelp = true; @@ -342,7 +362,7 @@ 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])) + "chimeracheck.chimeras"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + getOutputFileNameTag("chimera"); outputNames.push_back(outputFileName); outputTypes["chimera"].push_back(outputFileName); #ifdef USE_MPI diff --git a/chimeracheckcommand.h b/chimeracheckcommand.h index 918b4e5..61129cd 100644 --- a/chimeracheckcommand.h +++ b/chimeracheckcommand.h @@ -27,6 +27,7 @@ public: vector setParameters(); string getCommandName() { return "chimera.check"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 e7294a8..e3691e8 100644 --- a/chimeraperseuscommand.cpp +++ b/chimeraperseuscommand.cpp @@ -58,6 +58,27 @@ string ChimeraPerseusCommand::getHelpString(){ } } //********************************************************************************************************************** +string ChimeraPerseusCommand::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 == "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); + } +} +//********************************************************************************************************************** ChimeraPerseusCommand::ChimeraPerseusCommand(){ try { abort = true; calledHelp = true; @@ -376,8 +397,9 @@ int ChimeraPerseusCommand::execute(){ 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])) + "perseus.chimera"; - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "perseus.accnos"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("chimera"); + string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("accnos"); + //string newFasta = m->getRootName(fastaFileNames[s]) + "temp"; //you provided a groupfile diff --git a/chimeraperseuscommand.h b/chimeraperseuscommand.h index 01f5768..1c4baa3 100644 --- a/chimeraperseuscommand.h +++ b/chimeraperseuscommand.h @@ -28,6 +28,7 @@ public: vector setParameters(); string getCommandName() { return "chimera.perseus"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Chimera.perseus\n"; } string getDescription() { return "detect chimeric sequences"; } diff --git a/chimerapintailcommand.cpp b/chimerapintailcommand.cpp index 7311173..c5c678e 100644 --- a/chimerapintailcommand.cpp +++ b/chimerapintailcommand.cpp @@ -69,6 +69,27 @@ string ChimeraPintailCommand::getHelpString(){ } } //********************************************************************************************************************** +string ChimeraPintailCommand::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 == "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); + } +} +//********************************************************************************************************************** ChimeraPintailCommand::ChimeraPintailCommand(){ try { abort = true; calledHelp = true; @@ -397,11 +418,11 @@ 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)) + ".pintail.chimeras"; - accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + m->getSimpleName(m->getRootName(maskfile)) + ".pintail.accnos"; + 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])) + "pintail.chimeras"; - accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "pintail.accnos"; + outputFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("chimera"); + accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("accnos"); } 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 ddbb648..1f30b7d 100644 --- a/chimerapintailcommand.h +++ b/chimerapintailcommand.h @@ -28,6 +28,7 @@ public: vector setParameters(); string getCommandName() { return "chimera.pintail"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 e2b9331..59dd0a5 100644 --- a/chimeraslayercommand.cpp +++ b/chimeraslayercommand.cpp @@ -98,6 +98,28 @@ string ChimeraSlayerCommand::getHelpString(){ } } //********************************************************************************************************************** +string ChimeraSlayerCommand::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 == "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); + } +} +//********************************************************************************************************************** ChimeraSlayerCommand::ChimeraSlayerCommand(){ try { abort = true; calledHelp = true; @@ -556,9 +578,9 @@ int ChimeraSlayerCommand::execute(){ 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])) + "slayer.chimera"; - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.accnos"; - string trimFastaFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "slayer.fasta"; + 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"); //clears files ofstream out, out1, out2; diff --git a/chimeraslayercommand.h b/chimeraslayercommand.h index 2c6fec8..a2e22ae 100644 --- a/chimeraslayercommand.h +++ b/chimeraslayercommand.h @@ -27,6 +27,7 @@ public: vector setParameters(); string getCommandName() { return "chimera.slayer"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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. \nhttp://www.mothur.org/wiki/Chimera.slayer"; } string getDescription() { return "detect chimeric sequences"; } diff --git a/chimerauchimecommand.cpp b/chimerauchimecommand.cpp index b1d996b..bd31c19 100644 --- a/chimerauchimecommand.cpp +++ b/chimerauchimecommand.cpp @@ -98,6 +98,28 @@ string ChimeraUchimeCommand::getHelpString(){ } } //********************************************************************************************************************** +string ChimeraUchimeCommand::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 == "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); + } +} +//********************************************************************************************************************** ChimeraUchimeCommand::ChimeraUchimeCommand(){ try { abort = true; calledHelp = true; @@ -522,9 +544,9 @@ 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])) + "uchime.chimera"; - string accnosFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "uchime.accnos"; - string alnsFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "uchime.alns"; + 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"); string newFasta = m->getRootName(fastaFileNames[s]) + "temp"; //you provided a groupfile diff --git a/chimerauchimecommand.h b/chimerauchimecommand.h index dfb410f..5423a17 100644 --- a/chimerauchimecommand.h +++ b/chimerauchimecommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "chimera.uchime"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "uchime by Robert C. Edgar\nhttp://drive5.com/uchime\nThis code is donated to the public domain.\nhttp://www.mothur.org/wiki/Chimera.uchime\nEdgar,R.C., Haas,B.J., Clemente,J.C., Quince,C. and Knight,R. (2011), UCHIME improves sensitivity and speed of chimera detection, Bioinformatics, in press.\n"; } string getDescription() { return "detect chimeric sequences"; } diff --git a/chopseqscommand.cpp b/chopseqscommand.cpp index 4e06201..05037f6 100644 --- a/chopseqscommand.cpp +++ b/chopseqscommand.cpp @@ -51,7 +51,27 @@ string ChopSeqsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string ChopSeqsCommand::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 = "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); + } +} //********************************************************************************************************************** ChopSeqsCommand::ChopSeqsCommand(){ try { @@ -147,8 +167,8 @@ int ChopSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.fasta"; - string outputFileNameAccnos = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "chop.accnos"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta"); + string outputFileNameAccnos = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("accnos"); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/chopseqscommand.h b/chopseqscommand.h index e73714d..cc22c75 100644 --- a/chopseqscommand.h +++ b/chopseqscommand.h @@ -25,7 +25,8 @@ class ChopSeqsCommand : public Command { vector setParameters(); string getCommandName() { return "chop.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Chops.seqs"; } string getDescription() { return "trim sequence length"; } diff --git a/classify.cpp b/classify.cpp index 7726b3e..212e563 100644 --- a/classify.cpp +++ b/classify.cpp @@ -306,28 +306,12 @@ int Classify::readTaxonomy(string file) { MPI_File_close(&inMPI); MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case -#else - ifstream inTax; - m->openInputFile(file, inTax); - - //read template seqs and save - while (!inTax.eof()) { - inTax >> name; m->gobble(inTax); - inTax >> taxInfo; - - if (m->debug) { m->mothurOut("[DEBUG]: name = '" + name + "' tax = '" + taxInfo + "'\n"); } - - taxonomy[name] = taxInfo; - - phyloTree->addSeqToTree(name, taxInfo); - - m->gobble(inTax); - } - inTax.close(); -#endif - +#else - + taxonomy.clear(); + m->readTax(file, taxonomy); + for (map::iterator itTax = taxonomy.begin(); itTax != taxonomy.end(); itTax++) { phyloTree->addSeqToTree(itTax->first, itTax->second); } +#endif phyloTree->assignHeirarchyIDs(0); phyloTree->setUp(file); diff --git a/classifyotucommand.cpp b/classifyotucommand.cpp index ef41ee1..00ae690 100644 --- a/classifyotucommand.cpp +++ b/classifyotucommand.cpp @@ -63,6 +63,27 @@ string ClassifyOtuCommand::getHelpString(){ } } //********************************************************************************************************************** +string ClassifyOtuCommand::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 == "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); + } +} +//********************************************************************************************************************** ClassifyOtuCommand::ClassifyOtuCommand(){ try { abort = true; calledHelp = true; @@ -234,10 +255,10 @@ int ClassifyOtuCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //if user gave a namesfile then use it - if (namefile != "") { readNamesFile(); } + if (namefile != "") { m->readNames(namefile, nameMap, true); } //read taxonomy file and save in map for easy access in building bin trees - readTaxonomyFile(); + m->readTax(taxfile, taxMap); if (m->control_pressed) { return 0; } @@ -327,67 +348,6 @@ int ClassifyOtuCommand::execute(){ exit(1); } } - -//********************************************************************************************************************** -int ClassifyOtuCommand::readNamesFile() { - try { - - ifstream inNames; - m->openInputFile(namefile, inNames); - - string name, names; - - while(!inNames.eof()){ - inNames >> name; //read from first column A - inNames >> names; //read from second column A,B,C,D - m->gobble(inNames); - - //parse names into vector - vector theseNames; - m->splitAtComma(names, theseNames); - - for (int i = 0; i < theseNames.size(); i++) { nameMap[theseNames[i]] = name; } - - if (m->control_pressed) { inNames.close(); nameMap.clear(); return 0; } - } - inNames.close(); - - return 0; - } - catch(exception& e) { - m->errorOut(e, "ClassifyOtuCommand", "readNamesFile"); - exit(1); - } -} -//********************************************************************************************************************** -int ClassifyOtuCommand::readTaxonomyFile() { - try { - - ifstream in; - m->openInputFile(taxfile, in); - - string name, tax; - - while(!in.eof()){ - in >> name >> tax; - m->gobble(in); - - //are there confidence scores, if so remove them - if (tax.find_first_of('(') != -1) { m->removeConfidences(tax); } - - taxMap[name] = tax; - - if (m->control_pressed) { in.close(); taxMap.clear(); return 0; } - } - in.close(); - - return 0; - } - catch(exception& e) { - m->errorOut(e, "ClassifyOtuCommand", "readTaxonomyFile"); - exit(1); - } -} //********************************************************************************************************************** vector ClassifyOtuCommand::findConsensusTaxonomy(int bin, ListVector* thisList, int& size, string& conTax) { try{ @@ -526,12 +486,12 @@ int ClassifyOtuCommand::process(ListVector* processList) { if (outputDir == "") { outputDir += m->hasPath(listfile); } ofstream out; - string outputFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + ".cons.taxonomy"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + getOutputFileNameTag("constaxonomy"); 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() + ".cons.tax.summary"; + string outputSumFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + getOutputFileNameTag("taxsummary"); m->openOutputFile(outputSumFile, outSum); outputNames.push_back(outputSumFile); outputTypes["taxsummary"].push_back(outputSumFile); diff --git a/classifyotucommand.h b/classifyotucommand.h index a0baf18..b924775 100644 --- a/classifyotucommand.h +++ b/classifyotucommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "classify.otu"; } string getCommandCategory() { return "Phylotype Analysis"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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. \nhttp://www.mothur.org/wiki/Classify.otu"; } string getDescription() { return "find the concensus taxonomy for each OTU"; } @@ -44,8 +45,6 @@ private: map nameMap; map taxMap; - int readNamesFile(); - int readTaxonomyFile(); int process(ListVector*); string addUnclassifieds(string, int); vector findConsensusTaxonomy(int, ListVector*, int&, string&); // returns the name of the "representative" taxonomy of given bin diff --git a/classifyseqscommand.cpp b/classifyseqscommand.cpp index 158069e..c76b047 100644 --- a/classifyseqscommand.cpp +++ b/classifyseqscommand.cpp @@ -85,6 +85,29 @@ string ClassifySeqsCommand::getHelpString(){ } } //********************************************************************************************************************** +string ClassifySeqsCommand::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 == "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); + } +} +//********************************************************************************************************************** ClassifySeqsCommand::ClassifySeqsCommand(){ try { abort = true; calledHelp = true; @@ -506,7 +529,6 @@ int ClassifySeqsCommand::execute(){ string RippedTaxName = ""; bool foundDot = false; for (int i = baseTName.length()-1; i >= 0; i--) { - cout << baseTName[i] << endl; if (foundDot && (baseTName[i] != '.')) { RippedTaxName = baseTName[i] + RippedTaxName; } else if (foundDot && (baseTName[i] == '.')) { break; } else if (!foundDot && (baseTName[i] == '.')) { foundDot = true; } @@ -514,13 +536,13 @@ int ClassifySeqsCommand::execute(){ if (RippedTaxName != "") { RippedTaxName += "."; } if (outputDir == "") { outputDir += m->hasPath(fastaFileNames[s]); } - string newTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + "taxonomy"; - string newaccnosFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + "flip.accnos"; + string newTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + getOutputFileNameTag("taxonomy"); + string newaccnosFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + getOutputFileNameTag("accnos"); string tempTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "taxonomy.temp"; - string taxSummary = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + "tax.summary"; + string taxSummary = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + getOutputFileNameTag("taxsummary"); if ((method == "knn") && (search == "distance")) { - string DistName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "match.dist"; + string DistName = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("matchdist"); classify->setDistName(DistName); outputNames.push_back(DistName); outputTypes["matchdist"].push_back(DistName); } @@ -666,23 +688,8 @@ int ClassifySeqsCommand::execute(){ if(namefile != "") { m->mothurOut("Reading " + namefileNames[s] + "..."); cout.flush(); - nameMap.clear(); //remove old names - - ifstream inNames; - m->openInputFile(namefileNames[s], inNames); - - string firstCol, secondCol; - while(!inNames.eof()) { - inNames >> firstCol >> secondCol; m->gobble(inNames); - - vector temp; - m->splitAtComma(secondCol, temp); - - nameMap[firstCol] = temp; - } - inNames.close(); - + m->readNames(namefileNames[s], nameMap); m->mothurOut(" Done."); m->mothurOutEndLine(); } #endif diff --git a/classifyseqscommand.h b/classifyseqscommand.h index 1316a25..4965642 100644 --- a/classifyseqscommand.h +++ b/classifyseqscommand.h @@ -41,6 +41,7 @@ public: vector setParameters(); string getCommandName() { return "classify.seqs"; } string getCommandCategory() { return "Phylotype Analysis"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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/classifytreecommand.cpp b/classifytreecommand.cpp index bcf2769..7861a01 100644 --- a/classifytreecommand.cpp +++ b/classifytreecommand.cpp @@ -49,7 +49,27 @@ string ClassifyTreeCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string ClassifyTreeCommand::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 == "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); + } +} //********************************************************************************************************************** ClassifyTreeCommand::ClassifyTreeCommand(){ try { @@ -197,11 +217,11 @@ int ClassifyTreeCommand::execute(){ Tree* outputTree = T[0]; delete reader; - if (namefile != "") { readNamesFile(); } + if (namefile != "") { m->readNames(namefile, nameMap, nameCount); } if (m->control_pressed) { delete tmap; delete outputTree; return 0; } - readTaxonomyFile(); + m->readTax(taxonomyfile, taxMap); /***************************************************/ // get concensus taxonomies // @@ -242,7 +262,7 @@ int ClassifyTreeCommand::getClassifications(Tree*& T){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(treefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(treefile)) + "taxonomy.summary"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("summary"); outputNames.push_back(outputFileName); outputTypes["summary"].push_back(outputFileName); ofstream out; @@ -256,7 +276,7 @@ int ClassifyTreeCommand::getClassifications(Tree*& T){ string treeOutputDir = outputDir; if (outputDir == "") { treeOutputDir += m->hasPath(treefile); } - string outputTreeFileName = treeOutputDir + m->getRootName(m->getSimpleName(treefile)) + "taxonomy.tre"; + string outputTreeFileName = treeOutputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("tree"); //create a map from tree node index to names of descendants, save time later map > > nodeToDescendants; //node# -> (groupName -> groupMembers) @@ -453,68 +473,6 @@ map > ClassifyTreeCommand::getDescendantList(Tree*& T, int i exit(1); } } -//********************************************************************************************************************** -int ClassifyTreeCommand::readTaxonomyFile() { - try { - - ifstream in; - m->openInputFile(taxonomyfile, in); - - string name, tax; - - while(!in.eof()){ - in >> name >> tax; - m->gobble(in); - - //are there confidence scores, if so remove them - if (tax.find_first_of('(') != -1) { m->removeConfidences(tax); } - - taxMap[name] = tax; - - if (m->control_pressed) { in.close(); taxMap.clear(); return 0; } - } - in.close(); - - return 0; - } - catch(exception& e) { - m->errorOut(e, "ClassifyTreeCommand", "readTaxonomyFile"); - exit(1); - } -} - -/*****************************************************************/ -int ClassifyTreeCommand::readNamesFile() { - try { - ifstream inNames; - m->openInputFile(namefile, inNames); - - string name, names; - - while(!inNames.eof()){ - inNames >> name; //read from first column A - inNames >> names; //read from second column A,B,C,D - m->gobble(inNames); - - //parse names into vector - vector theseNames; - m->splitAtComma(names, theseNames); - - for (int i = 0; i < theseNames.size(); i++) { nameMap[theseNames[i]] = name; } - nameCount[name] = theseNames.size(); - - if (m->control_pressed) { inNames.close(); nameMap.clear(); return 0; } - } - inNames.close(); - - return 0; - } - catch(exception& e) { - m->errorOut(e, "ClassifyTreeCommand", "readNamesFile"); - exit(1); - } -} - /*****************************************************************/ diff --git a/classifytreecommand.h b/classifytreecommand.h index 30957af..758a438 100644 --- a/classifytreecommand.h +++ b/classifytreecommand.h @@ -22,6 +22,7 @@ public: vector setParameters(); string getCommandName() { return "classify.tree"; } string getCommandCategory() { return "Phylotype Analysis"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Classify.tree"; } string getDescription() { return "Find the consensus taxonomy for the descendant of each tree node"; } @@ -41,8 +42,6 @@ private: int getClassifications(Tree*&); map > getDescendantList(Tree*&, int, map > >); string getTaxonomy(set, int&); - int readNamesFile(); - int readTaxonomyFile(); }; diff --git a/clearcutcommand.cpp b/clearcutcommand.cpp index d3c7fa4..6a0eb25 100644 --- a/clearcutcommand.cpp +++ b/clearcutcommand.cpp @@ -86,7 +86,27 @@ string ClearcutCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string ClearcutCommand::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 == "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); + } +} //********************************************************************************************************************** ClearcutCommand::ClearcutCommand(){ try { @@ -244,7 +264,7 @@ int ClearcutCommand::execute() { if (abort == true) { if (calledHelp) { return 0; } return 2; } //prepare filename - string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + "tre"; + string outputName = outputDir + m->getRootName(m->getSimpleName(inputFile)) + getOutputFileNameTag("tree"); outputNames.push_back(outputName); outputTypes["tree"].push_back(outputName); vector cPara; diff --git a/clearcutcommand.h b/clearcutcommand.h index 942953f..8f3773e 100644 --- a/clearcutcommand.h +++ b/clearcutcommand.h @@ -30,6 +30,7 @@ public: vector setParameters(); string getCommandName() { return "clearcut"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 abdc555..e1f3972 100644 --- a/clearmemorycommand.cpp +++ b/clearmemorycommand.cpp @@ -22,6 +22,25 @@ 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 9017561..1208315 100644 --- a/clearmemorycommand.h +++ b/clearmemorycommand.h @@ -21,6 +21,7 @@ public: vector setParameters(); string getCommandName() { return "clear.memory"; } string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 528f71c..8019def 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -54,6 +54,28 @@ string ClusterCommand::getHelpString(){ } } //********************************************************************************************************************** +string ClusterCommand::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 == "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); + } +} +//********************************************************************************************************************** ClusterCommand::ClusterCommand(){ try { abort = true; calledHelp = true; @@ -287,13 +309,17 @@ int ClusterCommand::execute(){ if (outputDir == "") { outputDir += m->hasPath(distfile); } fileroot = outputDir + m->getRootName(m->getSimpleName(distfile)); - m->openOutputFile(fileroot+ tag + ".sabund", sabundFile); - m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); - m->openOutputFile(fileroot+ tag + ".list", listFile); + string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); + string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); + string listFileName = fileroot+ tag + "." + getOutputFileNameTag("list"); + + m->openOutputFile(sabundFileName, sabundFile); + m->openOutputFile(rabundFileName, rabundFile); + m->openOutputFile(listFileName, listFile); - outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); - outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); - outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list"); + outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName); + outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName); + outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName); time_t estart = time(NULL); diff --git a/clustercommand.h b/clustercommand.h index 268ec31..7349961 100644 --- a/clustercommand.h +++ b/clustercommand.h @@ -34,6 +34,7 @@ public: vector setParameters(); string getCommandName() { return "cluster"; } string getCommandCategory() { return "Clustering"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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. \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 603bd73..9bfb52b 100644 --- a/clusterdoturcommand.cpp +++ b/clusterdoturcommand.cpp @@ -49,6 +49,28 @@ string ClusterDoturCommand::getHelpString(){ } } //********************************************************************************************************************** +string ClusterDoturCommand::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 == "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); + } +} +//********************************************************************************************************************** ClusterDoturCommand::ClusterDoturCommand(){ try { abort = true; calledHelp = true; @@ -201,13 +223,17 @@ int ClusterDoturCommand::execute(){ if (outputDir == "") { outputDir += m->hasPath(phylipfile); } fileroot = outputDir + m->getRootName(m->getSimpleName(phylipfile)); - m->openOutputFile(fileroot+ tag + ".sabund", sabundFile); - m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); - m->openOutputFile(fileroot+ tag + ".list", listFile); - - outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); - outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); - outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list"); + string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); + string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); + string listFileName = fileroot+ tag + "." + getOutputFileNameTag("list"); + + m->openOutputFile(sabundFileName, sabundFile); + m->openOutputFile(rabundFileName, rabundFile); + m->openOutputFile(listFileName, listFile); + + outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName); + outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName); + outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName); float previousDist = 0.00000; float rndPreviousDist = 0.00000; diff --git a/clusterdoturcommand.h b/clusterdoturcommand.h index 643551a..ec2f083 100644 --- a/clusterdoturcommand.h +++ b/clusterdoturcommand.h @@ -27,7 +27,8 @@ public: vector setParameters(); string getCommandName() { return "cluster.classic"; } string getCommandCategory() { return "Clustering"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); string getCitation() { return "Schloss 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"; } string getDescription() { return "cluster your sequences into OTUs using DOTUR’s method"; } diff --git a/clusterfragmentscommand.cpp b/clusterfragmentscommand.cpp index 772113b..4a33841 100644 --- a/clusterfragmentscommand.cpp +++ b/clusterfragmentscommand.cpp @@ -66,6 +66,28 @@ string ClusterFragmentsCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string ClusterFragmentsCommand::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 = "fragclust.fasta"; } + else if (type == "name") { outputFileName = "fragclust.names"; } + 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); + } +} + //********************************************************************************************************************** ClusterFragmentsCommand::ClusterFragmentsCommand(){ try { @@ -230,8 +252,8 @@ int ClusterFragmentsCommand::execute(){ string fileroot = outputDir + m->getRootName(m->getSimpleName(fastafile)); - string newFastaFile = fileroot + "fragclust.fasta"; - string newNamesFile = fileroot + "fragclust.names"; + string newFastaFile = fileroot + getOutputFileNameTag("fasta"); + string newNamesFile = fileroot + getOutputFileNameTag("name"); if (m->control_pressed) { return 0; } diff --git a/clusterfragmentscommand.h b/clusterfragmentscommand.h index c7ea7e0..c322529 100644 --- a/clusterfragmentscommand.h +++ b/clusterfragmentscommand.h @@ -37,6 +37,7 @@ public: vector setParameters(); string getCommandName() { return "cluster.fragments"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 2eee59f..fc0211e 100644 --- a/clustersplitcommand.cpp +++ b/clustersplitcommand.cpp @@ -77,6 +77,29 @@ string ClusterSplitCommand::getHelpString(){ } } //********************************************************************************************************************** +string ClusterSplitCommand::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 == "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); + } +} +//********************************************************************************************************************** ClusterSplitCommand::ClusterSplitCommand(){ try { abort = true; calledHelp = true; @@ -750,14 +773,17 @@ int ClusterSplitCommand::mergeLists(vector listNames, map us if (outputDir == "") { outputDir += m->hasPath(distfile); } fileroot = outputDir + m->getRootName(m->getSimpleName(distfile)); - m->openOutputFile(fileroot+ tag + ".sabund", outSabund); - m->openOutputFile(fileroot+ tag + ".rabund", outRabund); - m->openOutputFile(fileroot+ tag + ".list", outList); - - outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["list"].push_back(fileroot+ tag + ".list"); - outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); - outputNames.push_back(fileroot+ tag + ".list"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); + string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); + string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); + string listFileName = fileroot+ tag + "." + getOutputFileNameTag("list"); + + m->openOutputFile(sabundFileName, outSabund); + m->openOutputFile(rabundFileName, outRabund); + m->openOutputFile(listFileName, outList); + outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName); + outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName); + outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName); map::iterator itLabel; //for each label needed @@ -1331,7 +1357,7 @@ int ClusterSplitCommand::createMergedDistanceFile(vector< map > string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir = m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "dist"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("column"); m->mothurRemove(outputFileName); diff --git a/clustersplitcommand.h b/clustersplitcommand.h index a82d022..28de948 100644 --- a/clustersplitcommand.h +++ b/clustersplitcommand.h @@ -35,6 +35,7 @@ public: vector setParameters(); string getCommandName() { return "cluster.split"; } string getCommandCategory() { return "Clustering"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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. \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 7ad4136..73de2a4 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -81,6 +81,50 @@ string CollectCommand::getHelpString(){ } } //********************************************************************************************************************** +string CollectCommand::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 == "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); + } +} +//********************************************************************************************************************** CollectCommand::CollectCommand(){ try { abort = true; calledHelp = true; @@ -322,80 +366,80 @@ int CollectCommand::execute(){ for (int i=0; i >::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 == "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); + } +} +//********************************************************************************************************************** CollectSharedCommand::CollectSharedCommand(){ try { abort = true; calledHelp = true; @@ -288,122 +346,122 @@ CollectSharedCommand::CollectSharedCommand(string option) { for (int i=0; i setParameters(); string getCommandName() { return "collect.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 22f1181..f5e0904 100644 --- a/command.hpp +++ b/command.hpp @@ -33,6 +33,7 @@ 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. virtual vector setParameters() = 0; //to fill parameters virtual vector getParameters() { return parameters; } diff --git a/commandfactory.cpp b/commandfactory.cpp index 2822d0b..54ff4a1 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -8,9 +8,6 @@ */ #include "command.hpp" -#include "readdistcommand.h" -#include "readtreecommand.h" -#include "readotucommand.h" #include "clustercommand.h" #include "collectcommand.h" #include "collectsharedcommand.h" @@ -136,6 +133,7 @@ #include "getotulabelscommand.h" #include "removeotulabelscommand.h" #include "makecontigscommand.h" +#include "loadlogfilecommand.h" /*******************************************************/ @@ -168,9 +166,6 @@ CommandFactory::CommandFactory(){ append = false; //initialize list of valid commands - commands["read.dist"] = "read.dist"; - commands["read.otu"] = "read.otu"; - commands["read.tree"] = "read.tree"; commands["make.shared"] = "make.shared"; commands["bin.seqs"] = "bin.seqs"; commands["get.oturep"] = "get.oturep"; @@ -293,6 +288,7 @@ CommandFactory::CommandFactory(){ commands["get.otulabels"] = "get.otulabels"; commands["remove.otulabels"] = "remove.otulabels"; commands["make.contigs"] = "make.contigs"; + commands["load.logfile"] = "load.logfile"; commands["quit"] = "MPIEnabled"; } @@ -382,10 +378,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ else { optionString += "inputdir=" + inputDir; } } - if(commandName == "read.dist") { command = new ReadDistCommand(optionString); } - else if(commandName == "read.otu") { command = new ReadOtuCommand(optionString); } - else if(commandName == "read.tree") { command = new ReadTreeCommand(optionString); } - else if(commandName == "cluster") { command = new ClusterCommand(optionString); } + if(commandName == "cluster") { command = new ClusterCommand(optionString); } else if(commandName == "unique.seqs") { command = new DeconvoluteCommand(optionString); } else if(commandName == "parsimony") { command = new ParsimonyCommand(optionString); } else if(commandName == "help") { command = new HelpCommand(optionString); } @@ -508,6 +501,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ else if(commandName == "get.otulabels") { command = new GetOtuLabelsCommand(optionString); } else if(commandName == "remove.otulabels") { command = new RemoveOtuLabelsCommand(optionString); } else if(commandName == "make.contigs") { command = new MakeContigsCommand(optionString); } + else if(commandName == "load.logfile") { command = new LoadLogfileCommand(optionString); } else { command = new NoCommand(optionString); } return command; @@ -539,10 +533,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString, str else { optionString += "inputdir=" + inputDir; } } - if(commandName == "read.dist") { pipecommand = new ReadDistCommand(optionString); } - else if(commandName == "read.otu") { pipecommand = new ReadOtuCommand(optionString); } - else if(commandName == "read.tree") { pipecommand = new ReadTreeCommand(optionString); } - else if(commandName == "cluster") { pipecommand = new ClusterCommand(optionString); } + if(commandName == "cluster") { pipecommand = new ClusterCommand(optionString); } else if(commandName == "unique.seqs") { pipecommand = new DeconvoluteCommand(optionString); } else if(commandName == "parsimony") { pipecommand = new ParsimonyCommand(optionString); } else if(commandName == "help") { pipecommand = new HelpCommand(optionString); } @@ -664,6 +655,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString, str else if(commandName == "get.otulabels") { pipecommand = new GetOtuLabelsCommand(optionString); } else if(commandName == "remove.otulabels") { pipecommand = new RemoveOtuLabelsCommand(optionString); } else if(commandName == "make.contigs") { pipecommand = new MakeContigsCommand(optionString); } + else if(commandName == "load.logfile") { pipecommand = new LoadLogfileCommand(optionString); } else { pipecommand = new NoCommand(optionString); } return pipecommand; @@ -681,10 +673,7 @@ Command* CommandFactory::getCommand(string commandName){ try { delete shellcommand; //delete the old command - if(commandName == "read.dist") { shellcommand = new ReadDistCommand(); } - else if(commandName == "read.otu") { shellcommand = new ReadOtuCommand(); } - else if(commandName == "read.tree") { shellcommand = new ReadTreeCommand(); } - else if(commandName == "cluster") { shellcommand = new ClusterCommand(); } + if(commandName == "cluster") { shellcommand = new ClusterCommand(); } else if(commandName == "unique.seqs") { shellcommand = new DeconvoluteCommand(); } else if(commandName == "parsimony") { shellcommand = new ParsimonyCommand(); } else if(commandName == "help") { shellcommand = new HelpCommand(); } @@ -806,6 +795,7 @@ Command* CommandFactory::getCommand(string commandName){ else if(commandName == "get.otulabels") { shellcommand = new GetOtuLabelsCommand(); } else if(commandName == "remove.otulabels") { shellcommand = new RemoveOtuLabelsCommand(); } else if(commandName == "make.contigs") { shellcommand = new MakeContigsCommand(); } + else if(commandName == "load.logfile") { shellcommand = new LoadLogfileCommand(); } else { shellcommand = new NoCommand(); } return shellcommand; diff --git a/consensusseqscommand.cpp b/consensusseqscommand.cpp index 55ec802..d6158ba 100644 --- a/consensusseqscommand.cpp +++ b/consensusseqscommand.cpp @@ -53,6 +53,28 @@ string ConsensusSeqsCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string ConsensusSeqsCommand::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 = "cons.fasta"; } + else if (type == "name") { outputFileName = "cons.names"; } + 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); + } +} //********************************************************************************************************************** ConsensusSeqsCommand::ConsensusSeqsCommand(){ @@ -194,7 +216,7 @@ int ConsensusSeqsCommand::execute(){ if (listfile == "") { ofstream outSummary; - string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "cons.summary"; + string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("summary"); m->openOutputFile(outputSummaryFile, outSummary); outSummary.setf(ios::fixed, ios::floatfield); outSummary.setf(ios::showpoint); outputNames.push_back(outputSummaryFile); outputTypes["summary"].push_back(outputSummaryFile); @@ -202,7 +224,7 @@ int ConsensusSeqsCommand::execute(){ outSummary << "PositioninAlignment\tA\tT\tG\tC\tGap\tNumberofSeqs\tConsensusBase" << endl; ofstream outFasta; - string outputFastaFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "cons.fasta"; + string outputFastaFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta"); m->openOutputFile(outputFastaFile, outFasta); outputNames.push_back(outputFastaFile); outputTypes["fasta"].push_back(outputFastaFile); @@ -370,18 +392,18 @@ int ConsensusSeqsCommand::processList(ListVector*& list){ try{ ofstream outSummary; - string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + ".cons.summary"; + string outputSummaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + getOutputFileNameTag("summary"); 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() + ".cons.names"; + string outputNameFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + getOutputFileNameTag("name"); 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() + ".cons.fasta"; + string outputFastaFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + list->getLabel() + getOutputFileNameTag("fasta"); m->openOutputFile(outputFastaFile, outFasta); outputNames.push_back(outputFastaFile); outputTypes["fasta"].push_back(outputFastaFile); diff --git a/consensusseqscommand.h b/consensusseqscommand.h index 423c4e4..1459b43 100644 --- a/consensusseqscommand.h +++ b/consensusseqscommand.h @@ -23,6 +23,7 @@ public: vector setParameters(); string getCommandName() { return "consensus.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 e4c915d..00de4d6 100644 --- a/cooccurrencecommand.cpp +++ b/cooccurrencecommand.cpp @@ -51,6 +51,26 @@ string CooccurrenceCommand::getHelpString(){ } } //********************************************************************************************************************** +string CooccurrenceCommand::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 == "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); + } +} +//********************************************************************************************************************** CooccurrenceCommand::CooccurrenceCommand(){ try { abort = true; calledHelp = true; @@ -176,7 +196,7 @@ int CooccurrenceCommand::execute(){ set userLabels = labels; ofstream out; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "cooccurence.summary"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("summary"); 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 8f60e08..530db9e 100644 --- a/cooccurrencecommand.h +++ b/cooccurrencecommand.h @@ -28,6 +28,7 @@ public: vector setParameters(); string getCommandName() { return "Cooccurrence"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://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 c27eb4b..f8083cc 100644 --- a/corraxescommand.cpp +++ b/corraxescommand.cpp @@ -56,12 +56,32 @@ string CorrAxesCommand::getHelpString(){ } } //********************************************************************************************************************** +string CorrAxesCommand::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 == "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); + } +} +//********************************************************************************************************************** CorrAxesCommand::CorrAxesCommand(){ try { abort = true; calledHelp = true; setParameters(); vector tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["corraxes"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "CorrAxesCommand", "CorrAxesCommand"); @@ -92,7 +112,7 @@ CorrAxesCommand::CorrAxesCommand(string option) { } vector tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["corraxes"] = 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); @@ -266,8 +286,8 @@ int CorrAxesCommand::execute(){ // calc the r values // /************************************************************************************/ - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + method + ".corr.axes"; - outputNames.push_back(outputFileName); outputTypes["corr.axes"].push_back(outputFileName); + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + method + "." + getOutputFileNameTag("corraxes"); + outputNames.push_back(outputFileName); outputTypes["corraxes"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); diff --git a/corraxescommand.h b/corraxescommand.h index 2aa7ae0..067228f 100644 --- a/corraxescommand.h +++ b/corraxescommand.h @@ -24,6 +24,7 @@ public: vector setParameters(); string getCommandName() { return "corr.axes"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 0c03882..ccf8988 100644 --- a/countgroupscommand.cpp +++ b/countgroupscommand.cpp @@ -170,7 +170,7 @@ int CountGroupsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //get groups you want to remove - if (accnosfile != "") { readAccnos(); } + if (accnosfile != "") { m->readAccnos(accnosfile, Groups); m->setGroups(Groups); } if (groupfile != "") { GroupMap groupMap(groupfile); @@ -208,31 +208,5 @@ int CountGroupsCommand::execute(){ } } //********************************************************************************************************************** -void CountGroupsCommand::readAccnos(){ - try { - Groups.clear(); - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - Groups.push_back(name); - - m->gobble(in); - } - in.close(); - - m->setGroups(Groups); - - } - catch(exception& e) { - m->errorOut(e, "CountGroupsCommand", "readAccnos"); - exit(1); - } -} -//********************************************************************************************************************** diff --git a/countgroupscommand.h b/countgroupscommand.h index 2532a80..dd0e0a2 100644 --- a/countgroupscommand.h +++ b/countgroupscommand.h @@ -23,6 +23,7 @@ public: vector setParameters(); string getCommandName() { return "count.groups"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Count.groups"; } string getDescription() { return "counts the number of sequences in each group"; } @@ -35,8 +36,6 @@ private: string sharedfile, groupfile, outputDir, groups, accnosfile; bool abort; vector Groups; - - void readAccnos(); }; #endif diff --git a/countseqscommand.cpp b/countseqscommand.cpp index e83c603..8a18fc7 100644 --- a/countseqscommand.cpp +++ b/countseqscommand.cpp @@ -46,7 +46,26 @@ string CountSeqsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string CountSeqsCommand::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 == "summary") { outputFileName = "seq.count"; } + 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); + } +} //********************************************************************************************************************** CountSeqsCommand::CountSeqsCommand(){ try { @@ -147,7 +166,7 @@ int CountSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } ofstream out; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + "seq.count"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("summary"); m->openOutputFile(outputFileName, out); outputTypes["summary"].push_back(outputFileName); out << "Representative_Sequence\ttotal\t"; diff --git a/countseqscommand.h b/countseqscommand.h index 89549a9..54982c1 100644 --- a/countseqscommand.h +++ b/countseqscommand.h @@ -23,6 +23,7 @@ public: vector setParameters(); string getCommandName() { return "count.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 57d5264..febd762 100644 --- a/createdatabasecommand.cpp +++ b/createdatabasecommand.cpp @@ -53,6 +53,27 @@ string CreateDatabaseCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string CreateDatabaseCommand::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 == "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); + } +} + //********************************************************************************************************************** CreateDatabaseCommand::CreateDatabaseCommand(){ try { @@ -244,7 +265,7 @@ int CreateDatabaseCommand::execute(){ if (m->control_pressed) { delete list; if (groupfile != "") { delete groupmap; } return 0; } if (outputDir == "") { outputDir += m->hasPath(listfile); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + "database"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("database"); outputNames.push_back(outputFileName); outputTypes["database"].push_back(outputFileName); ofstream out; diff --git a/createdatabasecommand.h b/createdatabasecommand.h index 37e3013..85e2367 100644 --- a/createdatabasecommand.h +++ b/createdatabasecommand.h @@ -22,6 +22,7 @@ public: vector setParameters(); string getCommandName() { return "create.database"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 3d0c0d5..bab5a63 100644 --- a/deconvolutecommand.cpp +++ b/deconvolutecommand.cpp @@ -45,6 +45,27 @@ string DeconvoluteCommand::getHelpString(){ } } //********************************************************************************************************************** +string DeconvoluteCommand::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 = "unique" + m->getExtension(inputName); } + else if (type == "name") { outputFileName = "names"; } + 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); + } +} +//********************************************************************************************************************** DeconvoluteCommand::DeconvoluteCommand(){ try { abort = true; calledHelp = true; @@ -149,14 +170,14 @@ 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)) + "names"; - string outFastaFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + "unique" + m->getExtension(inFastaName); + string outNameFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + getOutputFileNameTag("name"); + string outFastaFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + getOutputFileNameTag("fasta", inFastaName); map nameMap; map::iterator itNames; if (oldNameMapFName != "") { m->readNames(oldNameMapFName, nameMap); - if (oldNameMapFName == outNameFile){ outNameFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + "unique.names"; } + if (oldNameMapFName == outNameFile){ outNameFile = outputDir + m->getRootName(m->getSimpleName(inFastaName)) + "unique." + getOutputFileNameTag("name"); } } if (m->control_pressed) { return 0; } diff --git a/deconvolutecommand.h b/deconvolutecommand.h index 487c460..7d4cb50 100644 --- a/deconvolutecommand.h +++ b/deconvolutecommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "unique.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 1d83f3b..318a05e 100644 --- a/degapseqscommand.cpp +++ b/degapseqscommand.cpp @@ -46,6 +46,26 @@ string DegapSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** +string DegapSeqsCommand::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 = "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); + } +} +//********************************************************************************************************************** DegapSeqsCommand::DegapSeqsCommand(){ try { abort = true; calledHelp = true; @@ -193,7 +213,7 @@ int DegapSeqsCommand::execute(){ ofstream outFASTA; string tempOutputDir = outputDir; if (outputDir == "") { tempOutputDir = m->hasPath(fastaFileNames[s]); } - string degapFile = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "ng.fasta"; + string degapFile = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("fasta"); m->openOutputFile(degapFile, outFASTA); while(!inFASTA.eof()){ diff --git a/degapseqscommand.h b/degapseqscommand.h index 342cd36..c6adac2 100644 --- a/degapseqscommand.h +++ b/degapseqscommand.h @@ -22,6 +22,7 @@ public: vector setParameters(); string getCommandName() { return "degap.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 7481416..918079c 100644 --- a/deuniqueseqscommand.cpp +++ b/deuniqueseqscommand.cpp @@ -45,6 +45,26 @@ string DeUniqueSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** +string DeUniqueSeqsCommand::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 = "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); + } +} +//********************************************************************************************************************** DeUniqueSeqsCommand::DeUniqueSeqsCommand(){ try { abort = true; calledHelp = true; @@ -148,9 +168,9 @@ int DeUniqueSeqsCommand::execute() { string outFastaFile = m->getRootName(m->getSimpleName(fastaFile)); int pos = outFastaFile.find("unique"); if (pos != string::npos) { - outFastaFile = outputDir + outFastaFile.substr(0, pos) + "redundant" + m->getExtension(fastaFile); + outFastaFile = outputDir + outFastaFile.substr(0, pos) + getOutputFileNameTag("fasta"); }else{ - outFastaFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "redundant" + m->getExtension(fastaFile); + outFastaFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + getOutputFileNameTag("fasta"); } m->openOutputFile(outFastaFile, out); diff --git a/deuniqueseqscommand.h b/deuniqueseqscommand.h index 300a1ca..5310b83 100644 --- a/deuniqueseqscommand.h +++ b/deuniqueseqscommand.h @@ -23,6 +23,7 @@ public: vector setParameters(); string getCommandName() { return "deunique.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 c33c8e4..662282b 100644 --- a/deuniquetreecommand.cpp +++ b/deuniquetreecommand.cpp @@ -43,6 +43,26 @@ string DeuniqueTreeCommand::getHelpString(){ } } //********************************************************************************************************************** +string DeuniqueTreeCommand::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 == "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); + } +} +//********************************************************************************************************************** DeuniqueTreeCommand::DeuniqueTreeCommand(){ try { abort = true; calledHelp = true; @@ -145,7 +165,7 @@ int DeuniqueTreeCommand::execute() { delete reader; //print new Tree - string outputFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + "deunique.tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); ofstream out; m->openOutputFile(outputFile, out); diff --git a/deuniquetreecommand.h b/deuniquetreecommand.h index 18a6e5e..afb25a4 100644 --- a/deuniquetreecommand.h +++ b/deuniquetreecommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "deunique.tree"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 79b8fe7..99e89ba 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -59,6 +59,27 @@ string DistanceCommand::getHelpString(){ } } //********************************************************************************************************************** +string DistanceCommand::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 == "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); + } +} +//********************************************************************************************************************** DistanceCommand::DistanceCommand(){ try { abort = true; calledHelp = true; @@ -229,12 +250,12 @@ int DistanceCommand::execute(){ string outputFile; if (output == "lt") { //does the user want lower triangle phylip formatted file - outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "phylip.dist"; + outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "phylip." + getOutputFileNameTag("phylip"); 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)) + "dist"; + outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("column"); outputTypes["column"].push_back(outputFile); //so we don't accidentally overwrite @@ -245,7 +266,7 @@ int DistanceCommand::execute(){ m->mothurRemove(outputFile); }else { //assume square - outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "square.dist"; + outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "square." + getOutputFileNameTag("phylip"); m->mothurRemove(outputFile); outputTypes["phylip"].push_back(outputFile); } diff --git a/distancecommand.h b/distancecommand.h index 91f0ed5..9dea351 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -178,6 +178,7 @@ public: vector setParameters(); string getCommandName() { return "dist.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 a7d42b3..7a8fbc8 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -57,6 +57,27 @@ string FilterSeqsCommand::getHelpString(){ } } //********************************************************************************************************************** +string FilterSeqsCommand::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 = "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); + } +} +//********************************************************************************************************************** FilterSeqsCommand::FilterSeqsCommand(){ try { abort = true; calledHelp = true; @@ -278,8 +299,8 @@ int FilterSeqsCommand::execute() { //prevent giantic file name string filterFile; - if (fastafileNames.size() > 3) { filterFile = outputDir + "merge.filter"; } - else { filterFile = outputDir + filterFileName + ".filter"; } + if (fastafileNames.size() > 3) { filterFile = outputDir + "merge." + getOutputFileNameTag("filter"); } + else { filterFile = outputDir + filterFileName + "." + getOutputFileNameTag("filter"); } m->openOutputFile(filterFile, outFilter); outFilter << filter << endl; @@ -342,7 +363,7 @@ 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])) + "filter.fasta"; + string filteredFasta = outputDir + m->getRootName(m->getSimpleName(fastafileNames[s])) + getOutputFileNameTag("fasta"); #ifdef USE_MPI int pid, numSeqsPerProcessor, num; int tag = 2001; diff --git a/filterseqscommand.h b/filterseqscommand.h index 4405c33..b232237 100644 --- a/filterseqscommand.h +++ b/filterseqscommand.h @@ -24,6 +24,7 @@ public: vector setParameters(); string getCommandName() { return "filter.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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.h b/getcommandinfocommand.h index 463c94c..b72c236 100644 --- a/getcommandinfocommand.h +++ b/getcommandinfocommand.h @@ -27,6 +27,7 @@ public: vector setParameters(); string getCommandName() { return "get.commandinfo"; } string getCommandCategory() { return "Hidden"; } + string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); string getCitation() { return "no citation"; } string getDescription() { return "get.commandinfo"; } diff --git a/getcoremicrobiomecommand.cpp b/getcoremicrobiomecommand.cpp index 47dc963..63af3ab 100644 --- a/getcoremicrobiomecommand.cpp +++ b/getcoremicrobiomecommand.cpp @@ -51,6 +51,27 @@ string GetCoreMicroBiomeCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string GetCoreMicroBiomeCommand::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 == "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); + } +} + //********************************************************************************************************************** GetCoreMicroBiomeCommand::GetCoreMicroBiomeCommand(){ try { @@ -287,7 +308,7 @@ int GetCoreMicroBiomeCommand::execute(){ int GetCoreMicroBiomeCommand::createTable(vector& lookup){ try { - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + ".core.microbiome"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + getOutputFileNameTag("coremicrobiome"); outputNames.push_back(outputFileName); outputTypes["coremicrobiome"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/getcoremicrobiomecommand.h b/getcoremicrobiomecommand.h index c8aaab3..469214c 100644 --- a/getcoremicrobiomecommand.h +++ b/getcoremicrobiomecommand.h @@ -26,7 +26,8 @@ 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 getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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.h b/getcurrentcommand.h index dfff0fa..f10e6d4 100644 --- a/getcurrentcommand.h +++ b/getcurrentcommand.h @@ -22,7 +22,8 @@ class GetCurrentCommand : public Command { vector setParameters(); string getCommandName() { return "get.current"; } string getCommandCategory() { return "General"; } - string getHelpString(); + string getOutputFileNameTag(string, string) { return ""; } + string getHelpString(); 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 8dae3f3..faef2ac 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -31,7 +31,6 @@ string GetgroupCommand::getHelpString(){ try { string helpString = ""; helpString += "The get.group command parameter is shared and it's required if you have no valid current file.\n"; - //m->mothurOut("The get.group command outputs a .bootGroups file to you can use in addition to the tree file generated by the bootstrap.shared command to run the consensus command.\n"); helpString += "You may not use any parameters with the get.group command.\n"; helpString += "The get.group command should be in the following format: \n"; helpString += "get.group()\n"; @@ -43,13 +42,12 @@ string GetgroupCommand::getHelpString(){ exit(1); } } + //********************************************************************************************************************** GetgroupCommand::GetgroupCommand(){ try { abort = true; calledHelp = true; setParameters(); - vector tempOutNames; - outputTypes["bootgroup"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); @@ -78,10 +76,6 @@ GetgroupCommand::GetgroupCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - //initialize outputTypes - vector tempOutNames; - outputTypes["bootgroup"] = 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); if (inputDir == "not found"){ inputDir = ""; } @@ -122,27 +116,17 @@ int GetgroupCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - - //open output file - outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "bootGroups"; - m->openOutputFile(outputFile, out); - + InputData input(sharedfile, "sharedfile"); vector lookup = input.getSharedRAbundVectors(); for (int i = 0; i < lookup.size(); i++) { - out << lookup[i]->getGroup() << '\t' << lookup[i]->getGroup() << endl; m->mothurOut(lookup[i]->getGroup()); m->mothurOutEndLine(); delete lookup[i]; } - - out.close(); - - if (m->control_pressed) { m->mothurRemove(outputFile); return 0; } - + m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - m->mothurOut(outputFile); m->mothurOutEndLine(); outputNames.push_back(outputFile); outputTypes["bootgroup"].push_back(outputFile); m->mothurOutEndLine(); return 0; @@ -153,5 +137,6 @@ int GetgroupCommand::execute(){ exit(1); } } +//********************************************************************************************************************** diff --git a/getgroupcommand.h b/getgroupcommand.h index a3e47e0..7924d7b 100644 --- a/getgroupcommand.h +++ b/getgroupcommand.h @@ -21,6 +21,7 @@ public: vector setParameters(); string getCommandName() { return "get.group"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); 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 5ed31dd..fe6f571 100644 --- a/getgroupscommand.cpp +++ b/getgroupscommand.cpp @@ -57,6 +57,33 @@ string GetGroupsCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string GetGroupsCommand::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 = "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 == "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); + } +} + //********************************************************************************************************************** GetGroupsCommand::GetGroupsCommand(){ try { @@ -293,7 +320,7 @@ int GetGroupsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //get groups you want to remove - if (accnosfile != "") { readAccnos(); } + if (accnosfile != "") { m->readAccnos(accnosfile, Groups); m->setGroups(Groups); } if (groupfile != "") { groupMap = new GroupMap(groupfile); @@ -385,7 +412,7 @@ int GetGroupsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); ofstream out; m->openOutputFile(outputFileName, out); @@ -453,7 +480,7 @@ int GetGroupsCommand::readShared(){ while(lookup[0] != NULL) { - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + ".pick" + m->getExtension(sharedfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("shared", sharedfile); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); @@ -498,7 +525,7 @@ int GetGroupsCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -591,7 +618,7 @@ int GetGroupsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); ofstream out; m->openOutputFile(outputFileName, out); @@ -672,7 +699,7 @@ int GetGroupsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -719,7 +746,7 @@ int GetGroupsCommand::readDesign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(designfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + "pick" + m->getExtension(designfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + getOutputFileNameTag("design", designfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -769,7 +796,7 @@ int GetGroupsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -814,32 +841,6 @@ int GetGroupsCommand::readTax(){ } } //********************************************************************************************************************** -void GetGroupsCommand::readAccnos(){ - try { - Groups.clear(); - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - Groups.push_back(name); - - m->gobble(in); - } - in.close(); - - m->setGroups(Groups); - - } - catch(exception& e) { - m->errorOut(e, "GetGroupsCommand", "readAccnos"); - exit(1); - } -} -//********************************************************************************************************************** int GetGroupsCommand::fillNames(){ try { vector seqs = groupMap->getNamesSeqs(); diff --git a/getgroupscommand.h b/getgroupscommand.h index 224f4f0..80230b4 100644 --- a/getgroupscommand.h +++ b/getgroupscommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "get.groups"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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"; } @@ -47,7 +48,6 @@ private: int readFasta(); int readName(); int readGroup(); - void readAccnos(); int readList(); int readTax(); int fillNames(); diff --git a/getlabelcommand.h b/getlabelcommand.h index c5dc1a1..7a4d9b5 100644 --- a/getlabelcommand.h +++ b/getlabelcommand.h @@ -24,6 +24,7 @@ public: vector setParameters(); string getCommandName() { return "get.label"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Get.label"; } string getDescription() { return "outputs labels"; } diff --git a/getlineagecommand.cpp b/getlineagecommand.cpp index c2be580..1aba0fe 100644 --- a/getlineagecommand.cpp +++ b/getlineagecommand.cpp @@ -57,7 +57,31 @@ string GetLineageCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string GetLineageCommand::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 = "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 == "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); + } +} //********************************************************************************************************************** GetLineageCommand::GetLineageCommand(){ try { @@ -298,7 +322,7 @@ int GetLineageCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); ofstream out; m->openOutputFile(outputFileName, out); @@ -345,7 +369,7 @@ int GetLineageCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -417,7 +441,7 @@ int GetLineageCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); ofstream out; m->openOutputFile(outputFileName, out); @@ -503,7 +527,7 @@ int GetLineageCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -550,7 +574,7 @@ int GetLineageCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -739,7 +763,7 @@ int GetLineageCommand::readAlign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport"); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/getlineagecommand.h b/getlineagecommand.h index a677061..0ab042b 100644 --- a/getlineagecommand.h +++ b/getlineagecommand.h @@ -23,7 +23,8 @@ class GetLineageCommand : public Command { vector setParameters(); string getCommandName() { return "get.lineage"; } string getCommandCategory() { return "Phylotype Analysis"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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 980c886..b7c4f17 100644 --- a/getlistcountcommand.cpp +++ b/getlistcountcommand.cpp @@ -49,6 +49,26 @@ string GetListCountCommand::getHelpString(){ } } //********************************************************************************************************************** +string GetListCountCommand::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 == "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); + } +} +//********************************************************************************************************************** GetListCountCommand::GetListCountCommand(){ try { abort = true; calledHelp = true; @@ -234,7 +254,7 @@ void GetListCountCommand::process(ListVector* list) { try { string binnames; if (outputDir == "") { outputDir += m->hasPath(listfile); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + list->getLabel() + ".otu"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + list->getLabel() + "." +getOutputFileNameTag("otu"); m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["otu"].push_back(outputFileName); diff --git a/getlistcountcommand.h b/getlistcountcommand.h index 7a0c109..629e9b9 100644 --- a/getlistcountcommand.h +++ b/getlistcountcommand.h @@ -28,6 +28,7 @@ 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(); int execute(); diff --git a/getotulabelscommand.cpp b/getotulabelscommand.cpp index 40ad69f..a281f9f 100644 --- a/getotulabelscommand.cpp +++ b/getotulabelscommand.cpp @@ -46,14 +46,36 @@ string GetOtuLabelsCommand::getHelpString(){ } } //********************************************************************************************************************** +string GetOtuLabelsCommand::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 == "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); + } +} +//********************************************************************************************************************** GetOtuLabelsCommand::GetOtuLabelsCommand(){ try { abort = true; calledHelp = true; setParameters(); vector tempOutNames; - outputTypes["contaxonomy"] = tempOutNames; - outputTypes["otu.corr"] = tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["constaxonomy"] = tempOutNames; + outputTypes["otucorr"] = tempOutNames; + outputTypes["corraxes"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "GetOtuLabelsCommand", "GetOtuLabelsCommand"); @@ -126,9 +148,9 @@ GetOtuLabelsCommand::GetOtuLabelsCommand(string option) { } vector tempOutNames; - outputTypes["contaxonomy"] = tempOutNames; - outputTypes["otu.corr"] = tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["constaxonomy"] = tempOutNames; + outputTypes["otucorr"] = tempOutNames; + outputTypes["corraxes"] = tempOutNames; //check for parameters accnosfile = validParameter.validFile(parameters, "accnos", true); @@ -175,7 +197,7 @@ int GetOtuLabelsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //get labels you want to keep - readAccnos(); + labels = m->readAccnos(accnosfile); if (m->control_pressed) { return 0; } @@ -204,7 +226,7 @@ int GetOtuLabelsCommand::readClassifyOtu(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(constaxonomyfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + "pick.taxonomy"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + getOutputFileNameTag("constaxonomy"); ofstream out; m->openOutputFile(outputFileName, out); @@ -255,7 +277,7 @@ int GetOtuLabelsCommand::readOtuAssociation(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(otucorrfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + "pick.corr"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + getOutputFileNameTag("otucorr"); ofstream out; m->openOutputFile(outputFileName, out); @@ -289,7 +311,7 @@ int GetOtuLabelsCommand::readOtuAssociation(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any labels from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); outputTypes["otu.corr"].push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); m->mothurOut("Selected " + toString(selectedCount) + " lines from your otu.corr file."); m->mothurOutEndLine(); @@ -306,7 +328,7 @@ int GetOtuLabelsCommand::readCorrAxes(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(corraxesfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + "pick.axes"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + getOutputFileNameTag("corraxes"); ofstream out; m->openOutputFile(outputFileName, out); @@ -340,7 +362,7 @@ int GetOtuLabelsCommand::readCorrAxes(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file does not contain any labels from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); outputTypes["corr.axes"].push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["corraxes"].push_back(outputFileName); m->mothurOut("Selected " + toString(selectedCount) + " lines from your corr.axes file."); m->mothurOutEndLine(); @@ -352,30 +374,4 @@ int GetOtuLabelsCommand::readCorrAxes(){ exit(1); } } - -//********************************************************************************************************************** -int GetOtuLabelsCommand::readAccnos(){ - try { - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - labels.insert(name); - - m->gobble(in); - } - in.close(); - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "GetOtuLabelsCommand", "readAccnos"); - exit(1); - } -} //********************************************************************************************************************** diff --git a/getotulabelscommand.h b/getotulabelscommand.h index bad0f55..8cfe8b9 100644 --- a/getotulabelscommand.h +++ b/getotulabelscommand.h @@ -23,7 +23,8 @@ public: vector setParameters(); string getCommandName() { return "get.otulabels"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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."; } @@ -39,8 +40,6 @@ private: int readClassifyOtu(); int readOtuAssociation(); int readCorrAxes(); - int readAccnos(); - }; /**************************************************************************************************/ diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 35437e7..4ebde29 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -95,6 +95,27 @@ string GetOTURepCommand::getHelpString(){ } } //********************************************************************************************************************** +string GetOTURepCommand::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 = "rep.fasta"; } + else if (type == "name") { outputFileName = "rep.names"; } + 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); + } +} +//********************************************************************************************************************** GetOTURepCommand::GetOTURepCommand(){ try { abort = true; calledHelp = true; @@ -771,7 +792,7 @@ int GetOTURepCommand::process(ListVector* processList) { map filehandles; if (Groups.size() == 0) { //you don't want to use groups - outputNamesFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + ".rep.names"; + outputNamesFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." + getOutputFileNameTag("name"); m->openOutputFile(outputNamesFile, newNamesOutput); outputNames.push_back(outputNamesFile); outputTypes["name"].push_back(outputNamesFile); outputNameFiles[outputNamesFile] = processList->getLabel(); @@ -780,7 +801,7 @@ int GetOTURepCommand::process(ListVector* processList) { for (int i=0; igetRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." + Groups[i] + ".rep.names"; + outputNamesFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + processList->getLabel() + "." + Groups[i] + "." + getOutputFileNameTag("name"); m->openOutputFile(outputNamesFile, *(temp)); outputNames.push_back(outputNamesFile); outputTypes["name"].push_back(outputNamesFile); @@ -868,7 +889,7 @@ 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 + ".rep.fasta"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + label + "." + getOutputFileNameTag("fasta"); m->openOutputFile(outputFileName, out); vector reps; outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName); diff --git a/getoturepcommand.h b/getoturepcommand.h index 4168000..5af0340 100644 --- a/getoturepcommand.h +++ b/getoturepcommand.h @@ -43,6 +43,7 @@ public: vector setParameters(); string getCommandName() { return "get.oturep"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 4e8d319..8d20e63 100644 --- a/getotuscommand.cpp +++ b/getotuscommand.cpp @@ -53,7 +53,27 @@ string GetOtusCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string GetOtusCommand::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 == "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); + } +} //********************************************************************************************************************** GetOtusCommand::GetOtusCommand(){ try { @@ -182,7 +202,7 @@ int GetOtusCommand::execute(){ groupMap->readMap(); //get groups you want to get - if (accnosfile != "") { readAccnos(); } + if (accnosfile != "") { m->readAccnos(accnosfile, Groups); m->setGroups(Groups); } //make sure groups are valid //takes care of user setting groupNames that are invalid or setting groups=all @@ -231,14 +251,14 @@ int GetOtusCommand::readListGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick." + label + m->getExtension(listfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + label + "." + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); string GroupOutputDir = outputDir; if (outputDir == "") { GroupOutputDir += m->hasPath(groupfile); } - string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick." + label + m->getExtension(groupfile); + string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + label + "." + getOutputFileNameTag("group", groupfile); ofstream outGroup; m->openOutputFile(outputGroupFileName, outGroup); @@ -400,29 +420,5 @@ int GetOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstream } } //********************************************************************************************************************** -void GetOtusCommand::readAccnos(){ - try { - Groups.clear(); - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - Groups.push_back(name); - - m->gobble(in); - } - in.close(); - - } - catch(exception& e) { - m->errorOut(e, "GetOtusCommand", "readAccnos"); - exit(1); - } -} -//********************************************************************************************************************** diff --git a/getotuscommand.h b/getotuscommand.h index 1a78493..4eff4b6 100644 --- a/getotuscommand.h +++ b/getotuscommand.h @@ -27,6 +27,7 @@ public: vector setParameters(); string getCommandName() { return "get.otus"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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"; } @@ -42,7 +43,6 @@ private: vector outputNames, Groups; GroupMap* groupMap; - void readAccnos(); int readListGroup(); int processList(ListVector*&, GroupMap*&, ofstream&, ofstream&, bool&); diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index 5a33253..5f33f3a 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -47,7 +47,26 @@ string GetRAbundCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string GetRAbundCommand::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 == "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); + } +} //********************************************************************************************************************** GetRAbundCommand::GetRAbundCommand(){ try { @@ -173,7 +192,7 @@ int GetRAbundCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "rabund"; + filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("rabund"); m->openOutputFile(filename, out); input = new InputData(inputfile, format); diff --git a/getrabundcommand.h b/getrabundcommand.h index cb9e270..7e93630 100644 --- a/getrabundcommand.h +++ b/getrabundcommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "get.rabund"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 8c8d8e1..7c623fb 100644 --- a/getrelabundcommand.cpp +++ b/getrelabundcommand.cpp @@ -49,6 +49,26 @@ string GetRelAbundCommand::getHelpString(){ } } //********************************************************************************************************************** +string GetRelAbundCommand::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 == "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); + } +} +//********************************************************************************************************************** GetRelAbundCommand::GetRelAbundCommand(){ try { abort = true; calledHelp = true; @@ -154,7 +174,7 @@ int GetRelAbundCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "relabund"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("relabund"); 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 1d5163d..c5b50e6 100644 --- a/getrelabundcommand.h +++ b/getrelabundcommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "get.relabund"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 4ae2eaa..5425c41 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -45,7 +45,26 @@ string GetSAbundCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string GetSAbundCommand::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 == "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); + } +} //********************************************************************************************************************** GetSAbundCommand::GetSAbundCommand(){ try { @@ -166,7 +185,7 @@ int GetSAbundCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "sabund"; + filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("sabund"); m->openOutputFile(filename, out); input = new InputData(inputfile, format); diff --git a/getsabundcommand.h b/getsabundcommand.h index 5be00df..4c967b5 100644 --- a/getsabundcommand.h +++ b/getsabundcommand.h @@ -24,6 +24,7 @@ public: vector setParameters(); string getCommandName() { return "get.sabund"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 84fe0ac..ccabafb 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -76,6 +76,33 @@ GetSeqsCommand::GetSeqsCommand(){ } } //********************************************************************************************************************** +string GetSeqsCommand::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 = "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 == "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); + } +} +//********************************************************************************************************************** GetSeqsCommand::GetSeqsCommand(string option) { try { abort = false; calledHelp = false; @@ -270,7 +297,7 @@ int GetSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //get names you want to keep - readAccnos(); + names = m->readAccnos(accnosfile); if (m->control_pressed) { return 0; } @@ -343,7 +370,7 @@ int GetSeqsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); ofstream out; m->openOutputFile(outputFileName, out); @@ -399,7 +426,7 @@ int GetSeqsCommand::readQual(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + "pick" + m->getExtension(qualfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -471,7 +498,7 @@ int GetSeqsCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -550,7 +577,7 @@ int GetSeqsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); ofstream out; m->openOutputFile(outputFileName, out); @@ -650,7 +677,7 @@ int GetSeqsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -706,7 +733,7 @@ int GetSeqsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -760,7 +787,7 @@ int GetSeqsCommand::readAlign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport"); ofstream out; m->openOutputFile(outputFileName, out); @@ -827,32 +854,6 @@ int GetSeqsCommand::readAlign(){ } } //********************************************************************************************************************** - -int GetSeqsCommand::readAccnos(){ - try { - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - names.insert(name); - - m->gobble(in); - } - in.close(); - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "GetSeqsCommand", "readAccnos"); - exit(1); - } -} -//********************************************************************************************************************** //just looking at common mistakes. int GetSeqsCommand::runSanityCheck(){ try { @@ -952,7 +953,7 @@ int GetSeqsCommand::compareAccnos(){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(accnosfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(accnosfile)) + "accnos.report"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(accnosfile)) + getOutputFileNameTag("accnosreport"); ofstream out; m->openOutputFile(outputFileName, out); @@ -1045,7 +1046,7 @@ int GetSeqsCommand::compareAccnos(){ } catch(exception& e) { - m->errorOut(e, "GetSeqsCommand", "readAccnos"); + m->errorOut(e, "GetSeqsCommand", "compareAccnos"); exit(1); } } diff --git a/getseqscommand.h b/getseqscommand.h index 0f606ff..c71b5f2 100644 --- a/getseqscommand.h +++ b/getseqscommand.h @@ -23,7 +23,8 @@ class GetSeqsCommand : public Command { vector setParameters(); string getCommandName() { return "get.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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"; } @@ -44,7 +45,6 @@ class GetSeqsCommand : public Command { int readName(); int readGroup(); int readAlign(); - int readAccnos(); int readList(); int readTax(); int readQual(); diff --git a/getsharedotucommand.cpp b/getsharedotucommand.cpp index 02d8413..9beca6a 100644 --- a/getsharedotucommand.cpp +++ b/getsharedotucommand.cpp @@ -58,6 +58,29 @@ string GetSharedOTUCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string GetSharedOTUCommand::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 = "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); + } +} + //********************************************************************************************************************** GetSharedOTUCommand::GetSharedOTUCommand(){ try { @@ -372,9 +395,9 @@ int GetSharedOTUCommand::process(ListVector* shared) { if (outputDir == "") { outputDir += m->hasPath(listfile); } if (output != "accnos") { - outputFileNames = outputDir + m->getRootName(m->getSimpleName(listfile)) + shared->getLabel() + userGroups + ".shared.seqs"; + outputFileNames = outputDir + m->getRootName(m->getSimpleName(listfile)) + shared->getLabel() + userGroups + "." + getOutputFileNameTag("sharedseqs"); }else { - outputFileNames = outputDir + m->getRootName(m->getSimpleName(listfile)) + shared->getLabel() + userGroups + ".accnos"; + outputFileNames = outputDir + m->getRootName(m->getSimpleName(listfile)) + shared->getLabel() + userGroups + "." + getOutputFileNameTag("accnos"); } m->openOutputFile(outputFileNames, outNames); @@ -481,7 +504,7 @@ 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 + ".shared.fasta"; + string outputFileFasta = outputDir + m->getRootName(m->getSimpleName(fastafile)) + shared->getLabel() + userGroups + "." + getOutputFileNameTag("fasta"); ofstream outFasta; m->openOutputFile(outputFileFasta, outFasta); outputNames.push_back(outputFileFasta); outputTypes["fasta"].push_back(outputFileFasta); diff --git a/getsharedotucommand.h b/getsharedotucommand.h index ea6ed94..e2026d7 100644 --- a/getsharedotucommand.h +++ b/getsharedotucommand.h @@ -28,7 +28,8 @@ class GetSharedOTUCommand : public Command { string getCommandName() { return "get.sharedseqs"; } string getCommandCategory() { return "OTU-Based Approaches"; } string getRequiredCommand() { return "none"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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 4713693..cf35cd9 100644 --- a/hclustercommand.cpp +++ b/hclustercommand.cpp @@ -52,6 +52,28 @@ string HClusterCommand::getHelpString(){ } } //********************************************************************************************************************** +string HClusterCommand::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 == "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); + } +} +//********************************************************************************************************************** HClusterCommand::HClusterCommand(){ try { abort = true; calledHelp = true; @@ -219,13 +241,17 @@ HClusterCommand::HClusterCommand(string option) { else if (method == "weighted") { tag = "wn"; } else { tag = "an"; } - m->openOutputFile(fileroot+ tag + ".sabund", sabundFile); - m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); - m->openOutputFile(fileroot+ tag + ".list", listFile); - - outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); - outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); - outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list"); + string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); + string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); + string listFileName = fileroot+ tag + "." + getOutputFileNameTag("list"); + + m->openOutputFile(sabundFileName, sabundFile); + m->openOutputFile(rabundFileName, rabundFile); + m->openOutputFile(listFileName, listFile); + + outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName); + outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName); + outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName); } } } diff --git a/hclustercommand.h b/hclustercommand.h index aeeb3bc..6bf559a 100644 --- a/hclustercommand.h +++ b/hclustercommand.h @@ -38,6 +38,7 @@ public: vector setParameters(); string getCommandName() { return "hcluster"; } string getCommandCategory() { return "Clustering"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 7d9b482..d160525 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -61,6 +61,28 @@ string HeatMapCommand::getHelpString(){ } } +//********************************************************************************************************************** + +string HeatMapCommand::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 == "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); + } +} + //********************************************************************************************************************** HeatMapCommand::HeatMapCommand(){ try { diff --git a/heatmapcommand.h b/heatmapcommand.h index ccd5f48..58eaa36 100644 --- a/heatmapcommand.h +++ b/heatmapcommand.h @@ -28,6 +28,7 @@ public: vector setParameters(); string getCommandName() { return "heatmap.bin"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 de35075..3de10e6 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -72,6 +72,28 @@ string HeatMapSimCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** + +string HeatMapSimCommand::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 == "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); + } +} + //********************************************************************************************************************** HeatMapSimCommand::HeatMapSimCommand(){ try { diff --git a/heatmapsimcommand.h b/heatmapsimcommand.h index 74e20be..7b74880 100644 --- a/heatmapsimcommand.h +++ b/heatmapsimcommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "heatmap.sim"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 cba0708..31dbd2b 100644 --- a/helpcommand.h +++ b/helpcommand.h @@ -25,6 +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 getCitation() { return "no citation"; } string getDescription() { return "help"; } diff --git a/homovacommand.cpp b/homovacommand.cpp index 9b7ec9f..006f1e4 100644 --- a/homovacommand.cpp +++ b/homovacommand.cpp @@ -49,9 +49,27 @@ string HomovaCommand::getHelpString(){ exit(1); } } - //********************************************************************************************************************** - +string HomovaCommand::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 == "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); + } +} +//********************************************************************************************************************** HomovaCommand::HomovaCommand(){ try { abort = true; calledHelp = true; @@ -190,7 +208,7 @@ int HomovaCommand::execute(){ //create a new filename ofstream HOMOVAFile; - string HOMOVAFileName = outputDir + m->getRootName(m->getSimpleName(phylipFileName)) + "homova"; + string HOMOVAFileName = outputDir + m->getRootName(m->getSimpleName(phylipFileName)) + getOutputFileNameTag("homova"); m->openOutputFile(HOMOVAFileName, HOMOVAFile); outputNames.push_back(HOMOVAFileName); outputTypes["homova"].push_back(HOMOVAFileName); diff --git a/homovacommand.h b/homovacommand.h index 4afaeb8..b6f2109 100644 --- a/homovacommand.h +++ b/homovacommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "homova"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 8d1d7f7..f98620b 100644 --- a/indicatorcommand.cpp +++ b/indicatorcommand.cpp @@ -57,7 +57,27 @@ string IndicatorCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string IndicatorCommand::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 == "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); + } +} //********************************************************************************************************************** IndicatorCommand::IndicatorCommand(){ try { @@ -385,7 +405,7 @@ int IndicatorCommand::GetIndicatorSpecies(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(inputFileName); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(inputFileName)) + "indicator.summary"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(inputFileName)) + getOutputFileNameTag("summary"); outputNames.push_back(outputFileName); outputTypes["summary"].push_back(outputFileName); ofstream out; @@ -500,7 +520,7 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(inputFileName); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(inputFileName)) + "indicator.summary"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(inputFileName)) + getOutputFileNameTag("summary"); outputNames.push_back(outputFileName); outputTypes["summary"].push_back(outputFileName); ofstream out; @@ -520,7 +540,7 @@ int IndicatorCommand::GetIndicatorSpecies(Tree*& T){ string treeOutputDir = outputDir; if (outputDir == "") { treeOutputDir += m->hasPath(treefile); } - string outputTreeFileName = treeOutputDir + m->getRootName(m->getSimpleName(treefile)) + "indicator.tre"; + string outputTreeFileName = treeOutputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("tree"); //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 c5112e6..2c36c35 100644 --- a/indicatorcommand.h +++ b/indicatorcommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "indicator"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 1d1d41f..7f8cd9b 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -65,6 +65,27 @@ string LibShuffCommand::getHelpString(){ } } //********************************************************************************************************************** +string LibShuffCommand::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 == "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); + } +} +//********************************************************************************************************************** LibShuffCommand::LibShuffCommand(){ try { abort = true; calledHelp = true; @@ -341,7 +362,7 @@ int LibShuffCommand::printCoverageFile() { try { ofstream outCov; - summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "libshuff.coverage"; + summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("coverage"); m->openOutputFile(summaryFile, outCov); outputNames.push_back(summaryFile); outputTypes["coverage"].push_back(summaryFile); outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint); @@ -437,7 +458,7 @@ int LibShuffCommand::printSummaryFile() { try { ofstream outSum; - summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "libshuff.summary"; + summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("libshuffsummary"); m->openOutputFile(summaryFile, outSum); outputNames.push_back(summaryFile); outputTypes["libshuffsummary"].push_back(summaryFile); diff --git a/libshuffcommand.h b/libshuffcommand.h index 465a67f..81ae17a 100644 --- a/libshuffcommand.h +++ b/libshuffcommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "libshuff"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 93b1510..4a12197 100644 --- a/listotulabelscommand.cpp +++ b/listotulabelscommand.cpp @@ -46,6 +46,27 @@ string ListOtuLabelsCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string ListOtuLabelsCommand::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 == "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); + } +} + //********************************************************************************************************************** ListOtuLabelsCommand::ListOtuLabelsCommand(){ try { @@ -344,7 +365,7 @@ int ListOtuLabelsCommand::execute(){ int ListOtuLabelsCommand::createList(vector& lookup){ try { - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + ".otu.labels"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("otulabels"); outputNames.push_back(outputFileName); outputTypes["otulabels"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); @@ -366,7 +387,7 @@ int ListOtuLabelsCommand::createList(vector& lookup){ int ListOtuLabelsCommand::createList(vector& lookup){ try { - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + ".otu.labels"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("otulabels"); outputNames.push_back(outputFileName); outputTypes["accnos"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/listotulabelscommand.h b/listotulabelscommand.h index dbfd5d4..1b10331 100644 --- a/listotulabelscommand.h +++ b/listotulabelscommand.h @@ -25,7 +25,8 @@ 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 getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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 afbacc0..bfbb078 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -49,7 +49,26 @@ string ListSeqsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string ListSeqsCommand::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 == "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); + } +} //********************************************************************************************************************** ListSeqsCommand::ListSeqsCommand(){ try { @@ -214,7 +233,7 @@ int ListSeqsCommand::execute(){ if (outputDir == "") { outputDir += m->hasPath(inputFileName); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + "accnos"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + getOutputFileNameTag("accnos"); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/listseqscommand.h b/listseqscommand.h index f814d84..1a31a6d 100644 --- a/listseqscommand.h +++ b/listseqscommand.h @@ -23,7 +23,8 @@ class ListSeqsCommand : public Command { vector setParameters(); string getCommandName() { return "list.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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 new file mode 100644 index 0000000..66eb7b6 --- /dev/null +++ b/loadlogfilecommand.cpp @@ -0,0 +1,251 @@ +// +// loadlogfilecommand.cpp +// Mothur +// +// Created by Sarah Westcott on 6/13/12. +// Copyright (c) 2012 Schloss Lab. All rights reserved. +// + +#include "loadlogfilecommand.h" +#include "commandoptionparser.hpp" +#include "commandfactory.hpp" +#include "setcurrentcommand.h" + +//********************************************************************************************************************** +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); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } + return myArray; + } + catch(exception& e) { + m->errorOut(e, "LoadLogfileCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string LoadLogfileCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The load.logfile command extracts the current file names from a logfile.\n"; + helpString += "The load.logfile parameter is logfile, and it is required.\n"; + helpString += "The load.logfile command should be in the following format: \n"; + helpString += "load.logfile(logfile=yourLogFile)\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "LoadLogfileCommand", "getHelpString"); + exit(1); + } +} +//********************************************************************************************************************** +LoadLogfileCommand::LoadLogfileCommand(){ + try { + abort = true; calledHelp = true; + setParameters(); + } + catch(exception& e) { + m->errorOut(e, "LoadLogfileCommand", "LoadLogfileCommand"); + exit(1); + } +} +//********************************************************************************************************************** +LoadLogfileCommand::LoadLogfileCommand(string option) { + try { + abort = false; calledHelp = false; + + //allow user to run help + if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} + + else { + //valid paramters for this command + vector myArray = setParameters(); + + OptionParser parser(option); + map parameters = parser.getParameters(); + + ValidParameters validParameter; + map::iterator it; + //check to make sure all parameters are valid for command + for (it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } + } + + //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); + if (inputDir == "not found"){ inputDir = ""; } + else { + + string path; + it = parameters.find("logfile"); + //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["logfile"] = inputDir + it->second; } + } + + } + + //get shared file, it is required + logfile = validParameter.validFile(parameters, "logfile", true); + if (logfile == "not open") { logfile = ""; abort = true; } + else if (logfile == "not found") { m->mothurOut("The logfile parameter is required."); m->mothurOutEndLine();abort = true; } + + //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(logfile); //if user entered a file with a path then preserve it + } + } + + } + catch(exception& e) { + m->errorOut(e, "NewCommand", "NewCommand"); + exit(1); + } +} +//********************************************************************************************************************** + +int LoadLogfileCommand::execute(){ + try { + + if (abort == true) { if (calledHelp) { return 0; } return 2; } + + m->mothurOutEndLine(); + m->mothurOut("Extracting current files names..."); m->mothurOutEndLine(); + m->mothurOutEndLine(); + + CommandFactory* cFactory; + cFactory = CommandFactory::getInstance(); + + ifstream in; + m->openInputFile(logfile, in); + + set currentTypes = m->getCurrentTypes(); + map currentFiles; + string commandName = ""; + bool skip = false; + string line = ""; + + while (!in.eof()) { + if (m->control_pressed) { break; } + + if (!skip) { line = m->getline(in); m->gobble(in); } + m->gobble(in); + + //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("*****************"); + + //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("*****************"); + if (posTemp != string::npos) { break; } + } + } + + if (pos != string::npos) { + skip=false; + //extract command name and option string + string input = line.substr(pos+9); + CommandOptionParser parser(input); + commandName = parser.getCommandString(); + string options = parser.getOptionString(); + + //parse out parameters in option string + map parameters; + OptionParser optionParser(options, parameters); + + for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + if (currentTypes.count((it->first)) != 0) { //if this is a type we save + if (it->second != "current") { currentFiles[it->first] = it->second; }//save the input file name as current + } + } + }else if (pos2 != string::npos) { + //read file output file names + vector theseOutputNames; + while (!in.eof()) { + if (m->control_pressed) { break; } + line = m->getline(in); m->gobble(in); + int pos = line.find("mothur > "); + if (pos != string::npos) { skip = true; break; } + else { theseOutputNames.push_back(line); } + } + //ask command for the output names for each type based on inputs + 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 + map::iterator itCurrentFiles = currentFiles.find(it->first); + 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; + } + } + } + } + } + } + in.close(); + + if (m->control_pressed) { return 0; } + + //output results + string inputString = ""; + for (map::iterator it = currentFiles.begin(); it != currentFiles.end(); it++) { inputString += it->first + "=" + it->second + ","; } + + if (inputString != "") { + inputString = inputString.substr(0, inputString.length()-1); + m->mothurOutEndLine(); + m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + m->mothurOut("Running command: set.current(" + inputString + ")"); m->mothurOutEndLine(); + m->mothurCalling = true; + + Command* currentCommand = new SetCurrentCommand(inputString); + currentCommand->execute(); + + delete currentCommand; + m->mothurCalling = false; + m->mothurOut("/******************************************/"); m->mothurOutEndLine(); + + + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "LoadLogfileCommand", "execute"); + exit(1); + } +} +//********************************************************************************************************************** + + diff --git a/loadlogfilecommand.h b/loadlogfilecommand.h new file mode 100644 index 0000000..0fd82a8 --- /dev/null +++ b/loadlogfilecommand.h @@ -0,0 +1,45 @@ +#ifndef Mothur_loadlogfilecommand_h +#define Mothur_loadlogfilecommand_h + +// +// loadlogfilecommand.h +// Mothur +// +// Created by Sarah Westcott on 6/13/12. +// Copyright (c) 2012 Schloss Lab. All rights reserved. +// + + +#include "command.hpp" + +/**************************************************************************************************/ + +class LoadLogfileCommand : public Command { +public: + LoadLogfileCommand(string); + LoadLogfileCommand(); + ~LoadLogfileCommand(){} + + vector setParameters(); + string getCommandName() { return "load.logfile"; } + string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string) { return ""; } + string getHelpString(); + string getCitation() { return "http://www.mothur.org/wiki/Load.logfile"; } + string getDescription() { return "extracts current files from a logfile"; } + + int execute(); + void help() { m->mothurOut(getHelpString()); } + +private: + bool abort; + string outputDir, logfile; + vector outputNames; +}; + +/**************************************************************************************************/ + + + + +#endif diff --git a/makebiomcommand.cpp b/makebiomcommand.cpp index 03e7baf..9e8d3e3 100644 --- a/makebiomcommand.cpp +++ b/makebiomcommand.cpp @@ -129,6 +129,27 @@ string MakeBiomCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string MakeBiomCommand::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 == "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); + } +} + //********************************************************************************************************************** MakeBiomCommand::MakeBiomCommand(){ try { @@ -352,7 +373,7 @@ int MakeBiomCommand::execute(){ int MakeBiomCommand::getBiom(vector& lookup){ try { - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + ".biom"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("biom"); ofstream out; m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["biom"].push_back(outputFileName); diff --git a/makebiomcommand.h b/makebiomcommand.h index 9f80c2e..8a458fe 100644 --- a/makebiomcommand.h +++ b/makebiomcommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "make.biom"; } string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 523edd5..ed2f05d 100644 --- a/makecontigscommand.cpp +++ b/makecontigscommand.cpp @@ -56,7 +56,28 @@ string MakeContigsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string MakeContigsCommand::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 = "contigs.fasta"; } + else if (type == "qfile") { outputFileName = "contigs.qual"; } + 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); + } +} //********************************************************************************************************************** MakeContigsCommand::MakeContigsCommand(){ try { @@ -189,9 +210,9 @@ int MakeContigsCommand::execute(){ if (m->control_pressed) { return 0; } - string outFastaFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + "contigs.fasta"; - string outQualFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + "contigs.qual"; - string outMisMatchFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + "contigs.mismatches"; + string outFastaFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + getOutputFileNameTag("fasta"); + string outQualFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + getOutputFileNameTag("qfile"); + string outMisMatchFile = outputDir + m->getRootName(m->getSimpleName(ffastqfile)) + getOutputFileNameTag("mismatches"); outputNames.push_back(outFastaFile); outputTypes["fasta"].push_back(outFastaFile); outputNames.push_back(outQualFile); outputTypes["qfile"].push_back(outQualFile); outputNames.push_back(outMisMatchFile); outputTypes["mismatch"].push_back(outMisMatchFile); diff --git a/makecontigscommand.h b/makecontigscommand.h index cc08842..dc094a2 100644 --- a/makecontigscommand.h +++ b/makecontigscommand.h @@ -41,7 +41,8 @@ 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 getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Make.contigs"; } string getDescription() { return "description"; } diff --git a/makefastqcommand.cpp b/makefastqcommand.cpp index 0f6e030..c6dcf2c 100644 --- a/makefastqcommand.cpp +++ b/makefastqcommand.cpp @@ -46,6 +46,26 @@ string MakeFastQCommand::getHelpString(){ } } //********************************************************************************************************************** +string MakeFastQCommand::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 == "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); + } +} +//********************************************************************************************************************** MakeFastQCommand::MakeFastQCommand(){ try { abort = true; calledHelp = true; @@ -145,7 +165,7 @@ int MakeFastQCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "fastq"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fastq"); outputNames.push_back(outputFile); outputTypes["fastq"].push_back(outputFile); ofstream out; diff --git a/makefastqcommand.h b/makefastqcommand.h index 1c209aa..9119ebd 100644 --- a/makefastqcommand.h +++ b/makefastqcommand.h @@ -24,6 +24,7 @@ public: vector setParameters(); string getCommandName() { return "make.fastq"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Make.fastq"; } string getDescription() { return "creates a fastq file from a fasta and quality file"; } diff --git a/makegroupcommand.cpp b/makegroupcommand.cpp index 0add62e..77c2a29 100644 --- a/makegroupcommand.cpp +++ b/makegroupcommand.cpp @@ -48,6 +48,26 @@ string MakeGroupCommand::getHelpString(){ } } //********************************************************************************************************************** +string MakeGroupCommand::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 == "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); + } +} +//********************************************************************************************************************** MakeGroupCommand::MakeGroupCommand(){ try { abort = true; calledHelp = true; @@ -165,8 +185,8 @@ MakeGroupCommand::MakeGroupCommand(string option) { } //prevent giantic file name - if (fastaFileNames.size() > 3) { filename = outputDir + "merge.groups"; } - else { filename += "groups"; } + if (fastaFileNames.size() > 3) { filename = outputDir + "merge." + getOutputFileNameTag("group"); } + else { filename += getOutputFileNameTag("group"); } //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 e0c7092..b8521d7 100644 --- a/makegroupcommand.h +++ b/makegroupcommand.h @@ -22,6 +22,7 @@ public: vector setParameters(); string getCommandName() { return "make.group"; } string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 409eae4..f3259e6 100644 --- a/mantelcommand.cpp +++ b/mantelcommand.cpp @@ -50,6 +50,26 @@ string MantelCommand::getHelpString(){ } } //********************************************************************************************************************** +string MantelCommand::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 == "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); + } +} +//********************************************************************************************************************** MantelCommand::MantelCommand(){ try { abort = true; calledHelp = true; @@ -206,7 +226,7 @@ int MantelCommand::execute(){ if (m->control_pressed) { return 0; } - string outputFile = outputDir + m->getRootName(m->getSimpleName(phylipfile1)) + "mantel"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(phylipfile1)) + getOutputFileNameTag("mantel"); outputNames.push_back(outputFile); outputTypes["mantel"].push_back(outputFile); ofstream out; diff --git a/mantelcommand.h b/mantelcommand.h index 0a2c404..644d9b2 100644 --- a/mantelcommand.h +++ b/mantelcommand.h @@ -22,6 +22,7 @@ public: vector setParameters(); string getCommandName() { return "mantel"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 e1c8a98..4b92c57 100644 --- a/matrixoutputcommand.cpp +++ b/matrixoutputcommand.cpp @@ -61,6 +61,26 @@ string MatrixOutputCommand::getHelpString(){ } } //********************************************************************************************************************** +string MatrixOutputCommand::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 == "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); + } +} +//********************************************************************************************************************** MatrixOutputCommand::MatrixOutputCommand(){ try { abort = true; calledHelp = true; @@ -653,7 +673,7 @@ int MatrixOutputCommand::process(vector thisLookup){ matrix[column][row] = dist; } - string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist"; + string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + "." + getOutputFileNameTag("phylip"); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outDist; m->openOutputFile(distFileName, outDist); @@ -757,7 +777,7 @@ int MatrixOutputCommand::process(vector thisLookup){ stdmatrix[column][row] = stdDist; } - string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".ave.dist"; + string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".ave." + getOutputFileNameTag("phylip"); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outAve; m->openOutputFile(distFileName, outAve); @@ -767,7 +787,7 @@ int MatrixOutputCommand::process(vector thisLookup){ outAve.close(); - distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".std.dist"; + distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".std." + getOutputFileNameTag("phylip"); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outSTD; m->openOutputFile(distFileName, outSTD); diff --git a/matrixoutputcommand.h b/matrixoutputcommand.h index 594fe30..ff05ef7 100644 --- a/matrixoutputcommand.h +++ b/matrixoutputcommand.h @@ -73,6 +73,7 @@ public: vector setParameters(); string getCommandName() { return "dist.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 04c92fa..0501859 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -41,7 +41,6 @@ string MergeFileCommand::getHelpString(){ exit(1); } } - //********************************************************************************************************************** MergeFileCommand::MergeFileCommand(){ try { @@ -130,29 +129,10 @@ int MergeFileCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - ofstream outputFile; - m->openOutputFile(outputFileName, outputFile); - - char c; - for(int i=0;iopenInputFile(fileNames[i], inputFile); - - while(!inputFile.eof()){ - if (m->control_pressed) { outputTypes.clear(); inputFile.close(); outputFile.close(); m->mothurRemove(outputFileName); return 0; } - - c = inputFile.get(); - //-1 is eof char - if (int(c) != -1) { outputFile << c; } - } - - inputFile.close(); - } - - outputFile.close(); + m->mothurRemove(outputFileName); + for(int i=0;iappendFiles(fileNames[i], outputFileName); } - if (m->control_pressed) { outputTypes.clear(); m->mothurRemove(outputFileName); return 0; } + if (m->control_pressed) { m->mothurRemove(outputFileName); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); diff --git a/mergefilecommand.h b/mergefilecommand.h index 1c3c4d5..9cb999b 100644 --- a/mergefilecommand.h +++ b/mergefilecommand.h @@ -22,6 +22,7 @@ public: vector setParameters(); string getCommandName() { return "merge.files"; } string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); 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 e30558c..5a67220 100644 --- a/mergegroupscommand.cpp +++ b/mergegroupscommand.cpp @@ -53,6 +53,27 @@ string MergeGroupsCommand::getHelpString(){ } } //********************************************************************************************************************** +string MergeGroupsCommand::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 == "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); + } +} +//********************************************************************************************************************** MergeGroupsCommand::MergeGroupsCommand(){ try { abort = true; calledHelp = true; @@ -284,8 +305,8 @@ int MergeGroupsCommand::processSharedFile(GroupMap*& designMap){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "merge" + m->getExtension(sharedfile); - outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("shared", sharedfile); + outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); @@ -387,7 +408,7 @@ int MergeGroupsCommand::processGroupFile(GroupMap*& designMap){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "merge" + m->getExtension(groupfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; diff --git a/mergegroupscommand.h b/mergegroupscommand.h index 7f216eb..4db3447 100644 --- a/mergegroupscommand.h +++ b/mergegroupscommand.h @@ -24,6 +24,7 @@ public: vector setParameters(); string getCommandName() { return "merge.groups"; } string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 c5d349b..b5b01e7 100644 --- a/metastatscommand.cpp +++ b/metastatscommand.cpp @@ -60,6 +60,27 @@ string MetaStatsCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string MetaStatsCommand::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 == "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); + } +} + //********************************************************************************************************************** MetaStatsCommand::MetaStatsCommand(){ try { @@ -449,7 +470,7 @@ 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 + ".metastats"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + thisLookUp[0]->getLabel() + "." + setA + "-" + setB + "." + getOutputFileNameTag("metastats"); 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 b4800b7..377adf1 100644 --- a/metastatscommand.h +++ b/metastatscommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "metastats"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 9c45afe..870536d 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -61,6 +61,28 @@ string MGClusterCommand::getHelpString(){ } } //********************************************************************************************************************** +string MGClusterCommand::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 == "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); + } +} +//********************************************************************************************************************** MGClusterCommand::MGClusterCommand(){ try { abort = true; calledHelp = true; @@ -223,10 +245,13 @@ int MGClusterCommand::execute(){ else if (method == "nearest") { tag = "nn"; } else { tag = "an"; } - //open output files - m->openOutputFile(fileroot+ tag + ".list", listFile); - m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); - m->openOutputFile(fileroot+ tag + ".sabund", sabundFile); + string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); + string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); + string listFileName = fileroot+ tag + "." + getOutputFileNameTag("list"); + + m->openOutputFile(sabundFileName, sabundFile); + m->openOutputFile(rabundFileName, rabundFile); + m->openOutputFile(listFileName, listFile); if (m->control_pressed) { delete nameMap; delete read; delete list; delete rabund; @@ -493,9 +518,9 @@ int MGClusterCommand::execute(){ m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); - m->mothurOut(fileroot+ tag + ".list"); m->mothurOutEndLine(); outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list"); - m->mothurOut(fileroot+ tag + ".rabund"); m->mothurOutEndLine(); outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); - m->mothurOut(fileroot+ tag + ".sabund"); m->mothurOutEndLine(); outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); + m->mothurOut(listFileName); m->mothurOutEndLine(); outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName); + m->mothurOut(rabundFileName); m->mothurOutEndLine(); outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName); + m->mothurOut(sabundFileName); m->mothurOutEndLine(); outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName); m->mothurOutEndLine(); if (saveCutoff != cutoff) { diff --git a/mgclustercommand.h b/mgclustercommand.h index df0c526..ea2c1de 100644 --- a/mgclustercommand.h +++ b/mgclustercommand.h @@ -31,6 +31,7 @@ public: vector setParameters(); string getCommandName() { return "mgcluster"; } string getCommandCategory() { return "Clustering"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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/mothurout.cpp b/mothurout.cpp index f98bea8..eacad37 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -18,8 +18,45 @@ MothurOut* MothurOut::getInstance() { return _uniqueInstance; } /*********************************************************************************************/ +set MothurOut::getCurrentTypes() { + try { + + set types; + types.insert("fasta"); + types.insert("accnos"); + types.insert("column"); + types.insert("design"); + types.insert("group"); + types.insert("list"); + types.insert("name"); + types.insert("oligos"); + types.insert("order"); + types.insert("ordergroup"); + types.insert("phylip"); + types.insert("qfile"); + types.insert("relabund"); + types.insert("sabund"); + types.insert("rabund"); + types.insert("sff"); + types.insert("shared"); + types.insert("taxonomy"); + types.insert("tree"); + types.insert("flow"); + types.insert("biom"); + types.insert("processors"); + + return types; + } + catch(exception& e) { + errorOut(e, "MothurOut", "getCurrentTypes"); + exit(1); + } +} +/*********************************************************************************************/ void MothurOut::printCurrentFiles() { try { + + if (accnosfile != "") { mothurOut("accnos=" + accnosfile); mothurOutEndLine(); } if (columnfile != "") { mothurOut("column=" + columnfile); mothurOutEndLine(); } if (designfile != "") { mothurOut("design=" + designfile); mothurOutEndLine(); } @@ -1477,7 +1514,163 @@ vector MothurOut::splitWhiteSpace(string& rest, char buffer[], int size) return pieces; } catch(exception& e) { - errorOut(e, "MothurOut", "parsePieces"); + errorOut(e, "MothurOut", "splitWhiteSpace"); + exit(1); + } +} +/***********************************************************************/ +vector MothurOut::splitWhiteSpace(string input){ + try { + vector pieces; + string rest = ""; + + for (int i = 0; i < input.length(); i++) { + if (!isspace(input[i])) { rest += input[i]; } + else { + pieces.push_back(rest); rest = ""; + while (i < input.length()) { //gobble white space + if (isspace(input[i])) { i++; } + else { rest = input[i]; break; } //cout << "next piece buffer = " << nextPiece << endl; + } + } + } + + if (rest != "") { pieces.push_back(rest); } + + return pieces; + } + catch(exception& e) { + errorOut(e, "MothurOut", "splitWhiteSpace"); + exit(1); + } +} +//********************************************************************************************************************** +int MothurOut::readTax(string namefile, map& taxMap) { + try { + + //open input file + ifstream in; + openInputFile(namefile, in); + + string rest = ""; + char buffer[4096]; + bool pairDone = false; + bool columnOne = true; + string firstCol, secondCol; + + while (!in.eof()) { + if (control_pressed) { break; } + + in.read(buffer, 4096); + vector pieces = splitWhiteSpace(rest, buffer, in.gcount()); + + for (int i = 0; i < pieces.size(); i++) { + if (columnOne) { firstCol = pieces[i]; columnOne=false; } + else { secondCol = pieces[i]; pairDone = true; columnOne=true; } + + if (pairDone) { + //are there confidence scores, if so remove them + if (secondCol.find_first_of('(') != -1) { removeConfidences(secondCol); } + taxMap[firstCol] = secondCol; + if (debug) { mothurOut("[DEBUG]: name = '" + firstCol + "' tax = '" + secondCol + "'\n"); } + pairDone = false; + } + } + } + in.close(); + + return taxMap.size(); + + } + catch(exception& e) { + errorOut(e, "MothurOut", "readTax"); + exit(1); + } +} +/**********************************************************************************************************************/ +int MothurOut::readNames(string namefile, map& nameMap, bool redund) { + try { + + //open input file + ifstream in; + openInputFile(namefile, in); + + string rest = ""; + char buffer[4096]; + bool pairDone = false; + bool columnOne = true; + string firstCol, secondCol; + + while (!in.eof()) { + if (control_pressed) { break; } + + in.read(buffer, 4096); + vector pieces = splitWhiteSpace(rest, buffer, in.gcount()); + + for (int i = 0; i < pieces.size(); i++) { + if (columnOne) { firstCol = pieces[i]; columnOne=false; } + else { secondCol = pieces[i]; pairDone = true; columnOne=true; } + + if (pairDone) { + //parse names into vector + vector theseNames; + splitAtComma(secondCol, theseNames); + for (int i = 0; i < theseNames.size(); i++) { nameMap[theseNames[i]] = firstCol; } + pairDone = false; + } + } + } + in.close(); + + return nameMap.size(); + + } + catch(exception& e) { + errorOut(e, "MothurOut", "readNames"); + exit(1); + } +} +/**********************************************************************************************************************/ +int MothurOut::readNames(string namefile, map& nameMap, map& nameCount) { + try { + nameMap.clear(); nameCount.clear(); + //open input file + ifstream in; + openInputFile(namefile, in); + + string rest = ""; + char buffer[4096]; + bool pairDone = false; + bool columnOne = true; + string firstCol, secondCol; + + while (!in.eof()) { + if (control_pressed) { break; } + + in.read(buffer, 4096); + vector pieces = splitWhiteSpace(rest, buffer, in.gcount()); + + for (int i = 0; i < pieces.size(); i++) { + if (columnOne) { firstCol = pieces[i]; columnOne=false; } + else { secondCol = pieces[i]; pairDone = true; columnOne=true; } + + if (pairDone) { + //parse names into vector + vector theseNames; + splitAtComma(secondCol, theseNames); + for (int i = 0; i < theseNames.size(); i++) { nameMap[theseNames[i]] = firstCol; } + nameCount[firstCol] = theseNames.size(); + pairDone = false; + } + } + } + in.close(); + + return nameMap.size(); + + } + catch(exception& e) { + errorOut(e, "MothurOut", "readNames"); exit(1); } } @@ -1652,7 +1845,62 @@ int MothurOut::readNames(string namefile, vector& nameVector, m exit(1); } } - +//********************************************************************************************************************** +set MothurOut::readAccnos(string accnosfile){ + try { + set names; + ifstream in; + openInputFile(accnosfile, in); + string name; + + string rest = ""; + char buffer[4096]; + + while (!in.eof()) { + if (control_pressed) { break; } + + in.read(buffer, 4096); + vector pieces = splitWhiteSpace(rest, buffer, in.gcount()); + + for (int i = 0; i < pieces.size(); i++) { names.insert(pieces[i]); } + } + in.close(); + + return names; + } + catch(exception& e) { + errorOut(e, "MothurOut", "readAccnos"); + exit(1); + } +} +//********************************************************************************************************************** +int MothurOut::readAccnos(string accnosfile, vector& names){ + try { + names.clear(); + ifstream in; + openInputFile(accnosfile, in); + string name; + + string rest = ""; + char buffer[4096]; + + while (!in.eof()) { + if (control_pressed) { break; } + + in.read(buffer, 4096); + vector pieces = splitWhiteSpace(rest, buffer, in.gcount()); + + for (int i = 0; i < pieces.size(); i++) { names.push_back(pieces[i]); } + } + in.close(); + + return 0; + } + catch(exception& e) { + errorOut(e, "MothurOut", "readAccnos"); + exit(1); + } +} /***********************************************************************/ int MothurOut::getNumNames(string names){ diff --git a/mothurout.h b/mothurout.h index b19c05a..b2c638a 100644 --- a/mothurout.h +++ b/mothurout.h @@ -98,8 +98,14 @@ class MothurOut { void gobble(istream&); void gobble(istringstream&); vector splitWhiteSpace(string& rest, char[], int); - map readNames(string); + vector splitWhiteSpace(string); + set readAccnos(string); + int readAccnos(string, vector&); + map readNames(string); + int readTax(string, map&); + int readNames(string, map&, map&); int readNames(string, map&); + int readNames(string, map&, bool); int readNames(string, map >&); int readNames(string, vector&, map&); int mothurRemove(string); @@ -145,7 +151,7 @@ class MothurOut { int control_pressed; bool executing, runParse, jumble, gui, mothurCalling, debug; - //current files - if you add a new type you must edit optionParser->getParameters, get.current command and mothurOut->printCurrentFiles/clearCurrentFiles. + //current files - if you add a new type you must edit optionParser->getParameters, get.current command and mothurOut->printCurrentFiles/clearCurrentFiles/getCurrentTypes. string getPhylipFile() { return phylipfile; } string getColumnFile() { return columnfile; } string getListFile() { return listfile; } @@ -190,11 +196,12 @@ class MothurOut { void setTaxonomyFile(string f) { taxonomyfile = getFullPathName(f); } void setFlowFile(string f) { flowfile = getFullPathName(f); } void setBiomFile(string f) { biomfile = getFullPathName(f); } - void setProcessors(string p) { processors = p; } + void setProcessors(string p) { processors = p; mothurOut("\nUsing " + toString(p) + " processors.\n"); } void printCurrentFiles(); bool hasCurrentFiles(); void clearCurrentFiles(); + set getCurrentTypes(); private: static MothurOut* _uniqueInstance; diff --git a/newcommandtemplate.cpp b/newcommandtemplate.cpp index 9299206..085039e 100644 --- a/newcommandtemplate.cpp +++ b/newcommandtemplate.cpp @@ -64,6 +64,28 @@ string NewCommand::getHelpString(){ } } //********************************************************************************************************************** +string NewCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string tag = ""; + 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 == "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); + } +} +//********************************************************************************************************************** NewCommand::NewCommand(){ try { abort = true; calledHelp = true; @@ -71,7 +93,7 @@ NewCommand::NewCommand(){ vector tempOutNames; outputTypes["fileType1"] = tempOutNames; //filetypes should be things like: shared, fasta, accnos... outputTypes["fileType2"] = tempOutNames; - outputTypes["FileType2"] = tempOutNames; + outputTypes["FileType3"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "NewCommand", "NewCommand"); diff --git a/newcommandtemplate.h b/newcommandtemplate.h index 5fd36b1..ae57bd8 100644 --- a/newcommandtemplate.h +++ b/newcommandtemplate.h @@ -35,8 +35,9 @@ public: vector setParameters(); string getCommandName() { return "newCommandNameToBeSeenByUser"; } string getCommandCategory() { return "commandCategory"; } + string getOutputFileNameTag(string, 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 e2a3712..900f50b 100644 --- a/nmdscommand.cpp +++ b/nmdscommand.cpp @@ -55,6 +55,28 @@ string NMDSCommand::getHelpString(){ } } //********************************************************************************************************************** +string NMDSCommand::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 == "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); + } +} +//********************************************************************************************************************** NMDSCommand::NMDSCommand(){ try { abort = true; calledHelp = true; @@ -186,8 +208,8 @@ int NMDSCommand::execute(){ vector< vector > axes; if (axesfile != "") { axes = readAxes(names); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "nmds.iters"; - string stressFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "nmds.stress"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("iters"); + string stressFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("stress"); outputNames.push_back(outputFileName); outputTypes["iters"].push_back(outputFileName); outputNames.push_back(stressFileName); outputTypes["stress"].push_back(stressFileName); @@ -256,7 +278,7 @@ int NMDSCommand::execute(){ out.close(); out2.close(); //output best config - string BestFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "nmds.axes"; + string BestFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("nmds"); 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 c05c9fe..90364ad 100644 --- a/nmdscommand.h +++ b/nmdscommand.h @@ -37,6 +37,7 @@ public: vector setParameters(); string getCommandName() { return "nmds"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 5ed7e12..a5855dc 100644 --- a/nocommands.h +++ b/nocommands.h @@ -21,12 +21,13 @@ public: NoCommand() {} ~NoCommand(){} - vector setParameters() { return outputNames; } //dummy, doesn't really do anything - string getCommandName() { return "NoCommand"; } - string getCommandCategory() { return "Hidden"; } - string getHelpString() { return "No Command"; } - string getCitation() { return "no citation"; } - string getDescription() { return "no description"; } + vector setParameters() { return outputNames; } //dummy, doesn't really do anything + string getCommandName() { return "NoCommand"; } + string getCommandCategory() { return "Hidden"; } + string getHelpString() { return "No Command"; } + string getOutputFileNameTag(string, string) { return ""; } + string getCitation() { return "no citation"; } + string getDescription() { return "no description"; } int execute(); diff --git a/normalizesharedcommand.cpp b/normalizesharedcommand.cpp index bbf9a83..e41cfd9 100644 --- a/normalizesharedcommand.cpp +++ b/normalizesharedcommand.cpp @@ -54,7 +54,26 @@ string NormalizeSharedCommand::getHelpString(){ } } - +//********************************************************************************************************************** +string NormalizeSharedCommand::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 == "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); + } +} //********************************************************************************************************************** NormalizeSharedCommand::NormalizeSharedCommand(){ try { @@ -449,7 +468,7 @@ int NormalizeSharedCommand::normalize(vector& thisLookUp){ if (pickedGroups) { eliminateZeroOTUS(thisLookUp); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + ".norm.shared"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + "." + getOutputFileNameTag("shared"); ofstream out; m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName); @@ -540,7 +559,7 @@ 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() + ".norm.shared"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + "." + getOutputFileNameTag("shared"); ofstream out; m->openOutputFile(outputFileName, out); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName); diff --git a/normalizesharedcommand.h b/normalizesharedcommand.h index 4b6f7fd..2feb40d 100644 --- a/normalizesharedcommand.h +++ b/normalizesharedcommand.h @@ -24,6 +24,7 @@ public: vector setParameters(); string getCommandName() { return "normalize.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Normalize.shared"; } string getDescription() { return "normalize samples in a shared or relabund file"; } diff --git a/optionparser.cpp b/optionparser.cpp index 0d6ed2d..2d13cd0 100644 --- a/optionparser.cpp +++ b/optionparser.cpp @@ -38,7 +38,37 @@ OptionParser::OptionParser(string option) { exit(1); } } +/***********************************************************************/ +OptionParser::OptionParser(string option, map& copy) { + try { + m = MothurOut::getInstance(); + if (option != "") { + + string key, value; + //reads in parameters and values + while((option.find_first_of(',') != -1)) { //while there are parameters + m->splitAtComma(value, option); + m->splitAtEquals(key, value); + if ((key == "candidate") || (key == "query")) { key = "fasta"; } + if (key == "template") { key = "reference"; } + parameters[key] = value; + } + + //in case there is no comma and to get last parameter after comma + m->splitAtEquals(key, option); + if ((key == "candidate") || (key == "query")) { key = "fasta"; } + if (key == "template") { key = "reference"; } + parameters[key] = option; + } + + copy = parameters; + } + catch(exception& e) { + m->errorOut(e, "OptionParser", "OptionParser"); + exit(1); + } +} /***********************************************************************/ map OptionParser::getParameters() { @@ -47,65 +77,66 @@ map OptionParser::getParameters() { //loop through parameters and look for "current" so you can return the appropriate file //doing it here to avoid code duplication in each of the commands - map::iterator it; - for (it = parameters.begin(); it != parameters.end();) { - - if (it->second == "current") { - - //look for file types - if (it->first == "fasta") { - it->second = m->getFastaFile(); - }else if (it->first == "qfile") { - it->second = m->getQualFile(); - }else if (it->first == "phylip") { - it->second = m->getPhylipFile(); - }else if (it->first == "column") { - it->second = m->getColumnFile(); - }else if (it->first == "list") { - it->second = m->getListFile(); - }else if (it->first == "rabund") { - it->second = m->getRabundFile(); - }else if (it->first == "sabund") { - it->second = m->getSabundFile(); - }else if (it->first == "name") { - it->second = m->getNameFile(); - }else if (it->first == "group") { - it->second = m->getGroupFile(); - }else if (it->first == "order") { - it->second = m->getOrderFile(); - }else if (it->first == "ordergroup") { - it->second = m->getOrderGroupFile(); - }else if (it->first == "tree") { - it->second = m->getTreeFile(); - }else if (it->first == "shared") { - it->second = m->getSharedFile(); - }else if (it->first == "relabund") { - it->second = m->getRelAbundFile(); - }else if (it->first == "design") { - it->second = m->getDesignFile(); - }else if (it->first == "sff") { - it->second = m->getSFFFile(); - }else if (it->first == "oligos") { - it->second = m->getOligosFile(); - }else if (it->first == "accnos") { - it->second = m->getAccnosFile(); - }else if (it->first == "taxonomy") { - it->second = m->getTaxonomyFile(); - }else if (it->first == "biom") { + + map::iterator it; + for (it = parameters.begin(); it != parameters.end();) { + + if (it->second == "current") { + + //look for file types + if (it->first == "fasta") { + it->second = m->getFastaFile(); + }else if (it->first == "qfile") { + it->second = m->getQualFile(); + }else if (it->first == "phylip") { + it->second = m->getPhylipFile(); + }else if (it->first == "column") { + it->second = m->getColumnFile(); + }else if (it->first == "list") { + it->second = m->getListFile(); + }else if (it->first == "rabund") { + it->second = m->getRabundFile(); + }else if (it->first == "sabund") { + it->second = m->getSabundFile(); + }else if (it->first == "name") { + it->second = m->getNameFile(); + }else if (it->first == "group") { + it->second = m->getGroupFile(); + }else if (it->first == "order") { + it->second = m->getOrderFile(); + }else if (it->first == "ordergroup") { + it->second = m->getOrderGroupFile(); + }else if (it->first == "tree") { + it->second = m->getTreeFile(); + }else if (it->first == "shared") { + it->second = m->getSharedFile(); + }else if (it->first == "relabund") { + it->second = m->getRelAbundFile(); + }else if (it->first == "design") { + it->second = m->getDesignFile(); + }else if (it->first == "sff") { + it->second = m->getSFFFile(); + }else if (it->first == "oligos") { + it->second = m->getOligosFile(); + }else if (it->first == "accnos") { + it->second = m->getAccnosFile(); + }else if (it->first == "taxonomy") { + it->second = m->getTaxonomyFile(); + }else if (it->first == "biom") { it->second = m->getBiomFile(); - }else { - m->mothurOut("[ERROR]: mothur does not save a current file for " + it->first); m->mothurOutEndLine(); - } - - if (it->second == "") { //no file was saved for that type, warn and remove from parameters - m->mothurOut("[WARNING]: no file was saved for " + it->first + " parameter."); m->mothurOutEndLine(); - parameters.erase(it++); - }else { - m->mothurOut("Using " + it->second + " as input file for the " + it->first + " parameter."); m->mothurOutEndLine(); - it++; - } - }else{ it++; } - } + }else { + m->mothurOut("[ERROR]: mothur does not save a current file for " + it->first); m->mothurOutEndLine(); + } + + if (it->second == "") { //no file was saved for that type, warn and remove from parameters + m->mothurOut("[WARNING]: no file was saved for " + it->first + " parameter."); m->mothurOutEndLine(); + parameters.erase(it++); + }else { + m->mothurOut("Using " + it->second + " as input file for the " + it->first + " parameter."); m->mothurOutEndLine(); + it++; + } + }else{ it++; } + } return parameters; } diff --git a/optionparser.h b/optionparser.h index facd1f8..044299d 100644 --- a/optionparser.h +++ b/optionparser.h @@ -21,6 +21,7 @@ class OptionParser { public: OptionParser(string); + OptionParser(string, map&); ~OptionParser() {} map getParameters(); bool getNameFile(vector); diff --git a/otuassociationcommand.cpp b/otuassociationcommand.cpp index 93f46ba..06f83a4 100644 --- a/otuassociationcommand.cpp +++ b/otuassociationcommand.cpp @@ -53,12 +53,32 @@ string OTUAssociationCommand::getHelpString(){ } } //********************************************************************************************************************** +string OTUAssociationCommand::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 == "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); + } +} +//********************************************************************************************************************** OTUAssociationCommand::OTUAssociationCommand(){ try { abort = true; calledHelp = true; setParameters(); vector tempOutNames; - outputTypes["otu.corr"] = tempOutNames; + outputTypes["otucorr"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "OTUAssociationCommand", "OTUAssociationCommand"); @@ -90,7 +110,7 @@ OTUAssociationCommand::OTUAssociationCommand(string option) { } vector tempOutNames; - outputTypes["otu.corr"] = tempOutNames; + outputTypes["otucorr"] = 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); @@ -306,8 +326,8 @@ int OTUAssociationCommand::processShared(){ int OTUAssociationCommand::process(vector& lookup){ try { - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + method + ".otu.corr"; - outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName); + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + method + "." + getOutputFileNameTag("otucorr"); + outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); @@ -466,8 +486,8 @@ int OTUAssociationCommand::processRelabund(){ int OTUAssociationCommand::process(vector& lookup){ try { - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + method + ".otu.corr"; - outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName); + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + "." + method + "." + getOutputFileNameTag("otucorr"); + outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/otuassociationcommand.h b/otuassociationcommand.h index f1d047d..64995ac 100644 --- a/otuassociationcommand.h +++ b/otuassociationcommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "otu.association"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 2f99aa6..3898796 100644 --- a/otuhierarchycommand.cpp +++ b/otuhierarchycommand.cpp @@ -46,7 +46,26 @@ string OtuHierarchyCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string OtuHierarchyCommand::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 == "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); + } +} //********************************************************************************************************************** OtuHierarchyCommand::OtuHierarchyCommand(){ try { @@ -180,7 +199,7 @@ int OtuHierarchyCommand::execute(){ } ofstream out; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(listFile)) + lists[0].getLabel() + "-" + lists[1].getLabel() + ".otu.hierarchy"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listFile)) + lists[0].getLabel() + "-" + lists[1].getLabel() + "." + getOutputFileNameTag("otuhierarchy"); 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 8a2c862..ad6da0c 100644 --- a/otuhierarchycommand.h +++ b/otuhierarchycommand.h @@ -24,6 +24,7 @@ public: vector setParameters(); string getCommandName() { return "otu.hierarchy"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 a4ccbf8..1fa96e3 100644 --- a/pairwiseseqscommand.cpp +++ b/pairwiseseqscommand.cpp @@ -64,7 +64,27 @@ string PairwiseSeqsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string PairwiseSeqsCommand::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 == "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); + } +} //********************************************************************************************************************** PairwiseSeqsCommand::PairwiseSeqsCommand(){ try { @@ -272,14 +292,14 @@ int PairwiseSeqsCommand::execute(){ string outputFile = ""; if (output == "lt") { //does the user want lower triangle phylip formatted file - outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "phylip.dist"; + outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "phylip." + getOutputFileNameTag("phylip"); m->mothurRemove(outputFile); outputTypes["phylip"].push_back(outputFile); }else if (output == "column") { //user wants column format - outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "dist"; + outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + getOutputFileNameTag("column"); outputTypes["column"].push_back(outputFile); m->mothurRemove(outputFile); }else { //assume square - outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "square.dist"; + outputFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + "square." + getOutputFileNameTag("phylip"); m->mothurRemove(outputFile); outputTypes["phylip"].push_back(outputFile); } diff --git a/pairwiseseqscommand.h b/pairwiseseqscommand.h index e75f63c..0e749d5 100644 --- a/pairwiseseqscommand.h +++ b/pairwiseseqscommand.h @@ -40,6 +40,7 @@ public: vector setParameters(); string getCommandName() { return "pairwise.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 06ea359..1331b7f 100644 --- a/parsefastaqcommand.cpp +++ b/parsefastaqcommand.cpp @@ -46,6 +46,28 @@ string ParseFastaQCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string ParseFastaQCommand::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 = "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); + } +} + //********************************************************************************************************************** ParseFastaQCommand::ParseFastaQCommand(){ try { @@ -132,8 +154,8 @@ int ParseFastaQCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //open Output Files - string fastaFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + "fasta"; - string qualFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + "qual"; + string fastaFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + getOutputFileNameTag("fasta"); + string qualFile = outputDir + m->getRootName(m->getSimpleName(fastaQFile)) + getOutputFileNameTag("qfile"); ofstream outFasta, outQual; if (fasta) { m->openOutputFile(fastaFile, outFasta); outputNames.push_back(fastaFile); outputTypes["fasta"].push_back(fastaFile); } diff --git a/parsefastaqcommand.h b/parsefastaqcommand.h index 6feabce..4481b98 100644 --- a/parsefastaqcommand.h +++ b/parsefastaqcommand.h @@ -23,6 +23,7 @@ public: vector setParameters(); string getCommandName() { return "parse.fastq"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 bb096d8..4e61a58 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -45,6 +45,27 @@ string ParseListCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string ParseListCommand::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 == "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); + } +} + //********************************************************************************************************************** ParseListCommand::ParseListCommand(){ try { @@ -180,7 +201,7 @@ int ParseListCommand::execute(){ temp = new ofstream; filehandles[gGroups[i]] = temp; - string filename = fileroot + gGroups[i] + ".list"; + string filename = fileroot + gGroups[i] + "." + getOutputFileNameTag("list"); outputNames.push_back(filename); outputTypes["list"].push_back(filename); m->openOutputFile(filename, *temp); } diff --git a/parselistscommand.h b/parselistscommand.h index 9356299..1faeaeb 100644 --- a/parselistscommand.h +++ b/parselistscommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "parse.list"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 50e1bfa..f124b60 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -52,6 +52,27 @@ string ParsimonyCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string ParsimonyCommand::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 == "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); + } +} //********************************************************************************************************************** ParsimonyCommand::ParsimonyCommand(){ @@ -204,11 +225,11 @@ int ParsimonyCommand::execute() { delete reader; if(outputDir == "") { outputDir += m->hasPath(treefile); } - output = new ColumnFile(outputDir + m->getSimpleName(treefile) + ".parsimony", itersString); - outputNames.push_back(outputDir + m->getSimpleName(treefile) + ".parsimony"); - outputTypes["parsimony"].push_back(outputDir + m->getSimpleName(treefile) + ".parsimony"); + 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")); - sumFile = outputDir + m->getSimpleName(treefile) + ".psummary"; + sumFile = outputDir + m->getSimpleName(treefile) + "." + getOutputFileNameTag("psummary"); m->openOutputFile(sumFile, outSum); outputNames.push_back(sumFile); outputTypes["psummary"].push_back(sumFile); diff --git a/parsimonycommand.h b/parsimonycommand.h index 9172556..79613f5 100644 --- a/parsimonycommand.h +++ b/parsimonycommand.h @@ -28,6 +28,7 @@ public: vector setParameters(); string getCommandName() { return "parsimony"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 27e448b..2cb37bd 100644 --- a/pcacommand.cpp +++ b/pcacommand.cpp @@ -48,6 +48,28 @@ string PCACommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string PCACommand::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 == "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); + } +} + //********************************************************************************************************************** PCACommand::PCACommand(){ try { @@ -403,17 +425,19 @@ void PCACommand::output(string fnameRoot, vector name_list, vectoropenOutputFile((fnameRoot+"."+getOutputFileNameTag("pca")), pcaData); pcaData.setf(ios::fixed, ios::floatfield); pcaData.setf(ios::showpoint); - outputNames.push_back(fnameRoot+".pca.axes"); - outputTypes["pca"].push_back(fnameRoot+".pca.axes"); + outputNames.push_back(fnameRoot+"."+getOutputFileNameTag("pca")); + outputTypes["pca"].push_back(fnameRoot+"."+getOutputFileNameTag("pca")); - ofstream pcaLoadings((fnameRoot+".pca.loadings").c_str(), ios::trunc); + ofstream pcaLoadings; + m->openOutputFile((fnameRoot+"."+getOutputFileNameTag("loadings")), pcaLoadings); pcaLoadings.setf(ios::fixed, ios::floatfield); pcaLoadings.setf(ios::showpoint); - outputNames.push_back(fnameRoot+".pca.loadings"); - outputTypes["loadings"].push_back(fnameRoot+".pca.loadings"); + outputNames.push_back(fnameRoot+"."+getOutputFileNameTag("loadings")); + outputTypes["loadings"].push_back(fnameRoot+"."+getOutputFileNameTag("loadings")); 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 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"; } diff --git a/pcoacommand.cpp b/pcoacommand.cpp index 02e165e..354826f 100644 --- a/pcoacommand.cpp +++ b/pcoacommand.cpp @@ -46,6 +46,27 @@ string PCOACommand::getHelpString(){ } } +//********************************************************************************************************************** +string PCOACommand::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 == "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); + } +} //********************************************************************************************************************** PCOACommand::PCOACommand(){ @@ -229,17 +250,21 @@ void PCOACommand::output(string fnameRoot, vector name_list, vectoropenOutputFile(pcoaDataFile, pcaData); pcaData.setf(ios::fixed, ios::floatfield); pcaData.setf(ios::showpoint); - outputNames.push_back(fnameRoot+"pcoa.axes"); - outputTypes["pcoa"].push_back(fnameRoot+"pcoa.axes"); + outputNames.push_back(pcoaDataFile); + outputTypes["pcoa"].push_back(pcoaDataFile); - ofstream pcaLoadings((fnameRoot+"pcoa.loadings").c_str(), ios::trunc); + ofstream pcaLoadings; + string loadingsFile = fnameRoot+getOutputFileNameTag("loadings"); + m->openOutputFile(loadingsFile, pcaLoadings); pcaLoadings.setf(ios::fixed, ios::floatfield); pcaLoadings.setf(ios::showpoint); - outputNames.push_back(fnameRoot+"pcoa.loadings"); - outputTypes["loadings"].push_back(fnameRoot+"pcoa.loadings"); + outputNames.push_back(loadingsFile); + outputTypes["loadings"].push_back(loadingsFile); pcaLoadings << "axis\tloading\n"; for(int i=0;i setParameters(); string getCommandName() { return "pcoa"; } string getCommandCategory() { return "Hypothesis Testing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 420a5eb..baeca4e 100644 --- a/pcrseqscommand.h +++ b/pcrseqscommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "pcr.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Pcr.seqs"; } string getDescription() { return "pcr.seqs"; } diff --git a/phylodiversitycommand.cpp b/phylodiversitycommand.cpp index 29e2ef0..9d68cb5 100644 --- a/phylodiversitycommand.cpp +++ b/phylodiversitycommand.cpp @@ -61,7 +61,28 @@ string PhyloDiversityCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string PhyloDiversityCommand::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 == "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); + } +} //********************************************************************************************************************** PhyloDiversityCommand::PhyloDiversityCommand(){ @@ -237,9 +258,9 @@ int PhyloDiversityCommand::execute(){ if (m->control_pressed) { delete tmap; 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) + ".phylodiv.summary"; - string outRareFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(i+1) + ".phylodiv.rarefaction"; - string outCollectFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(i+1) + ".phylodiv"; + 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"); 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); } diff --git a/phylodiversitycommand.h b/phylodiversitycommand.h index 52cd3e2..9527692 100644 --- a/phylodiversitycommand.h +++ b/phylodiversitycommand.h @@ -25,7 +25,8 @@ class PhyloDiversityCommand : public Command { vector setParameters(); string getCommandName() { return "phylo.diversity"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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/phylosummary.cpp b/phylosummary.cpp index 2f56515..5f7bbc3 100644 --- a/phylosummary.cpp +++ b/phylosummary.cpp @@ -73,24 +73,16 @@ PhyloSummary::PhyloSummary(string groupFile){ int PhyloSummary::summarize(string userTfile){ try { - - ifstream in; - m->openInputFile(userTfile, in); - - //read in users taxonomy file and add sequences to tree - string name, tax; - int numSeqs = 0; - while(!in.eof()){ - in >> name >> tax; m->gobble(in); - - addSeqToTree(name, tax); + map temp; + m->readTax(userTfile, temp); + + for (map::iterator itTemp = temp.begin(); itTemp != temp.end();) { + addSeqToTree(itTemp->first, itTemp->second); numSeqs++; - - if (m->control_pressed) { break; } - } - in.close(); - - return numSeqs; + temp.erase(itTemp++); + } + + return numSeqs; } catch(exception& e) { m->errorOut(e, "PhyloSummary", "summarize"); diff --git a/phylotree.cpp b/phylotree.cpp index 4ed3d8c..3dde186 100644 --- a/phylotree.cpp +++ b/phylotree.cpp @@ -178,16 +178,13 @@ PhyloTree::PhyloTree(string tfile){ MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case #else - ifstream in; - m->openInputFile(tfile, in); - - //read in users taxonomy file and add sequences to tree - while(!in.eof()){ - in >> name >> tax; m->gobble(in); - - addSeqToTree(name, tax); - } - in.close(); + map temp; + m->readTax(tfile, temp); + + for (map::iterator itTemp = temp.begin(); itTemp != temp.end();) { + addSeqToTree(itTemp->first, itTemp->second); + temp.erase(itTemp++); + } #endif assignHeirarchyIDs(0); diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index 2d2db08..38d3bdf 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -53,7 +53,28 @@ string PhylotypeCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string PhylotypeCommand::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 == "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); + } +} //********************************************************************************************************************** PhylotypeCommand::PhylotypeCommand(){ try { @@ -198,13 +219,13 @@ int PhylotypeCommand::execute(){ string fileroot = outputDir + m->getRootName(m->getSimpleName(taxonomyFileName)); ofstream outList; - string outputListFile = fileroot + "tx.list"; + string outputListFile = fileroot + "tx." + getOutputFileNameTag("list"); m->openOutputFile(outputListFile, outList); ofstream outSabund; - string outputSabundFile = fileroot + "tx.sabund"; + string outputSabundFile = fileroot + "tx." + getOutputFileNameTag("sabund"); m->openOutputFile(outputSabundFile, outSabund); ofstream outRabund; - string outputRabundFile = fileroot + "tx.rabund"; + string outputRabundFile = fileroot + "tx." + getOutputFileNameTag("rabund"); m->openOutputFile(outputRabundFile, outRabund); outputNames.push_back(outputListFile); outputTypes["list"].push_back(outputListFile); diff --git a/phylotypecommand.h b/phylotypecommand.h index ecc7376..0e315ec 100644 --- a/phylotypecommand.h +++ b/phylotypecommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "phylotype"; } string getCommandCategory() { return "Clustering"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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.h b/pipelinepdscommand.h index 8abe0ea..2c621bb 100644 --- a/pipelinepdscommand.h +++ b/pipelinepdscommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "pipeline.pds"; } string getCommandCategory() { return "Hidden"; } + string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Pipeline.pds"; } string getDescription() { return "pat's pipeline"; } diff --git a/prcseqscommand.cpp b/prcseqscommand.cpp index 725136b..6b73d44 100644 --- a/prcseqscommand.cpp +++ b/prcseqscommand.cpp @@ -58,7 +58,30 @@ string PcrSeqsCommand::getHelpString(){ } } - +//********************************************************************************************************************** +string PcrSeqsCommand::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 = "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 == "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); + } +} //********************************************************************************************************************** PcrSeqsCommand::PcrSeqsCommand(){ @@ -265,10 +288,10 @@ int PcrSeqsCommand::execute(){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string trimSeqFile = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pcr.fasta"; + string trimSeqFile = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta"); outputNames.push_back(trimSeqFile); outputTypes["fasta"].push_back(trimSeqFile); - string badSeqFile = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pcr.scrap.fasta"; + string badSeqFile = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "scrap." + getOutputFileNameTag("fasta"); length = 0; @@ -857,7 +880,7 @@ int PcrSeqsCommand::writeAccnos(set badNames){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "bad.accnos"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("accnos"); outputNames.push_back(outputFileName); outputTypes["accnos"].push_back(outputFileName); ofstream out; @@ -919,7 +942,7 @@ int PcrSeqsCommand::readName(set& names){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pcr" + m->getExtension(namefile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); ofstream out; m->openOutputFile(outputFileName, out); @@ -977,7 +1000,7 @@ int PcrSeqsCommand::readGroup(set names){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pcr" + m->getExtension(groupfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -1024,7 +1047,7 @@ int PcrSeqsCommand::readTax(set names){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pcr" + m->getExtension(taxfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/preclustercommand.cpp b/preclustercommand.cpp index bcff0fc..951b200 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -51,7 +51,28 @@ string PreClusterCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string PreClusterCommand::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 = "precluster" + m->getExtension(inputName); } + else if (type == "name") { outputFileName = "precluster.names"; } + 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); + } +} //********************************************************************************************************************** PreClusterCommand::PreClusterCommand(){ try { @@ -184,9 +205,9 @@ int PreClusterCommand::execute(){ int start = time(NULL); string fileroot = outputDir + m->getRootName(m->getSimpleName(fastafile)); - string newFastaFile = fileroot + "precluster" + m->getExtension(fastafile); - string newNamesFile = fileroot + "precluster.names"; - string newMapFile = fileroot + "precluster.map"; //add group name if by group + string newFastaFile = fileroot + getOutputFileNameTag("fasta", fastafile); + string newNamesFile = fileroot + getOutputFileNameTag("name"); + string newMapFile = fileroot + getOutputFileNameTag("map"); //add group name if by group outputNames.push_back(newFastaFile); outputTypes["fasta"].push_back(newFastaFile); outputNames.push_back(newNamesFile); outputTypes["name"].push_back(newNamesFile); diff --git a/preclustercommand.h b/preclustercommand.h index 64efc7f..084bdc6 100644 --- a/preclustercommand.h +++ b/preclustercommand.h @@ -41,6 +41,7 @@ public: vector setParameters(); string getCommandName() { return "pre.cluster"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://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 6495800..63d6fd5 100644 --- a/quitcommand.h +++ b/quitcommand.h @@ -27,6 +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 getCitation() { return "no citation"; } string getDescription() { return "quit"; } diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index 0fdd079..612e3b4 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -74,6 +74,39 @@ string RareFactCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string RareFactCommand::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 == "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); + } +} //********************************************************************************************************************** RareFactCommand::RareFactCommand(){ @@ -305,52 +338,52 @@ int RareFactCommand::execute(){ for (i=0; i 1) { file2Group[outputNames.size()-1] = groups[p]; } } diff --git a/rarefactcommand.h b/rarefactcommand.h index 0e77a27..9c7e1ed 100644 --- a/rarefactcommand.h +++ b/rarefactcommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "rarefaction.single"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 fecf972..a312df0 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -62,7 +62,27 @@ string RareFactSharedCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string RareFactSharedCommand::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 == "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); + } +} //********************************************************************************************************************** RareFactSharedCommand::RareFactSharedCommand(){ try { @@ -286,11 +306,11 @@ int RareFactSharedCommand::process(GroupMap& designMap, string thisSet){ for (int i=0; i setParameters(); string getCommandName() { return "rarefaction.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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/readdistcommand.cpp b/readdistcommand.cpp deleted file mode 100644 index 8bf6996..0000000 --- a/readdistcommand.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/* - * readdistcommand.cpp - * Mothur - * - * Created by Sarah Westcott on 1/20/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "readdistcommand.h" -#include "readphylip.h" -#include "readcolumn.h" -#include "readmatrix.hpp" - -//********************************************************************************************************************** -ReadDistCommand::ReadDistCommand(string option) { - try { - abort = false; calledHelp = false; - - //allow user to run help - if(option == "help") { help(); abort = true; calledHelp = true; } - else if(option == "citation") { citation(); abort = true; calledHelp = true;} - - else { - /*//valid paramters for this command - string Array[] = {"phylip", "column", "name", "cutoff", "precision", "group","outputdir","inputdir","sim"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - - OptionParser parser(option); - map parameters = parser.getParameters(); - - ValidParameters validParameter; - map::iterator it; - - //check to make sure all parameters are valid for command - for (it = parameters.begin(); it != parameters.end(); it++) { - if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } - } - - globaldata->newRead(); - - //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); - if (inputDir == "not found"){ inputDir = ""; } - else { - string path; - it = parameters.find("phylip"); - //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["phylip"] = inputDir + it->second; } - } - - it = parameters.find("column"); - //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["column"] = inputDir + it->second; } - } - - it = parameters.find("name"); - //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["name"] = 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; } - } - } - - //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 = ""; } - - //check for required parameters - phylipfile = validParameter.validFile(parameters, "phylip", true); - if (phylipfile == "not open") { abort = true; } - else if (phylipfile == "not found") { phylipfile = ""; } - else { globaldata->setPhylipFile(phylipfile); globaldata->setFormat("phylip"); } - - columnfile = validParameter.validFile(parameters, "column", true); - if (columnfile == "not open") { abort = true; } - else if (columnfile == "not found") { columnfile = ""; } - else { globaldata->setColumnFile(columnfile); globaldata->setFormat("column"); } - - groupfile = validParameter.validFile(parameters, "group", true); - if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; } - else { - globaldata->setGroupFile(groupfile); - //groupMap = new GroupMap(groupfile); - //groupMap->readMap(); - } - - namefile = validParameter.validFile(parameters, "name", true); - if (namefile == "not open") { abort = true; } - else if (namefile == "not found") { namefile = ""; } - else { globaldata->setNameFile(namefile); } - - //you are doing a list and group shared - if ((phylipfile != "") && (groupfile != "")) { - globaldata->setFormat("matrix"); } - - if ((phylipfile == "") && (columnfile == "")) { m->mothurOut("When executing a read.dist command you must enter a phylip or a column."); m->mothurOutEndLine(); abort = true; } - else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When executing a read.dist command you must enter ONLY ONE of the following: phylip or column."); m->mothurOutEndLine(); abort = true; } - - if (columnfile != "") { - if (namefile == "") { cout << "You need to provide a namefile if you are going to use the column format." << endl; abort = true; } - } - - //check for optional parameter and set defaults - // ...at some point should added some additional type checking... - //get user cutoff and precision or use defaults - string temp; - temp = validParameter.validFile(parameters, "precision", false); if (temp == "not found") { temp = "100"; } - m->mothurConvert(temp, precision); - - temp = validParameter.validFile(parameters, "sim", false); if (temp == "not found") { temp = "F"; } - sim = m->isTrue(temp); - globaldata->sim = sim; - - temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "10"; } - convert(temp, cutoff); - cutoff += (5 / (precision * 10.0)); - - if (abort == false) { - distFileName = globaldata->inputFileName; - format = globaldata->getFormat(); - - if (format == "column") { read = new ReadColumnMatrix(distFileName); } - else if (format == "phylip") { read = new ReadPhylipMatrix(distFileName); } - else if (format == "matrix") { - groupMap = new GroupMap(groupfile); - int error = groupMap->readMap(); - if (error == 1) { delete groupMap; abort = true; } - else { - if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } - globaldata->gGroupmap = groupMap; - } - } - - if (format != "matrix" ) { - read->setCutoff(cutoff); - - if(namefile != ""){ - nameMap = new NameAssignment(namefile); - nameMap->readMap(); - }else{ - nameMap = NULL; - } - } - } -*/ - } - - } - catch(exception& e) { - m->errorOut(e, "ReadDistCommand", "ReadDistCommand"); - exit(1); - } -} -//********************************************************************************************************************** -int ReadDistCommand::execute(){ - try { - - if (abort == true) { if (calledHelp) { return 0; } return 2; } - m->mothurOut(getHelpString()); m->mothurOutEndLine(); -/* - time_t start = time(NULL); - size_t numDists = 0; - - if (format == "matrix") { - ifstream in; - m->openInputFile(distFileName, in); - matrix = new FullMatrix(in); //reads the matrix file - in.close(); - - if (m->control_pressed) { delete groupMap; delete matrix; return 0; } - - //if files don't match... - if (matrix->getNumSeqs() < groupMap->getNumSeqs()) { - m->mothurOut("Your distance file contains " + toString(matrix->getNumSeqs()) + " sequences, and your group file contains " + toString(groupMap->getNumSeqs()) + " sequences."); m->mothurOutEndLine(); - //create new group file - if(outputDir == "") { outputDir += m->hasPath(groupfile); } - - string newGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "editted.groups"; - outputNames.push_back(newGroupFile); - ofstream outGroups; - m->openOutputFile(newGroupFile, outGroups); - - for (int i = 0; i < matrix->getNumSeqs(); i++) { - if (m->control_pressed) { delete groupMap; delete matrix; outGroups.close(); m->mothurRemove(newGroupFile); return 0; } - - Names temp = matrix->getRowInfo(i); - outGroups << temp.seqName << '\t' << temp.groupName << endl; - } - outGroups.close(); - - m->mothurOut(newGroupFile + " is a new group file containing only the sequence that are in your distance file. I will read this file instead."); m->mothurOutEndLine(); - - //read new groupfile - delete groupMap; groupMap = NULL; - groupfile = newGroupFile; - globaldata->setGroupFile(groupfile); - - groupMap = new GroupMap(groupfile); - groupMap->readMap(); - - if (m->control_pressed) { delete groupMap; delete matrix; m->mothurRemove(newGroupFile); return 0; } - - globaldata->gGroupmap = groupMap; - } - - //memory leak prevention - if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix; } - globaldata->gMatrix = matrix; //save matrix for coverage commands - numDists = matrix->getSizes()[1]; - } else { - read->read(nameMap); - //to prevent memory leak - - if (m->control_pressed) { return 0; } - - if (globaldata->gListVector != NULL) { delete globaldata->gListVector; } - globaldata->gListVector = read->getListVector(); - - if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix; } - globaldata->gSparseMatrix = read->getMatrix(); - numDists = globaldata->gSparseMatrix->getNNodes(); - } - - if (m->control_pressed) { return 0; } - - if (outputNames.size() != 0) { - m->mothurOutEndLine(); - m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } - m->mothurOutEndLine(); - } - - m->mothurOut("It took " + toString(time(NULL) - start) + " secs to read "); m->mothurOutEndLine(); - */ - return 0; - - } - catch(exception& e) { - m->errorOut(e, "ReadDistCommand", "execute"); - exit(1); - } -} diff --git a/readdistcommand.h b/readdistcommand.h deleted file mode 100644 index afe077d..0000000 --- a/readdistcommand.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef READDISTCOMMAND_H -#define READDISTCOMMAND_H -/* - * readdistcommand.h - * Mothur - * - * Created by Sarah Westcott on 1/20/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "command.hpp" -#include "readmatrix.hpp" -#include "fullmatrix.h" -#include "groupmap.h" - -/* The read.dist command is used to read a distance matrix file. -The read.dist command parameter options are phylipfile, columnfile, namefile, cutoff and precision. -The read.dist command should be in the following format: read.dist(phylipfile=yourDistFile, -namefile=yourNameFile, cutoff=yourCutoff, precision=yourPrecision). The phylipfile or columnfile are required and if you use a columnfile the namefile is required. -If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed. */ - -class NameAssignment; - -class ReadDistCommand : public Command { -public: - ReadDistCommand(string); - ReadDistCommand() { abort = true; calledHelp = true; } - ~ReadDistCommand() {} - - vector setParameters() { return outputNames; } //dummy doesn't really do anything - string getCommandName() { return "read.dist"; } - string getCommandCategory() { return "Hidden"; } - string getHelpString() { return "This command is no longer available. You can provide your distance files directly to the downstream commands like cluster."; } - string getCitation() { return "http://www.mothur.org/wiki/Read.dist"; } - string getDescription() { return "read.dist"; } - - int execute(); - void help() { m->mothurOut(getHelpString()); } - -private: - double cutoff; - int precision; - ReadMatrix* read; - FullMatrix* matrix; - GroupMap* groupMap; - string distFileName, format, method; - string phylipfile, columnfile, namefile, groupfile, outputDir; - NameAssignment* nameMap; - vector outputNames; - - bool abort, sim; - -}; - -#endif diff --git a/readotucommand.cpp b/readotucommand.cpp deleted file mode 100644 index f39e8df..0000000 --- a/readotucommand.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* - * readotu.cpp - * Mothur - * - * Created by Sarah Westcott on 1/20/09. - * Copyright 2009 Schloss Lab UMASS AMherst. All rights reserved. - * - */ - -#include "readotucommand.h" - - -//********************************************************************************************************************** -ReadOtuCommand::ReadOtuCommand(){ - try { - abort = true; calledHelp = true; - setParameters(); - vector tempOutNames; - outputTypes["rabund"] = tempOutNames; - outputTypes["shared"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ReadOtuCommand", "ReadOtuCommand"); - exit(1); - } -} -//********************************************************************************************************************** -ReadOtuCommand::ReadOtuCommand(string option) { - try { - abort = false; calledHelp = false; - allLines = 1; - - //allow user to run help - if(option == "help") { help(); abort = true; calledHelp = true; } - else if(option == "citation") { citation(); abort = true; calledHelp = true;} - - else { - /* - //valid paramters for this command - string Array[] = {"list","order","shared","relabund","label","group","sabund", "rabund","groups","ordergroup","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - - OptionParser parser(option); - map parameters = parser.getParameters(); - - ValidParameters validParameter; - map::iterator it; - - //check to make sure all parameters are valid for command - for (it = parameters.begin(); it != parameters.end(); it++) { - if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } - } - - //initialize outputTypes - vector tempOutNames; - outputTypes["rabund"] = tempOutNames; - outputTypes["shared"] = tempOutNames; - - globaldata->newRead(); - - //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); - if (inputDir == "not found"){ inputDir = ""; } - else { - string path; - it = parameters.find("list"); - //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["list"] = inputDir + it->second; } - } - - it = parameters.find("order"); - //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["order"] = inputDir + it->second; } - } - - it = parameters.find("shared"); - //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["shared"] = 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("sabund"); - //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["sabund"] = inputDir + it->second; } - } - - it = parameters.find("rabund"); - //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["rabund"] = inputDir + it->second; } - } - - it = parameters.find("ordergroup"); - //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["ordergroup"] = inputDir + it->second; } - } - - it = parameters.find("relabund"); - //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["relabund"] = inputDir + it->second; } - } - } - - - //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 = ""; } - - //check for required parameters - listfile = validParameter.validFile(parameters, "list", true); - if (listfile == "not open") { abort = true; } - else if (listfile == "not found") { listfile = ""; } - else { globaldata->setListFile(listfile); globaldata->setFormat("list"); } - - sabundfile = validParameter.validFile(parameters, "sabund", true); - if (sabundfile == "not open") { abort = true; } - else if (sabundfile == "not found") { sabundfile = ""; } - else { globaldata->setSabundFile(sabundfile); globaldata->setFormat("sabund"); } - - rabundfile = validParameter.validFile(parameters, "rabund", true); - if (rabundfile == "not open") { abort = true; } - else if (rabundfile == "not found") { rabundfile = ""; } - else { globaldata->setRabundFile(rabundfile); globaldata->setFormat("rabund");} - - ordergroupfile = validParameter.validFile(parameters, "ordergroup", true); - if (ordergroupfile == "not open") { abort = true; } - else if (ordergroupfile == "not found") { ordergroupfile = ""; } - else { globaldata->setOrderGroupFile(ordergroupfile); } - - sharedfile = validParameter.validFile(parameters, "shared", true); - if (sharedfile == "not open") { abort = true; } - else if (sharedfile == "not found") { sharedfile = ""; } - else { globaldata->setSharedFile(sharedfile); globaldata->setFormat("sharedfile"); } - - relAbundfile = validParameter.validFile(parameters, "relabund", true); - if (relAbundfile == "not open") { abort = true; } - else if (relAbundfile == "not found") { relAbundfile = ""; } - else { globaldata->setRelAbundFile(relAbundfile); globaldata->setFormat("relabund"); } - - - groupfile = validParameter.validFile(parameters, "group", true); - if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; } - else { - globaldata->setGroupFile(groupfile); - groupMap = new GroupMap(groupfile); - - int error = groupMap->readMap(); - if (error == 1) { abort = true; } - - globaldata->gGroupmap = groupMap; - } - - groups = validParameter.validFile(parameters, "groups", false); - if (groups == "not found") { groups = ""; } - else { - m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; - } - - //you are doing a list and group shared - if ((listfile != "") && (groupfile != "")) { globaldata->setFormat("shared"); } - - //you have not given a file - if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "") && (relAbundfile == "")) { - m->mothurOut("You must enter either a listfile, rabundfile, sabundfile, relabund or a sharedfile with the read.otu command. "); m->mothurOutEndLine(); abort = true; - } - - //check for optional parameter and set defaults - // ...at some point should added some additional type checking... - label = validParameter.validFile(parameters, "label", false); - if (label == "not found") { label = ""; } - else { - if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } - else { allLines = 1; } - globaldata->labels = labels; - } - - globaldata->allLines = allLines; - - orderfile = validParameter.validFile(parameters, "order", true); - if (orderfile == "not open") { abort = true; } - else if (orderfile == "not found") { orderfile = ""; } - else { globaldata->setOrderFile(orderfile); } - - - if (abort == false) { - //gets whichever one of the above is set - filename = globaldata->inputFileName; - } - */ - } - - } - catch(exception& e) { - m->errorOut(e, "ReadOtuCommand", "ReadOtuCommand"); - exit(1); - } -} -///********************************************************************************************************************** - -int ReadOtuCommand::execute(){ - try { - - if (abort == true) { if (calledHelp) { return 0; } return 2; } - m->mothurOut(getHelpString()); m->mothurOutEndLine(); - - /* - if (globaldata->getFormat() == "shared") { - - shared = new SharedCommand(outputDir); - int okay = shared->execute(); - - //problem with shared - if (okay == 1) { - globaldata->setListFile(""); - globaldata->setGroupFile(""); - globaldata->setSharedFile(""); - }else { //shared command outputs the filenames - //m->mothurOutEndLine(); - //m->mothurOut("Output File Name: "); m->mothurOutEndLine(); - //m->mothurOut(globaldata->getSharedFile()); m->mothurOutEndLine(); - //m->mothurOutEndLine(); - } - - outputTypes = shared->getOutputFiles(); - - //set rabund file as new current rabundfile - string current = ""; - itTypes = outputTypes.find("rabund"); - if (itTypes != outputTypes.end()) { - if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); } - } - - itTypes = outputTypes.find("shared"); - if (itTypes != outputTypes.end()) { - if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); } - } - - delete shared; - } - */ - - return 0; - } - catch(exception& e) { - m->errorOut(e, "ReadOtuCommand", "execute"); - exit(1); - } -} -//********************************************************************************************************************** diff --git a/readotucommand.h b/readotucommand.h deleted file mode 100644 index c6d6503..0000000 --- a/readotucommand.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef READOTUCOMMAND_H -#define READOTUCOMMAND_H -/* - * readotu.h - * Mothur - * - * Created by Sarah Westcott on 1/20/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "command.hpp" -#include "inputdata.h" -#include "groupmap.h" -#include "sharedcommand.h" - -class ReadOtuCommand : public Command { -public: - ReadOtuCommand(string); - ReadOtuCommand(); - ~ReadOtuCommand() {} - - vector setParameters() { return outputNames; } //dummy doesn't really do anything - string getCommandName() { return "read.otu"; } - string getCommandCategory() { return "Hidden"; } - string getHelpString() { return "This command is no longer available. You can provide your files directly to the downstream commands like collect.shared."; } - string getCitation() { return "http://www.mothur.org/wiki/Read.otu"; } - string getDescription() { return "read.otu"; } - - int execute(); - void help() { m->mothurOut(getHelpString()); } - -private: - InputData* input; - Command* shared; - GroupMap* groupMap; - string filename, listfile, orderfile, sharedfile, label, groupfile, sabundfile, rabundfile, format, groups, outputDir, ordergroupfile, relAbundfile; - vector Groups, outputNames; - map > outputTypes; - - bool abort, allLines; - set labels; //holds labels to be used - -}; - -#endif diff --git a/readtreecommand.cpp b/readtreecommand.cpp deleted file mode 100644 index 7660643..0000000 --- a/readtreecommand.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - * readtreecommand.cpp - * Mothur - * - * Created by Sarah Westcott on 1/23/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "readtreecommand.h" - - -//********************************************************************************************************************** -ReadTreeCommand::ReadTreeCommand(string option) { - try { - abort = false; calledHelp = false; - - //allow user to run help - if(option == "help") { help(); abort = true; calledHelp = true; } - else if(option == "citation") { citation(); abort = true; calledHelp = true;} - - else { - /* - //valid paramters for this command - string Array[] = {"tree","group","name","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - - OptionParser parser(option); - map parameters = parser.getParameters(); - - ValidParameters validParameter; - map::iterator it; - - //check to make sure all parameters are valid for command - for (it = parameters.begin(); it != parameters.end(); it++) { - if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } - } - - globaldata->newRead(); - - //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); - if (inputDir == "not found"){ inputDir = ""; } - else { - string path; - it = parameters.find("tree"); - //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["tree"] = 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("name"); - //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["name"] = inputDir + it->second; } - } - - } - - - //check for required parameters - treefile = validParameter.validFile(parameters, "tree", true); - if (treefile == "not open") { abort = true; } - else if (treefile == "not found") { treefile = ""; m->mothurOut("tree is a required parameter for the read.tree command."); m->mothurOutEndLine(); abort = true; } - - groupfile = validParameter.validFile(parameters, "group", true); - if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { - groupfile = ""; - - m->mothurOut("You have not provided a group file. I am assumming all sequence are from the same group."); m->mothurOutEndLine(); - - if (treefile != "") { Tree* tree = new Tree(treefile); delete tree; } //extracts names from tree to make faked out groupmap - - //read in group map info. - treeMap = new TreeMap(); - for (int i = 0; i < m->Treenames.size(); i++) { treeMap->addSeq(m->Treenames[i], "Group1"); } - - }else { - //read in group map info. - treeMap = new TreeMap(groupfile); - treeMap->readMap(); - } - - namefile = validParameter.validFile(parameters, "name", true); - if (namefile == "not open") { abort = true; } - else if (namefile == "not found") { namefile = ""; } - else { readNamesFile(); } - - if (abort == false) { - filename = treefile; - read = new ReadNewickTree(filename); - } - */ - } - } - catch(exception& e) { - m->errorOut(e, "ReadTreeCommand", "ReadTreeCommand"); - exit(1); - } -} -//********************************************************************************************************************** - -int ReadTreeCommand::execute(){ - try { - - if (abort == true) { if (calledHelp) { return 0; } return 2; } - m->mothurOut(getHelpString()); m->mothurOutEndLine(); - /* - int readOk; - - readOk = read->read(treeMap); - - if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; } - - vector T = read->gTree; - - //assemble users trees - for (int i = 0; i < T.size(); i++) { - if (m->control_pressed) { - for (int i = 0; i < T.size(); i++) { delete T[i]; } - globaldata->gTree.clear(); - delete globaldata->gTreemap; - return 0; - } - - T[i]->assembleTree(); - } - - - //if you provide a namefile we will use the numNames in the namefile as long as the number of unique match the tree names size. - int numNamesInTree; - if (namefile != "") { - if (numUniquesInName == globaldata->Treenames.size()) { numNamesInTree = nameMap.size(); } - else { numNamesInTree = globaldata->Treenames.size(); } - }else { numNamesInTree = globaldata->Treenames.size(); } - - - //output any names that are in group file but not in tree - if (numNamesInTree < treeMap->getNumSeqs()) { - for (int i = 0; i < treeMap->namesOfSeqs.size(); i++) { - //is that name in the tree? - int count = 0; - for (int j = 0; j < globaldata->Treenames.size(); j++) { - if (treeMap->namesOfSeqs[i] == globaldata->Treenames[j]) { break; } //found it - count++; - } - - if (m->control_pressed) { - for (int i = 0; i < T.size(); i++) { delete T[i]; } - globaldata->gTree.clear(); - delete globaldata->gTreemap; - return 0; - } - - //then you did not find it so report it - if (count == globaldata->Treenames.size()) { - //if it is in your namefile then don't remove - map::iterator it = nameMap.find(treeMap->namesOfSeqs[i]); - - if (it == nameMap.end()) { - m->mothurOut(treeMap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine(); - treeMap->removeSeq(treeMap->namesOfSeqs[i]); - i--; //need this because removeSeq removes name from namesOfSeqs - } - } - } - - globaldata->gTreemap = treeMap; - } - */ - return 0; - } - catch(exception& e) { - m->errorOut(e, "ReadTreeCommand", "execute"); - exit(1); - } -} -/*****************************************************************/ -int ReadTreeCommand::readNamesFile() { - try { - /* - m->names.clear(); - numUniquesInName = 0; - - ifstream in; - m->openInputFile(namefile, in); - - string first, second; - map::iterator itNames; - - while(!in.eof()) { - in >> first >> second; m->gobble(in); - - numUniquesInName++; - - itNames = m->names.find(first); - if (itNames == globaldata->names.end()) { - globaldata->names[first] = second; - - //we need a list of names in your namefile to use above when removing extra seqs above so we don't remove them - vector dupNames; - m->splitAtComma(second, dupNames); - - for (int i = 0; i < dupNames.size(); i++) { nameMap[dupNames[i]] = dupNames[i]; if ((groupfile == "") && (i != 0)) { globaldata->gTreemap->addSeq(dupNames[i], "Group1"); } } - }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); namefile = ""; return 1; } - } - in.close(); - */ - return 0; - } - catch(exception& e) { - m->errorOut(e, "ReadTreeCommand", "readNamesFile"); - exit(1); - } -} - -//********************************************************************************************************************** diff --git a/readtreecommand.h b/readtreecommand.h deleted file mode 100644 index cbf3769..0000000 --- a/readtreecommand.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef READTREECOMMAND_H -#define READTREECOMMAND_H - -/* - * readtreecommand.h - * Mothur - * - * Created by Sarah Westcott on 1/23/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "command.hpp" -#include "readtree.h" -#include "treemap.h" - - -class ReadTreeCommand : public Command { -public: - ReadTreeCommand(string); - ReadTreeCommand() { abort = true; calledHelp = true; } - ~ReadTreeCommand() {} - - vector setParameters() { return outputNames; } //dummy doesn't really do anything - string getCommandName() { return "read.tree"; } - string getCommandCategory() { return "Hidden"; } - string getHelpString() { return "This command is no longer available. You can provide your files directly to the downstream commands like unifrac.unweighted."; } - string getCitation() { return "http://www.mothur.org/wiki/Read.tree"; } - string getDescription() { return "read.tree"; } - - int execute(); - void help() { m->mothurOut(getHelpString()); } - -private: - ReadTree* read; - TreeMap* treeMap; - string filename, treefile, groupfile, namefile; - bool abort; - map nameMap; - vector outputNames; - - int readNamesFile(); - int numUniquesInName; - -}; - - -#endif diff --git a/removegroupscommand.cpp b/removegroupscommand.cpp index 801029c..05b1170 100644 --- a/removegroupscommand.cpp +++ b/removegroupscommand.cpp @@ -57,7 +57,32 @@ string RemoveGroupsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string RemoveGroupsCommand::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 = "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 == "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); + } +} //********************************************************************************************************************** RemoveGroupsCommand::RemoveGroupsCommand(){ try { @@ -295,7 +320,7 @@ int RemoveGroupsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //get groups you want to remove - if (accnosfile != "") { readAccnos(); } + if (accnosfile != "") { m->readAccnos(accnosfile, Groups); m->setGroups(Groups); } if (groupfile != "") { groupMap = new GroupMap(groupfile); @@ -385,7 +410,7 @@ int RemoveGroupsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); ofstream out; m->openOutputFile(outputFileName, out); @@ -477,7 +502,7 @@ int RemoveGroupsCommand::readShared(){ while(lookup[0] != NULL) { - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + ".pick" + m->getExtension(sharedfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + "." + getOutputFileNameTag("shared", sharedfile); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); @@ -525,7 +550,7 @@ int RemoveGroupsCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -615,8 +640,7 @@ int RemoveGroupsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); ofstream out; m->openOutputFile(outputFileName, out); @@ -696,8 +720,7 @@ int RemoveGroupsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -743,7 +766,7 @@ int RemoveGroupsCommand::readDesign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(designfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + "pick" + m->getExtension(designfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + getOutputFileNameTag("design", designfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -791,7 +814,7 @@ int RemoveGroupsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -837,32 +860,6 @@ int RemoveGroupsCommand::readTax(){ } } //********************************************************************************************************************** -void RemoveGroupsCommand::readAccnos(){ - try { - Groups.clear(); - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - Groups.push_back(name); - - m->gobble(in); - } - in.close(); - - m->setGroups(Groups); - - } - catch(exception& e) { - m->errorOut(e, "RemoveGroupsCommand", "readAccnos"); - exit(1); - } -} -//********************************************************************************************************************** int RemoveGroupsCommand::fillNames(){ try { vector seqs = groupMap->getNamesSeqs(); diff --git a/removegroupscommand.h b/removegroupscommand.h index 24062ba..c6db380 100644 --- a/removegroupscommand.h +++ b/removegroupscommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "remove.groups"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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"; } @@ -48,7 +49,6 @@ private: int readShared(); int readName(); int readGroup(); - void readAccnos(); int readList(); int readTax(); int fillNames(); diff --git a/removelineagecommand.cpp b/removelineagecommand.cpp index 9fec249..4cec90f 100644 --- a/removelineagecommand.cpp +++ b/removelineagecommand.cpp @@ -57,8 +57,31 @@ string RemoveLineageCommand::getHelpString(){ exit(1); } } - - +//********************************************************************************************************************** +string RemoveLineageCommand::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 = "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 == "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); + } +} //********************************************************************************************************************** RemoveLineageCommand::RemoveLineageCommand(){ try { @@ -302,8 +325,7 @@ int RemoveLineageCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); ofstream out; m->openOutputFile(outputFileName, out); @@ -348,8 +370,7 @@ int RemoveLineageCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -419,8 +440,7 @@ int RemoveLineageCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); ofstream out; m->openOutputFile(outputFileName, out); @@ -497,8 +517,7 @@ int RemoveLineageCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -540,7 +559,7 @@ int RemoveLineageCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -740,7 +759,7 @@ int RemoveLineageCommand::readAlign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport"); ofstream out; m->openOutputFile(outputFileName, out); diff --git a/removelineagecommand.h b/removelineagecommand.h index a4ffea9..a5caec8 100644 --- a/removelineagecommand.h +++ b/removelineagecommand.h @@ -23,7 +23,8 @@ class RemoveLineageCommand : public Command { vector setParameters(); string getCommandName() { return "remove.lineage"; } string getCommandCategory() { return "Phylotype Analysis"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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 77305fb..01d8529 100644 --- a/removeotulabelscommand.cpp +++ b/removeotulabelscommand.cpp @@ -46,14 +46,36 @@ string RemoveOtuLabelsCommand::getHelpString(){ } } //********************************************************************************************************************** +string RemoveOtuLabelsCommand::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 == "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); + } +} +//********************************************************************************************************************** RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(){ try { abort = true; calledHelp = true; setParameters(); vector tempOutNames; outputTypes["contaxonomy"] = tempOutNames; - outputTypes["otu.corr"] = tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["otucorr"] = tempOutNames; + outputTypes["corraxes"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "RemoveOtuLabelsCommand", "RemoveOtuLabelsCommand"); @@ -127,8 +149,8 @@ RemoveOtuLabelsCommand::RemoveOtuLabelsCommand(string option) { vector tempOutNames; outputTypes["contaxonomy"] = tempOutNames; - outputTypes["otu.corr"] = tempOutNames; - outputTypes["corr.axes"] = tempOutNames; + outputTypes["otucorr"] = tempOutNames; + outputTypes["corraxes"] = tempOutNames; //check for parameters accnosfile = validParameter.validFile(parameters, "accnos", true); @@ -175,7 +197,7 @@ int RemoveOtuLabelsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //get labels you want to keep - readAccnos(); + labels = m->readAccnos(accnosfile); if (m->control_pressed) { return 0; } @@ -204,7 +226,7 @@ int RemoveOtuLabelsCommand::readClassifyOtu(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(constaxonomyfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + "pick.taxonomy"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(constaxonomyfile)) + getOutputFileNameTag("constaxonomy"); ofstream out; m->openOutputFile(outputFileName, out); @@ -253,7 +275,7 @@ int RemoveOtuLabelsCommand::readOtuAssociation(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(otucorrfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + "pick.corr"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(otucorrfile)) + getOutputFileNameTag("otucorr"); ofstream out; m->openOutputFile(outputFileName, out); @@ -286,7 +308,7 @@ int RemoveOtuLabelsCommand::readOtuAssociation(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file only contains labels from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); outputTypes["otu.corr"].push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["otucorr"].push_back(outputFileName); m->mothurOut("Removed " + toString(removedCount) + " lines from your otu.corr file."); m->mothurOutEndLine(); @@ -303,7 +325,7 @@ int RemoveOtuLabelsCommand::readCorrAxes(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(corraxesfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + "pick.axes"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(corraxesfile)) + getOutputFileNameTag("corraxes"); ofstream out; m->openOutputFile(outputFileName, out); @@ -336,7 +358,7 @@ int RemoveOtuLabelsCommand::readCorrAxes(){ out.close(); if (wroteSomething == false) { m->mothurOut("Your file only contains labels from the .accnos file."); m->mothurOutEndLine(); } - outputNames.push_back(outputFileName); outputTypes["corr.axes"].push_back(outputFileName); + outputNames.push_back(outputFileName); outputTypes["corraxes"].push_back(outputFileName); m->mothurOut("Removed " + toString(removedCount) + " lines from your corr.axes file."); m->mothurOutEndLine(); @@ -348,32 +370,6 @@ int RemoveOtuLabelsCommand::readCorrAxes(){ exit(1); } } - -//********************************************************************************************************************** -int RemoveOtuLabelsCommand::readAccnos(){ - try { - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - labels.insert(name); - - m->gobble(in); - } - in.close(); - - return 0; - - } - catch(exception& e) { - m->errorOut(e, "RemoveOtuLabelsCommand", "readAccnos"); - exit(1); - } -} //********************************************************************************************************************** diff --git a/removeotulabelscommand.h b/removeotulabelscommand.h index da2441d..ea59662 100644 --- a/removeotulabelscommand.h +++ b/removeotulabelscommand.h @@ -23,7 +23,8 @@ public: vector setParameters(); string getCommandName() { return "remove.otulabels"; } string getCommandCategory() { return "OTU-Based Approaches"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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."; } @@ -39,8 +40,6 @@ private: int readClassifyOtu(); int readOtuAssociation(); int readCorrAxes(); - int readAccnos(); - }; /**************************************************************************************************/ diff --git a/removeotuscommand.cpp b/removeotuscommand.cpp index 25ed99e..54adeb2 100644 --- a/removeotuscommand.cpp +++ b/removeotuscommand.cpp @@ -52,7 +52,27 @@ string RemoveOtusCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string RemoveOtusCommand::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 == "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); + } +} ///********************************************************************************************************************** RemoveOtusCommand::RemoveOtusCommand(){ try { @@ -182,7 +202,7 @@ int RemoveOtusCommand::execute(){ groupMap->readMap(); //get groups you want to remove - if (accnosfile != "") { readAccnos(); } + if (accnosfile != "") { m->readAccnos(accnosfile, Groups); m->setGroups(Groups); } //make sure groups are valid //takes care of user setting groupNames that are invalid or setting groups=all @@ -230,14 +250,14 @@ int RemoveOtusCommand::readListGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick." + label + m->getExtension(listfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + label + "." + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); string GroupOutputDir = outputDir; if (outputDir == "") { GroupOutputDir += m->hasPath(groupfile); } - string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick." + label + m->getExtension(groupfile); + string outputGroupFileName = GroupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + label + "." + getOutputFileNameTag("group", groupfile); ofstream outGroup; m->openOutputFile(outputGroupFileName, outGroup); @@ -407,30 +427,6 @@ int RemoveOtusCommand::processList(ListVector*& list, GroupMap*& groupMap, ofstr } } //********************************************************************************************************************** -void RemoveOtusCommand::readAccnos(){ - try { - Groups.clear(); - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - Groups.push_back(name); - - m->gobble(in); - } - in.close(); - - } - catch(exception& e) { - m->errorOut(e, "RemoveOtusCommand", "readAccnos"); - exit(1); - } -} -//********************************************************************************************************************** diff --git a/removeotuscommand.h b/removeotuscommand.h index 6a7cf8a..3a52a39 100644 --- a/removeotuscommand.h +++ b/removeotuscommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "remove.otus"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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"; } @@ -38,7 +39,6 @@ private: vector outputNames, Groups; GroupMap* groupMap; - void readAccnos(); int readListGroup(); int processList(ListVector*&, GroupMap*&, ofstream&, ofstream&, bool&); diff --git a/removerarecommand.cpp b/removerarecommand.cpp index 24b6165..923ca72 100644 --- a/removerarecommand.cpp +++ b/removerarecommand.cpp @@ -58,6 +58,31 @@ string RemoveRareCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string RemoveRareCommand::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 == "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 == "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); + } +} + //********************************************************************************************************************** RemoveRareCommand::RemoveRareCommand(){ try { @@ -301,9 +326,8 @@ int RemoveRareCommand::processList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile); - string outputGroupFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); + string outputGroupFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); ofstream out, outGroup; m->openOutputFile(outputFileName, out); @@ -423,7 +447,7 @@ int RemoveRareCommand::processSabund(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sabundfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + "pick" + m->getExtension(sabundfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + getOutputFileNameTag("sabund", sabundfile); outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -522,7 +546,7 @@ int RemoveRareCommand::processRabund(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(rabundfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + "pick" + m->getExtension(rabundfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + getOutputFileNameTag("rabund", rabundfile); outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -629,7 +653,7 @@ int RemoveRareCommand::processShared(){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "pick" + m->getExtension(sharedfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("shared", sharedfile); outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; diff --git a/removerarecommand.h b/removerarecommand.h index 9e58c06..2d70ba7 100644 --- a/removerarecommand.h +++ b/removerarecommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "remove.rare"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 2abe9ef..0d53c1a 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -53,7 +53,32 @@ string RemoveSeqsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string RemoveSeqsCommand::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 = "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 { 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); + } +} //********************************************************************************************************************** RemoveSeqsCommand::RemoveSeqsCommand(){ @@ -257,7 +282,7 @@ int RemoveSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //get names you want to keep - readAccnos(); + names = m->readAccnos(accnosfile); if (m->control_pressed) { return 0; } @@ -325,7 +350,7 @@ int RemoveSeqsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); ofstream out; m->openOutputFile(outputFileName, out); @@ -374,7 +399,7 @@ int RemoveSeqsCommand::readQual(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + "pick" + m->getExtension(qualfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -442,8 +467,7 @@ int RemoveSeqsCommand::readList(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -521,8 +545,7 @@ int RemoveSeqsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); ofstream out; m->openOutputFile(outputFileName, out); @@ -604,8 +627,7 @@ int RemoveSeqsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -651,7 +673,7 @@ int RemoveSeqsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); ofstream out; m->openOutputFile(outputFileName, out); @@ -697,7 +719,7 @@ int RemoveSeqsCommand::readAlign(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + "pick.align.report"; + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport"); ofstream out; m->openOutputFile(outputFileName, out); @@ -764,29 +786,5 @@ int RemoveSeqsCommand::readAlign(){ } } //********************************************************************************************************************** -void RemoveSeqsCommand::readAccnos(){ - try { - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - - while(!in.eof()){ - in >> name; - - names.insert(name); - - m->gobble(in); - } - in.close(); - - } - catch(exception& e) { - m->errorOut(e, "RemoveSeqsCommand", "readAccnos"); - exit(1); - } -} - -//********************************************************************************************************************** diff --git a/removeseqscommand.h b/removeseqscommand.h index df96e45..474951a 100644 --- a/removeseqscommand.h +++ b/removeseqscommand.h @@ -23,7 +23,8 @@ class RemoveSeqsCommand : public Command { vector setParameters(); string getCommandName() { return "remove.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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"; } @@ -41,7 +42,6 @@ class RemoveSeqsCommand : public Command { int readName(); int readGroup(); int readAlign(); - void readAccnos(); int readList(); int readTax(); int readQual(); diff --git a/reversecommand.cpp b/reversecommand.cpp index c664ad7..cde88b7 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -43,7 +43,27 @@ string ReverseSeqsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string ReverseSeqsCommand::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 = "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); + } +} //********************************************************************************************************************** ReverseSeqsCommand::ReverseSeqsCommand(){ try { @@ -162,7 +182,7 @@ 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)) + "rc" + m->getExtension(fastaFileName); + fastaReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(fastaFileName)) + getOutputFileNameTag("fasta", fastaFileName); m->openOutputFile(fastaReverseFileName, outFASTA); while(!inFASTA.eof()){ @@ -190,8 +210,8 @@ 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)) + "rc" + m->getExtension(qualFileName); - m->openOutputFile(qualReverseFileName, outQual); + string qualReverseFileName = tempOutputDir + m->getRootName(m->getSimpleName(qualFileName)) + getOutputFileNameTag("qfile", qualFileName); + m->openOutputFile(qualReverseFileName, outQual); while(!inQual.eof()){ if (m->control_pressed) { inQual.close(); outQual.close(); m->mothurRemove(qualReverseFileName); return 0; } diff --git a/reversecommand.h b/reversecommand.h index f0fdfa8..2c7a9e4 100644 --- a/reversecommand.h +++ b/reversecommand.h @@ -21,6 +21,7 @@ public: vector setParameters(); string getCommandName() { return "reverse.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 7ac910d..7f385d3 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -70,6 +70,33 @@ string ScreenSeqsCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string ScreenSeqsCommand::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 = "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 == "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); + } +} + //********************************************************************************************************************** ScreenSeqsCommand::ScreenSeqsCommand(){ try { @@ -309,8 +336,8 @@ int ScreenSeqsCommand::execute(){ #endif } - string goodSeqFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "good" + m->getExtension(fastafile); - string badAccnosFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "bad.accnos"; + string goodSeqFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); + string badAccnosFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("accnos"); int numFastaSeqs = 0; set badSeqNames; @@ -514,7 +541,7 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ string seqName, seqList, group; set::iterator it; - string goodNameFile = outputDir + m->getRootName(m->getSimpleName(namefile)) + "good" + m->getExtension(namefile); + string goodNameFile = outputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); outputNames.push_back(goodNameFile); outputTypes["name"].push_back(goodNameFile); ofstream goodNameOut; m->openOutputFile(goodNameFile, goodNameOut); @@ -560,7 +587,7 @@ int ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ ifstream inputGroups; m->openInputFile(groupfile, inputGroups); - string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile); + string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile); ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); @@ -893,8 +920,8 @@ int ScreenSeqsCommand::screenGroupFile(set badSeqNames){ string seqName, group; set::iterator it; - string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "good" + m->getExtension(groupfile); - outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile); + string goodGroupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + outputNames.push_back(goodGroupFile); outputTypes["group"].push_back(goodGroupFile); ofstream goodGroupOut; m->openOutputFile(goodGroupFile, goodGroupOut); while(!inputGroups.eof()){ @@ -945,7 +972,7 @@ int ScreenSeqsCommand::screenAlignReport(set badSeqNames){ string seqName, group; set::iterator it; - string goodAlignReportFile = outputDir + m->getRootName(m->getSimpleName(alignreport)) + "good" + m->getExtension(alignreport); + string goodAlignReportFile = outputDir + m->getRootName(m->getSimpleName(alignreport)) + getOutputFileNameTag("alignreport"); outputNames.push_back(goodAlignReportFile); outputTypes["alignreport"].push_back(goodAlignReportFile); ofstream goodAlignReportOut; m->openOutputFile(goodAlignReportFile, goodAlignReportOut); @@ -1009,7 +1036,7 @@ int ScreenSeqsCommand::screenTaxonomy(set badSeqNames){ string seqName, tax; set::iterator it; - string goodTaxFile = outputDir + m->getRootName(m->getSimpleName(taxonomy)) + "good" + m->getExtension(taxonomy); + string goodTaxFile = outputDir + m->getRootName(m->getSimpleName(taxonomy)) + getOutputFileNameTag("taxonomy", taxonomy); outputNames.push_back(goodTaxFile); outputTypes["taxonomy"].push_back(goodTaxFile); ofstream goodTaxOut; m->openOutputFile(goodTaxFile, goodTaxOut); @@ -1058,7 +1085,7 @@ int ScreenSeqsCommand::screenQual(set badSeqNames){ m->openInputFile(qualfile, in); set::iterator it; - string goodQualFile = outputDir + m->getRootName(m->getSimpleName(qualfile)) + "good" + m->getExtension(qualfile); + 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 54c8fbb..771113d 100644 --- a/screenseqscommand.h +++ b/screenseqscommand.h @@ -23,6 +23,7 @@ public: vector setParameters(); string getCommandName() { return "screen.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 24142e0..ee50ab1 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -45,6 +45,26 @@ string AlignCheckCommand::getHelpString(){ } } //********************************************************************************************************************** +string AlignCheckCommand::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 == "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); + } +} +//********************************************************************************************************************** AlignCheckCommand::AlignCheckCommand(){ try { abort = true; calledHelp = true; @@ -170,7 +190,7 @@ int AlignCheckCommand::execute(){ m->openInputFile(fastafile, in); ofstream out; - string outfile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "align.check"; + string outfile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("aligncheck"); m->openOutputFile(outfile, out); diff --git a/secondarystructurecommand.h b/secondarystructurecommand.h index 4e7bdea..110f019 100644 --- a/secondarystructurecommand.h +++ b/secondarystructurecommand.h @@ -39,7 +39,8 @@ class AlignCheckCommand : public Command { vector setParameters(); string getCommandName() { return "align.check"; } string getCommandCategory() { return "Sequence Processing"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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 55d90bd..cfa1f5b 100644 --- a/sensspeccommand.cpp +++ b/sensspeccommand.cpp @@ -45,6 +45,26 @@ string SensSpecCommand::getHelpString(){ } } //********************************************************************************************************************** +string SensSpecCommand::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 == "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); + } +} +//********************************************************************************************************************** SensSpecCommand::SensSpecCommand(){ try { abort = true; calledHelp = true; @@ -197,7 +217,7 @@ SensSpecCommand::SensSpecCommand(string option) { else { allLines = 1; } } - sensSpecFileName = outputDir + m->getRootName(m->getSimpleName(listFile)) + "sensspec"; + sensSpecFileName = outputDir + m->getRootName(m->getSimpleName(listFile)) + getOutputFileNameTag("sensspec"); } } catch(exception& e) { diff --git a/sensspeccommand.h b/sensspeccommand.h index 02e84c0..a5072e8 100644 --- a/sensspeccommand.h +++ b/sensspeccommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "sens.spec"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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. \nhttp://www.mothur.org/wiki/Sens.spec"; } string getDescription() { return "sens.spec"; } diff --git a/seqerrorcommand.cpp b/seqerrorcommand.cpp index 0dc15f5..8fd6368 100644 --- a/seqerrorcommand.cpp +++ b/seqerrorcommand.cpp @@ -63,20 +63,52 @@ string SeqErrorCommand::getHelpString(){ } } //********************************************************************************************************************** +string SeqErrorCommand::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 == "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); + } +} +//********************************************************************************************************************** SeqErrorCommand::SeqErrorCommand(){ try { abort = true; calledHelp = true; setParameters(); vector tempOutNames; - outputTypes["error.summary"] = tempOutNames; - outputTypes["error.seq"] = tempOutNames; - outputTypes["error.quality"] = tempOutNames; - outputTypes["error.qual.forward"] = tempOutNames; - outputTypes["error.qual.reverse"] = tempOutNames; - outputTypes["error.forward"] = tempOutNames; - outputTypes["error.reverse"] = tempOutNames; - outputTypes["error.count"] = tempOutNames; - outputTypes["error.matrix"] = tempOutNames; + outputTypes["errorsummary"] = tempOutNames; + outputTypes["errorseq"] = tempOutNames; + outputTypes["errorquality"] = tempOutNames; + outputTypes["errorqualforward"] = tempOutNames; + outputTypes["errorqualreverse"] = tempOutNames; + outputTypes["errorforward"] = tempOutNames; + outputTypes["errorreverse"] = tempOutNames; + outputTypes["errorcount"] = tempOutNames; + outputTypes["errormatrix"] = tempOutNames; + outputTypes["errorchimera"] = tempOutNames; + outputTypes["errorref-query"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "SeqErrorCommand", "SeqErrorCommand"); @@ -112,15 +144,17 @@ SeqErrorCommand::SeqErrorCommand(string option) { //initialize outputTypes vector tempOutNames; - outputTypes["error.summary"] = tempOutNames; - outputTypes["error.seq"] = tempOutNames; - outputTypes["error.quality"] = tempOutNames; - outputTypes["error.qual.forward"] = tempOutNames; - outputTypes["error.qual.reverse"] = tempOutNames; - outputTypes["error.forward"] = tempOutNames; - outputTypes["error.reverse"] = tempOutNames; - outputTypes["error.count"] = tempOutNames; - outputTypes["error.matrix"] = tempOutNames; + outputTypes["errorsummary"] = tempOutNames; + outputTypes["errorseq"] = tempOutNames; + outputTypes["errorquality"] = tempOutNames; + outputTypes["errorqualforward"] = tempOutNames; + outputTypes["errorqualreverse"] = tempOutNames; + outputTypes["errorforward"] = tempOutNames; + outputTypes["errorreverse"] = tempOutNames; + outputTypes["errorcount"] = tempOutNames; + outputTypes["errormatrix"] = tempOutNames; + outputTypes["errorchimera"] = tempOutNames; + outputTypes["errorref-query"] = tempOutNames; //if the user changes the input directory command factory will send this info to us in the output parameter @@ -269,14 +303,15 @@ int SeqErrorCommand::execute(){ totalBases = 0; totalMatches = 0; - string errorSummaryFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.summary"; - outputNames.push_back(errorSummaryFileName); outputTypes["error.summary"].push_back(errorSummaryFileName); + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(queryFileName)); + string errorSummaryFileName = fileNameRoot + getOutputFileNameTag("errorsummary"); + outputNames.push_back(errorSummaryFileName); outputTypes["errorsummary"].push_back(errorSummaryFileName); - string errorSeqFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.seq"; - outputNames.push_back(errorSeqFileName); outputTypes["error.seq"].push_back(errorSeqFileName); + string errorSeqFileName = fileNameRoot + getOutputFileNameTag("errorseq"); + outputNames.push_back(errorSeqFileName); outputTypes["errorseq"].push_back(errorSeqFileName); - string errorChimeraFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.chimera"; - outputNames.push_back(errorChimeraFileName); outputTypes["error.chimera"].push_back(errorChimeraFileName); + string errorChimeraFileName = fileNameRoot + getOutputFileNameTag("errorchimera"); + outputNames.push_back(errorChimeraFileName); outputTypes["errorchimera"].push_back(errorChimeraFileName); getReferences(); //read in reference sequences - make sure there's no ambiguous bases @@ -317,10 +352,10 @@ int SeqErrorCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } - string errorCountFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.count"; + string errorCountFileName = fileNameRoot + getOutputFileNameTag("errorcount"); ofstream errorCountFile; m->openOutputFile(errorCountFileName, errorCountFile); - outputNames.push_back(errorCountFileName); outputTypes["error.count"].push_back(errorCountFileName); + outputNames.push_back(errorCountFileName); outputTypes["errorcount"].push_back(errorCountFileName); m->mothurOut("Overall error rate:\t" + toString((double)(totalBases - totalMatches) / (double)totalBases) + "\n"); m->mothurOut("Errors\tSequences\n"); errorCountFile << "Errors\tSequences\n"; @@ -334,10 +369,10 @@ int SeqErrorCommand::execute(){ printSubMatrix(); - string megAlignmentFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.ref-query"; + string megAlignmentFileName = fileNameRoot + getOutputFileNameTag("errorref-query"); ofstream megAlignmentFile; m->openOutputFile(megAlignmentFileName, megAlignmentFile); - outputNames.push_back(megAlignmentFileName); outputTypes["error.ref-query"].push_back(megAlignmentFileName); + outputNames.push_back(megAlignmentFileName); outputTypes["errorref-query"].push_back(megAlignmentFileName); for(int i=0;igetRootName(m->getSimpleName(queryFileName)); + string subMatrixFileName = fileNameRoot + getOutputFileNameTag("errormatrix"); ofstream subMatrixFile; m->openOutputFile(subMatrixFileName, subMatrixFile); - outputNames.push_back(subMatrixFileName); outputTypes["error.matrix"].push_back(subMatrixFileName); + outputNames.push_back(subMatrixFileName); outputTypes["errormatrix"].push_back(subMatrixFileName); vector bases(6); bases[0] = "A"; bases[1] = "T"; @@ -1092,10 +1128,11 @@ void SeqErrorCommand::printSubMatrix(){ void SeqErrorCommand::printErrorFRFile(map > errorForward, map > errorReverse){ try{ - string errorForwardFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.seq.forward"; + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(queryFileName)); + string errorForwardFileName = fileNameRoot + getOutputFileNameTag("errorforward"); ofstream errorForwardFile; m->openOutputFile(errorForwardFileName, errorForwardFile); - outputNames.push_back(errorForwardFileName); outputTypes["error.forward"].push_back(errorForwardFileName); + outputNames.push_back(errorForwardFileName); outputTypes["errorforward"].push_back(errorForwardFileName); errorForwardFile << "position\ttotalseqs\tmatch\tsubstitution\tinsertion\tdeletion\tambiguous" << endl; for(int i=0;i > errorForward, map } errorForwardFile.close(); - string errorReverseFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.seq.reverse"; + string errorReverseFileName = fileNameRoot + getOutputFileNameTag("errorreverse"); ofstream errorReverseFile; m->openOutputFile(errorReverseFileName, errorReverseFile); - outputNames.push_back(errorReverseFileName); outputTypes["error.reverse"].push_back(errorReverseFileName); + outputNames.push_back(errorReverseFileName); outputTypes["errorreverse"].push_back(errorReverseFileName); errorReverseFile << "position\ttotalseqs\tmatch\tsubstitution\tinsertion\tdeletion\tambiguous" << endl; for(int i=0;i > errorForward, map void SeqErrorCommand::printErrorQuality(map > qScoreErrorMap){ try{ - - string errorQualityFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.quality"; + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(queryFileName)); + string errorQualityFileName = fileNameRoot + getOutputFileNameTag("errorquality"); ofstream errorQualityFile; m->openOutputFile(errorQualityFileName, errorQualityFile); - outputNames.push_back(errorQualityFileName); outputTypes["error.quality"].push_back(errorQualityFileName); + outputNames.push_back(errorQualityFileName); outputTypes["errorquality"].push_back(errorQualityFileName); errorQualityFile << "qscore\tmatches\tsubstitutions\tinsertions\tambiguous" << endl; for(int i=0;i<41;i++){ @@ -1172,11 +1209,11 @@ void SeqErrorCommand::printQualityFR(vector > qualForwardMap, vector } } } - - string qualityForwardFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.qual.forward"; + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(queryFileName)); + string qualityForwardFileName = fileNameRoot + getOutputFileNameTag("errorqualforward"); ofstream qualityForwardFile; m->openOutputFile(qualityForwardFileName, qualityForwardFile); - outputNames.push_back(qualityForwardFileName); outputTypes["error.qual.forward"].push_back(qualityForwardFileName); + outputNames.push_back(qualityForwardFileName); outputTypes["errorqualforward"].push_back(qualityForwardFileName); for(int i=0;i > qualForwardMap, vector qualityForwardFile.close(); - string qualityReverseFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.qual.reverse"; + string qualityReverseFileName = fileNameRoot + getOutputFileNameTag("errorqualreverse"); ofstream qualityReverseFile; m->openOutputFile(qualityReverseFileName, qualityReverseFile); - outputNames.push_back(qualityReverseFileName); outputTypes["error.qual.reverse"].push_back(qualityReverseFileName); + outputNames.push_back(qualityReverseFileName); outputTypes["errorqualreverse"].push_back(qualityReverseFileName); for(int i=0;i setParameters(); string getCommandName() { return "seq.error"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Seq.error"; } string getDescription() { return "seq.error"; } diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index 1ea58c5..c328a04 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -45,6 +45,26 @@ string SeqSummaryCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string SeqSummaryCommand::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 == "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); + } +} //********************************************************************************************************************** SeqSummaryCommand::SeqSummaryCommand(){ @@ -155,7 +175,7 @@ int SeqSummaryCommand::execute(){ //set current fasta to fastafile m->setFastaFile(fastafile); - string summaryFile = outputDir + m->getSimpleName(fastafile) + ".summary"; + string summaryFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("summary"); int numSeqs = 0; diff --git a/seqsummarycommand.h b/seqsummarycommand.h index d8837a3..79e8be9 100644 --- a/seqsummarycommand.h +++ b/seqsummarycommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "summary.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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/sequenceparser.cpp b/sequenceparser.cpp index 3eb508d..c45602e 100644 --- a/sequenceparser.cpp +++ b/sequenceparser.cpp @@ -68,71 +68,84 @@ SequenceParser::SequenceParser(string groupFile, string fastaFile, string nameFi int countName = 0; set thisnames1; - while(!inName.eof()) { - + string rest = ""; + char buffer[4096]; + bool pairDone = false; + bool columnOne = true; + string firstCol, secondCol; + + while (!inName.eof()) { if (m->control_pressed) { break; } - inName >> first; m->gobble(inName); - inName >> second; m->gobble(inName); - - vector names; - m->splitAtChar(second, names, ','); - - //get aligned string for these seqs from the fasta file - string alignedString = ""; - map::iterator itAligned = seqName.find(names[0]); - if (itAligned == seqName.end()) { - error = 1; m->mothurOut("[ERROR]: " + names[0] + " is in your name file and not in your fasta file, please correct."); m->mothurOutEndLine(); - }else { - alignedString = itAligned->second; - } - - //separate by group - parse one line in name file - map splitMap; //group -> name1,name2,... - map::iterator it; - for (int i = 0; i < names.size(); i++) { - - string group = groupMap->getGroup(names[i]); - if (group == "not found") { error = 1; m->mothurOut("[ERROR]: " + names[i] + " is in your name file and not in your groupfile, please correct."); m->mothurOutEndLine(); } - else { - - it = splitMap.find(group); - if (it != splitMap.end()) { //adding seqs to this group - (it->second) += "," + names[i]; - thisnames1.insert(names[i]); - countName++; - }else { //first sighting of this group - splitMap[group] = names[i]; - countName++; - thisnames1.insert(names[i]); - - //is this seq in the fasta file? - if (i != 0) { //if not then we need to add a duplicate sequence to the seqs for this group so the new "fasta" and "name" files will match - Sequence tempSeq(names[i], alignedString); //get the first guys sequence string since he's in the fasta file. - seqs[group].push_back(tempSeq); - } - } - } - - allSeqsMap[names[i]] = names[0]; - } - - - //fill nameMapPerGroup - holds all lines in namefile separated by group - for (it = splitMap.begin(); it != splitMap.end(); it++) { - //grab first name - string firstName = ""; - for(int i = 0; i < (it->second).length(); i++) { - if (((it->second)[i]) != ',') { - firstName += ((it->second)[i]); - }else { break; } - } - - //group1 -> seq1 -> seq1,seq2,seq3 - nameMapPerGroup[it->first][firstName] = it->second; - } + inName.read(buffer, 4096); + vector pieces = m->splitWhiteSpace(rest, buffer, inName.gcount()); + + for (int i = 0; i < pieces.size(); i++) { + if (columnOne) { firstCol = pieces[i]; columnOne=false; } + else { secondCol = pieces[i]; pairDone = true; columnOne=true; } + + if (pairDone) { //save one line + vector names; + m->splitAtChar(second, names, ','); + + //get aligned string for these seqs from the fasta file + string alignedString = ""; + map::iterator itAligned = seqName.find(names[0]); + if (itAligned == seqName.end()) { + error = 1; m->mothurOut("[ERROR]: " + names[0] + " is in your name file and not in your fasta file, please correct."); m->mothurOutEndLine(); + }else { + alignedString = itAligned->second; + } + + //separate by group - parse one line in name file + map splitMap; //group -> name1,name2,... + map::iterator it; + for (int i = 0; i < names.size(); i++) { + + string group = groupMap->getGroup(names[i]); + if (group == "not found") { error = 1; m->mothurOut("[ERROR]: " + names[i] + " is in your name file and not in your groupfile, please correct."); m->mothurOutEndLine(); } + else { + + it = splitMap.find(group); + if (it != splitMap.end()) { //adding seqs to this group + (it->second) += "," + names[i]; + thisnames1.insert(names[i]); + countName++; + }else { //first sighting of this group + splitMap[group] = names[i]; + countName++; + thisnames1.insert(names[i]); + + //is this seq in the fasta file? + if (i != 0) { //if not then we need to add a duplicate sequence to the seqs for this group so the new "fasta" and "name" files will match + Sequence tempSeq(names[i], alignedString); //get the first guys sequence string since he's in the fasta file. + seqs[group].push_back(tempSeq); + } + } + } + + allSeqsMap[names[i]] = names[0]; + } + + + //fill nameMapPerGroup - holds all lines in namefile separated by group + for (it = splitMap.begin(); it != splitMap.end(); it++) { + //grab first name + string firstName = ""; + for(int i = 0; i < (it->second).length(); i++) { + if (((it->second)[i]) != ',') { + firstName += ((it->second)[i]); + }else { break; } + } + + //group1 -> seq1 -> seq1,seq2,seq3 + nameMapPerGroup[it->first][firstName] = it->second; + } + + pairDone = false; + } + } } - inName.close(); if (error == 1) { m->control_pressed = true; } diff --git a/setcurrentcommand.h b/setcurrentcommand.h index 3949519..becc4d4 100644 --- a/setcurrentcommand.h +++ b/setcurrentcommand.h @@ -23,6 +23,7 @@ public: vector setParameters(); string getCommandName() { return "set.current"; } string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Set.current"; } string getDescription() { return "set current files for mothur"; } diff --git a/setdircommand.h b/setdircommand.h index 9afc4ea..837a8b5 100644 --- a/setdircommand.h +++ b/setdircommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "set.dir"; } string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Set.dir"; } string getDescription() { return "set input, output and default directories"; } diff --git a/setlogfilecommand.h b/setlogfilecommand.h index 8d3bfcd..a97c791 100644 --- a/setlogfilecommand.h +++ b/setlogfilecommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "set.logfile"; } string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string) { return ""; } string getHelpString(); 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 f267ba4..08cf21e 100644 --- a/sffinfocommand.cpp +++ b/sffinfocommand.cpp @@ -55,6 +55,29 @@ string SffInfoCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string SffInfoCommand::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 = "fasta"; } + else if (type == "flow") { outputFileName = "flow"; } + else if (type == "sfftxt") { outputFileName = "sff.txt"; } + 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); + } +} //********************************************************************************************************************** @@ -365,14 +388,14 @@ int SffInfoCommand::extractSffInfo(string input, string accnos){ string rootName = outputDir + m->getRootName(m->getSimpleName(input)); if(rootName.find_last_of(".") == rootName.npos){ rootName += "."; } - string sfftxtFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "sff.txt"; - string outFlowFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "flow"; + 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)) + "fasta"; - outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "qual"; + 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.fasta"; - outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw.qual"; + outFastaFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw." + getOutputFileNameTag("fasta"); + outQualFileName = outputDir + m->getRootName(m->getSimpleName(input)) + "raw." + getOutputFileNameTag("qfile"); } 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); } @@ -940,17 +963,17 @@ int SffInfoCommand::parseSffTxt() { fileRoot = m->getRootName(fileRoot); } - string outFlowFileName = outputDir + fileRoot + "flow"; + string outFlowFileName = outputDir + fileRoot + getOutputFileNameTag("flow"); if (trim) { - outFastaFileName = outputDir + fileRoot + "fasta"; - outQualFileName = outputDir + fileRoot + "qual"; + outFastaFileName = outputDir + fileRoot + getOutputFileNameTag("fasta"); + outQualFileName = outputDir + fileRoot + getOutputFileNameTag("qfile"); }else{ - outFastaFileName = outputDir + fileRoot + "raw.fasta"; - outQualFileName = outputDir + fileRoot + "raw.qual"; + outFastaFileName = outputDir + fileRoot + "raw." + getOutputFileNameTag("fasta"); + outQualFileName = outputDir + fileRoot + "raw." + getOutputFileNameTag("qfile"); } 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["qual"].push_back(outQualFileName); } + if (qual) { m->openOutputFile(outQualFileName, outQual); outputNames.push_back(outQualFileName); outputTypes["qfile"].push_back(outQualFileName); } if (flow) { m->openOutputFile(outFlowFileName, outFlow); outputNames.push_back(outFlowFileName); outFlow.setf(ios::fixed, ios::floatfield); outFlow.setf(ios::showpoint); outputTypes["flow"].push_back(outFlowFileName); } //read common header diff --git a/sffinfocommand.h b/sffinfocommand.h index 837435b..4e72a96 100644 --- a/sffinfocommand.h +++ b/sffinfocommand.h @@ -69,6 +69,7 @@ public: vector setParameters(); string getCommandName() { return "sffinfo"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Sffinfo"; } string getDescription() { return "extract sequences reads from a .sff file"; } diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 8f05cfc..f3330f7 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -52,6 +52,29 @@ string SharedCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string SharedCommand::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 == "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); + } +} + //********************************************************************************************************************** SharedCommand::SharedCommand(){ try { @@ -131,6 +154,10 @@ SharedCommand::SharedCommand(string option) { } } + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; + outputTypes["group"] = tempOutNames; //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 = ""; } @@ -221,7 +248,7 @@ int SharedCommand::execute(){ if (outputDir == "") { outputDir += m->hasPath(filename); } filename = outputDir + m->getRootName(m->getSimpleName(filename)); - filename = filename + "shared"; + filename = filename + getOutputFileNameTag("shared"); outputNames.push_back(filename); outputTypes["shared"].push_back(filename); if (listfile != "") { createSharedFromListGroup(filename); } @@ -762,9 +789,9 @@ int SharedCommand::createSharedFromListGroup(string filename) { //clears file before we start to write to it below for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); - outputNames.push_back((fileroot + Groups[i] + ".rabund")); - outputTypes["rabund"].push_back((fileroot + Groups[i] + ".rabund")); + m->mothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); + outputNames.push_back((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); + outputTypes["rabund"].push_back((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } string errorOff = "no error"; @@ -781,7 +808,7 @@ int SharedCommand::createSharedFromListGroup(string filename) { delete SharedList; delete groupMap; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } + for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } return 0; } @@ -818,7 +845,7 @@ int SharedCommand::createSharedFromListGroup(string filename) { } }else { groups = "merge"; } - string newGroupFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + groups + "groups"; + string newGroupFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + groups + getOutputFileNameTag("group"); outputTypes["group"].push_back(newGroupFile); outputNames.push_back(newGroupFile); ofstream outGroups; @@ -844,7 +871,7 @@ int SharedCommand::createSharedFromListGroup(string filename) { delete SharedList; delete groupMap; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } + for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } return 0; } @@ -862,7 +889,7 @@ 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] + ".rabund")); } + for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } return 0; } @@ -892,7 +919,7 @@ 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] + ".rabund")); } + for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } return 0; } @@ -938,7 +965,7 @@ int SharedCommand::createSharedFromListGroup(string filename) { delete groupMap; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } + for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } return 0; } @@ -958,7 +985,7 @@ int SharedCommand::createSharedFromListGroup(string filename) { if (m->control_pressed) { m->mothurRemove(filename); - for (int i=0; imothurRemove((fileroot + Groups[i] + ".rabund")); } + for (int i=0; imothurRemove((fileroot + Groups[i] + "." + getOutputFileNameTag("rabund"))); } return 0; } @@ -987,7 +1014,7 @@ void SharedCommand::printSharedData(vector thislookup, ofst Groups.push_back(thislookup[i]->getGroup()); RAbundVector rav = thislookup[i]->getRAbundVector(); - m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()])); + m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + "." + getOutputFileNameTag("rabund"), *(filehandles[thislookup[i]->getGroup()])); rav.print(*(filehandles[thislookup[i]->getGroup()])); (*(filehandles[thislookup[i]->getGroup()])).close(); } @@ -1015,7 +1042,7 @@ void SharedCommand::printSharedData(vector thislookup, ofst Groups.push_back((myIt->second)->getGroup()); RAbundVector rav = (myIt->second)->getRAbundVector(); - m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + ".rabund", *(filehandles[(myIt->second)->getGroup()])); + m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + "." + getOutputFileNameTag("rabund"), *(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 5d0daa2..1100c3d 100644 --- a/sharedcommand.h +++ b/sharedcommand.h @@ -30,6 +30,7 @@ public: vector setParameters(); string getCommandName() { return "make.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 8ae76d9..97629b6 100644 --- a/shhhercommand.cpp +++ b/shhhercommand.cpp @@ -47,6 +47,30 @@ 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); + } +} +//********************************************************************************************************************** ShhherCommand::ShhherCommand(){ try { @@ -54,8 +78,12 @@ ShhherCommand::ShhherCommand(){ setParameters(); //initialize outputTypes -// vector tempOutNames; -// outputTypes["pn.dist"] = tempOutNames; + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["counts"] = tempOutNames; + outputTypes["qfile"] = tempOutNames; } catch(exception& e) { @@ -96,9 +124,13 @@ ShhherCommand::ShhherCommand(string option) { } //initialize outputTypes - vector tempOutNames; -// outputTypes["pn.dist"] = tempOutNames; - // outputTypes["fasta"] = tempOutNames; + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["counts"] = tempOutNames; + outputTypes["qfile"] = 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); @@ -770,7 +802,7 @@ string ShhherCommand::createNamesFile(){ duplicateNames[mapSeqToUnique[i]] += seqNameVector[i] + ','; } - string nameFileName = flowFileName.substr(0,flowFileName.find_last_of('.')) + ".shhh.names"; + string nameFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName) + getOutputFileNameTag("name"); ofstream nameFile; m->openOutputFile(nameFileName, nameFile); @@ -1614,7 +1646,7 @@ void ShhherCommand::writeQualities(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string qualityFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.qual"; + string qualityFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("qfile"); ofstream qualityFile; m->openOutputFile(qualityFileName, qualityFile); @@ -1721,7 +1753,7 @@ void ShhherCommand::writeSequences(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string fastaFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.fasta"; + string fastaFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("fasta"); ofstream fastaFile; m->openOutputFile(fastaFileName, fastaFile); @@ -1769,7 +1801,7 @@ void ShhherCommand::writeNames(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string nameFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.names"; + string nameFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("name"); ofstream nameFile; m->openOutputFile(nameFileName, nameFile); @@ -1808,7 +1840,7 @@ void ShhherCommand::writeGroups(){ string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } string fileRoot = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)); - string groupFileName = fileRoot + "shhh.groups"; + string groupFileName = fileRoot + getOutputFileNameTag("group"); ofstream groupFile; m->openOutputFile(groupFileName, groupFile); @@ -1832,7 +1864,7 @@ void ShhherCommand::writeClusters(vector otuCounts){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowFileName); } - string otuCountsFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.counts"; + string otuCountsFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) +getOutputFileNameTag("counts"); ofstream otuCountsFile; m->openOutputFile(otuCountsFileName, otuCountsFile); @@ -2283,12 +2315,12 @@ 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)) + "shhh.qual"; - string fastaFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.fasta"; - string nameFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.names"; - string otuCountsFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)) + "shhh.counts"; + 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"); string fileRoot = thisOutputDir + m->getRootName(m->getSimpleName(flowFileName)); - string groupFileName = fileRoot + "shhh.groups"; + string groupFileName = fileRoot + getOutputFileNameTag("group"); writeQualities(numOTUs, numFlowCells, qualityFileName, otuCounts, nSeqsPerOTU, seqNumber, singleTau, flowDataIntI, uniqueFlowgrams, cumNumSeqs, mapUniqueToSeq, seqNameVector, centroids, aaI); if (m->control_pressed) { break; } @@ -2299,15 +2331,15 @@ int ShhherCommand::driver(vector filenames, string thisCompositeFASTAFil if (large) { if (g > 0) { - m->appendFiles(qualityFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.qual")); + m->appendFiles(qualityFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("qfile"))); m->mothurRemove(qualityFileName); - m->appendFiles(fastaFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.fasta")); + m->appendFiles(fastaFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("fasta"))); m->mothurRemove(fastaFileName); - m->appendFiles(nameFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.names")); + m->appendFiles(nameFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("name"))); m->mothurRemove(nameFileName); - m->appendFiles(otuCountsFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.counts")); + m->appendFiles(otuCountsFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("counts"))); m->mothurRemove(otuCountsFileName); - m->appendFiles(groupFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.groups")); + m->appendFiles(groupFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + getOutputFileNameTag("group"))); m->mothurRemove(groupFileName); } m->mothurRemove(theseFlowFileNames[g]); diff --git a/shhhercommand.h b/shhhercommand.h index 5ef43df..03f171e 100644 --- a/shhhercommand.h +++ b/shhhercommand.h @@ -41,6 +41,7 @@ public: vector setParameters(); string getCommandName() { return "shhh.flows"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Shhh.flows"; } string getDescription() { return "shhh.flows"; } diff --git a/shhhseqscommand.cpp b/shhhseqscommand.cpp index 5c6359e..63de2bb 100644 --- a/shhhseqscommand.cpp +++ b/shhhseqscommand.cpp @@ -54,6 +54,29 @@ string ShhhSeqsCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string ShhhSeqsCommand::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_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); + } +} + //********************************************************************************************************************** ShhhSeqsCommand::ShhhSeqsCommand(){ @@ -185,9 +208,9 @@ 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)) + "shhh.fasta"; - string nameFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "shhh.names"; - string mapFileName = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "shhh.map"; + 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 (groupfile != "") { //Parse sequences by group diff --git a/shhhseqscommand.h b/shhhseqscommand.h index 7174ac7..a4695be 100644 --- a/shhhseqscommand.h +++ b/shhhseqscommand.h @@ -29,6 +29,7 @@ public: vector setParameters(); string getCommandName() { return "shhh.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Shhh.seqs"; } string getDescription() { return "shhh.seqs"; } diff --git a/sortseqscommand.cpp b/sortseqscommand.cpp index 0236a50..ee7bf73 100644 --- a/sortseqscommand.cpp +++ b/sortseqscommand.cpp @@ -52,6 +52,31 @@ string SortSeqsCommand::getHelpString(){ } } +//********************************************************************************************************************** +string SortSeqsCommand::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 = "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 == "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); + } +} //********************************************************************************************************************** SortSeqsCommand::SortSeqsCommand(){ @@ -230,7 +255,13 @@ int SortSeqsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } //read through the correct file and output lines you want to keep - if (accnosfile != "") { readAccnos(); } + if (accnosfile != "") { + vector temp; + m->readAccnos(accnosfile, temp); + for (int i = 0; i < temp.size(); i++) { names[temp[i]] = i; } + m->mothurOut("\nUsing " + accnosfile + " to determine the order. It contains " + toString(temp.size()) + " representative sequences.\n"); + } + if (fastafile != "") { readFasta(); } if (flowfile != "") { readFlow(); } if (qualfile != "") { readQual(); } @@ -294,7 +325,7 @@ int SortSeqsCommand::readFasta(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "sorted" + m->getExtension(fastafile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); outputTypes["fasta"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -467,7 +498,7 @@ int SortSeqsCommand::readFlow(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(flowfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowfile)) + "sorted" + m->getExtension(flowfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(flowfile)) + getOutputFileNameTag("flow", flowfile); outputTypes["flow"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -645,7 +676,7 @@ int SortSeqsCommand::readQual(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + "sorted" + m->getExtension(qualfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile); outputTypes["qfile"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -825,7 +856,7 @@ int SortSeqsCommand::readName(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(namefile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "sorted" + m->getExtension(namefile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); outputTypes["name"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -902,8 +933,8 @@ int SortSeqsCommand::readGroup(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile); - outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); + outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; m->openOutputFile(outputFileName, out); @@ -978,7 +1009,7 @@ int SortSeqsCommand::readTax(){ try { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile); + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile); outputTypes["taxonomy"].push_back(outputFileName); outputNames.push_back(outputFileName); ofstream out; @@ -1051,38 +1082,6 @@ int SortSeqsCommand::readTax(){ } } //********************************************************************************************************************** -int SortSeqsCommand::readAccnos(){ - try { - - ifstream in; - m->openInputFile(accnosfile, in); - string name; - int count = 0; - - while(!in.eof()){ - - if (m->control_pressed) { break; } - - in >> name; m->gobble(in); - - if (name != "") { - names[name] = count; - count++; - } - } - in.close(); - - m->mothurOut("\nUsing " + accnosfile + " to determine the order. It contains " + toString(count) + " representative sequences.\n"); - - return 0; - } - catch(exception& e) { - m->errorOut(e, "SortSeqsCommand", "readAccnos"); - exit(1); - } -} - -//********************************************************************************************************************** diff --git a/sortseqscommand.h b/sortseqscommand.h index 0685d3b..6d9c5ed 100644 --- a/sortseqscommand.h +++ b/sortseqscommand.h @@ -25,7 +25,8 @@ public: vector setParameters(); string getCommandName() { return "sort.seqs"; } string getCommandCategory() { return "Sequence Processing"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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"; } @@ -43,7 +44,6 @@ private: int readFlow(); int readName(); int readGroup(); - int readAccnos(); int readTax(); int readQual(); diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index 8131fa9..bc1cdb3 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -56,7 +56,30 @@ string SplitAbundCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string SplitAbundCommand::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 = "fasta"; } + else if (type == "list") { outputFileName = "list"; } + else if (type == "name") { outputFileName = "names"; } + 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); + } +} //********************************************************************************************************************** SplitAbundCommand::SplitAbundCommand(){ try { @@ -434,11 +457,11 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag) { ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "rare.list"; + string rare = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "rare." + getOutputFileNameTag("list"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["list"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "abund.list"; + string abund = outputDir + m->getRootName(m->getSimpleName(listfile)) + tag + "abund." + getOutputFileNameTag("list"); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["list"].push_back(abund); @@ -476,10 +499,12 @@ int SplitAbundCommand::writeList(ListVector* thisList, string tag) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + Groups[i] + tag + ".rare.list", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + Groups[i] + tag + ".abund.list", *(filehandles[Groups[i]+".abund"])); - outputNames.push_back(fileroot + Groups[i] + tag + ".rare.list"); outputTypes["list"].push_back(fileroot + Groups[i] + tag + ".rare.list"); - outputNames.push_back(fileroot + Groups[i] + tag + ".abund.list"); outputTypes["list"].push_back(fileroot + Groups[i] + tag + ".abund.list"); + string rareGroupFileName = fileroot + Groups[i] + tag + ".rare." + getOutputFileNameTag("list"); + string abundGroupFileName = fileroot + Groups[i] + tag + ".abund." + getOutputFileNameTag("list"); + m->openOutputFile(rareGroupFileName, *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(abundGroupFileName, *(filehandles[Groups[i]+".abund"])); + outputNames.push_back(rareGroupFileName); outputTypes["list"].push_back(rareGroupFileName); + outputNames.push_back(abundGroupFileName); outputTypes["list"].push_back(abundGroupFileName); } map groupVector; @@ -642,11 +667,11 @@ int SplitAbundCommand::writeNames() { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare.names"; + string rare = outputDir + m->getRootName(m->getSimpleName(namefile)) + "rare." + getOutputFileNameTag("name"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["name"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund.names"; + string abund = outputDir + m->getRootName(m->getSimpleName(namefile)) + "abund." + getOutputFileNameTag("name"); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["name"].push_back(abund); @@ -677,8 +702,10 @@ int SplitAbundCommand::writeNames() { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + Groups[i] + ".rare.names", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + Groups[i] + ".abund.names", *(filehandles[Groups[i]+".abund"])); + string rareGroupFileName = fileroot + Groups[i] + ".rare." + getOutputFileNameTag("name"); + string abundGroupFileName = fileroot + Groups[i] + ".abund." + getOutputFileNameTag("name"); + m->openOutputFile(rareGroupFileName, *(filehandles[Groups[i]+".rare"])); + m->openOutputFile(abundGroupFileName, *(filehandles[Groups[i]+".abund"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { @@ -714,7 +741,7 @@ int SplitAbundCommand::writeNames() { //namefile for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { (*(filehandles[it3->first])).close(); - outputNames.push_back(fileroot + it3->first + ".names"); outputTypes["name"].push_back(fileroot + it3->first + ".names"); + outputNames.push_back(fileroot + it3->first + "." + getOutputFileNameTag("name")); outputTypes["name"].push_back(fileroot + it3->first + "." + getOutputFileNameTag("name")); delete it3->second; } } @@ -739,7 +766,7 @@ int SplitAbundCommand::writeAccnos(string tag) { ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare.accnos"; + string rare = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "rare." + getOutputFileNameTag("accnos"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["accnos"].push_back(rare); @@ -748,7 +775,7 @@ int SplitAbundCommand::writeAccnos(string tag) { } rout.close(); - string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund.accnos"; + string abund = outputDir + m->getRootName(m->getSimpleName(inputFile)) + tag + "abund." + getOutputFileNameTag("accnos"); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["accnos"].push_back(abund); @@ -770,8 +797,8 @@ int SplitAbundCommand::writeAccnos(string tag) { temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + tag + Groups[i] + ".rare.accnos", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + tag + Groups[i] + ".abund.accnos", *(filehandles[Groups[i]+".abund"])); + 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"])); } //write rare @@ -795,7 +822,7 @@ 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 + ".accnos"); outputTypes["accnos"].push_back(fileroot + tag + it3->first + ".accnos"); + outputNames.push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("accnos")); outputTypes["accnos"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("accnos")); delete it3->second; } } @@ -818,11 +845,12 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare.groups"; + string rare = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "rare." + getOutputFileNameTag("group"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["group"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund.groups"; + string abund = outputDir + m->getRootName(m->getSimpleName(groupfile)) + tag + "abund." + getOutputFileNameTag("group"); +; m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["group"].push_back(abund); @@ -862,8 +890,8 @@ int SplitAbundCommand::parseGroup(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + tag + Groups[i] + ".rare.groups", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + tag + Groups[i] + ".abund.groups", *(filehandles[Groups[i]+".abund"])); + 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"])); } for (map::iterator itName = nameMap.begin(); itName != nameMap.end(); itName++) { @@ -889,7 +917,7 @@ 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 + ".groups"); outputTypes["group"].push_back(fileroot + tag + it3->first + ".groups"); + outputNames.push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("group")); outputTypes["group"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("group")); delete it3->second; } } @@ -912,11 +940,11 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile ofstream aout; ofstream rout; - string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare.fasta"; + string rare = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "rare." + getOutputFileNameTag("fasta"); m->openOutputFile(rare, rout); outputNames.push_back(rare); outputTypes["fasta"].push_back(rare); - string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund.fasta"; + string abund = outputDir + m->getRootName(m->getSimpleName(fastafile)) + tag + "abund." + getOutputFileNameTag("fasta"); m->openOutputFile(abund, aout); outputNames.push_back(abund); outputTypes["fasta"].push_back(abund); @@ -963,8 +991,8 @@ int SplitAbundCommand::parseFasta(string tag) { //namefile temp2 = new ofstream; filehandles[Groups[i]+".abund"] = temp2; - m->openOutputFile(fileroot + tag + Groups[i] + ".rare.fasta", *(filehandles[Groups[i]+".rare"])); - m->openOutputFile(fileroot + tag + Groups[i] + ".abund.fasta", *(filehandles[Groups[i]+".abund"])); + 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"])); } //open input file @@ -1009,7 +1037,7 @@ 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 + ".fasta"); outputTypes["fasta"].push_back(fileroot + tag + it3->first + ".fasta"); + outputNames.push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("fasta")); outputTypes["fasta"].push_back(fileroot + tag + it3->first + "." + getOutputFileNameTag("fasta")); delete it3->second; } } diff --git a/splitabundcommand.h b/splitabundcommand.h index df925f3..232c36b 100644 --- a/splitabundcommand.h +++ b/splitabundcommand.h @@ -35,6 +35,7 @@ public: vector setParameters(); string getCommandName() { return "split.abund"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 2671655..af3ca66 100644 --- a/splitgroupscommand.cpp +++ b/splitgroupscommand.cpp @@ -51,6 +51,27 @@ string SplitGroupCommand::getHelpString(){ } } //********************************************************************************************************************** +string SplitGroupCommand::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 = "fasta"; } + else if (type == "name") { outputFileName = "names"; } + 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); + } +} +//********************************************************************************************************************** SplitGroupCommand::SplitGroupCommand(){ try { abort = true; calledHelp = true; @@ -188,8 +209,8 @@ int SplitGroupCommand::execute(){ m->mothurOut("Processing group: " + Groups[i]); m->mothurOutEndLine(); - string newFasta = fastafileRoot + Groups[i] + ".fasta"; - string newName = namefileRoot + Groups[i] + ".names"; + string newFasta = fastafileRoot + Groups[i] + "." + getOutputFileNameTag("fasta"); + string newName = namefileRoot + Groups[i] + "." + getOutputFileNameTag("name"); parser->getSeqs(Groups[i], newFasta, false); outputNames.push_back(newFasta); outputTypes["fasta"].push_back(newFasta); diff --git a/splitgroupscommand.h b/splitgroupscommand.h index a6b8854..a8dc9a1 100644 --- a/splitgroupscommand.h +++ b/splitgroupscommand.h @@ -30,6 +30,7 @@ public: vector setParameters(); string getCommandName() { return "split.group"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 59e49a7..384b09a 100644 --- a/splitmatrix.cpp +++ b/splitmatrix.cpp @@ -91,16 +91,13 @@ int SplitMatrix::splitClassify(){ //build tree from users taxonomy file PhyloTree* phylo = new PhyloTree(); - ifstream in; - m->openInputFile(taxFile, in); - - //read in users taxonomy file and add sequences to tree - string seqname, tax; - while(!in.eof()){ - in >> seqname >> tax; m->gobble(in); - phylo->addSeqToTree(seqname, tax); - } - in.close(); + map temp; + m->readTax(taxFile, temp); + + for (map::iterator itTemp = temp.begin(); itTemp != temp.end();) { + phylo->addSeqToTree(itTemp->first, itTemp->second); + temp.erase(itTemp++); + } phylo->assignHeirarchyIDs(0); diff --git a/subsamplecommand.cpp b/subsamplecommand.cpp index aebba6b..3544101 100644 --- a/subsamplecommand.cpp +++ b/subsamplecommand.cpp @@ -63,6 +63,33 @@ string SubSampleCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string SubSampleCommand::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 = "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 == "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); + } +} + //********************************************************************************************************************** SubSampleCommand::SubSampleCommand(){ try { @@ -479,8 +506,7 @@ int SubSampleCommand::getSubSampleFasta() { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "subsample" + m->getExtension(fastafile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile); ofstream out; m->openOutputFile(outputFileName, out); @@ -528,6 +554,7 @@ int SubSampleCommand::getSubSampleFasta() { if (namefile != "") { m->mothurOut("Deconvoluting subsampled fasta file... "); m->mothurOutEndLine(); + string outputNameFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile); //use unique.seqs to create new name and fastafile string inputString = "fasta=" + outputFileName; m->mothurOut("/******************************************/"); m->mothurOutEndLine(); @@ -542,10 +569,11 @@ int SubSampleCommand::getSubSampleFasta() { delete uniqueCommand; m->mothurCalling = false; - outputTypes["name"].push_back(filenames["name"][0]); outputNames.push_back(filenames["name"][0]); - m->mothurRemove(outputFileName); - outputFileName = filenames["fasta"][0]; - + m->renameFile(filenames["name"][0], outputNameFileName); + m->renameFile(filenames["fasta"][0], outputFileName); + + outputTypes["name"].push_back(outputNameFileName); outputNames.push_back(outputNameFileName); + m->mothurOut("/******************************************/"); m->mothurOutEndLine(); m->mothurOut("Done."); m->mothurOutEndLine(); @@ -558,7 +586,7 @@ int SubSampleCommand::getSubSampleFasta() { string groupOutputDir = outputDir; if (outputDir == "") { groupOutputDir += m->hasPath(groupfile); } - string groupOutputFileName = groupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "subsample" + m->getExtension(groupfile); + string groupOutputFileName = groupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile); ofstream outGroup; m->openOutputFile(groupOutputFileName, outGroup); @@ -780,8 +808,7 @@ 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() + ".subsample" + m->getExtension(sharedfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + thislookup[0]->getLabel() + getOutputFileNameTag("shared", sharedfile); SubSample sample; vector subsampledLabels = sample.getSample(thislookup, size); @@ -819,8 +846,7 @@ int SubSampleCommand::getSubSampleList() { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(listfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "subsample" + m->getExtension(listfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName); @@ -1164,8 +1190,7 @@ int SubSampleCommand::getSubSampleRabund() { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(rabundfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + "subsample" + m->getExtension(rabundfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + getOutputFileNameTag("rabund", rabundfile); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName); @@ -1319,8 +1344,7 @@ int SubSampleCommand::getSubSampleSabund() { string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sabundfile); } - string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + "subsample" + m->getExtension(sabundfile); - + string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + getOutputFileNameTag("sabund", sabundfile); ofstream out; m->openOutputFile(outputFileName, out); outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName); diff --git a/subsamplecommand.h b/subsamplecommand.h index 7235a7b..c746e14 100644 --- a/subsamplecommand.h +++ b/subsamplecommand.h @@ -28,6 +28,7 @@ public: vector setParameters(); string getCommandName() { return "sub.sample"; } string getCommandCategory() { return "General"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 85f0970..9a6aac8 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -84,7 +84,26 @@ string SummaryCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string SummaryCommand::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 == "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); + } +} //********************************************************************************************************************** SummaryCommand::SummaryCommand(){ try { @@ -288,13 +307,10 @@ int SummaryCommand::execute(){ numLines = 0; numCols = 0; - string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "summary"; - string fileNameAve = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "ave"; - string fileNameSTD = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "std"; - outputNames.push_back(fileNameRoot); outputTypes["summary"].push_back(fileNameRoot); + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + getOutputFileNameTag("summary"); + string fileNameAve = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "ave-std." + getOutputFileNameTag("summary"); + outputNames.push_back(fileNameRoot); outputTypes["summary"].push_back(fileNameRoot); - - if (inputFileNames.size() > 1) { m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); groupIndex[fileNameRoot] = groups[p]; @@ -369,18 +385,14 @@ int SummaryCommand::execute(){ m->openOutputFile(fileNameRoot, outputFileHandle); outputFileHandle << "label"; - ofstream outAve, outSTD; + ofstream outAve; if (subsample) { m->openOutputFile(fileNameAve, outAve); - m->openOutputFile(fileNameSTD, outSTD); - outputNames.push_back(fileNameAve); outputTypes["ave"].push_back(fileNameAve); - outputNames.push_back(fileNameSTD); outputTypes["std"].push_back(fileNameSTD); - outAve << "label"; outSTD << "label"; + outputNames.push_back(fileNameAve); outputTypes["summary"].push_back(fileNameAve); + outAve << "label\tmethod"; outAve.setf(ios::fixed, ios::floatfield); outAve.setf(ios::showpoint); - outSTD.setf(ios::fixed, ios::floatfield); outSTD.setf(ios::showpoint); if (inputFileNames.size() > 1) { groupIndex[fileNameAve] = groups[p]; - groupIndex[fileNameSTD] = groups[p]; } } @@ -391,17 +403,17 @@ int SummaryCommand::execute(){ for(int i=0;igetCols() == 1){ outputFileHandle << '\t' << sumCalculators[i]->getName(); - if (subsample) { outAve << '\t' << sumCalculators[i]->getName(); outSTD << '\t' << sumCalculators[i]->getName(); } + if (subsample) { outAve << '\t' << sumCalculators[i]->getName(); } numCols++; } else{ outputFileHandle << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; - if (subsample) { outAve << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; outSTD << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; } + if (subsample) { outAve << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci"; } numCols += 3; } } outputFileHandle << endl; - if (subsample) { outSTD << endl; outAve << endl; } + if (subsample) { outAve << endl; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -409,11 +421,11 @@ int SummaryCommand::execute(){ - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;igetLabel()) == 1){ @@ -421,9 +433,9 @@ int SummaryCommand::execute(){ processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); - process(sabund, outputFileHandle, outAve, outSTD); + process(sabund, outputFileHandle, outAve); - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;igetLabel()); userLabels.erase(sabund->getLabel()); - process(sabund, outputFileHandle, outAve, outSTD); + process(sabund, outputFileHandle, outAve); - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;igetSAbundVector(); } - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i::iterator it; @@ -473,15 +485,15 @@ int SummaryCommand::execute(){ sabund = input->getSAbundVector(lastLabel); m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); - process(sabund, outputFileHandle, outAve, outSTD); + process(sabund, outputFileHandle, outAve); - if (m->control_pressed) { outputFileHandle.close(); outAve.close(); outSTD.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { outputFileHandle.close(); outAve.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;icontrol_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } for(int i=0;i data -> values @@ -559,7 +571,7 @@ int SummaryCommand::process(SAbundVector*& sabund, ofstream& outputFileHandle, o outputFileHandle << endl; if (subsample) { - outAve << sabund->getLabel() << '\t'; outStd << sabund->getLabel() << '\t'; + outAve << sabund->getLabel() << '\t' << "ave\t"; //find ave and std for this label and output //will need to modify the createGroupSummary to combine results and not mess with the .summary file. @@ -594,14 +606,15 @@ int SummaryCommand::process(SAbundVector*& sabund, ofstream& outputFileHandle, o } } + outAve << endl << sabund->getLabel() << '\t' << "std\t"; for (int i = 0; i < stdDev.size(); i++) { //finds average. for (int j = 0; j < stdDev[i].size(); j++) { stdDev[i][j] /= (float) iters; stdDev[i][j] = sqrt(stdDev[i][j]); - outStd << stdDev[i][j] << '\t'; + outAve << stdDev[i][j] << '\t'; } } - outAve << endl; outStd << endl; + outAve << endl; } return 0; @@ -702,38 +715,37 @@ vector SummaryCommand::createGroupSummaryFile(int numLines, int numCols, //open each groups summary file vector newComboNames; - string newLabel = ""; + map > > files; + map filesTypesLabels; + map filesTypesNumLines; for (int i=0; igetExtension(outputNames[i]); - string combineFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "groups" + extension; - m->mothurRemove(combineFileName); //remove old file - vector thisFilesLines; ifstream temp; m->openInputFile(outputNames[i], temp); //read through first line - labels - string tempLabel; - if (i == 0) { //we want to save the labels to output below - for (int j = 0; j < numCols+1; j++) { - temp >> tempLabel; - - if (j == 1) { newLabel += "group\t" + tempLabel + '\t'; - }else{ newLabel += tempLabel + '\t'; } - } - }else{ for (int j = 0; j < numCols+1; j++) { temp >> tempLabel; } } + string labelsLine = m->getline(temp); + vector theseLabels = m->splitWhiteSpace(labelsLine); + + string newLabel = ""; + for (int j = 0; j < theseLabels.size(); j++) { + if (j == 1) { newLabel += "group\t" + theseLabels[j] + '\t'; + }else{ newLabel += theseLabels[j] + '\t'; } + } m->gobble(temp); + int stop = numLines; + if (theseLabels.size() != numCols+1) { stop = numLines*2; } //for each label - for (int k = 0; k < numLines; k++) { + for (int k = 0; k < stop; k++) { string thisLine = ""; string tempLabel; - for (int j = 0; j < numCols+1; j++) { + for (int j = 0; j < theseLabels.size(); j++) { temp >> tempLabel; //save for later @@ -748,6 +760,13 @@ vector SummaryCommand::createGroupSummaryFile(int numLines, int numCols, m->gobble(temp); } + string extension = m->getExtension(outputNames[i]); + if (theseLabels.size() != numCols+1) { extension = ".ave-std" + extension; } + string combineFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "groups" + extension; + m->mothurRemove(combineFileName); //remove old file + filesTypesLabels[extension] = newLabel; + filesTypesNumLines[extension] = stop; + map > >::iterator itFiles = files.find(extension); if (itFiles != files.end()) { //add new files info to existing type files[extension][outputNames[i]] = thisFilesLines; @@ -758,7 +777,7 @@ vector SummaryCommand::createGroupSummaryFile(int numLines, int numCols, } temp.close(); - m->mothurRemove(outputNames[i]); + //m->mothurRemove(outputNames[i]); } @@ -775,10 +794,10 @@ vector SummaryCommand::createGroupSummaryFile(int numLines, int numCols, m->openOutputFile(combineFileName, out); //output label line to new file - out << newLabel << endl; + out << filesTypesLabels[extension] << endl; //for each label - for (int k = 0; k < numLines; k++) { + for (int k = 0; k < filesTypesNumLines[extension]; k++) { //grab summary data for each group for (map >::iterator itType = thisType.begin(); itType != thisType.end(); itType++) { diff --git a/summarycommand.h b/summarycommand.h index 1d93a33..4936dd8 100644 --- a/summarycommand.h +++ b/summarycommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "summary.single"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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"; } @@ -48,7 +49,7 @@ private: vector parseSharedFile(string); vector createGroupSummaryFile(int, int, vector&, map); - int process(SAbundVector*&, ofstream&, ofstream&, ofstream&); + int process(SAbundVector*&, ofstream&, ofstream&); }; diff --git a/summaryqualcommand.cpp b/summaryqualcommand.cpp index 5c17510..5d79713 100644 --- a/summaryqualcommand.cpp +++ b/summaryqualcommand.cpp @@ -45,7 +45,26 @@ string SummaryQualCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string SummaryQualCommand::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 == "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); + } +} //********************************************************************************************************************** SummaryQualCommand::SummaryQualCommand(){ try { @@ -189,7 +208,7 @@ int SummaryQualCommand::execute(){ if (m->control_pressed) { return 0; } //print summary file - string summaryFile = outputDir + m->getRootName(m->getSimpleName(qualfile)) + "qual.summary"; + string summaryFile = outputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("summary"); printQual(summaryFile, position, averageQ, scores); if (m->control_pressed) { m->mothurRemove(summaryFile); return 0; } diff --git a/summaryqualcommand.h b/summaryqualcommand.h index bbd103c..31390b4 100644 --- a/summaryqualcommand.h +++ b/summaryqualcommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "summary.qual"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 6792f19..50fbd32 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -64,12 +64,34 @@ string SummarySharedCommand::getHelpString(){ } } //********************************************************************************************************************** +string SummarySharedCommand::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 == "summary") { outputFileName = "shared.summary"; } + 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); + } +} +//********************************************************************************************************************** SummarySharedCommand::SummarySharedCommand(){ try { abort = true; calledHelp = true; setParameters(); vector tempOutNames; outputTypes["summary"] = tempOutNames; + outputTypes["phylip"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand"); @@ -104,6 +126,7 @@ SummarySharedCommand::SummarySharedCommand(string option) { //initialize outputTypes vector tempOutNames; outputTypes["summary"] = tempOutNames; + outputTypes["phylip"] = 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); @@ -294,7 +317,7 @@ int SummarySharedCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } ofstream outputFileHandle, outAll; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "shared.summary"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("summary"); //if the users entered no valid calculators don't execute command if (sumCalculators.size() == 0) { return 0; } @@ -325,7 +348,7 @@ int SummarySharedCommand::execute(){ outputFileHandle.close(); //create file and put column headers for multiple groups file - string outAllFileName = ((m->getRootName(sharedfile)) + "sharedmultiple.summary"); + string outAllFileName = ((m->getRootName(sharedfile)) + "multiple." + getOutputFileNameTag("summary")); if (mult == true) { m->openOutputFile(outAllFileName, outAll); outputNames.push_back(outAllFileName); @@ -763,7 +786,7 @@ 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 + ".dist"; + string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + "." + getOutputFileNameTag("phylip"); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outDist; m->openOutputFile(distFileName, outDist); @@ -856,7 +879,7 @@ 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.dist"; + string distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".ave." + getOutputFileNameTag("phylip");; outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outAve; m->openOutputFile(distFileName, outAve); @@ -866,7 +889,7 @@ int SummarySharedCommand::process(vector thisLookup, string outAve.close(); - distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".std.dist"; + distFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + sumCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".std." + getOutputFileNameTag("phylip"); outputNames.push_back(distFileName); outputTypes["phylip"].push_back(distFileName); ofstream outSTD; m->openOutputFile(distFileName, outSTD); diff --git a/summarysharedcommand.h b/summarysharedcommand.h index 99ed5d0..7c6a4b2 100644 --- a/summarysharedcommand.h +++ b/summarysharedcommand.h @@ -67,6 +67,7 @@ public: vector setParameters(); string getCommandName() { return "summary.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 ffa3041..3e16e74 100644 --- a/summarytaxcommand.cpp +++ b/summarytaxcommand.cpp @@ -48,7 +48,26 @@ string SummaryTaxCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string SummaryTaxCommand::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 == "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); + } +} //********************************************************************************************************************** SummaryTaxCommand::SummaryTaxCommand(){ try { @@ -225,7 +244,7 @@ int SummaryTaxCommand::execute(){ //print summary file ofstream outTaxTree; - string summaryFile = outputDir + m->getRootName(m->getSimpleName(taxfile)) + "tax.summary"; + string summaryFile = outputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("summary"); m->openOutputFile(summaryFile, outTaxTree); taxaSum->print(outTaxTree); outTaxTree.close(); diff --git a/summarytaxcommand.h b/summarytaxcommand.h index b5bdab1..5f0630f 100644 --- a/summarytaxcommand.h +++ b/summarytaxcommand.h @@ -23,7 +23,8 @@ class SummaryTaxCommand : public Command { vector setParameters(); string getCommandName() { return "summary.tax"; } string getCommandCategory() { return "Phylotype Analysis"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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.h b/systemcommand.h index 6a4b884..6dc09ef 100644 --- a/systemcommand.h +++ b/systemcommand.h @@ -24,7 +24,8 @@ class SystemCommand : public Command { vector setParameters(); string getCommandName() { return "system"; } string getCommandCategory() { return "General"; } - string getHelpString(); + string getOutputFileNameTag(string, string) { return ""; } + string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/System"; } string getDescription() { return "execute system commands from within mothur"; } diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index c26199d..888f502 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -70,6 +70,26 @@ string TreeGroupCommand::getHelpString(){ } } //********************************************************************************************************************** +string TreeGroupCommand::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 == "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); + } +} +//********************************************************************************************************************** TreeGroupCommand::TreeGroupCommand(){ try { abort = true; calledHelp = true; @@ -442,7 +462,7 @@ int TreeGroupCommand::execute(){ if (m->control_pressed) { return 0; } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); Tree* newTree = createTree(matrix); @@ -896,7 +916,7 @@ int TreeGroupCommand::process(vector thisLookup) { } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".ave.tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".ave." + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); //creates tree from similarity matrix and write out file @@ -909,7 +929,7 @@ 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.tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".all." + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); ofstream outAll; @@ -950,7 +970,7 @@ 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.tre"; + string conFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".cons." + getOutputFileNameTag("tree"); outputNames.push_back(conFile); outputTypes["tree"].push_back(conFile); ofstream outTree; m->openOutputFile(conFile, outTree); @@ -978,7 +998,7 @@ int TreeGroupCommand::process(vector thisLookup) { } //create a new filename - string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + getOutputFileNameTag("tree"); 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 d3c1b3e..a0e0d42 100644 --- a/treegroupscommand.h +++ b/treegroupscommand.h @@ -81,6 +81,7 @@ public: vector setParameters(); string getCommandName() { return "tree.shared"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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/treemap.cpp b/treemap.cpp index c228162..42ec336 100644 --- a/treemap.cpp +++ b/treemap.cpp @@ -21,75 +21,107 @@ TreeMap::~TreeMap(){} /************************************************************/ int TreeMap::readMap(string gf) { - - groupFileName = gf; - m->openInputFile(gf, fileHandle); - - string seqName, seqGroup; - int error = 0; - - while(fileHandle){ - fileHandle >> seqName; m->gobble(fileHandle); //read from first column - fileHandle >> seqGroup; //read from second column + try { + groupFileName = gf; + m->openInputFile(gf, fileHandle); - if (m->control_pressed) { fileHandle.close(); return 1; } - - setNamesOfGroups(seqGroup); + string seqName, seqGroup; + int error = 0; + + string rest = ""; + char buffer[4096]; + bool pairDone = false; + bool columnOne = true; - map::iterator itCheck = treemap.find(seqName); - if (itCheck != treemap.end()) { error = 1; m->mothurOut("[WARNING]: Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); m->mothurOutEndLine(); } - else { - namesOfSeqs.push_back(seqName); - treemap[seqName].groupname = seqGroup; //store data in map + while (!fileHandle.eof()) { + if (m->control_pressed) { fileHandle.close(); return 1; } - it2 = seqsPerGroup.find(seqGroup); - if (it2 == seqsPerGroup.end()) { //if it's a new group - seqsPerGroup[seqGroup] = 1; - }else {//it's a group we already have - seqsPerGroup[seqGroup]++; - } + fileHandle.read(buffer, 4096); + vector pieces = m->splitWhiteSpace(rest, buffer, fileHandle.gcount()); + + for (int i = 0; i < pieces.size(); i++) { + if (columnOne) { seqName = pieces[i]; columnOne=false; } + else { seqGroup = pieces[i]; pairDone = true; columnOne=true; } + + if (pairDone) { + setNamesOfGroups(seqGroup); + + map::iterator itCheck = treemap.find(seqName); + if (itCheck != treemap.end()) { error = 1; m->mothurOut("[WARNING]: Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); m->mothurOutEndLine(); } + else { + namesOfSeqs.push_back(seqName); + treemap[seqName].groupname = seqGroup; //store data in map + + it2 = seqsPerGroup.find(seqGroup); + if (it2 == seqsPerGroup.end()) { //if it's a new group + seqsPerGroup[seqGroup] = 1; + }else {//it's a group we already have + seqsPerGroup[seqGroup]++; + } + } + pairDone = false; + } + } } + fileHandle.close(); - m->gobble(fileHandle); + return error; } - fileHandle.close(); - - return error; + catch(exception& e) { + m->errorOut(e, "TreeMap", "readMap"); + exit(1); + } } /************************************************************/ int TreeMap::readMap() { - string seqName, seqGroup; - int error = 0; - - while(fileHandle){ - fileHandle >> seqName; m->gobble(fileHandle); //read from first column - fileHandle >> seqGroup; //read from second column - - if (m->control_pressed) { fileHandle.close(); return 1; } - - setNamesOfGroups(seqGroup); - - map::iterator itCheck = treemap.find(seqName); - if (itCheck != treemap.end()) { error = 1; m->mothurOut("[WARNING]: Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); m->mothurOutEndLine(); } - else { - namesOfSeqs.push_back(seqName); - treemap[seqName].groupname = seqGroup; //store data in map - - it2 = seqsPerGroup.find(seqGroup); - if (it2 == seqsPerGroup.end()) { //if it's a new group - seqsPerGroup[seqGroup] = 1; - }else {//it's a group we already have - seqsPerGroup[seqGroup]++; - } - } - - m->gobble(fileHandle); - } - fileHandle.close(); - - - return error; + try { + string seqName, seqGroup; + int error = 0; + + string rest = ""; + char buffer[4096]; + bool pairDone = false; + bool columnOne = true; + + while (!fileHandle.eof()) { + if (m->control_pressed) { fileHandle.close(); return 1; } + + fileHandle.read(buffer, 4096); + vector pieces = m->splitWhiteSpace(rest, buffer, fileHandle.gcount()); + + for (int i = 0; i < pieces.size(); i++) { + if (columnOne) { seqName = pieces[i]; columnOne=false; } + else { seqGroup = pieces[i]; pairDone = true; columnOne=true; } + + if (pairDone) { + setNamesOfGroups(seqGroup); + + map::iterator itCheck = treemap.find(seqName); + if (itCheck != treemap.end()) { error = 1; m->mothurOut("[WARNING]: Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); m->mothurOutEndLine(); } + else { + namesOfSeqs.push_back(seqName); + treemap[seqName].groupname = seqGroup; //store data in map + + it2 = seqsPerGroup.find(seqGroup); + if (it2 == seqsPerGroup.end()) { //if it's a new group + seqsPerGroup[seqGroup] = 1; + }else {//it's a group we already have + seqsPerGroup[seqGroup]++; + } + } + pairDone = false; + } + } + } + fileHandle.close(); + + return error; + } + catch(exception& e) { + m->errorOut(e, "TreeMap", "readMap"); + exit(1); + } } /************************************************************/ void TreeMap::addSeq(string seqName, string seqGroup) { diff --git a/trimflowscommand.cpp b/trimflowscommand.cpp index 0557c71..d45f20c 100644 --- a/trimflowscommand.cpp +++ b/trimflowscommand.cpp @@ -56,7 +56,28 @@ string TrimFlowsCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string TrimFlowsCommand::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 == "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); + } +} //********************************************************************************************************************** TrimFlowsCommand::TrimFlowsCommand(){ @@ -66,6 +87,7 @@ TrimFlowsCommand::TrimFlowsCommand(){ vector tempOutNames; outputTypes["flow"] = tempOutNames; outputTypes["fasta"] = tempOutNames; + outputTypes["file"] = tempOutNames; } catch(exception& e) { m->errorOut(e, "TrimFlowsCommand", "TrimFlowsCommand"); @@ -103,6 +125,7 @@ TrimFlowsCommand::TrimFlowsCommand(string option) { vector tempOutNames; outputTypes["flow"] = tempOutNames; outputTypes["fasta"] = tempOutNames; + outputTypes["file"] = 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); @@ -225,13 +248,13 @@ int TrimFlowsCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string trimFlowFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "trim.flow"; + string trimFlowFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "trim." + getOutputFileNameTag("flow"); outputNames.push_back(trimFlowFileName); outputTypes["flow"].push_back(trimFlowFileName); - string scrapFlowFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "scrap.flow"; + string scrapFlowFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "scrap." + getOutputFileNameTag("flow");; outputNames.push_back(scrapFlowFileName); outputTypes["flow"].push_back(scrapFlowFileName); - string fastaFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "flow.fasta"; + string fastaFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("fasta"); if(fasta){ outputNames.push_back(fastaFileName); outputTypes["fasta"].push_back(fastaFileName); } @@ -284,7 +307,7 @@ int TrimFlowsCommand::execute(){ if(allFiles){ set namesAlreadyProcessed; - flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + "flow.files"; + flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("file"); m->openOutputFile(flowFilesFileName, output); for(int i=0;igetRootName(m->getSimpleName(flowFileName)) + "flow.files"; + flowFilesFileName = outputDir + m->getRootName(m->getSimpleName(flowFileName)) + getOutputFileNameTag("file"); m->openOutputFile(flowFilesFileName, output); output << m->getFullPathName(trimFlowFileName) << endl; diff --git a/trimflowscommand.h b/trimflowscommand.h index 414c73c..b7fbf43 100644 --- a/trimflowscommand.h +++ b/trimflowscommand.h @@ -26,6 +26,7 @@ public: vector setParameters(); string getCommandName() { return "trim.flows"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Trim.flows"; } string getDescription() { return "trim.flows"; } diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index 6f5bb97..6a8afd0 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -97,6 +97,29 @@ string TrimSeqsCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string TrimSeqsCommand::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 == "qfile") { outputFileName = "qual"; } + else if (type == "fasta") { outputFileName = "fasta"; } + else if (type == "group") { outputFileName = "groups"; } + else if (type == "name") { outputFileName = "names"; } + 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); + } +} //********************************************************************************************************************** @@ -336,14 +359,14 @@ int TrimSeqsCommand::execute(){ vector > qualFileNames; vector > nameFileNames; - string trimSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim.fasta"; + string trimSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim." + getOutputFileNameTag("fasta"); outputNames.push_back(trimSeqFile); outputTypes["fasta"].push_back(trimSeqFile); - string scrapSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap.fasta"; + string scrapSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap." + getOutputFileNameTag("fasta"); outputNames.push_back(scrapSeqFile); outputTypes["fasta"].push_back(scrapSeqFile); - string trimQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim.qual"; - string scrapQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap.qual"; + 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); @@ -352,8 +375,8 @@ int TrimSeqsCommand::execute(){ outputTypes["qfile"].push_back(scrapQualFile); } - string trimNameFile = outputDir + m->getRootName(m->getSimpleName(nameFile)) + "trim.names"; - string scrapNameFile = outputDir + m->getRootName(m->getSimpleName(nameFile)) + "scrap.names"; + string trimNameFile = outputDir + m->getRootName(m->getSimpleName(nameFile)) + "trim." + getOutputFileNameTag("name"); + string scrapNameFile = outputDir + m->getRootName(m->getSimpleName(nameFile)) + "scrap." + getOutputFileNameTag("name"); if (nameFile != "") { m->readNames(nameFile, nameMap); @@ -369,7 +392,7 @@ int TrimSeqsCommand::execute(){ if(oligoFile != ""){ createGroup = getOligos(fastaFileNames, qualFileNames, nameFileNames); if (createGroup) { - outputGroupFileName = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "groups"; + outputGroupFileName = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + getOutputFileNameTag("group"); outputNames.push_back(outputGroupFileName); outputTypes["group"].push_back(outputGroupFileName); } } @@ -428,7 +451,7 @@ int TrimSeqsCommand::execute(){ m->openInputFile(it->first, in); ofstream out; - string thisGroupName = outputDir + m->getRootName(m->getSimpleName(it->first)) + "groups"; + string thisGroupName = outputDir + m->getRootName(m->getSimpleName(it->first)) + getOutputFileNameTag("group"); outputNames.push_back(thisGroupName); outputTypes["group"].push_back(thisGroupName); m->openOutputFile(thisGroupName, out); diff --git a/trimseqscommand.h b/trimseqscommand.h index e280c8a..957f37a 100644 --- a/trimseqscommand.h +++ b/trimseqscommand.h @@ -27,6 +27,7 @@ public: vector setParameters(); string getCommandName() { return "trim.seqs"; } string getCommandCategory() { return "Sequence Processing"; } + string getOutputFileNameTag(string, string); string getHelpString(); 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 318409f..0650ea0 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -63,6 +63,31 @@ string UnifracUnweightedCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +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); + } +} + //********************************************************************************************************************** UnifracUnweightedCommand::UnifracUnweightedCommand(){ try { @@ -248,7 +273,7 @@ int UnifracUnweightedCommand::execute() { map unique2Dup = reader->getNameMap(); delete reader; - sumFile = outputDir + m->getSimpleName(treefile) + ".uwsummary"; + sumFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + getOutputFileNameTag("uwsummary"); outputNames.push_back(sumFile); outputTypes["uwsummary"].push_back(sumFile); m->openOutputFile(sumFile, outSum); @@ -309,9 +334,9 @@ int UnifracUnweightedCommand::execute() { counter = 0; if (random) { - output = new ColumnFile(outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted", itersString); - outputNames.push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted"); - outputTypes["unweighted"].push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted"); + 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")); } @@ -480,15 +505,15 @@ int UnifracUnweightedCommand::getAverageSTDMatrices(vector< vector >& di } } - string aveFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".unweighted.ave.dist"; - outputNames.push_back(aveFileName); outputTypes["phylip"].push_back(aveFileName); - + string aveFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".unweighted.ave." + getOutputFileNameTag("phylip"); + 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.dist"; - outputNames.push_back(stdFileName); outputTypes["phylip"].push_back(stdFileName); - + string stdFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".unweighted.std." + getOutputFileNameTag("phylip"); + if (outputForm != "column") { outputNames.push_back(stdFileName); outputTypes["phylip"].push_back(stdFileName); } + else { outputNames.push_back(stdFileName); outputTypes["column"].push_back(stdFileName); } ofstream outStd; m->openOutputFile(stdFileName, outStd); @@ -569,7 +594,7 @@ 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.tre"; + string conFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(treeNum+1) + ".unweighted.cons." + getOutputFileNameTag("tree"); outputNames.push_back(conFile); outputTypes["tree"].push_back(conFile); ofstream outTree; m->openOutputFile(conFile, outTree); @@ -593,7 +618,7 @@ 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.tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(treeNum+1) + ".unweighted.all." + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); ofstream outAll; @@ -761,10 +786,10 @@ void UnifracUnweightedCommand::createPhylipFile(int i) { try { string phylipFileName; if ((outputForm == "lt") || (outputForm == "square")) { - phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted.phylip.dist"; + phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted.phylip." + getOutputFileNameTag("phylip"); outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName); }else { //column - phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted.column.dist"; + phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted.column." + getOutputFileNameTag("column"); outputNames.push_back(phylipFileName); outputTypes["column"].push_back(phylipFileName); } diff --git a/unifracunweightedcommand.h b/unifracunweightedcommand.h index fd39ae4..15c3b96 100644 --- a/unifracunweightedcommand.h +++ b/unifracunweightedcommand.h @@ -27,7 +27,8 @@ class UnifracUnweightedCommand : public Command { vector setParameters(); string getCommandName() { return "unifrac.unweighted"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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 1df7988..13d10fd 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -64,6 +64,30 @@ string UnifracWeightedCommand::getHelpString(){ } } //********************************************************************************************************************** +string UnifracWeightedCommand::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 == "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); + } +} +//********************************************************************************************************************** UnifracWeightedCommand::UnifracWeightedCommand(){ try { abort = true; calledHelp = true; @@ -242,7 +266,7 @@ int UnifracWeightedCommand::execute() { if (m->control_pressed) { delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } return 0; } - sumFile = outputDir + m->getSimpleName(treefile) + ".wsummary"; + sumFile = outputDir + m->getSimpleName(treefile) + getOutputFileNameTag("wsummary"); m->openOutputFile(sumFile, outSum); outputNames.push_back(sumFile); outputTypes["wsummary"].push_back(sumFile); @@ -306,9 +330,9 @@ 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) + ".weighted", itersString); - outputNames.push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted"); - outputTypes["weighted"].push_back(outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted"); + 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")); } userData = weighted.getValues(T[i], processors, outputDir); //userData[0] = weightedscore @@ -461,15 +485,15 @@ int UnifracWeightedCommand::getAverageSTDMatrices(vector< vector >& dist } } - string aveFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".weighted.ave.dist"; - outputNames.push_back(aveFileName); outputTypes["phylip"].push_back(aveFileName); - + string aveFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".weighted.ave." + getOutputFileNameTag("phylip"); + 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.dist"; - outputNames.push_back(stdFileName); outputTypes["phylip"].push_back(stdFileName); - + string stdFileName = outputDir + m->getSimpleName(treefile) + toString(treeNum+1) + ".weighted.std." + getOutputFileNameTag("phylip"); + if (outputForm != "column") { outputNames.push_back(stdFileName); outputTypes["phylip"].push_back(stdFileName); } + else { outputNames.push_back(stdFileName); outputTypes["column"].push_back(stdFileName); } ofstream outStd; m->openOutputFile(stdFileName, outStd); @@ -550,7 +574,7 @@ 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.tre"; + string conFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(treeNum+1) + ".weighted.cons." + getOutputFileNameTag("tree"); outputNames.push_back(conFile); outputTypes["tree"].push_back(conFile); ofstream outTree; m->openOutputFile(conFile, outTree); @@ -574,7 +598,7 @@ 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.tre"; + string outputFile = outputDir + m->getRootName(m->getSimpleName(treefile)) + toString(treeNum+1) + ".weighted.all." + getOutputFileNameTag("tree"); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); ofstream outAll; @@ -885,10 +909,10 @@ void UnifracWeightedCommand::createPhylipFile() { string phylipFileName; if ((outputForm == "lt") || (outputForm == "square")) { - phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted.phylip.dist"; + 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.dist"; + phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted.column." + getOutputFileNameTag("column"); outputNames.push_back(phylipFileName); outputTypes["column"].push_back(phylipFileName); } diff --git a/unifracweightedcommand.h b/unifracweightedcommand.h index 9deb065..06354ce 100644 --- a/unifracweightedcommand.h +++ b/unifracweightedcommand.h @@ -28,7 +28,8 @@ class UnifracWeightedCommand : public Command { vector setParameters(); string getCommandName() { return "unifrac.weighted"; } string getCommandCategory() { return "Hypothesis Testing"; } - string getHelpString(); + string getOutputFileNameTag(string, string); + string getHelpString(); 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 1b4e3bc..18bb635 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -66,6 +66,27 @@ string VennCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** + +string VennCommand::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 == "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); + } +} //********************************************************************************************************************** VennCommand::VennCommand(){ diff --git a/venncommand.h b/venncommand.h index ae3c121..9f36928 100644 --- a/venncommand.h +++ b/venncommand.h @@ -25,6 +25,7 @@ public: vector setParameters(); string getCommandName() { return "venn"; } string getCommandCategory() { return "OTU-Based Approaches"; } + string getOutputFileNameTag(string, string); string getHelpString(); string getCitation() { return "http://www.mothur.org/wiki/Venn"; } string getDescription() { return "generates a Venn diagram from data provided in a shared file"; }