From ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6 Mon Sep 17 00:00:00 2001 From: westcott Date: Wed, 6 Apr 2011 13:22:57 +0000 Subject: [PATCH] removed read.dist, read.otu, read.tree and globaldata. added current to defaults for required parameters, changed virtual functions for the command class --- Mothur.xcodeproj/project.pbxproj | 208 ++++++++-------- aligncommand.cpp | 122 +++++----- aligncommand.h | 13 +- amovacommand.cpp | 96 ++++---- amovacommand.h | 18 +- anosimcommand.cpp | 97 ++++---- anosimcommand.h | 15 +- binsequencecommand.cpp | 188 +++++++-------- binsequencecommand.h | 24 +- blastalign.cpp | 7 +- blastalign.hpp | 3 +- blastdb.cpp | 4 +- blastdb.hpp | 2 - bootstrapsharedcommand.cpp | 201 +++++++--------- bootstrapsharedcommand.h | 24 +- catchallcommand.cpp | 116 ++++----- catchallcommand.h | 21 +- chimerabellerophoncommand.cpp | 98 ++++---- chimerabellerophoncommand.h | 18 +- chimeraccodecommand.cpp | 129 +++++----- chimeraccodecommand.h | 19 +- chimeracheckcommand.cpp | 116 ++++----- chimeracheckcommand.h | 20 +- chimerapintailcommand.cpp | 132 +++++------ chimerapintailcommand.h | 18 +- chimeraseqscommand.cpp | 67 ------ chimeraseqscommand.h | 40 ---- chimeraslayercommand.cpp | 174 +++++++------- chimeraslayercommand.h | 18 +- chopseqscommand.cpp | 91 ++++--- chopseqscommand.h | 19 +- classifyotucommand.cpp | 119 +++++----- classifyotucommand.h | 17 +- classifyseqscommand.cpp | 153 ++++++------ classifyseqscommand.h | 16 +- clearcutcommand.cpp | 148 ++++++------ clearcutcommand.h | 18 +- clusterclassic.cpp | 11 +- clusterclassic.h | 7 +- clustercommand.cpp | 272 ++++++++++++--------- clustercommand.h | 22 +- clusterdoturcommand.cpp | 98 ++++---- clusterdoturcommand.h | 20 +- clusterfragmentscommand.cpp | 94 ++++---- clusterfragmentscommand.h | 17 +- clustersplitcommand.cpp | 188 ++++++++------- clustersplitcommand.h | 21 +- collect.cpp | 22 +- collect.h | 2 - collectcommand.cpp | 248 +++++++++++--------- collectcommand.h | 29 +-- collectsharedcommand.cpp | 181 +++++++------- collectsharedcommand.h | 31 +-- command.hpp | 19 +- commandfactory.cpp | 46 ++-- commandoptionparser.cpp | 4 +- consensuscommand.cpp | 78 +++--- consensuscommand.h | 21 +- consensusseqscommand.cpp | 97 ++++---- consensusseqscommand.h | 17 +- corraxescommand.cpp | 102 ++++---- corraxescommand.h | 20 +- datavector.hpp | 2 + decalc.cpp | 2 +- deconvolutecommand.cpp | 79 +++---- deconvolutecommand.h | 16 +- degapseqscommand.cpp | 86 +++---- degapseqscommand.h | 18 +- deuniqueseqscommand.cpp | 84 +++---- deuniqueseqscommand.h | 16 +- distancecommand.cpp | 118 +++++----- distancecommand.h | 18 +- engine.cpp | 9 +- engine.hpp | 7 +- filterseqscommand.cpp | 104 ++++---- filterseqscommand.h | 15 +- fullmatrix.cpp | 10 +- fullmatrix.h | 7 +- getcurrentcommand.cpp | 67 ++---- getcurrentcommand.h | 20 +- getgroupcommand.cpp | 124 +++++----- getgroupcommand.h | 24 +- getgroupscommand.cpp | 102 ++++---- getgroupscommand.h | 16 +- getlabelcommand.cpp | 191 ++++++++++----- getlabelcommand.h | 27 ++- getlineagecommand.cpp | 104 ++++---- getlineagecommand.h | 20 +- getlistcountcommand.cpp | 153 ++++-------- getlistcountcommand.h | 26 +- getoturepcommand.cpp | 211 +++++++++-------- getoturepcommand.h | 26 +- getotuscommand.cpp | 102 ++++---- getotuscommand.h | 16 +- getrabundcommand.cpp | 234 +++++++++--------- getrabundcommand.h | 26 +- getrelabundcommand.cpp | 152 ++++++------ getrelabundcommand.h | 23 +- getsabundcommand.cpp | 230 +++++++++--------- getsabundcommand.h | 25 +- getseqscommand.cpp | 99 ++++---- getseqscommand.h | 20 +- getsharedotucommand.cpp | 133 +++++------ getsharedotucommand.h | 25 +- globaldata.cpp | 14 +- globaldata.hpp | 35 +-- groupmap.cpp | 2 + hclustercommand.cpp | 138 +++++------ hclustercommand.h | 20 +- heatmap.cpp | 10 +- heatmap.h | 7 +- heatmapcommand.cpp | 273 ++++++++++++--------- heatmapcommand.h | 25 +- heatmapsim.cpp | 9 +- heatmapsim.h | 6 +- heatmapsimcommand.cpp | 231 +++++++++--------- heatmapsimcommand.h | 28 +-- helpcommand.cpp | 47 +--- helpcommand.h | 21 +- homovacommand.cpp | 109 ++++----- homovacommand.h | 15 +- indicatorcommand.cpp | 156 ++++++------ indicatorcommand.h | 17 +- inputdata.cpp | 16 +- inputdata.h | 1 - libshuffcommand.cpp | 310 ++++++++++++++---------- libshuffcommand.h | 26 +- listseqscommand.cpp | 75 +++--- listseqscommand.h | 18 +- makefastqcommand.cpp | 91 +++---- makefastqcommand.h | 16 +- makegroupcommand.cpp | 90 +++---- makegroupcommand.h | 15 +- mantelcommand.cpp | 75 +++--- mantelcommand.h | 15 +- matrixoutputcommand.cpp | 158 ++++++------- matrixoutputcommand.h | 23 +- mergefilecommand.cpp | 71 ++---- mergefilecommand.h | 19 +- mergegroupscommand.cpp | 116 ++++----- mergegroupscommand.h | 20 +- metastatscommand.cpp | 175 +++++++------- metastatscommand.h | 26 +- mgclustercommand.cpp | 110 ++++----- mgclustercommand.h | 22 +- mothur.cpp | 1 - mothurout.cpp | 1 - mothurout.h | 12 +- nmdscommand.cpp | 97 ++++---- nmdscommand.h | 17 +- nocommands.cpp | 37 --- nocommands.h | 18 +- normalizesharedcommand.cpp | 225 ++++++++++-------- normalizesharedcommand.h | 25 +- optionparser.cpp | 6 +- otuhierarchycommand.cpp | 91 +++---- otuhierarchycommand.h | 18 +- pairwiseseqscommand.cpp | 110 ++++----- pairwiseseqscommand.h | 16 +- parsefastaqcommand.cpp | 74 ++---- parsefastaqcommand.h | 16 +- parselistscommand.cpp | 98 ++++---- parselistscommand.h | 17 +- parsimony.cpp | 11 +- parsimony.h | 2 - parsimonycommand.cpp | 390 +++++++++++++++++++----------- parsimonycommand.h | 34 +-- pcacommand.cpp | 143 ++++++----- pcacommand.h | 26 +- pcoacommand.cpp | 88 +++---- pcoacommand.h | 17 +- phylodiversity.h | 4 +- phylodiversitycommand.cpp | 334 ++++++++++++++++++-------- phylodiversitycommand.h | 32 +-- phylotypecommand.cpp | 99 ++++---- phylotypecommand.h | 16 +- pipelinepdscommand.cpp | 263 ++++++++++----------- pipelinepdscommand.h | 19 +- preclustercommand.cpp | 90 +++---- preclustercommand.h | 16 +- quitcommand.cpp | 51 ---- quitcommand.h | 16 +- rarefact.cpp | 4 +- rarefact.h | 5 +- rarefactcommand.cpp | 247 +++++++++++-------- rarefactcommand.h | 29 +-- rarefactsharedcommand.cpp | 232 ++++++++---------- rarefactsharedcommand.h | 28 +-- readcluster.cpp | 2 - readcluster.h | 1 - readcolumn.cpp | 12 +- readcolumn.h | 1 + readdistcommand.cpp | 77 +----- readdistcommand.h | 20 +- readmatrix.hpp | 4 +- readotu.cpp | 6 +- readotu.h | 4 +- readotucommand.cpp | 76 +----- readotucommand.h | 19 +- readphylip.cpp | 17 +- readphylip.h | 1 + readtree.cpp | 77 +++--- readtree.h | 17 +- readtreecommand.cpp | 87 +------ readtreecommand.h | 19 +- removegroupscommand.cpp | 94 ++++---- removegroupscommand.h | 16 +- removelineagecommand.cpp | 97 ++++---- removelineagecommand.h | 17 +- removeotuscommand.cpp | 106 ++++----- removeotuscommand.h | 15 +- removerarecommand.cpp | 117 ++++----- removerarecommand.h | 18 +- removeseqscommand.cpp | 96 ++++---- removeseqscommand.h | 18 +- reversecommand.cpp | 110 ++++----- reversecommand.h | 17 +- screenseqscommand.cpp | 137 +++++------ screenseqscommand.h | 18 +- secondarystructurecommand.cpp | 81 +++---- secondarystructurecommand.h | 17 +- sensspeccommand.cpp | 145 +++++++----- sensspeccommand.h | 19 +- seqerrorcommand.cpp | 97 ++++---- seqerrorcommand.h | 17 +- seqsummarycommand.cpp | 90 +++---- seqsummarycommand.h | 16 +- setcurrentcommand.cpp | 89 ++++--- setcurrentcommand.h | 17 +- setdircommand.cpp | 80 +++---- setdircommand.h | 21 +- setlogfilecommand.cpp | 57 ++--- setlogfilecommand.h | 17 +- sffinfocommand.cpp | 105 ++++----- sffinfocommand.h | 17 +- sharedcommand.cpp | 339 +++++++++++++++++---------- sharedcommand.h | 27 +-- sharedjackknife.cpp | 3 +- sharedjackknife.h | 2 - sharedlistvector.cpp | 22 +- sharedlistvector.h | 4 +- sharedordervector.cpp | 31 ++- sharedordervector.h | 5 - sharedrabundfloatvector.cpp | 31 +-- sharedrabundfloatvector.h | 6 +- sharedrabundvector.cpp | 33 +-- sharedrabundvector.h | 8 +- sharedutilities.cpp | 5 +- sharedutilities.h | 2 +- shhhercommand.cpp | 100 +++----- shhhercommand.h | 19 +- splitabundcommand.cpp | 109 ++++----- splitabundcommand.h | 17 +- splitgroupscommand.cpp | 84 +++---- splitgroupscommand.h | 18 +- subsamplecommand.cpp | 112 ++++----- subsamplecommand.h | 21 +- summarycommand.cpp | 255 +++++++++++--------- summarycommand.h | 25 +- summarysharedcommand.cpp | 190 +++++++-------- summarysharedcommand.h | 26 +- systemcommand.cpp | 47 +--- systemcommand.h | 18 +- tree.cpp | 63 +++-- tree.h | 12 +- treegroupscommand.cpp | 391 +++++++++++++++---------------- treegroupscommand.h | 22 +- treemap.cpp | 6 +- treemap.h | 2 +- trimflowscommand.cpp | 99 +++----- trimflowscommand.h | 20 +- trimseqscommand.cpp | 172 +++++++------- trimseqscommand.h | 17 +- unifracunweightedcommand.cpp | 341 +++++++++++++++++++-------- unifracunweightedcommand.h | 28 ++- unifracweightedcommand.cpp | 343 ++++++++++++++++++--------- unifracweightedcommand.h | 31 ++- unweighted.cpp | 20 +- unweighted.h | 1 - validcalculator.cpp | 75 ++++++ validcalculator.h | 1 + venn.cpp | 14 +- venn.h | 6 +- venncommand.cpp | 276 +++++++++++----------- venncommand.h | 27 +-- weighted.cpp | 7 +- weighted.h | 1 - 287 files changed, 9024 insertions(+), 9480 deletions(-) delete mode 100644 chimeraseqscommand.cpp delete mode 100644 chimeraseqscommand.h diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 4bc5960..582beaf 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -46,7 +46,6 @@ A7E9B89A12D37EC400DA6239 /* chimeracheckrdp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B68012D37EC400DA6239 /* chimeracheckrdp.cpp */; }; A7E9B89B12D37EC400DA6239 /* chimerapintailcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B68212D37EC400DA6239 /* chimerapintailcommand.cpp */; }; A7E9B89C12D37EC400DA6239 /* chimerarealigner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B68412D37EC400DA6239 /* chimerarealigner.cpp */; }; - A7E9B89D12D37EC400DA6239 /* chimeraseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B68612D37EC400DA6239 /* chimeraseqscommand.cpp */; }; A7E9B89E12D37EC400DA6239 /* chimeraslayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B68812D37EC400DA6239 /* chimeraslayer.cpp */; }; A7E9B89F12D37EC400DA6239 /* chimeraslayercommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B68A12D37EC400DA6239 /* chimeraslayercommand.cpp */; }; A7E9B8A012D37EC400DA6239 /* chopseqscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7E9B68C12D37EC400DA6239 /* chopseqscommand.cpp */; }; @@ -332,6 +331,7 @@ A7A61F2B130062E000E05B6B /* amovacommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amovacommand.h; sourceTree = ""; }; A7A61F2C130062E000E05B6B /* amovacommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = amovacommand.cpp; sourceTree = ""; }; A7AACFBA132FE008003D6C4D /* currentfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = currentfile.h; sourceTree = ""; }; + A7DAAFA3133A254E003956EB /* commandparameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = commandparameter.h; sourceTree = ""; }; A7E9B64F12D37EC300DA6239 /* ace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ace.cpp; sourceTree = ""; }; A7E9B65012D37EC300DA6239 /* ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ace.h; sourceTree = ""; }; A7E9B65112D37EC300DA6239 /* aligncommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = aligncommand.cpp; sourceTree = ""; }; @@ -387,8 +387,6 @@ A7E9B68312D37EC400DA6239 /* chimerapintailcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimerapintailcommand.h; sourceTree = ""; }; A7E9B68412D37EC400DA6239 /* chimerarealigner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimerarealigner.cpp; sourceTree = ""; }; A7E9B68512D37EC400DA6239 /* chimerarealigner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimerarealigner.h; sourceTree = ""; }; - A7E9B68612D37EC400DA6239 /* chimeraseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimeraseqscommand.cpp; sourceTree = ""; }; - A7E9B68712D37EC400DA6239 /* chimeraseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimeraseqscommand.h; sourceTree = ""; }; A7E9B68812D37EC400DA6239 /* chimeraslayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimeraslayer.cpp; sourceTree = ""; }; A7E9B68912D37EC400DA6239 /* chimeraslayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimeraslayer.h; sourceTree = ""; }; A7E9B68A12D37EC400DA6239 /* chimeraslayercommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimeraslayercommand.cpp; sourceTree = ""; }; @@ -951,6 +949,7 @@ A7E9B6B012D37EC400DA6239 /* commandfactory.hpp */, A7E9B6B112D37EC400DA6239 /* commandoptionparser.cpp */, A7E9B6B212D37EC400DA6239 /* commandoptionparser.hpp */, + A7DAAFA3133A254E003956EB /* commandparameter.h */, A7E9B6B412D37EC400DA6239 /* completelinkage.cpp */, A7E9BA4212D3960D00DA6239 /* containers */, A7AACFBA132FE008003D6C4D /* currentfile.h */, @@ -1042,222 +1041,220 @@ isa = PBXGroup; children = ( A7E9B6AE12D37EC400DA6239 /* command.hpp */, - A7E9B65112D37EC300DA6239 /* aligncommand.cpp */, A7E9B65212D37EC300DA6239 /* aligncommand.h */, + A7E9B65112D37EC300DA6239 /* aligncommand.cpp */, A7A61F2B130062E000E05B6B /* amovacommand.h */, A7A61F2C130062E000E05B6B /* amovacommand.cpp */, - A71CB15E130B04A2001E7287 /* anosimcommand.cpp */, A71CB15F130B04A2001E7287 /* anosimcommand.h */, - A7E9B66012D37EC300DA6239 /* binsequencecommand.cpp */, + A71CB15E130B04A2001E7287 /* anosimcommand.cpp */, A7E9B66112D37EC300DA6239 /* binsequencecommand.h */, - A7E9B66A12D37EC400DA6239 /* bootstrapsharedcommand.cpp */, + A7E9B66012D37EC300DA6239 /* binsequencecommand.cpp */, A7E9B66B12D37EC400DA6239 /* bootstrapsharedcommand.h */, - A7E9B67212D37EC400DA6239 /* catchallcommand.cpp */, + A7E9B66A12D37EC400DA6239 /* bootstrapsharedcommand.cpp */, A7E9B67312D37EC400DA6239 /* catchallcommand.h */, - A7E9B67A12D37EC400DA6239 /* chimerabellerophoncommand.cpp */, + A7E9B67212D37EC400DA6239 /* catchallcommand.cpp */, A7E9B67B12D37EC400DA6239 /* chimerabellerophoncommand.h */, - A7E9B67C12D37EC400DA6239 /* chimeraccodecommand.cpp */, + A7E9B67A12D37EC400DA6239 /* chimerabellerophoncommand.cpp */, A7E9B67D12D37EC400DA6239 /* chimeraccodecommand.h */, - A7E9B67E12D37EC400DA6239 /* chimeracheckcommand.cpp */, + A7E9B67C12D37EC400DA6239 /* chimeraccodecommand.cpp */, A7E9B67F12D37EC400DA6239 /* chimeracheckcommand.h */, - A7E9B68212D37EC400DA6239 /* chimerapintailcommand.cpp */, + A7E9B67E12D37EC400DA6239 /* chimeracheckcommand.cpp */, A7E9B68312D37EC400DA6239 /* chimerapintailcommand.h */, - A7E9B68612D37EC400DA6239 /* chimeraseqscommand.cpp */, - A7E9B68712D37EC400DA6239 /* chimeraseqscommand.h */, - A7E9B68A12D37EC400DA6239 /* chimeraslayercommand.cpp */, + A7E9B68212D37EC400DA6239 /* chimerapintailcommand.cpp */, A7E9B68B12D37EC400DA6239 /* chimeraslayercommand.h */, - A7E9B68C12D37EC400DA6239 /* chopseqscommand.cpp */, + A7E9B68A12D37EC400DA6239 /* chimeraslayercommand.cpp */, A7E9B68D12D37EC400DA6239 /* chopseqscommand.h */, - A7E9B69012D37EC400DA6239 /* classifyotucommand.cpp */, + A7E9B68C12D37EC400DA6239 /* chopseqscommand.cpp */, A7E9B69112D37EC400DA6239 /* classifyotucommand.h */, - A7E9B69212D37EC400DA6239 /* classifyseqscommand.cpp */, + A7E9B69012D37EC400DA6239 /* classifyotucommand.cpp */, A7E9B69312D37EC400DA6239 /* classifyseqscommand.h */, - A7E9B69612D37EC400DA6239 /* clearcutcommand.cpp */, + A7E9B69212D37EC400DA6239 /* classifyseqscommand.cpp */, A7E9B69712D37EC400DA6239 /* clearcutcommand.h */, - A7E9B69C12D37EC400DA6239 /* clustercommand.cpp */, + A7E9B69612D37EC400DA6239 /* clearcutcommand.cpp */, A7E9B69D12D37EC400DA6239 /* clustercommand.h */, - A7E9B69E12D37EC400DA6239 /* clusterdoturcommand.cpp */, + A7E9B69C12D37EC400DA6239 /* clustercommand.cpp */, A7E9B69F12D37EC400DA6239 /* clusterdoturcommand.h */, - A7E9B6A012D37EC400DA6239 /* clusterfragmentscommand.cpp */, + A7E9B69E12D37EC400DA6239 /* clusterdoturcommand.cpp */, A7E9B6A112D37EC400DA6239 /* clusterfragmentscommand.h */, - A7E9B6A212D37EC400DA6239 /* clustersplitcommand.cpp */, + A7E9B6A012D37EC400DA6239 /* clusterfragmentscommand.cpp */, A7E9B6A312D37EC400DA6239 /* clustersplitcommand.h */, - A7E9B6A812D37EC400DA6239 /* collectcommand.cpp */, + A7E9B6A212D37EC400DA6239 /* clustersplitcommand.cpp */, A7E9B6A912D37EC400DA6239 /* collectcommand.h */, - A7E9B6AC12D37EC400DA6239 /* collectsharedcommand.cpp */, + A7E9B6A812D37EC400DA6239 /* collectcommand.cpp */, A7E9B6AD12D37EC400DA6239 /* collectsharedcommand.h */, - A7E9B6B512D37EC400DA6239 /* consensuscommand.cpp */, + A7E9B6AC12D37EC400DA6239 /* collectsharedcommand.cpp */, A7E9B6B612D37EC400DA6239 /* consensuscommand.h */, - A7E9B6B712D37EC400DA6239 /* consensusseqscommand.cpp */, + A7E9B6B512D37EC400DA6239 /* consensuscommand.cpp */, A7E9B6B812D37EC400DA6239 /* consensusseqscommand.h */, - A7E9B6B912D37EC400DA6239 /* corraxescommand.cpp */, + A7E9B6B712D37EC400DA6239 /* consensusseqscommand.cpp */, A7E9B6BA12D37EC400DA6239 /* corraxescommand.h */, - A7E9B6C312D37EC400DA6239 /* deconvolutecommand.cpp */, + A7E9B6B912D37EC400DA6239 /* corraxescommand.cpp */, A7E9B6C412D37EC400DA6239 /* deconvolutecommand.h */, - A7E9B6C512D37EC400DA6239 /* degapseqscommand.cpp */, + A7E9B6C312D37EC400DA6239 /* deconvolutecommand.cpp */, A7E9B6C612D37EC400DA6239 /* degapseqscommand.h */, - A7E9B6C712D37EC400DA6239 /* deuniqueseqscommand.cpp */, + A7E9B6C512D37EC400DA6239 /* degapseqscommand.cpp */, A7E9B6C812D37EC400DA6239 /* deuniqueseqscommand.h */, - A7E9B6CB12D37EC400DA6239 /* distancecommand.cpp */, + A7E9B6C712D37EC400DA6239 /* deuniqueseqscommand.cpp */, A7E9B6CC12D37EC400DA6239 /* distancecommand.h */, - A7E9B6E312D37EC400DA6239 /* filterseqscommand.cpp */, + A7E9B6CB12D37EC400DA6239 /* distancecommand.cpp */, A7E9B6E412D37EC400DA6239 /* filterseqscommand.h */, + A7E9B6E312D37EC400DA6239 /* filterseqscommand.cpp */, A7FE7C3E1330EA1000F7B327 /* getcurrentcommand.h */, A7FE7C3F1330EA1000F7B327 /* getcurrentcommand.cpp */, - A7E9B6F212D37EC400DA6239 /* getgroupcommand.cpp */, A7E9B6F312D37EC400DA6239 /* getgroupcommand.h */, - A7E9B6F412D37EC400DA6239 /* getgroupscommand.cpp */, + A7E9B6F212D37EC400DA6239 /* getgroupcommand.cpp */, A7E9B6F512D37EC400DA6239 /* getgroupscommand.h */, - A7E9B6F612D37EC400DA6239 /* getlabelcommand.cpp */, + A7E9B6F412D37EC400DA6239 /* getgroupscommand.cpp */, A7E9B6F712D37EC400DA6239 /* getlabelcommand.h */, - A7E9B6F812D37EC400DA6239 /* getlineagecommand.cpp */, + A7E9B6F612D37EC400DA6239 /* getlabelcommand.cpp */, A7E9B6F912D37EC400DA6239 /* getlineagecommand.h */, - A7E9B6FA12D37EC400DA6239 /* getlistcountcommand.cpp */, + A7E9B6F812D37EC400DA6239 /* getlineagecommand.cpp */, A7E9B6FB12D37EC400DA6239 /* getlistcountcommand.h */, - A7E9B6FE12D37EC400DA6239 /* getoturepcommand.cpp */, + A7E9B6FA12D37EC400DA6239 /* getlistcountcommand.cpp */, A7E9B6FF12D37EC400DA6239 /* getoturepcommand.h */, - A7E9B70012D37EC400DA6239 /* getotuscommand.cpp */, + A7E9B6FE12D37EC400DA6239 /* getoturepcommand.cpp */, A7E9B70112D37EC400DA6239 /* getotuscommand.h */, - A7E9B70212D37EC400DA6239 /* getrabundcommand.cpp */, + A7E9B70012D37EC400DA6239 /* getotuscommand.cpp */, A7E9B70312D37EC400DA6239 /* getrabundcommand.h */, - A7E9B70412D37EC400DA6239 /* getrelabundcommand.cpp */, + A7E9B70212D37EC400DA6239 /* getrabundcommand.cpp */, A7E9B70512D37EC400DA6239 /* getrelabundcommand.h */, - A7E9B70612D37EC400DA6239 /* getsabundcommand.cpp */, + A7E9B70412D37EC400DA6239 /* getrelabundcommand.cpp */, A7E9B70712D37EC400DA6239 /* getsabundcommand.h */, - A7E9B70812D37EC400DA6239 /* getseqscommand.cpp */, + A7E9B70612D37EC400DA6239 /* getsabundcommand.cpp */, A7E9B70912D37EC400DA6239 /* getseqscommand.h */, - A7E9B70A12D37EC400DA6239 /* getsharedotucommand.cpp */, + A7E9B70812D37EC400DA6239 /* getseqscommand.cpp */, A7E9B70B12D37EC400DA6239 /* getsharedotucommand.h */, - A7E9B71A12D37EC400DA6239 /* hclustercommand.cpp */, + A7E9B70A12D37EC400DA6239 /* getsharedotucommand.cpp */, A7E9B71B12D37EC400DA6239 /* hclustercommand.h */, - A7E9B71E12D37EC400DA6239 /* heatmapcommand.cpp */, + A7E9B71A12D37EC400DA6239 /* hclustercommand.cpp */, A7E9B71F12D37EC400DA6239 /* heatmapcommand.h */, - A7E9B72212D37EC400DA6239 /* heatmapsimcommand.cpp */, + A7E9B71E12D37EC400DA6239 /* heatmapcommand.cpp */, A7E9B72312D37EC400DA6239 /* heatmapsimcommand.h */, - A7E9B72812D37EC400DA6239 /* helpcommand.cpp */, + A7E9B72212D37EC400DA6239 /* heatmapsimcommand.cpp */, A7E9B72912D37EC400DA6239 /* helpcommand.h */, + A7E9B72812D37EC400DA6239 /* helpcommand.cpp */, A75790571301749D00A30DAB /* homovacommand.h */, A75790581301749D00A30DAB /* homovacommand.cpp */, - A7E9B72B12D37EC400DA6239 /* indicatorcommand.cpp */, A7E9B72C12D37EC400DA6239 /* indicatorcommand.h */, - A7E9B73B12D37EC400DA6239 /* libshuffcommand.cpp */, + A7E9B72B12D37EC400DA6239 /* indicatorcommand.cpp */, A7E9B73C12D37EC400DA6239 /* libshuffcommand.h */, - A7E9B73D12D37EC400DA6239 /* listseqscommand.cpp */, + A7E9B73B12D37EC400DA6239 /* libshuffcommand.cpp */, A7E9B73E12D37EC400DA6239 /* listseqscommand.h */, + A7E9B73D12D37EC400DA6239 /* listseqscommand.cpp */, A7FA10001302E096003860FE /* mantelcommand.h */, A7FA10011302E096003860FE /* mantelcommand.cpp */, A799F5B71309A3E000AEEFA0 /* makefastqcommand.h */, A799F5B81309A3E000AEEFA0 /* makefastqcommand.cpp */, - A7E9B74312D37EC400DA6239 /* makegroupcommand.cpp */, A7E9B74412D37EC400DA6239 /* makegroupcommand.h */, - A7E9B74912D37EC400DA6239 /* matrixoutputcommand.cpp */, + A7E9B74312D37EC400DA6239 /* makegroupcommand.cpp */, A7E9B74A12D37EC400DA6239 /* matrixoutputcommand.h */, - A7E9B75312D37EC400DA6239 /* mergefilecommand.cpp */, + A7E9B74912D37EC400DA6239 /* matrixoutputcommand.cpp */, A7E9B75412D37EC400DA6239 /* mergefilecommand.h */, + A7E9B75312D37EC400DA6239 /* mergefilecommand.cpp */, A71FE12A12EDF72400963CA7 /* mergegroupscommand.h */, A71FE12B12EDF72400963CA7 /* mergegroupscommand.cpp */, - A7E9B75712D37EC400DA6239 /* metastatscommand.cpp */, A7E9B75812D37EC400DA6239 /* metastatscommand.h */, - A7E9B75912D37EC400DA6239 /* mgclustercommand.cpp */, + A7E9B75712D37EC400DA6239 /* metastatscommand.cpp */, A7E9B75A12D37EC400DA6239 /* mgclustercommand.h */, + A7E9B75912D37EC400DA6239 /* mgclustercommand.cpp */, A7E9B76A12D37EC400DA6239 /* nocommands.h */, A7E9B76912D37EC400DA6239 /* nocommands.cpp */, - A7E9B76B12D37EC400DA6239 /* normalizesharedcommand.cpp */, A7E9B76C12D37EC400DA6239 /* normalizesharedcommand.h */, + A7E9B76B12D37EC400DA6239 /* normalizesharedcommand.cpp */, A713EBEB12DC7C5E000092AC /* nmdscommand.h */, A713EBEC12DC7C5E000092AC /* nmdscommand.cpp */, - A7E9B77912D37EC400DA6239 /* otuhierarchycommand.cpp */, A7E9B77A12D37EC400DA6239 /* otuhierarchycommand.h */, - A7E9B77D12D37EC400DA6239 /* pairwiseseqscommand.cpp */, + A7E9B77912D37EC400DA6239 /* otuhierarchycommand.cpp */, A7E9B77E12D37EC400DA6239 /* pairwiseseqscommand.h */, - A7E9B77F12D37EC400DA6239 /* parsefastaqcommand.cpp */, + A7E9B77D12D37EC400DA6239 /* pairwiseseqscommand.cpp */, A7E9B78012D37EC400DA6239 /* parsefastaqcommand.h */, - A7E9B78112D37EC400DA6239 /* parselistscommand.cpp */, + A7E9B77F12D37EC400DA6239 /* parsefastaqcommand.cpp */, A7E9B78212D37EC400DA6239 /* parselistscommand.h */, - A7E9B78512D37EC400DA6239 /* parsimonycommand.cpp */, + A7E9B78112D37EC400DA6239 /* parselistscommand.cpp */, A7E9B78612D37EC400DA6239 /* parsimonycommand.h */, + A7E9B78512D37EC400DA6239 /* parsimonycommand.cpp */, A7FC486512D795D60055BC5C /* pcacommand.h */, A7FC486612D795D60055BC5C /* pcacommand.cpp */, - A7E9B78712D37EC400DA6239 /* pcoacommand.cpp */, A7E9B78812D37EC400DA6239 /* pcoacommand.h */, - A7E9B78B12D37EC400DA6239 /* phylodiversitycommand.cpp */, + A7E9B78712D37EC400DA6239 /* pcoacommand.cpp */, A7E9B78C12D37EC400DA6239 /* phylodiversitycommand.h */, - A7E9B79112D37EC400DA6239 /* phylotypecommand.cpp */, + A7E9B78B12D37EC400DA6239 /* phylodiversitycommand.cpp */, A7E9B79212D37EC400DA6239 /* phylotypecommand.h */, - A7E9B79512D37EC400DA6239 /* pipelinepdscommand.cpp */, + A7E9B79112D37EC400DA6239 /* phylotypecommand.cpp */, A7E9B79612D37EC400DA6239 /* pipelinepdscommand.h */, - A7E9B79712D37EC400DA6239 /* preclustercommand.cpp */, + A7E9B79512D37EC400DA6239 /* pipelinepdscommand.cpp */, A7E9B79812D37EC400DA6239 /* preclustercommand.h */, - A7E9B7A112D37EC400DA6239 /* quitcommand.cpp */, + A7E9B79712D37EC400DA6239 /* preclustercommand.cpp */, A7E9B7A212D37EC400DA6239 /* quitcommand.h */, - A7E9B7AB12D37EC400DA6239 /* rarefactcommand.cpp */, + A7E9B7A112D37EC400DA6239 /* quitcommand.cpp */, A7E9B7AC12D37EC400DA6239 /* rarefactcommand.h */, - A7E9B7AE12D37EC400DA6239 /* rarefactsharedcommand.cpp */, + A7E9B7AB12D37EC400DA6239 /* rarefactcommand.cpp */, A7E9B7AF12D37EC400DA6239 /* rarefactsharedcommand.h */, - A7E9B7B612D37EC400DA6239 /* readdistcommand.cpp */, + A7E9B7AE12D37EC400DA6239 /* rarefactsharedcommand.cpp */, A7E9B7B712D37EC400DA6239 /* readdistcommand.h */, - A7E9B7BB12D37EC400DA6239 /* readotucommand.cpp */, + A7E9B7B612D37EC400DA6239 /* readdistcommand.cpp */, A7E9B7BC12D37EC400DA6239 /* readotucommand.h */, - A7E9B7C112D37EC400DA6239 /* readtreecommand.cpp */, + A7E9B7BB12D37EC400DA6239 /* readotucommand.cpp */, A7E9B7C212D37EC400DA6239 /* readtreecommand.h */, - A7E9B7C312D37EC400DA6239 /* removegroupscommand.cpp */, + A7E9B7C112D37EC400DA6239 /* readtreecommand.cpp */, A7E9B7C412D37EC400DA6239 /* removegroupscommand.h */, - A7E9B7C512D37EC400DA6239 /* removelineagecommand.cpp */, + A7E9B7C312D37EC400DA6239 /* removegroupscommand.cpp */, A7E9B7C612D37EC400DA6239 /* removelineagecommand.h */, - A7E9B7C712D37EC400DA6239 /* removeotuscommand.cpp */, + A7E9B7C512D37EC400DA6239 /* removelineagecommand.cpp */, A7E9B7C812D37EC400DA6239 /* removeotuscommand.h */, + A7E9B7C712D37EC400DA6239 /* removeotuscommand.cpp */, A727864212E9E28C00F86ABA /* removerarecommand.h */, A727864312E9E28C00F86ABA /* removerarecommand.cpp */, - A7E9B7C912D37EC400DA6239 /* removeseqscommand.cpp */, A7E9B7CA12D37EC400DA6239 /* removeseqscommand.h */, - A7E9B7CD12D37EC400DA6239 /* reversecommand.cpp */, + A7E9B7C912D37EC400DA6239 /* removeseqscommand.cpp */, A7E9B7CE12D37EC400DA6239 /* reversecommand.h */, - A7E9B7D112D37EC400DA6239 /* screenseqscommand.cpp */, + A7E9B7CD12D37EC400DA6239 /* reversecommand.cpp */, A7E9B7D212D37EC400DA6239 /* screenseqscommand.h */, - A7E9B7D312D37EC400DA6239 /* secondarystructurecommand.cpp */, + A7E9B7D112D37EC400DA6239 /* screenseqscommand.cpp */, A7E9B7D412D37EC400DA6239 /* secondarystructurecommand.h */, - A7E9B7D512D37EC400DA6239 /* sensspeccommand.cpp */, + A7E9B7D312D37EC400DA6239 /* secondarystructurecommand.cpp */, A7E9B7D612D37EC400DA6239 /* sensspeccommand.h */, - A7E9B7D712D37EC400DA6239 /* seqerrorcommand.cpp */, + A7E9B7D512D37EC400DA6239 /* sensspeccommand.cpp */, A7E9B7D812D37EC400DA6239 /* seqerrorcommand.h */, - A7E9B7D912D37EC400DA6239 /* seqsummarycommand.cpp */, + A7E9B7D712D37EC400DA6239 /* seqerrorcommand.cpp */, A7E9B7DA12D37EC400DA6239 /* seqsummarycommand.h */, + A7E9B7D912D37EC400DA6239 /* seqsummarycommand.cpp */, A7FE7E6B13311EA400F7B327 /* setcurrentcommand.h */, A7FE7E6C13311EA400F7B327 /* setcurrentcommand.cpp */, - A7E9B7DF12D37EC400DA6239 /* setdircommand.cpp */, A7E9B7E012D37EC400DA6239 /* setdircommand.h */, - A7E9B7E112D37EC400DA6239 /* setlogfilecommand.cpp */, + A7E9B7DF12D37EC400DA6239 /* setdircommand.cpp */, A7E9B7E212D37EC400DA6239 /* setlogfilecommand.h */, - A7E9B7E312D37EC400DA6239 /* sffinfocommand.cpp */, + A7E9B7E112D37EC400DA6239 /* setlogfilecommand.cpp */, A7E9B7E412D37EC400DA6239 /* sffinfocommand.h */, - A7E9B7F212D37EC400DA6239 /* sharedcommand.cpp */, + A7E9B7E312D37EC400DA6239 /* sffinfocommand.cpp */, A7E9B7F312D37EC400DA6239 /* sharedcommand.h */, - A7E9B82712D37EC400DA6239 /* shhhercommand.cpp */, + A7E9B7F212D37EC400DA6239 /* sharedcommand.cpp */, A7E9B82812D37EC400DA6239 /* shhhercommand.h */, - A7E9B83F12D37EC400DA6239 /* splitabundcommand.cpp */, + A7E9B82712D37EC400DA6239 /* shhhercommand.cpp */, A7E9B84012D37EC400DA6239 /* splitabundcommand.h */, - A7E9B84112D37EC400DA6239 /* splitgroupscommand.cpp */, + A7E9B83F12D37EC400DA6239 /* splitabundcommand.cpp */, A7E9B84212D37EC400DA6239 /* splitgroupscommand.h */, - A7E9B84F12D37EC400DA6239 /* subsamplecommand.cpp */, + A7E9B84112D37EC400DA6239 /* splitgroupscommand.cpp */, A7E9B85012D37EC400DA6239 /* subsamplecommand.h */, - A7E9B85712D37EC400DA6239 /* summarycommand.cpp */, + A7E9B84F12D37EC400DA6239 /* subsamplecommand.cpp */, A7E9B85812D37EC400DA6239 /* summarycommand.h */, - A7E9B85912D37EC400DA6239 /* summarysharedcommand.cpp */, + A7E9B85712D37EC400DA6239 /* summarycommand.cpp */, A7E9B85A12D37EC400DA6239 /* summarysharedcommand.h */, - A7E9B85B12D37EC400DA6239 /* systemcommand.cpp */, + A7E9B85912D37EC400DA6239 /* summarysharedcommand.cpp */, A7E9B85C12D37EC400DA6239 /* systemcommand.h */, - A7E9B86212D37EC400DA6239 /* treegroupscommand.cpp */, + A7E9B85B12D37EC400DA6239 /* systemcommand.cpp */, A7E9B86312D37EC400DA6239 /* treegroupscommand.h */, - A7E9B86812D37EC400DA6239 /* trimflowscommand.cpp */, + A7E9B86212D37EC400DA6239 /* treegroupscommand.cpp */, A7E9B86912D37EC400DA6239 /* trimflowscommand.h */, - A7E9B86A12D37EC400DA6239 /* trimseqscommand.cpp */, + A7E9B86812D37EC400DA6239 /* trimflowscommand.cpp */, A7E9B86B12D37EC400DA6239 /* trimseqscommand.h */, - A7E9B86C12D37EC400DA6239 /* unifracunweightedcommand.cpp */, + A7E9B86A12D37EC400DA6239 /* trimseqscommand.cpp */, A7E9B86D12D37EC400DA6239 /* unifracunweightedcommand.h */, - A7E9B86E12D37EC400DA6239 /* unifracweightedcommand.cpp */, + A7E9B86C12D37EC400DA6239 /* unifracunweightedcommand.cpp */, A7E9B86F12D37EC400DA6239 /* unifracweightedcommand.h */, - A7E9B87A12D37EC400DA6239 /* venncommand.cpp */, + A7E9B86E12D37EC400DA6239 /* unifracweightedcommand.cpp */, A7E9B87B12D37EC400DA6239 /* venncommand.h */, + A7E9B87A12D37EC400DA6239 /* venncommand.cpp */, ); name = commands; sourceTree = ""; @@ -1414,12 +1411,12 @@ A7E9B84D12D37EC400DA6239 /* structpearson.cpp */, A7E9B84E12D37EC400DA6239 /* structpearson.h */, A7E9B86112D37EC400DA6239 /* treecalculator.h */, - A7E9B87012D37EC400DA6239 /* unweighted.cpp */, A7E9B87112D37EC400DA6239 /* unweighted.h */, + A7E9B87012D37EC400DA6239 /* unweighted.cpp */, A7E9B87212D37EC400DA6239 /* uvest.cpp */, A7E9B87312D37EC400DA6239 /* uvest.h */, - A7E9B87C12D37EC400DA6239 /* weighted.cpp */, A7E9B87D12D37EC400DA6239 /* weighted.h */, + A7E9B87C12D37EC400DA6239 /* weighted.cpp */, A7E9B87F12D37EC400DA6239 /* whittaker.cpp */, A7E9B88012D37EC400DA6239 /* whittaker.h */, ); @@ -1476,8 +1473,8 @@ A7E9B7DE12D37EC400DA6239 /* sequencedb.h */, A7E9B80412D37EC400DA6239 /* sharedlistvector.cpp */, A7E9B80512D37EC400DA6239 /* sharedlistvector.h */, - A7E9B80D12D37EC400DA6239 /* sharedordervector.cpp */, A7E9B80E12D37EC400DA6239 /* sharedordervector.h */, + A7E9B80D12D37EC400DA6239 /* sharedordervector.cpp */, A7E9B80F12D37EC400DA6239 /* sharedrabundfloatvector.cpp */, A7E9B81012D37EC400DA6239 /* sharedrabundfloatvector.h */, A7E9B81112D37EC400DA6239 /* sharedrabundvector.cpp */, @@ -1577,8 +1574,8 @@ A7E9B7B412D37EC400DA6239 /* readcolumn.cpp */, A7E9B7B512D37EC400DA6239 /* readcolumn.h */, A7E9B7B812D37EC400DA6239 /* readmatrix.hpp */, - A7E9B7B912D37EC400DA6239 /* readotu.cpp */, A7E9B7BA12D37EC400DA6239 /* readotu.h */, + A7E9B7B912D37EC400DA6239 /* readotu.cpp */, A7E9B7BD12D37EC400DA6239 /* readphylip.cpp */, A7E9B7BE12D37EC400DA6239 /* readphylip.h */, A7E9B7BF12D37EC400DA6239 /* readtree.cpp */, @@ -1689,7 +1686,6 @@ A7E9B89A12D37EC400DA6239 /* chimeracheckrdp.cpp in Sources */, A7E9B89B12D37EC400DA6239 /* chimerapintailcommand.cpp in Sources */, A7E9B89C12D37EC400DA6239 /* chimerarealigner.cpp in Sources */, - A7E9B89D12D37EC400DA6239 /* chimeraseqscommand.cpp in Sources */, A7E9B89E12D37EC400DA6239 /* chimeraslayer.cpp in Sources */, A7E9B89F12D37EC400DA6239 /* chimeraslayercommand.cpp in Sources */, A7E9B8A012D37EC400DA6239 /* chopseqscommand.cpp in Sources */, diff --git a/aligncommand.cpp b/aligncommand.cpp index a820542..5f64411 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -25,39 +25,59 @@ #include "nast.hpp" #include "nastreport.hpp" - -//********************************************************************************************************************** -vector AlignCommand::getValidParameters(){ - try { - string AlignArray[] = {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "AlignCommand", "getValidParameters"); - exit(1); - } -} //********************************************************************************************************************** -vector AlignCommand::getRequiredParameters(){ +vector AlignCommand::setParameters(){ try { - string AlignArray[] = {"template","candidate"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); + CommandParameter pcandidate("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pcandidate); + CommandParameter psearch("search", "Multiple", "kmer-blast-suffix", "kmer", "", "", "",false,false); parameters.push_back(psearch); + CommandParameter pksize("ksize", "Number", "", "8", "", "", "",false,false); parameters.push_back(pksize); + CommandParameter pmatch("match", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pmatch); + CommandParameter palign("align", "Multiple", "needleman-gotoh-blast-noalign", "needleman", "", "", "",false,false); parameters.push_back(palign); + CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pmismatch); + CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "",false,false); parameters.push_back(pgapopen); + CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pgapextend); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pflip("flip", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pflip); + CommandParameter pthreshold("threshold", "Number", "", "0.50", "", "", "",false,false); parameters.push_back(pthreshold); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "AlignCommand", "getRequiredParameters"); + m->errorOut(e, "AlignCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector AlignCommand::getRequiredFiles(){ +string AlignCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The align.seqs command reads a file containing sequences and creates an alignment file and a report file.\n"; + helpString += "The align.seqs command parameters are reference, fasta, search, ksize, align, match, mismatch, gapopen, gapextend and processors.\n"; + helpString += "The reference and fasta parameters are required. You may leave fasta blank if you have a valid fasta file. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"; + helpString += "The search parameter allows you to specify the method to find most similar template. Your options are: suffix, kmer and blast. The default is kmer.\n"; + helpString += "The align parameter allows you to specify the alignment method to use. Your options are: gotoh, needleman, blast and noalign. The default is needleman.\n"; + helpString += "The ksize parameter allows you to specify the kmer size for finding most similar template to candidate. The default is 8.\n"; + helpString += "The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n"; + helpString += "The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n"; + helpString += "The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n"; + helpString += "The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n"; + helpString += "The flip parameter is used to specify whether or not you want mothur to try the reverse complement if a sequence falls below the threshold. The default is false.\n"; + helpString += "The threshold is used to specify a cutoff at which an alignment is deemed 'bad' and the reverse complement may be tried. The default threshold is 0.50, meaning 50% of the bases are removed in the alignment.\n"; + helpString += "If the flip parameter is set to true the reverse complement of the sequence is aligned and the better alignment is reported.\n"; + helpString += "The default for the threshold parameter is 0.50, meaning at least 50% of the bases must remain or the sequence is reported as potentially reversed.\n"; + helpString += "The align.seqs command should be in the following format: \n"; + helpString += "align.seqs(reference=yourTemplateFile, fasta=yourCandidateFile, align=yourAlignmentMethod, search=yourSearchmethod, ksize=yourKmerSize, match=yourMatchBonus, mismatch=yourMismatchpenalty, gapopen=yourGapopenPenalty, gapextend=yourGapExtendPenalty) \n"; + helpString += "Example align.seqs(candidate=candidate.fasta, template=core.filtered, align=kmer, search=gotoh, ksize=8, match=2.0, mismatch=3.0, gapopen=-2.0, gapextend=-1.0)\n"; + helpString += "Note: No spaces between parameter labels (i.e. candidate), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "AlignCommand", "getRequiredFiles"); + m->errorOut(e, "AlignCommand", "getHelpString"); exit(1); } } @@ -65,6 +85,7 @@ vector AlignCommand::getRequiredFiles(){ AlignCommand::AlignCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["alignreport"] = tempOutNames; @@ -84,10 +105,7 @@ AlignCommand::AlignCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true;} else { - - //valid paramters for this command - string AlignArray[] = {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -117,27 +135,31 @@ AlignCommand::AlignCommand(string option) { else { string path; - it = parameters.find("template"); + it = parameters.find("reference"); //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["template"] = inputDir + it->second; } + if (path == "") { parameters["reference"] = inputDir + it->second; } } } //check for required parameters - templateFileName = validParameter.validFile(parameters, "template", true); + templateFileName = validParameter.validFile(parameters, "reference", true); if (templateFileName == "not found") { - m->mothurOut("template is a required parameter for the align.seqs command."); + m->mothurOut("reference is a required parameter for the align.seqs command."); m->mothurOutEndLine(); abort = true; }else if (templateFileName == "not open") { abort = true; } - candidateFileName = validParameter.validFile(parameters, "candidate", false); + candidateFileName = validParameter.validFile(parameters, "fasta", false); if (candidateFileName == "not found") { + //if there is a current fasta file, use it + string filename = m->getFastaFile(); + if (filename != "") { candidateFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the candidate parameter is required."); m->mothurOutEndLine(); abort = true; } }else { m->splitAtDash(candidateFileName, candidateFileNames); @@ -213,7 +235,8 @@ AlignCommand::AlignCommand(string option) { temp = validParameter.validFile(parameters, "gapextend", false); if (temp == "not found"){ temp = "-1.0"; } convert(temp, gapExtend); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); temp = validParameter.validFile(parameters, "flip", false); if (temp == "not found"){ temp = "f"; } @@ -223,8 +246,11 @@ AlignCommand::AlignCommand(string option) { convert(temp, threshold); search = validParameter.validFile(parameters, "search", false); if (search == "not found"){ search = "kmer"; } + if ((search != "suffix") && (search != "kmer") && (search != "blast")) { m->mothurOut("invalid search option: choices are kmer, suffix or blast."); m->mothurOutEndLine(); abort=true; } align = validParameter.validFile(parameters, "align", false); if (align == "not found"){ align = "needleman"; } + if ((align != "needleman") && (align != "gotoh") && (align != "blast") && (align != "noalign")) { m->mothurOut("invalid align option: choices are needleman, gotoh, blast or noalign."); m->mothurOutEndLine(); abort=true; } + } } @@ -234,7 +260,6 @@ AlignCommand::AlignCommand(string option) { } } //********************************************************************************************************************** - AlignCommand::~AlignCommand(){ if (abort == false) { @@ -243,37 +268,6 @@ AlignCommand::~AlignCommand(){ delete alignment; } } - -//********************************************************************************************************************** - -void AlignCommand::help(){ - try { - m->mothurOut("The align.seqs command reads a file containing sequences and creates an alignment file and a report file.\n"); - m->mothurOut("The align.seqs command parameters are template, candidate, search, ksize, align, match, mismatch, gapopen, gapextend and processors.\n"); - m->mothurOut("The template and candidate parameters are required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"); - m->mothurOut("The search parameter allows you to specify the method to find most similar template. Your options are: suffix, kmer and blast. The default is kmer.\n"); - m->mothurOut("The align parameter allows you to specify the alignment method to use. Your options are: gotoh, needleman, blast and noalign. The default is needleman.\n"); - m->mothurOut("The ksize parameter allows you to specify the kmer size for finding most similar template to candidate. The default is 8.\n"); - m->mothurOut("The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n"); - m->mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n"); - m->mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n"); - m->mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n"); - m->mothurOut("The flip parameter is used to specify whether or not you want mothur to try the reverse complement if a sequence falls below the threshold. The default is false.\n"); - m->mothurOut("The threshold is used to specify a cutoff at which an alignment is deemed 'bad' and the reverse complement may be tried. The default threshold is 0.50, meaning 50% of the bases are removed in the alignment.\n"); - m->mothurOut("If the flip parameter is set to true the reverse complement of the sequence is aligned and the better alignment is reported.\n"); - m->mothurOut("The default for the threshold parameter is 0.50, meaning at least 50% of the bases must remain or the sequence is reported as potentially reversed.\n"); - m->mothurOut("The align.seqs command should be in the following format: \n"); - m->mothurOut("align.seqs(template=yourTemplateFile, candidate=yourCandidateFile, align=yourAlignmentMethod, search=yourSearchmethod, ksize=yourKmerSize, match=yourMatchBonus, mismatch=yourMismatchpenalty, gapopen=yourGapopenPenalty, gapextend=yourGapExtendPenalty) \n"); - m->mothurOut("Example align.seqs(candidate=candidate.fasta, template=core.filtered, align=kmer, search=gotoh, ksize=8, match=2.0, mismatch=3.0, gapopen=-2.0, gapextend=-1.0)\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. candidate), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "AlignCommand", "help"); - exit(1); - } -} - - //********************************************************************************************************************** int AlignCommand::execute(){ @@ -815,7 +809,7 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s num = driver(lines[0], alignFileName, reportFileName, accnosFName, filename); //force parent to wait until all the processes are done - for (int i=0;i getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + + vector setParameters(); + string getCommandName() { return "align.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } private: struct linePair { @@ -38,7 +40,6 @@ private: vector processIDS; //processid vector lines; bool MPIWroteAccnos; - map > outputTypes; AlignmentDB* templateDB; Alignment* alignment; diff --git a/amovacommand.cpp b/amovacommand.cpp index 8ab0855..8e3edd5 100644 --- a/amovacommand.cpp +++ b/amovacommand.cpp @@ -11,56 +11,60 @@ #include "readphylipvector.h" #include "groupmap.h" + //********************************************************************************************************************** -vector AmovaCommand::getValidParameters(){ +vector AmovaCommand::setParameters(){ try { - string Array[] = {"outputdir","iters","phylip","design","alpha", "inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(palpha); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "AmovaCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -AmovaCommand::AmovaCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["amova"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "AmovaCommand", "AmovaCommand"); + m->errorOut(e, "AmovaCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector AmovaCommand::getRequiredParameters(){ +string AmovaCommand::getHelpString(){ try { - string Array[] = {"design"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "Referenced: Anderson MJ (2001). A new method for non-parametric multivariate analysis of variance. Austral Ecol 26: 32-46.\n"; + helpString += "The amova command outputs a .amova file. \n"; + helpString += "The amova command parameters are phylip, iters, and alpha. The phylip and design parameters are required, unless you have valid current files.\n"; + helpString += "The design parameter allows you to assign your samples to groups when you are running amova. It is required. \n"; + helpString += "The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the sample name and the second column is the group the sample belongs to.\n"; + helpString += "The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"; + helpString += "The amova command should be in the following format: amova(phylip=file.dist, design=file.design).\n"; + helpString += "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e. 1000).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "AmovaCommand", "getRequiredParameters"); + m->errorOut(e, "AmovaCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector AmovaCommand::getRequiredFiles(){ +AmovaCommand::AmovaCommand(){ try { - string Array[] = {}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["amova"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "AmovaCommand", "getRequiredFiles"); + m->errorOut(e, "AmovaCommand", "AmovaCommand"); exit(1); } } //********************************************************************************************************************** - AmovaCommand::AmovaCommand(string option) { try { abort = false; calledHelp = false; @@ -69,9 +73,7 @@ AmovaCommand::AmovaCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"design","outputdir","iters","phylip","alpha", "inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -116,14 +118,20 @@ AmovaCommand::AmovaCommand(string option) { phylipFileName = validParameter.validFile(parameters, "phylip", true); if (phylipFileName == "not open") { phylipFileName = ""; abort = true; } else if (phylipFileName == "not found") { - phylipFileName = ""; + //if there is a current phylip file, use it + phylipFileName = m->getPhylipFile(); + if (phylipFileName != "") { m->mothurOut("Using " + phylipFileName + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current phylip file and the phylip parameter is required."); m->mothurOutEndLine(); abort = true; } } //check for required parameters designFileName = validParameter.validFile(parameters, "design", true); if (designFileName == "not open") { abort = true; } else if (designFileName == "not found") { - designFileName = ""; + //if there is a current design file, use it + designFileName = m->getDesignFile(); + if (designFileName != "") { m->mothurOut("Using " + designFileName + " as input file for the design parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current design file and the design parameter is required."); m->mothurOutEndLine(); abort = true; } } string temp = validParameter.validFile(parameters, "iters", false); @@ -140,30 +148,6 @@ AmovaCommand::AmovaCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void AmovaCommand::help(){ - try { - m->mothurOut("Referenced: Anderson MJ (2001). A new method for non-parametric multivariate analysis of variance. Austral Ecol 26: 32-46.\n"); - m->mothurOut("The amova command outputs a .amova file. \n"); - m->mothurOut("The amova command parameters are phylip, iters, and alpha. The phylip and design parameters are required.\n"); - m->mothurOut("The design parameter allows you to assign your samples to groups when you are running amova. It is required. \n"); - m->mothurOut("The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the sample name and the second column is the group the sample belongs to.\n"); - m->mothurOut("The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"); - m->mothurOut("The amova command should be in the following format: amova(phylip=file.dist, design=file.design).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e. 1000).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "AmovaCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -AmovaCommand::~AmovaCommand(){} - //********************************************************************************************************************** int AmovaCommand::execute(){ diff --git a/amovacommand.h b/amovacommand.h index 51a4200..f50df46 100644 --- a/amovacommand.h +++ b/amovacommand.h @@ -11,8 +11,6 @@ */ #include "command.hpp" - -//class GlobalData; class GroupMap; class AmovaCommand : public Command { @@ -20,13 +18,15 @@ class AmovaCommand : public Command { public: AmovaCommand(string); AmovaCommand(); - ~AmovaCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + ~AmovaCommand() {} + + vector setParameters(); + string getCommandName() { return "amova"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } private: double runAMOVA(ofstream&, map >, double); @@ -34,9 +34,7 @@ private: double calcSSTotal(map >&); map > getRandomizedGroups(map >); - bool abort; - map > outputTypes; vector outputNames; string outputDir, inputDir, designFileName, phylipFileName; diff --git a/anosimcommand.cpp b/anosimcommand.cpp index 79064a4..623b433 100644 --- a/anosimcommand.cpp +++ b/anosimcommand.cpp @@ -12,50 +12,54 @@ #include "readphylipvector.h" //********************************************************************************************************************** -vector AnosimCommand::getValidParameters(){ +vector AnosimCommand::setParameters(){ try { - string Array[] = {"outputdir","iters","phylip","design", "alpha","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(palpha); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "AnosimCommand", "getValidParameters"); + m->errorOut(e, "AnosimCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -AnosimCommand::AnosimCommand(){ +string AnosimCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["anosim"] = tempOutNames; + string helpString = ""; + helpString += "Referenced: Clarke, K. R. (1993). Non-parametric multivariate analysis of changes in community structure. _Australian Journal of Ecology_ 18, 117-143.\n"; + helpString += "The anosim command outputs a .anosim file. \n"; + helpString += "The anosim command parameters are phylip, iters, and alpha. The phylip and design parameters are required, unless you have valid current files.\n"; + helpString += "The design parameter allows you to assign your samples to groups when you are running anosim. It is required. \n"; + helpString += "The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the sample name and the second column is the group the sample belongs to.\n"; + helpString += "The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"; + helpString += "The anosim command should be in the following format: anosim(phylip=file.dist, design=file.design).\n"; + helpString += "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e. 1000).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "AnosimCommand", "AnosimCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector AnosimCommand::getRequiredParameters(){ - try { - string Array[] = {"design"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "AnosimCommand", "getRequiredParameters"); + m->errorOut(e, "AnosimCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector AnosimCommand::getRequiredFiles(){ +AnosimCommand::AnosimCommand(){ try { - string Array[] = {}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["anosim"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "AnosimCommand", "getRequiredFiles"); + m->errorOut(e, "AnosimCommand", "AnosimCommand"); exit(1); } } @@ -69,9 +73,7 @@ AnosimCommand::AnosimCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"outputdir","iters","phylip","design", "alpha","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -116,14 +118,21 @@ AnosimCommand::AnosimCommand(string option) { phylipFileName = validParameter.validFile(parameters, "phylip", true); if (phylipFileName == "not open") { phylipFileName = ""; abort = true; } else if (phylipFileName == "not found") { - phylipFileName = ""; + //if there is a current phylip file, use it + phylipFileName = m->getPhylipFile(); + if (phylipFileName != "") { m->mothurOut("Using " + phylipFileName + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current phylip file and the phylip parameter is required."); m->mothurOutEndLine(); abort = true; } + } //check for required parameters designFileName = validParameter.validFile(parameters, "design", true); if (designFileName == "not open") { abort = true; } else if (designFileName == "not found") { - designFileName = ""; + //if there is a current design file, use it + designFileName = m->getDesignFile(); + if (designFileName != "") { m->mothurOut("Using " + designFileName + " as input file for the design parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current design file and the design parameter is required."); m->mothurOutEndLine(); abort = true; } } string temp = validParameter.validFile(parameters, "iters", false); @@ -141,33 +150,7 @@ AnosimCommand::AnosimCommand(string option) { exit(1); } } - //********************************************************************************************************************** - -void AnosimCommand::help(){ - try { - m->mothurOut("Referenced: Clarke, K. R. (1993). Non-parametric multivariate analysis of changes in community structure. _Australian Journal of Ecology_ 18, 117-143.\n"); - m->mothurOut("The anosim command outputs a .anosim file. \n"); - m->mothurOut("The anosim command parameters are phylip, iters, and alpha. The phylip and design parameters are required.\n"); - m->mothurOut("The design parameter allows you to assign your samples to groups when you are running anosim. It is required. \n"); - m->mothurOut("The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the sample name and the second column is the group the sample belongs to.\n"); - m->mothurOut("The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"); - m->mothurOut("The anosim command should be in the following format: anosim(phylip=file.dist, design=file.design).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e. 1000).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "AnosimCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -AnosimCommand::~AnosimCommand(){} - -//********************************************************************************************************************** - int AnosimCommand::execute(){ try { diff --git a/anosimcommand.h b/anosimcommand.h index ab72400..7bc5655 100644 --- a/anosimcommand.h +++ b/anosimcommand.h @@ -20,18 +20,19 @@ class AnosimCommand : public Command { public: AnosimCommand(string); AnosimCommand(); - ~AnosimCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + ~AnosimCommand(){} + + vector setParameters(); + string getCommandName() { return "anosim"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } private: bool abort; GroupMap* designMap; - map > outputTypes; string outputDir, inputDir, designFileName, phylipFileName; vector > convertToRanks(vector >); diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index 8b137c8..d1764ac 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -9,39 +9,43 @@ #include "binsequencecommand.h" + //********************************************************************************************************************** -vector BinSeqCommand::getValidParameters(){ - try { - string AlignArray[] = {"fasta","label","name", "group","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "BinSeqCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector BinSeqCommand::getRequiredParameters(){ +vector BinSeqCommand::setParameters(){ try { - string AlignArray[] = {"fasta"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "BinSeqCommand", "getRequiredParameters"); + m->errorOut(e, "BinSeqCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector BinSeqCommand::getRequiredFiles(){ +string BinSeqCommand::getHelpString(){ try { - string AlignArray[] = {"list"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The bin.seqs command parameters are list, fasta, name, label and group. The fasta and list are required, unless you have a valid current list and fasta file.\n"; + helpString += "The label parameter allows you to select what distance levels you would like a output files created for, and are separated by dashes.\n"; + helpString += "The bin.seqs command should be in the following format: bin.seqs(fasta=yourFastaFile, name=yourNamesFile, group=yourGroupFile, label=yourLabels).\n"; + helpString += "Example bin.seqs(fasta=amazon.fasta, group=amazon.groups, name=amazon.names).\n"; + helpString += "The default value for label is all lines in your inputfile.\n"; + helpString += "The bin.seqs command outputs a .fasta file for each distance you specify appending the OTU number to each name.\n"; + helpString += "If you provide a groupfile, then it also appends the sequences group to the name.\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "BinSeqCommand", "getRequiredFiles"); + m->errorOut(e, "BinSeqCommand", "getHelpString"); exit(1); } } @@ -49,6 +53,7 @@ vector BinSeqCommand::getRequiredFiles(){ BinSeqCommand::BinSeqCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; } @@ -60,7 +65,6 @@ BinSeqCommand::BinSeqCommand(){ //********************************************************************************************************************** BinSeqCommand::BinSeqCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; labels.clear(); @@ -69,9 +73,7 @@ BinSeqCommand::BinSeqCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"fasta","label","name", "group","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -88,20 +90,6 @@ BinSeqCommand::BinSeqCommand(string option) { vector tempOutNames; outputTypes["fasta"] = 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 = ""; - outputDir += m->hasPath(globaldata->getListFile()); //if user entered a file with a path then preserve it - } - - - //make sure the user has already run the read.otu command - if (globaldata->getListFile() == "") { - m->mothurOut("You must read a listfile before running the bin.seqs command."); - m->mothurOutEndLine(); - 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 = ""; } @@ -115,6 +103,14 @@ BinSeqCommand::BinSeqCommand(string option) { if (path == "") { parameters["fasta"] = inputDir + it->second; } } + 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("name"); //user has given a template file if(it != parameters.end()){ @@ -135,8 +131,27 @@ BinSeqCommand::BinSeqCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the bin.seqs command."); m->mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { //if there is a current phylip file, use it + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fasta file and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (fastafile == "not open") { abort = true; } + + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not found") { + listfile = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; } + } + else if (listfile == "not open") { listfile = ""; 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 = ""; + outputDir += m->hasPath(listfile); //if user entered a file with a path then preserve it + } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -148,12 +163,6 @@ BinSeqCommand::BinSeqCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - namesfile = validParameter.validFile(parameters, "name", true); if (namesfile == "not open") { abort = true; } else if (namesfile == "not found") { namesfile = ""; } @@ -162,17 +171,6 @@ BinSeqCommand::BinSeqCommand(string option) { if (groupfile == "not open") { abort = true; } else if (groupfile == "not found") { groupfile = ""; } - if (abort == false) { -// m->openInputFile(fastafile, in); - fasta = new FastaMap(); - if (groupfile != "") { - groupMap = new GroupMap(groupfile); - - int error = groupMap->readMap(); - if (error == 1) { delete groupMap; abort = true; } - } - } - } } catch(exception& e) { @@ -182,37 +180,7 @@ BinSeqCommand::BinSeqCommand(string option) { } //********************************************************************************************************************** -void BinSeqCommand::help(){ - try { - m->mothurOut("The bin.seqs command can only be executed after a successful read.otu command of a listfile.\n"); - m->mothurOut("The bin.seqs command parameters are fasta, name, label and group. The fasta parameter is required.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like a output files created for, and are separated by dashes.\n"); - m->mothurOut("The bin.seqs command should be in the following format: bin.seqs(fasta=yourFastaFile, name=yourNamesFile, group=yourGroupFile, label=yourLabels).\n"); - m->mothurOut("Example bin.seqs(fasta=amazon.fasta, group=amazon.groups, name=amazon.names).\n"); - m->mothurOut("The default value for label is all lines in your inputfile.\n"); - m->mothurOut("The bin.seqs command outputs a .fasta file for each distance you specify appending the OTU number to each name.\n"); - m->mothurOut("If you provide a groupfile, then it also appends the sequences group to the name.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "BinSeqCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -BinSeqCommand::~BinSeqCommand(){ - //made new in execute - if (abort == false) { - delete input; globaldata->ginput = NULL; - delete read; - globaldata->gListVector = NULL; - delete fasta; - if (groupfile != "") { delete groupMap; globaldata->gGroupmap = NULL; } - } -} - +BinSeqCommand::~BinSeqCommand(){} //********************************************************************************************************************** int BinSeqCommand::execute(){ @@ -221,27 +189,25 @@ int BinSeqCommand::execute(){ int error = 0; + fasta = new FastaMap(); + if (groupfile != "") { + groupMap = new GroupMap(groupfile); + groupMap->readMap(); + } + //read fastafile fasta->readFastaFile(fastafile); - - //set format to list so input can get listvector -// globaldata->setFormat("list"); - //if user gave a namesfile then use it if (namesfile != "") { readNamesFile(); } - //read list file - read = new ReadOTUFile(globaldata->getListFile()); - read->read(&*globaldata); - - input = globaldata->ginput; - list = globaldata->gListVector; + input = new InputData(listfile, "list"); + list = input->getListVector(); string lastLabel = list->getLabel(); - if (m->control_pressed) { return 0; } + if (m->control_pressed) { delete input; delete fasta; if (groupfile != "") { delete groupMap; } return 0; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -250,12 +216,12 @@ int BinSeqCommand::execute(){ while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete fasta; if (groupfile != "") { delete groupMap; } return 0; } if(allLines == 1 || labels.count(list->getLabel()) == 1){ error = process(list); - if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete fasta; if (groupfile != "") { delete groupMap; } return 0; } processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -268,7 +234,7 @@ int BinSeqCommand::execute(){ list = input->getListVector(lastLabel); error = process(list); - if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete fasta; if (groupfile != "") { delete groupMap; } return 0; } processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -283,7 +249,7 @@ int BinSeqCommand::execute(){ list = input->getListVector(); } - if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete fasta; if (groupfile != "") { delete groupMap; } return 0; } //output error messages about any remaining user labels set::iterator it; @@ -304,13 +270,21 @@ int BinSeqCommand::execute(){ list = input->getListVector(lastLabel); error = process(list); - if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } delete input; delete fasta; if (groupfile != "") { delete groupMap; } return 0; } delete list; } - if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } - + delete input; + delete fasta; + if (groupfile != "") { delete groupMap; } + + if(m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + + delete input; + delete fasta; + if (groupfile != "") { delete groupMap; } + m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } @@ -364,7 +338,7 @@ int BinSeqCommand::process(ListVector* list) { try { string binnames, name, sequence; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->getListFile())) + list->getLabel() + ".fasta"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(listfile)) + list->getLabel() + ".fasta"; m->openOutputFile(outputFileName, out); //save to output list of output file names diff --git a/binsequencecommand.h b/binsequencecommand.h index df7ea75..fe83f20 100644 --- a/binsequencecommand.h +++ b/binsequencecommand.h @@ -14,40 +14,36 @@ #include "command.hpp" #include "inputdata.h" #include "listvector.hpp" -#include "readotu.h" #include "fastamap.h" #include "groupmap.h" - -class GlobalData; - class BinSeqCommand : public Command { public: BinSeqCommand(string); BinSeqCommand(); ~BinSeqCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "bin.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; + ListVector* list; - ReadOTUFile* read; InputData* input; FastaMap* fasta; GroupMap* groupMap; bool abort, allLines; set labels; //holds labels to be used - string filename, fastafile, namesfile, groupfile, label, outputDir; + string filename, fastafile, listfile, namesfile, groupfile, label, outputDir; ofstream out; ifstream in, inNames; vector outputNames; - map > outputTypes; void readNamesFile(); int process(ListVector*); diff --git a/blastalign.cpp b/blastalign.cpp index 5e7fb61..9af31df 100644 --- a/blastalign.cpp +++ b/blastalign.cpp @@ -18,12 +18,11 @@ //**************************************************************************************************/ -BlastAlignment::BlastAlignment(float go, float ge, float m, float mm) : - match(m), // This is the score to award for two nucleotides matching (match >= 0) +BlastAlignment::BlastAlignment(float go, float ge, float ma, float mm) : + match(ma), // This is the score to award for two nucleotides matching (match >= 0) mismatch(mm) // This is the penalty to assess for a mismatch (mismatch <= 0) { - globaldata = GlobalData::getInstance(); - path = globaldata->argv; + path = m->argv; path = path.substr(0, (path.find_last_of('m'))); gapOpen = abs(go); // This is the penalty to assess for opening a gap (gapOpen >= 0) diff --git a/blastalign.hpp b/blastalign.hpp index 94bce82..5b78da6 100644 --- a/blastalign.hpp +++ b/blastalign.hpp @@ -12,7 +12,7 @@ */ #include "mothur.h" -#include "globaldata.hpp" + class BlastAlignment : public Alignment { @@ -34,6 +34,5 @@ private: float mismatch; float gapOpen; float gapExtend; - GlobalData* globaldata; }; diff --git a/blastdb.cpp b/blastdb.cpp index bc92e1c..7769555 100644 --- a/blastdb.cpp +++ b/blastdb.cpp @@ -17,7 +17,6 @@ BlastDB::BlastDB(float gO, float gE, float m, float mM) : Database(), gapOpen(gO), gapExtend(gE), match(m), misMatch(mM) { - globaldata = GlobalData::getInstance(); count = 0; int randNumber = rand(); @@ -30,7 +29,6 @@ gapOpen(gO), gapExtend(gE), match(m), misMatch(mM) { BlastDB::BlastDB() : Database() { try { - globaldata = GlobalData::getInstance(); count = 0; int randNumber = rand(); @@ -185,7 +183,7 @@ void BlastDB::generateDB() { //m->mothurOut("Generating the temporary BLAST database...\t"); cout.flush(); - path = globaldata->argv; + path = m->argv; path = path.substr(0, (path.find_last_of('m'))); string formatdbCommand = path + "blast/bin/formatdb -p F -o T -i " + dbFileName; // format the database, -o option gives us the ability diff --git a/blastdb.hpp b/blastdb.hpp index 2e7423d..9398ba0 100644 --- a/blastdb.hpp +++ b/blastdb.hpp @@ -12,7 +12,6 @@ */ #include "mothur.h" -#include "globaldata.hpp" class BlastDB : public Database { @@ -37,7 +36,6 @@ private: float gapExtend; float match; float misMatch; - GlobalData* globaldata; }; #endif diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index afc3cf1..7f7683b 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -19,96 +19,106 @@ #include "sharedmorisitahorn.h" #include "sharedbraycurtis.h" + //********************************************************************************************************************** -vector BootSharedCommand::getValidParameters(){ +vector BootSharedCommand::setParameters(){ try { - string AlignArray[] = {"label","calc","groups","iters","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pcalc("calc", "Multiple", "jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-morisitahorn-braycurtis", "jclass-thetayc", "", "", "",true,false); parameters.push_back(pcalc); + 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, "BootSharedCommand", "getValidParameters"); + m->errorOut(e, "BootSharedCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -BootSharedCommand::BootSharedCommand(){ +string BootSharedCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["tree"] = tempOutNames; + string helpString = ""; + helpString += "The bootstrap.shared command parameters are shared, groups, calc, iters and label. shared is required.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n"; + helpString += "The group names are separated by dashes. The label parameter allows you to select what distance levels you would like trees created for, and is also separated by dashes.\n"; + helpString += "The bootstrap.shared command should be in the following format: bootstrap.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels, iters=yourIters).\n"; + helpString += "Example bootstrap.shared(groups=A-B-C, calc=jabund-sorabund, iters=100).\n"; + helpString += "The default value for groups is all the groups in your groupfile.\n"; + helpString += "The default value for calc is jclass-thetayc. The default for iters is 1000.\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "BootSharedCommand", "BootSharedCommand"); + m->errorOut(e, "BootSharedCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector BootSharedCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "BootSharedCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector BootSharedCommand::getRequiredFiles(){ +BootSharedCommand::BootSharedCommand(){ try { - string AlignArray[] = {"shared"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["tree"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "BootSharedCommand", "getRequiredFiles"); + m->errorOut(e, "BootSharedCommand", "BootSharedCommand"); exit(1); } } //********************************************************************************************************************** BootSharedCommand::BootSharedCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; - allLines = 1; - labels.clear(); - Groups.clear(); - Estimators.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"label","calc","groups","iters","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } //initialize outputTypes vector tempOutNames; outputTypes["tree"] = 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 = ""; } + else { + string path; + 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; } + } + } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not found") { m->mothurOut("shared is a required parameter."); m->mothurOutEndLine(); sharedfile = ""; abort = true; } + else if (sharedfile == "not open") { sharedfile = ""; 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 = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it - } - - - //make sure the user has already run the read.otu command - if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the bootstrap.shared command."); m->mothurOutEndLine(); abort = true; } - else if (globaldata->getGroupFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the bootstrap.shared command."); m->mothurOutEndLine(); abort = true; } + outputDir += m->hasPath(sharedfile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -119,18 +129,12 @@ BootSharedCommand::BootSharedCommand(string option) { if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } - - //if the user has not specified any labels use the ones from read.otu - if(label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - + groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } calc = validParameter.validFile(parameters, "calc", false); @@ -147,10 +151,13 @@ BootSharedCommand::BootSharedCommand(string option) { if (abort == false) { //used in tree constructor - globaldata->runParse = false; + m->runParse = false; validCalculator = new ValidCalculators(); + + //NOTE: if you add a calc to this if statement you must add it to the setParameters function + //or it will not be visible in the gui int i; for (i=0; iisValidCalculator("boot", Estimators[i]) == true) { @@ -197,51 +204,19 @@ BootSharedCommand::BootSharedCommand(string option) { exit(1); } } - //********************************************************************************************************************** - -void BootSharedCommand::help(){ - try { - m->mothurOut("The bootstrap.shared command can only be executed after a successful read.otu command.\n"); - m->mothurOut("The bootstrap.shared command parameters are groups, calc, iters and label.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n"); - m->mothurOut("The group names are separated by dashes. The label parameter allows you to select what distance levels you would like trees created for, and is also separated by dashes.\n"); - m->mothurOut("The bootstrap.shared command should be in the following format: bootstrap.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels, iters=yourIters).\n"); - m->mothurOut("Example bootstrap.shared(groups=A-B-C, calc=jabund-sorabund, iters=100).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile.\n"); - m->mothurOut("The default value for calc is jclass-thetayc. The default for iters is 1000.\n"); - } - catch(exception& e) { - m->errorOut(e, "BootSharedCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -BootSharedCommand::~BootSharedCommand(){ - //made new in execute - if (abort == false) { - delete input; globaldata->ginput = NULL; - delete read; - delete util; - globaldata->gorder = NULL; - } -} - +BootSharedCommand::~BootSharedCommand(){} //********************************************************************************************************************** int BootSharedCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - - util = new SharedUtil(); - + + m->mothurOut("bootstrap.shared command is no longer available."); m->mothurOutEndLine(); + /* //read first line - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - input = globaldata->ginput; + input = new InputData(sharedfile, "sharedfile"); order = input->getSharedOrderVector(); string lastLabel = order->getLabel(); @@ -253,14 +228,16 @@ int BootSharedCommand::execute(){ set userLabels = labels; //set users groups - util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "treegroup"); - numGroups = globaldata->Groups.size(); + util = new SharedUtil(); + util->setGroups(m->Groups, m->namesOfGroups, "treegroup"); + + numGroups = m->Groups.size(); //clear globaldatas old tree names if any globaldata->Treenames.clear(); //fills globaldatas tree names - globaldata->Treenames = globaldata->Groups; + globaldata->Treenames = m->Groups; //create treemap class from groupmap for tree class to use tmap = new TreeMap(); @@ -268,13 +245,13 @@ int BootSharedCommand::execute(){ globaldata->gTreemap = tmap; while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); delete input;delete util; return 0; } if(allLines == 1 || labels.count(order->getLabel()) == 1){ m->mothurOut(order->getLabel()); m->mothurOutEndLine(); int error = process(order); - if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); delete input;delete util; return 0; } processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); @@ -288,7 +265,7 @@ int BootSharedCommand::execute(){ order = input->getSharedOrderVector(lastLabel); m->mothurOut(order->getLabel()); m->mothurOutEndLine(); int error = process(order); - if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); delete input;delete util; return 0; } processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); @@ -306,7 +283,7 @@ int BootSharedCommand::execute(){ } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); delete input; delete util; return 0; } //output error messages about any remaining user labels set::iterator it; @@ -321,7 +298,7 @@ int BootSharedCommand::execute(){ } } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); delete input; delete util; return 0; } //run last line if you need to if (needToRun == true) { @@ -329,13 +306,13 @@ int BootSharedCommand::execute(){ order = input->getSharedOrderVector(lastLabel); m->mothurOut(order->getLabel()); m->mothurOutEndLine(); int error = process(order); - if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (error == 1) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); delete input; delete util; return 0; } delete order; } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear();delete input; delete util; return 0; } //reset groups parameter globaldata->Groups.clear(); @@ -347,11 +324,14 @@ int BootSharedCommand::execute(){ if ((itTypes->second).size() != 0) { currentTree = (itTypes->second)[0]; m->setTreeFile(currentTree); } } + delete input; + delete util; + m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine(); - +*/ return 0; } @@ -364,7 +344,7 @@ int BootSharedCommand::execute(){ int BootSharedCommand::createTree(ostream* out, Tree* t){ try { - + /* //do merges and create tree structure by setting parents and children //there are numGroups - 1 merges to do for (int i = 0; i < (numGroups - 1); i++) { @@ -428,7 +408,7 @@ int BootSharedCommand::createTree(ostream* out, Tree* t){ if (m->control_pressed) { return 1; } //print newick file - t->print(*out); + t->print(*out);*/ return 0; @@ -458,13 +438,13 @@ void BootSharedCommand::printSims() { /***********************************************************/ int BootSharedCommand::process(SharedOrderVector* order) { try{ - EstOutput data; + /* EstOutput data; vector subset; //open an ostream for each calc to print to for (int z = 0; z < treeCalculators.size(); z++) { //create a new filename - outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre"; + outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre"; m->openOutputFile(outputFile, *(out[z])); outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); } @@ -476,7 +456,7 @@ int BootSharedCommand::process(SharedOrderVector* order) { if (m->control_pressed) { return 1; } - util->getSharedVectorswithReplacement(globaldata->Groups, lookup, order); //fills group vectors from order vector. + util->getSharedVectorswithReplacement(m->Groups, lookup, order); //fills group vectors from order vector. //for each calculator @@ -528,10 +508,7 @@ int BootSharedCommand::process(SharedOrderVector* order) { } m->mothurOut("\tDone."); m->mothurOutEndLine(); - //delete globaldata's tree - //for (int m = 0; m < globaldata->gTree.size(); m++) { delete globaldata->gTree[m]; } - //globaldata->gTree.clear(); - + //create consensus trees for each bootstrapped tree set for (int k = 0; k < trees.size(); k++) { @@ -543,7 +520,7 @@ int BootSharedCommand::process(SharedOrderVector* order) { //set global data to calc trees globaldata->gTree = trees[k]; - string filename = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[k]->getName() + ".boot" + order->getLabel(); + string filename = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + treeCalculators[k]->getName() + ".boot" + order->getLabel(); consensus = new ConcensusCommand(filename); consensus->execute(); delete consensus; @@ -551,17 +528,13 @@ int BootSharedCommand::process(SharedOrderVector* order) { outputNames.push_back(filename + ".cons.pairs"); outputNames.push_back(filename + ".cons.tre"); - //delete globaldata's tree - //for (int m = 0; m < globaldata->gTree.size(); m++) { delete globaldata->gTree[m]; } - //globaldata->gTree.clear(); - } //close ostream for each calc for (int z = 0; z < treeCalculators.size(); z++) { out[z]->close(); } - + */ return 0; } diff --git a/bootstrapsharedcommand.h b/bootstrapsharedcommand.h index 53f6a26..50297b8 100644 --- a/bootstrapsharedcommand.h +++ b/bootstrapsharedcommand.h @@ -14,14 +14,11 @@ #include "sharedordervector.h" #include "inputdata.h" #include "groupmap.h" -#include "readotu.h" #include "validcalculator.h" #include "tree.h" #include "treemap.h" #include "sharedutilities.h" #include "consensuscommand.h" - -class GlobalData; class BootSharedCommand : public Command { @@ -29,22 +26,21 @@ public: BootSharedCommand(string); BootSharedCommand(); ~BootSharedCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "bootstrap.shared"; } + string getCommandCategory() { return "Hidden"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: int createTree(ostream*, Tree*); void printSims(); int process(SharedOrderVector*); - - GlobalData* globaldata; SharedUtil* util; - ReadOTUFile* read; TreeMap* tmap; Tree* t; Tree* tempTree; @@ -61,11 +57,9 @@ private: bool abort, allLines; set labels; //holds labels to be used - string outputFile, calc, groups, label, outputDir; + string outputFile, calc, groups, label, outputDir, sharedfile; int numGroups, iters; vector Estimators, Groups, outputNames; //holds estimators to be used - map< string, vector > outputTypes; - }; diff --git a/catchallcommand.cpp b/catchallcommand.cpp index ace1b00..3effaf4 100644 --- a/catchallcommand.cpp +++ b/catchallcommand.cpp @@ -11,58 +11,63 @@ #include "globaldata.hpp" //********************************************************************************************************************** -vector CatchAllCommand::getValidParameters(){ +vector CatchAllCommand::setParameters(){ try { - string AlignArray[] = {"sabund","shared","label","inputdir","outputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + //can choose shared or sabund not both, so put them in the same chooseOnlyOneGroup + CommandParameter pshared("shared", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none",false,false); parameters.push_back(pshared); + CommandParameter psabund("sabund", "InputTypes", "", "", "catchallInputs", "catchallInputs", "none",false,false); parameters.push_back(psabund); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "CatchAllCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -CatchAllCommand::CatchAllCommand(){ - try { - abort = true; calledHelp = true; - //initialize outputTypes - vector tempOutNames; - outputTypes["csv"] = tempOutNames; - outputTypes["summary"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "CatchAllCommand", "CatchAllCommand"); + m->errorOut(e, "CatchAllCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector CatchAllCommand::getRequiredParameters(){ +string CatchAllCommand::getHelpString(){ try { - string AlignArray[] = {"sabund","shared","or"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The catchall command interfaces mothur with the catchall program written by Linda Woodard, Sean Connolly and John Bunge.\n"; + helpString += "For more information about catchall refer to http://www.northeastern.edu/catchall/index.html \n"; + helpString += "The catchall executable must be in the same folder as your mothur executable. \n"; + helpString += "If you are a MAC or Linux user you must also have installed mono, a link to mono is on the webpage. \n"; + helpString += "The catchall command parameters are shared, sabund and label. shared or sabund is required. \n"; + helpString += "The label parameter is used to analyze specific labels in your input.\n"; + helpString += "The catchall command should be in the following format: \n"; + helpString += "catchall(sabund=yourSabundFile) \n"; + helpString += "Example: catchall(sabund=abrecovery.fn.sabund) \n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "CatchAllCommand", "getRequiredParameters"); + m->errorOut(e, "CatchAllCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector CatchAllCommand::getRequiredFiles(){ +CatchAllCommand::CatchAllCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + //initialize outputTypes + vector tempOutNames; + outputTypes["csv"] = tempOutNames; + outputTypes["summary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "CatchAllCommand", "getRequiredFiles"); + m->errorOut(e, "CatchAllCommand", "CatchAllCommand"); exit(1); } } /**************************************************************************************/ CatchAllCommand::CatchAllCommand(string option) { try { - globaldata = GlobalData::getInstance(); + abort = false; calledHelp = false; allLines = 1; @@ -70,9 +75,7 @@ CatchAllCommand::CatchAllCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"shared","sabund","label","inputdir","outputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -116,17 +119,11 @@ CatchAllCommand::CatchAllCommand(string option) { sabundfile = validParameter.validFile(parameters, "sabund", true); if (sabundfile == "not open") { sabundfile = ""; abort = true; } else if (sabundfile == "not found") { sabundfile = ""; } - else { globaldata->setSabundFile(sabundfile); globaldata->setFormat("sabund"); } sharedfile = validParameter.validFile(parameters, "shared", true); if (sharedfile == "not open") { sharedfile = ""; abort = true; } else if (sharedfile == "not found") { sharedfile = ""; } - //check for shared file loaded during read.otu - if (sharedfile == "") { - if (globaldata->getSharedFile() != "") { sharedfile = globaldata->getSharedFile(); } - } - string label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; } else { @@ -134,8 +131,22 @@ CatchAllCommand::CatchAllCommand(string option) { else { allLines = 1; } } - if ((sharedfile == "") && (sabundfile == "")) { m->mothurOut("You must provide a sabund or shared file for the catchall command."); m->mothurOutEndLine(); abort=true; } - + if ((sharedfile == "") && (sabundfile == "")) { + //is there are current file available for either of these? + //give priority to shared, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + sabundfile = m->getSabundFile(); + if (sabundfile != "") { m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a sabund or shared file before you can use the catchall command."); 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"){ @@ -150,26 +161,6 @@ CatchAllCommand::CatchAllCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void CatchAllCommand::help(){ - try { - m->mothurOut("The catchall command interfaces mothur with the catchall program written by Linda Woodard, Sean Connolly and John Bunge.\n"); - m->mothurOut("For more information about catchall refer to http://www.northeastern.edu/catchall/index.html \n"); - m->mothurOut("The catchall executable must be in the same folder as your mothur executable. \n"); - m->mothurOut("If you are a MAC or Linux user you must also have installed mono, a link to mono is on the webpage. \n"); - m->mothurOut("The catchall command parameters are shared, sabund and label. shared or sabund is required. \n"); - m->mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - m->mothurOut("The catchall command should be in the following format: \n"); - m->mothurOut("catchall(sabund=yourSabundFile) \n"); - m->mothurOut("Example: catchall(sabund=abrecovery.fn.sabund) \n"); - } - catch(exception& e) { - m->errorOut(e, "CatchAllCommand", "help"); - exit(1); - } -} - /**************************************************************************************/ int CatchAllCommand::execute() { try { @@ -177,8 +168,7 @@ int CatchAllCommand::execute() { if (abort == true) { if (calledHelp) { return 0; } return 2; } //get location of catchall - GlobalData* globaldata = GlobalData::getInstance(); - path = globaldata->argv; + path = m->argv; path = path.substr(0, (path.find_last_of("othur")-5)); path = m->getFullPathName(path); @@ -196,7 +186,7 @@ int CatchAllCommand::execute() { outputDir = m->getFullPathName(outputDir); vector inputFileNames; - if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile); globaldata->setFormat("sabund"); } + if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile); } else { inputFileNames.push_back(sabundfile); } for (int p = 0; p < inputFileNames.size(); p++) { @@ -386,8 +376,6 @@ int CatchAllCommand::execute() { } string summaryfilename = combineSummmary(sumNames); outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename); - - globaldata->setSharedFile(sharedfile); globaldata->setFormat("sharedfile"); } m->mothurOutEndLine(); diff --git a/catchallcommand.h b/catchallcommand.h index 44bde02..583191d 100644 --- a/catchallcommand.h +++ b/catchallcommand.h @@ -12,7 +12,6 @@ #include "command.hpp" #include "inputdata.h" -#include "readotu.h" #include "sabundvector.hpp" /* @@ -28,22 +27,20 @@ public: CatchAllCommand(string); CatchAllCommand(); ~CatchAllCommand() {} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map< string, vector > getOutputFiles() { return outputTypes; } - int execute(); - void help(); -private: - - GlobalData* globaldata; + vector setParameters(); + string getCommandName() { return "catchall"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); - string outputDir, sharedfile, sabundfile, rabundfile, listfile, format, path, savedOutputDir; + int execute(); + void help() { m->mothurOut(getHelpString()); } + +private: + string outputDir, sharedfile, sabundfile, format, path, savedOutputDir; bool abort, allLines; set labels; vector outputNames; - map< string, vector > outputTypes; vector groups; string process(SAbundVector*, string); diff --git a/chimerabellerophoncommand.cpp b/chimerabellerophoncommand.cpp index 140a949..cc0aa43 100644 --- a/chimerabellerophoncommand.cpp +++ b/chimerabellerophoncommand.cpp @@ -11,37 +11,48 @@ #include "bellerophon.h" //********************************************************************************************************************** -vector ChimeraBellerophonCommand::getValidParameters(){ +vector ChimeraBellerophonCommand::setParameters(){ try { - string AlignArray[] = {"fasta","filter","correction","processors","window","increment","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ChimeraBellerophonCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ChimeraBellerophonCommand::getRequiredParameters(){ - try { - string AlignArray[] = {"fasta"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none","none","none",false,true); parameters.push_back(pfasta); + CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pfilter); + CommandParameter pcorrection("filter", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pcorrection); + CommandParameter pwindow("window", "Number", "", "0", "", "", "",false,false); parameters.push_back(pwindow); + CommandParameter pincrement("increment", "Number", "", "25", "", "", "",false,false); parameters.push_back(pincrement); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ChimeraBellerophonCommand", "getRequiredParameters"); + m->errorOut(e, "ChimeraBellerophonCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ChimeraBellerophonCommand::getRequiredFiles(){ +string ChimeraBellerophonCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The chimera.bellerophon command reads a fastafile and creates list of potentially chimeric sequences.\n"; + helpString += "The chimera.bellerophon command parameters are fasta, filter, correction, processors, window, increment. The fasta parameter is required, unless you have a valid current file.\n"; + helpString += "The fasta parameter is required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"; + helpString += "The filter parameter allows you to specify if you would like to apply a vertical and 50% soft filter, default=false. \n"; + helpString += "The correction parameter allows you to put more emphasis on the distance between highly similar sequences and less emphasis on the differences between remote homologs, default=true.\n"; + helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"; +#ifdef USE_MPI + helpString += "When using MPI, the processors parameter is set to the number of MPI processes running. \n"; +#endif + helpString += "The window parameter allows you to specify the window size for searching for chimeras, default is 1/4 sequence length. \n"; + helpString += "The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default is 25.\n"; + helpString += "chimera.bellerophon(fasta=yourFastaFile, filter=yourFilter, correction=yourCorrection, processors=yourProcessors) \n"; + helpString += "Example: chimera.bellerophon(fasta=AD.align, filter=True, correction=true, window=200) \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ChimeraBellerophonCommand", "getRequiredFiles"); + m->errorOut(e, "ChimeraBellerophonCommand", "getHelpString"); exit(1); } } @@ -49,6 +60,7 @@ vector ChimeraBellerophonCommand::getRequiredFiles(){ ChimeraBellerophonCommand::ChimeraBellerophonCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["chimera"] = tempOutNames; outputTypes["accnos"] = tempOutNames; @@ -67,9 +79,8 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","filter","correction","processors","window","increment","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -92,8 +103,12 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { if (inputDir == "not found"){ inputDir = ""; } fastafile = validParameter.validFile(parameters, "fasta", false); - if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.bellerophon command."); m->mothurOutEndLine(); abort = true; } - else { + if (fastafile == "not found") { + //if there is a current fasta file, use it + string filename = m->getFastaFile(); + if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them @@ -158,7 +173,8 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { temp = validParameter.validFile(parameters, "correction", false); if (temp == "not found") { temp = "T"; } correction = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); temp = validParameter.validFile(parameters, "window", false); if (temp == "not found") { temp = "0"; } @@ -173,37 +189,7 @@ ChimeraBellerophonCommand::ChimeraBellerophonCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ChimeraBellerophonCommand::help(){ - try { - m->mothurOut("The chimera.bellerophon command reads a fastafile and creates list of potentially chimeric sequences.\n"); - m->mothurOut("The chimera.bellerophon command parameters are fasta, filter, correction, processors, window, increment. The fasta parameter is required.\n"); - m->mothurOut("The fasta parameter is required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"); - m->mothurOut("The filter parameter allows you to specify if you would like to apply a vertical and 50% soft filter, default=false. \n"); - m->mothurOut("The correction parameter allows you to put more emphasis on the distance between highly similar sequences and less emphasis on the differences between remote homologs, default=true.\n"); - m->mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"); - #ifdef USE_MPI - m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n"); - #endif - m->mothurOut("The window parameter allows you to specify the window size for searching for chimeras, default is 1/4 sequence length. \n"); - m->mothurOut("The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default is 25.\n"); - m->mothurOut("chimera.bellerophon(fasta=yourFastaFile, filter=yourFilter, correction=yourCorrection, processors=yourProcessors) \n"); - m->mothurOut("Example: chimera.bellerophon(fasta=AD.align, filter=True, correction=true, window=200) \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ChimeraBellerophonCommand", "help"); - exit(1); - } -} - //*************************************************************************************************************** - -ChimeraBellerophonCommand::~ChimeraBellerophonCommand(){ /* do nothing */ } - -//*************************************************************************************************************** - int ChimeraBellerophonCommand::execute(){ try{ diff --git a/chimerabellerophoncommand.h b/chimerabellerophoncommand.h index 6e1ae50..867d361 100644 --- a/chimerabellerophoncommand.h +++ b/chimerabellerophoncommand.h @@ -21,13 +21,16 @@ class ChimeraBellerophonCommand : public Command { public: ChimeraBellerophonCommand(string); ChimeraBellerophonCommand(); - ~ChimeraBellerophonCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map< string, vector > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ChimeraBellerophonCommand(){} + + vector setParameters(); + string getCommandName() { return "chimera.bellerophon"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: @@ -36,7 +39,6 @@ private: int processors, window, increment, numSeqs; Chimera* chimera; vector outputNames; - map > outputTypes; vector fastaFileNames; }; diff --git a/chimeraccodecommand.cpp b/chimeraccodecommand.cpp index 457eaf3..0b6117a 100644 --- a/chimeraccodecommand.cpp +++ b/chimeraccodecommand.cpp @@ -9,53 +9,69 @@ #include "chimeraccodecommand.h" #include "ccode.h" - //********************************************************************************************************************** -vector ChimeraCcodeCommand::getValidParameters(){ +vector ChimeraCcodeCommand::setParameters(){ try { - string AlignArray[] = {"fasta", "filter", "processors", "window", "template", "mask", "numwanted", "outputdir","inputdir" }; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pfilter); + CommandParameter pwindow("window", "Number", "", "0", "", "", "",false,false); parameters.push_back(pwindow); + CommandParameter pnumwanted("numwanted", "Number", "", "20", "", "", "",false,false); parameters.push_back(pnumwanted); + CommandParameter pmask("mask", "String", "", "", "", "", "",false,false); parameters.push_back(pmask); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ChimeraCcodeCommand", "getValidParameters"); + m->errorOut(e, "ChimeraCcodeCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ChimeraCcodeCommand::ChimeraCcodeCommand(){ +string ChimeraCcodeCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["chimera"] = tempOutNames; - outputTypes["mapinfo"] = tempOutNames; - outputTypes["accnos"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector ChimeraCcodeCommand::getRequiredParameters(){ - try { - string AlignArray[] = {"template","fasta"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The chimera.ccode command reads a fastafile and referencefile and outputs potentially chimeric sequences.\n"; + helpString += "This command was created using the algorythms described in the 'Evaluating putative chimeric sequences from PCR-amplified products' paper by Juan M. Gonzalez, Johannes Zimmerman and Cesareo Saiz-Jimenez.\n"; + helpString += "The chimera.ccode command parameters are fasta, reference, filter, mask, processors, window and numwanted.\n"; + helpString += "The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required unless you have a valid current fasta file. \n"; + helpString += "You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"; + helpString += "The reference parameter allows you to enter a reference file containing known non-chimeric sequences, and is required. \n"; + helpString += "The filter parameter allows you to specify if you would like to apply a vertical and 50% soft filter. \n"; + helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"; +#ifdef USE_MPI + helpString += "When using MPI, the processors parameter is set to the number of MPI processes running. \n"; +#endif + helpString += "The mask parameter allows you to specify a file containing one sequence you wish to use as a mask for the your sequences. \n"; + helpString += "The window parameter allows you to specify the window size for searching for chimeras. \n"; + helpString += "The numwanted parameter allows you to specify how many sequences you would each query sequence compared with.\n"; + helpString += "The chimera.ccode command should be in the following format: \n"; + helpString += "chimera.ccode(fasta=yourFastaFile, reference=yourTemplate) \n"; + helpString += "Example: chimera.ccode(fasta=AD.align, reference=core_set_aligned.imputed.fasta) \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ChimeraCcodeCommand", "getRequiredParameters"); + m->errorOut(e, "ChimeraCcodeCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ChimeraCcodeCommand::getRequiredFiles(){ +ChimeraCcodeCommand::ChimeraCcodeCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["mapinfo"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ChimeraCcodeCommand", "getRequiredFiles"); + m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand"); exit(1); } } @@ -68,9 +84,7 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta", "filter", "processors", "window", "template", "mask", "numwanted", "outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -93,19 +107,22 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { if (inputDir == "not found"){ inputDir = ""; } else { string path; - it = parameters.find("template"); + it = parameters.find("reference"); //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["template"] = inputDir + it->second; } + if (path == "") { parameters["reference"] = inputDir + it->second; } } } //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", false); - if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.ccode command."); m->mothurOutEndLine(); abort = true; } - else { + if (fastafile == "not found") { //if there is a current fasta file, use it + string filename = m->getFastaFile(); + if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them @@ -162,9 +179,9 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } - templatefile = validParameter.validFile(parameters, "template", true); + templatefile = validParameter.validFile(parameters, "reference", true); if (templatefile == "not open") { abort = true; } - else if (templatefile == "not found") { templatefile = ""; m->mothurOut("template is a required parameter for the chimera.ccode command."); m->mothurOutEndLine(); abort = true; } + else if (templatefile == "not found") { templatefile = ""; m->mothurOut("reference is a required parameter for the chimera.ccode command."); m->mothurOutEndLine(); abort = true; } maskfile = validParameter.validFile(parameters, "mask", false); if (maskfile == "not found") { maskfile = ""; } @@ -185,7 +202,8 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { temp = validParameter.validFile(parameters, "filter", false); if (temp == "not found") { temp = "F"; } filter = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); temp = validParameter.validFile(parameters, "window", false); if (temp == "not found") { temp = "0"; } @@ -201,42 +219,7 @@ ChimeraCcodeCommand::ChimeraCcodeCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ChimeraCcodeCommand::help(){ - try { - - m->mothurOut("The chimera.ccode command reads a fastafile and templatefile and outputs potentially chimeric sequences.\n"); - m->mothurOut("This command was created using the algorythms described in the 'Evaluating putative chimeric sequences from PCR-amplified products' paper by Juan M. Gonzalez, Johannes Zimmerman and Cesareo Saiz-Jimenez.\n"); - m->mothurOut("The chimera.ccode command parameters are fasta, template, filter, mask, processors, window and numwanted.\n"); - m->mothurOut("The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required. \n"); - m->mothurOut("You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"); - m->mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences, and is required. \n"); - m->mothurOut("The filter parameter allows you to specify if you would like to apply a vertical and 50% soft filter. \n"); - m->mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"); - #ifdef USE_MPI - m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n"); - #endif - m->mothurOut("The mask parameter allows you to specify a file containing one sequence you wish to use as a mask for the your sequences. \n"); - m->mothurOut("The window parameter allows you to specify the window size for searching for chimeras. \n"); - m->mothurOut("The numwanted parameter allows you to specify how many sequences you would each query sequence compared with.\n"); - m->mothurOut("The chimera.ccode command should be in the following format: \n"); - m->mothurOut("chimera.ccode(fasta=yourFastaFile, template=yourTemplate) \n"); - m->mothurOut("Example: chimera.ccode(fasta=AD.align, template=core_set_aligned.imputed.fasta) \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ChimeraCcodeCommand", "help"); - exit(1); - } -} - //*************************************************************************************************************** - -ChimeraCcodeCommand::~ChimeraCcodeCommand(){ /* do nothing */ } - -//*************************************************************************************************************** - int ChimeraCcodeCommand::execute(){ try{ diff --git a/chimeraccodecommand.h b/chimeraccodecommand.h index a9ed223..4f047e1 100644 --- a/chimeraccodecommand.h +++ b/chimeraccodecommand.h @@ -21,13 +21,15 @@ class ChimeraCcodeCommand : public Command { public: ChimeraCcodeCommand(string); ChimeraCcodeCommand(); - ~ChimeraCcodeCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ChimeraCcodeCommand(){} + + vector setParameters(); + string getCommandName() { return "chimera.ccode"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: @@ -52,9 +54,6 @@ private: Chimera* chimera; vector fastaFileNames; vector outputNames; - map > outputTypes; - - }; /***********************************************************/ diff --git a/chimeracheckcommand.cpp b/chimeracheckcommand.cpp index c766b9a..5a72afd 100644 --- a/chimeracheckcommand.cpp +++ b/chimeracheckcommand.cpp @@ -10,37 +10,54 @@ #include "chimeracheckcommand.h" //********************************************************************************************************************** -vector ChimeraCheckCommand::getValidParameters(){ +vector ChimeraCheckCommand::setParameters(){ try { - string AlignArray[] = {"fasta","processors","increment","template","ksize","svg", "name","outputdir","inputdir" }; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ChimeraCheckCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ChimeraCheckCommand::getRequiredParameters(){ - try { - string AlignArray[] = {"template","fasta"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter psvg("svg", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psvg); + CommandParameter pincrement("increment", "Number", "", "10", "", "", "",false,false); parameters.push_back(pincrement); + CommandParameter pksize("ksize", "Number", "", "7", "", "", "",false,false); parameters.push_back(pksize); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ChimeraCheckCommand", "getRequiredParameters"); + m->errorOut(e, "ChimeraCheckCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ChimeraCheckCommand::getRequiredFiles(){ +string ChimeraCheckCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The chimera.check command reads a fastafile and referencefile and outputs potentially chimeric sequences.\n"; + helpString += "This command was created using the algorythms described in CHIMERA_CHECK version 2.7 written by Niels Larsen. \n"; + helpString += "The chimera.check command parameters are fasta, reference, processors, ksize, increment, svg and name.\n"; + helpString += "The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required unless you have a valid current fasta file. \n"; + helpString += "You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"; + helpString += "The reference parameter allows you to enter a reference file containing known non-chimeric sequences, and is required. \n"; + helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"; +#ifdef USE_MPI + helpString += "When using MPI, the processors parameter is set to the number of MPI processes running. \n"; +#endif + helpString += "The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default is 10.\n"; + helpString += "The ksize parameter allows you to input kmersize, default is 7. \n"; + helpString += "The svg parameter allows you to specify whether or not you would like a svg file outputted for each query sequence, default is False.\n"; + helpString += "The name parameter allows you to enter a file containing names of sequences you would like .svg files for.\n"; + helpString += "You may enter multiple name files by separating their names with dashes. ie. fasta=abrecovery.svg.names-amzon.svg.names \n"; + helpString += "The chimera.check command should be in the following format: \n"; + helpString += "chimera.check(fasta=yourFastaFile, reference=yourTemplateFile, processors=yourProcessors, ksize=yourKmerSize) \n"; + helpString += "Example: chimera.check(fasta=AD.fasta, reference=core_set_aligned,imputed.fasta, processors=4, ksize=8) \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ChimeraCheckCommand", "getRequiredFiles"); + m->errorOut(e, "ChimeraCheckCommand", "getHelpString"); exit(1); } } @@ -48,6 +65,7 @@ vector ChimeraCheckCommand::getRequiredFiles(){ ChimeraCheckCommand::ChimeraCheckCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["chimera"] = tempOutNames; } @@ -65,9 +83,7 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","processors","increment","template","ksize","svg", "name","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -87,19 +103,23 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { string inputDir = validParameter.validFile(parameters, "inputdir", false); if (inputDir == "not found"){ inputDir = ""; } else { - it = parameters.find("template"); + it = parameters.find("reference"); //user has given a template file if(it != parameters.end()){ string path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. - if (path == "") { parameters["template"] = inputDir + it->second; } + if (path == "") { parameters["reference"] = inputDir + it->second; } } } //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", false); - if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.check command."); m->mothurOutEndLine(); abort = true; } - else { + if (fastafile == "not found") { + //if there is a current fasta file, use it + string filename = m->getFastaFile(); + if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them @@ -156,9 +176,9 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } - templatefile = validParameter.validFile(parameters, "template", true); + templatefile = validParameter.validFile(parameters, "reference", true); if (templatefile == "not open") { abort = true; } - else if (templatefile == "not found") { templatefile = ""; m->mothurOut("template is a required parameter for the chimera.check command."); m->mothurOutEndLine(); abort = true; } + else if (templatefile == "not found") { templatefile = ""; m->mothurOut("reference is a required parameter for the chimera.check command."); m->mothurOutEndLine(); abort = true; } namefile = validParameter.validFile(parameters, "name", false); if (namefile == "not found") { namefile = ""; } @@ -222,7 +242,8 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { } } - string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } + string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); temp = validParameter.validFile(parameters, "ksize", false); if (temp == "not found") { temp = "7"; } @@ -241,41 +262,6 @@ ChimeraCheckCommand::ChimeraCheckCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ChimeraCheckCommand::help(){ - try { - - m->mothurOut("The chimera.check command reads a fastafile and templatefile and outputs potentially chimeric sequences.\n"); - m->mothurOut("This command was created using the algorythms described in CHIMERA_CHECK version 2.7 written by Niels Larsen. \n"); - m->mothurOut("The chimera.check command parameters are fasta, template, processors, ksize, increment, svg and name.\n"); - m->mothurOut("The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required. \n"); - m->mothurOut("You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"); - m->mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences, and is required. \n"); - m->mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"); - #ifdef USE_MPI - m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n"); - #endif - m->mothurOut("The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default is 10.\n"); - m->mothurOut("The ksize parameter allows you to input kmersize, default is 7. \n"); - m->mothurOut("The svg parameter allows you to specify whether or not you would like a svg file outputted for each query sequence, default is False.\n"); - m->mothurOut("The name parameter allows you to enter a file containing names of sequences you would like .svg files for.\n"); - m->mothurOut("You may enter multiple name files by separating their names with dashes. ie. fasta=abrecovery.svg.names-amzon.svg.names \n"); - m->mothurOut("The chimera.check command should be in the following format: \n"); - m->mothurOut("chimera.check(fasta=yourFastaFile, template=yourTemplateFile, processors=yourProcessors, ksize=yourKmerSize) \n"); - m->mothurOut("Example: chimera.check(fasta=AD.fasta, template=core_set_aligned,imputed.fasta, processors=4, ksize=8) \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ChimeraCheckCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -ChimeraCheckCommand::~ChimeraCheckCommand(){ /* do nothing */ } - //*************************************************************************************************************** int ChimeraCheckCommand::execute(){ diff --git a/chimeracheckcommand.h b/chimeracheckcommand.h index 6e81812..221d35f 100644 --- a/chimeracheckcommand.h +++ b/chimeracheckcommand.h @@ -22,15 +22,17 @@ class ChimeraCheckCommand : public Command { public: ChimeraCheckCommand(string); ChimeraCheckCommand(); - ~ChimeraCheckCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ChimeraCheckCommand(){} + + vector setParameters(); + string getCommandName() { return "chimera.check"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + - private: struct linePair { @@ -56,8 +58,6 @@ private: vector fastaFileNames; vector nameFileNames; vector outputNames; - map > outputTypes; - }; /***********************************************************/ diff --git a/chimerapintailcommand.cpp b/chimerapintailcommand.cpp index 038460f..2b6ed03 100644 --- a/chimerapintailcommand.cpp +++ b/chimerapintailcommand.cpp @@ -11,50 +11,71 @@ #include "pintail.h" //********************************************************************************************************************** -vector ChimeraPintailCommand::getValidParameters(){ +vector ChimeraPintailCommand::setParameters(){ try { - string AlignArray[] = {"fasta","filter","processors","window" ,"increment","template","conservation","quantile","mask","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pconservation("conservation", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pconservation); + CommandParameter pquantile("quantile", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pquantile); + CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pfilter); + CommandParameter pwindow("window", "Number", "", "0", "", "", "",false,false); parameters.push_back(pwindow); + CommandParameter pincrement("increment", "Number", "", "25", "", "", "",false,false); parameters.push_back(pincrement); + CommandParameter pmask("mask", "String", "", "", "", "", "",false,false); parameters.push_back(pmask); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ChimeraPintailCommand", "getValidParameters"); + m->errorOut(e, "ChimeraPintailCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ChimeraPintailCommand::ChimeraPintailCommand(){ +string ChimeraPintailCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["chimera"] = tempOutNames; - outputTypes["accnos"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ChimeraPintailCommand", "ChimeraPintailCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector ChimeraPintailCommand::getRequiredParameters(){ - try { - string AlignArray[] = {"template","fasta"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The chimera.pintail command reads a fastafile and referencefile and outputs potentially chimeric sequences.\n"; + helpString += "This command was created using the algorythms described in the 'At Least 1 in 20 16S rRNA Sequence Records Currently Held in the Public Repositories is Estimated To Contain Substantial Anomalies' paper by Kevin E. Ashelford 1, Nadia A. Chuzhanova 3, John C. Fry 1, Antonia J. Jones 2 and Andrew J. Weightman 1.\n"; + helpString += "The chimera.pintail command parameters are fasta, reference, filter, mask, processors, window, increment, conservation and quantile.\n"; + helpString += "The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required unless you have a valid current fasta file. \n"; + helpString += "You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"; + helpString += "The reference parameter allows you to enter a reference file containing known non-chimeric sequences, and is required. \n"; + helpString += "The filter parameter allows you to specify if you would like to apply a vertical and 50% soft filter. \n"; + helpString += "The mask parameter allows you to specify a file containing one sequence you wish to use as a mask for the your sequences, by default no mask is applied. You can apply an ecoli mask by typing, mask=default. \n"; + helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"; +#ifdef USE_MPI + helpString += "When using MPI, the processors parameter is set to the number of MPI processes running. \n"; +#endif + helpString += "The window parameter allows you to specify the window size for searching for chimeras, default=300. \n"; + helpString += "The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default=25.\n"; + helpString += "The conservation parameter allows you to enter a frequency file containing the highest bases frequency at each place in the alignment.\n"; + helpString += "The quantile parameter allows you to enter a file containing quantiles for a template files sequences, if you use the filter the quantile file generated becomes unique to the fasta file you used.\n"; + helpString += "The chimera.pintail command should be in the following format: \n"; + helpString += "chimera.pintail(fasta=yourFastaFile, reference=yourTemplate) \n"; + helpString += "Example: chimera.pintail(fasta=AD.align, reference=silva.bacteria.fasta) \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ChimeraPintailCommand", "getRequiredParameters"); + m->errorOut(e, "ChimeraPintailCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ChimeraPintailCommand::getRequiredFiles(){ +ChimeraPintailCommand::ChimeraPintailCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ChimeraPintailCommand", "getRequiredFiles"); + m->errorOut(e, "ChimeraPintailCommand", "ChimeraPintailCommand"); exit(1); } } @@ -67,9 +88,7 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","filter","processors","window" ,"increment","template","conservation","quantile","mask","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -91,12 +110,12 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { if (inputDir == "not found"){ inputDir = ""; } else { string path; - it = parameters.find("template"); + it = parameters.find("reference"); //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["template"] = inputDir + it->second; } + if (path == "") { parameters["reference"] = inputDir + it->second; } } it = parameters.find("conservation"); @@ -119,8 +138,12 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", false); - if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.pintail command."); m->mothurOutEndLine(); abort = true; } - else { + if (fastafile == "not found") { + //if there is a current fasta file, use it + string filename = m->getFastaFile(); + if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them @@ -177,7 +200,8 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { temp = validParameter.validFile(parameters, "filter", false); if (temp == "not found") { temp = "F"; } filter = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); temp = validParameter.validFile(parameters, "window", false); if (temp == "not found") { temp = "0"; } @@ -231,9 +255,9 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } - templatefile = validParameter.validFile(parameters, "template", true); + templatefile = validParameter.validFile(parameters, "reference", true); if (templatefile == "not open") { abort = true; } - else if (templatefile == "not found") { templatefile = ""; m->mothurOut("template is a required parameter for the chimera.pintail command."); m->mothurOutEndLine(); abort = true; } + else if (templatefile == "not found") { templatefile = ""; m->mothurOut("reference is a required parameter for the chimera.pintail command."); m->mothurOutEndLine(); abort = true; } consfile = validParameter.validFile(parameters, "conservation", true); if (consfile == "not open") { abort = true; } @@ -269,42 +293,6 @@ ChimeraPintailCommand::ChimeraPintailCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ChimeraPintailCommand::help(){ - try { - - m->mothurOut("The chimera.pintail command reads a fastafile and templatefile and outputs potentially chimeric sequences.\n"); - m->mothurOut("This command was created using the algorythms described in the 'At Least 1 in 20 16S rRNA Sequence Records Currently Held in the Public Repositories is Estimated To Contain Substantial Anomalies' paper by Kevin E. Ashelford 1, Nadia A. Chuzhanova 3, John C. Fry 1, Antonia J. Jones 2 and Andrew J. Weightman 1.\n"); - m->mothurOut("The chimera.pintail command parameters are fasta, template, filter, mask, processors, window, increment, conservation and quantile.\n"); - m->mothurOut("The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required. \n"); - m->mothurOut("You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"); - m->mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences, and is required. \n"); - m->mothurOut("The filter parameter allows you to specify if you would like to apply a vertical and 50% soft filter. \n"); - m->mothurOut("The mask parameter allows you to specify a file containing one sequence you wish to use as a mask for the your sequences, by default no mask is applied. You can apply an ecoli mask by typing, mask=default. \n"); - m->mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"); - #ifdef USE_MPI - m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n"); - #endif - m->mothurOut("The window parameter allows you to specify the window size for searching for chimeras, default=300. \n"); - m->mothurOut("The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default=25.\n"); - m->mothurOut("The conservation parameter allows you to enter a frequency file containing the highest bases frequency at each place in the alignment.\n"); - m->mothurOut("The quantile parameter allows you to enter a file containing quantiles for a template files sequences, if you use the filter the quantile file generated becomes unique to the fasta file you used.\n"); - m->mothurOut("The chimera.pintail command should be in the following format: \n"); - m->mothurOut("chimera.pintail(fasta=yourFastaFile, template=yourTemplate) \n"); - m->mothurOut("Example: chimera.pintail(fasta=AD.align, template=silva.bacteria.fasta) \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ChimeraPintailCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -ChimeraPintailCommand::~ChimeraPintailCommand(){ /* do nothing */ } - //*************************************************************************************************************** int ChimeraPintailCommand::execute(){ diff --git a/chimerapintailcommand.h b/chimerapintailcommand.h index d2b2e03..abaef19 100644 --- a/chimerapintailcommand.h +++ b/chimerapintailcommand.h @@ -23,14 +23,15 @@ public: ChimeraPintailCommand(string); ChimeraPintailCommand(); - ~ChimeraPintailCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ChimeraPintailCommand(){} + vector setParameters(); + string getCommandName() { return "chimera.pintail"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: struct linePair { @@ -54,10 +55,7 @@ private: int processors, window, increment, numSeqs, templateSeqsLength; Chimera* chimera; vector outputNames; - map > outputTypes; vector fastaFileNames; - - }; /***********************************************************/ diff --git a/chimeraseqscommand.cpp b/chimeraseqscommand.cpp deleted file mode 100644 index 9013e7d..0000000 --- a/chimeraseqscommand.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * chimeraseqscommand.cpp - * Mothur - * - * Created by Sarah Westcott on 6/29/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "chimeraseqscommand.h" - -//********************************************************************************************************************** -vector ChimeraSeqsCommand::getValidParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ChimeraSeqsCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ChimeraSeqsCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ChimeraSeqsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ChimeraSeqsCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ChimeraSeqsCommand", "getRequiredFiles"); - exit(1); - } -} -//*************************************************************************************************************** - -ChimeraSeqsCommand::ChimeraSeqsCommand(string option) {} -//********************************************************************************************************************** - -void ChimeraSeqsCommand::help(){} - -//*************************************************************************************************************** - -ChimeraSeqsCommand::~ChimeraSeqsCommand(){ /* do nothing */ } - -//*************************************************************************************************************** - -int ChimeraSeqsCommand::execute(){ - - m->mothurOut("The chimera.seqs command has been broken up into 5 separate commands.\n"); - m->mothurOut("The chimera.bellerophon, chimera.ccode, chimera.check, chimera.pintail and chimera.slayer commands.\n"); - - return 0; -} -//********************************************************************************************************************** - - diff --git a/chimeraseqscommand.h b/chimeraseqscommand.h deleted file mode 100644 index 7e51748..0000000 --- a/chimeraseqscommand.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef CHIMERACOMMAND_H -#define CHIMERACOMMAND_H - -/* - * chimeraseqscommand.h - * Mothur - * - * Created by Sarah Westcott on 6/29/09. - * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved. - * - */ - -#include "mothur.h" -#include "command.hpp" - -/***********************************************************/ - -class ChimeraSeqsCommand : public Command { -public: - ChimeraSeqsCommand(string); - ChimeraSeqsCommand() {} - ~ChimeraSeqsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map< string, vector > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - - -private: - vector outputNames; - map< string, vector > outputTypes; - -}; - -/***********************************************************/ - -#endif - diff --git a/chimeraslayercommand.cpp b/chimeraslayercommand.cpp index 9b4a87b..1556cb2 100644 --- a/chimeraslayercommand.cpp +++ b/chimeraslayercommand.cpp @@ -12,52 +12,98 @@ #include "deconvolutecommand.h" //********************************************************************************************************************** -vector ChimeraSlayerCommand::getValidParameters(){ +vector ChimeraSlayerCommand::setParameters(){ try { - string AlignArray[] = {"fasta", "processors","trim","split", "name","window", "include","template","numwanted", "ksize", "match","mismatch", - "divergence", "minsim","mincov","minbs", "minsnp","parents", "iters","outputdir","inputdir", "search","realign" }; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pwindow("window", "Number", "", "50", "", "", "",false,false); parameters.push_back(pwindow); + CommandParameter pksize("ksize", "Number", "", "7", "", "", "",false,false); parameters.push_back(pksize); + CommandParameter pmatch("match", "Number", "", "5.0", "", "", "",false,false); parameters.push_back(pmatch); + CommandParameter pmismatch("mismatch", "Number", "", "-4.0", "", "", "",false,false); parameters.push_back(pmismatch); + CommandParameter pminsim("minsim", "Number", "", "90", "", "", "",false,false); parameters.push_back(pminsim); + CommandParameter pmincov("mincov", "Number", "", "70", "", "", "",false,false); parameters.push_back(pmincov); + CommandParameter pminsnp("minsnp", "Number", "", "100", "", "", "",false,false); parameters.push_back(pminsnp); + CommandParameter pminbs("minbs", "Number", "", "90", "", "", "",false,false); parameters.push_back(pminbs); + CommandParameter psearch("search", "Multiple", "kmer-blast-distance", "distance", "", "", "",false,false); parameters.push_back(psearch); + CommandParameter pinclude("include", "Multiple", "greater-greaterequal-all", "greater", "", "", "",false,false); parameters.push_back(pinclude); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter prealign("realign", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(prealign); + CommandParameter ptrim("trim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptrim); + CommandParameter psplit("split", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psplit); + CommandParameter pnumwanted("numwanted", "Number", "", "15", "", "", "",false,false); parameters.push_back(pnumwanted); + CommandParameter piters("iters", "Number", "", "100", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pdivergence("divergence", "Number", "", "1.007", "", "", "",false,false); parameters.push_back(pdivergence); + CommandParameter pparents("parents", "Number", "", "3", "", "", "",false,false); parameters.push_back(pparents); + CommandParameter pincrement("increment", "Number", "", "5", "", "", "",false,false); parameters.push_back(pincrement); + CommandParameter 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, "ChimeraSlayerCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -ChimeraSlayerCommand::ChimeraSlayerCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["chimera"] = tempOutNames; - outputTypes["accnos"] = tempOutNames; - outputTypes["fasta"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ChimeraSlayerCommand", "ChimeraSlayerCommand"); + m->errorOut(e, "ChimeraSlayerCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ChimeraSlayerCommand::getRequiredParameters(){ +string ChimeraSlayerCommand::getHelpString(){ try { - string AlignArray[] = {"template","fasta"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The chimera.slayer command reads a fastafile and referencefile and outputs potentially chimeric sequences.\n"; + helpString += "This command was modeled after the chimeraSlayer written by the Broad Institute.\n"; + helpString += "The chimera.slayer command parameters are fasta, name, template, processors, trim, ksize, window, match, mismatch, divergence. minsim, mincov, minbs, minsnp, parents, search, iters, increment and numwanted.\n"; //realign, + helpString += "The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required, unless you have a valid current fasta file. \n"; + helpString += "The name parameter allows you to provide a name file, if you are using template=self. \n"; + helpString += "You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amazon.fasta \n"; + helpString += "The reference parameter allows you to enter a reference file containing known non-chimeric sequences, and is required. You may also set template=self, in this case the abundant sequences will be used as potential parents. \n"; + helpString += "The include parameter is used when template=self and allows you to choose which sequences will make up the \"template\". Options are greater, greaterequal and all, default=greater, meaning sequences with greater abundance than the query sequence. \n"; + helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"; +#ifdef USE_MPI + helpString += "When using MPI, the processors parameter is set to the number of MPI processes running. \n"; +#endif + helpString += "The trim parameter allows you to output a new fasta file containing your sequences with the chimeric ones trimmed to include only their longest piece, default=F. \n"; + helpString += "The split parameter allows you to check both pieces of non-chimeric sequence for chimeras, thus looking for trimeras and quadmeras. default=F. \n"; + helpString += "The window parameter allows you to specify the window size for searching for chimeras, default=50. \n"; + helpString += "The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default=5.\n"; + helpString += "The numwanted parameter allows you to specify how many sequences you would each query sequence compared with, default=15.\n"; + helpString += "The ksize parameter allows you to input kmersize, default is 7, used if search is kmer. \n"; + helpString += "The match parameter allows you to reward matched bases in blast search, default is 5. \n"; + helpString += "The parents parameter allows you to select the number of potential parents to investigate from the numwanted best matches after rating them, default is 3. \n"; + helpString += "The mismatch parameter allows you to penalize mismatched bases in blast search, default is -4. \n"; + helpString += "The divergence parameter allows you to set a cutoff for chimera determination, default is 1.007. \n"; + helpString += "The iters parameter allows you to specify the number of bootstrap iters to do with the chimeraslayer method, default=100.\n"; + helpString += "The minsim parameter allows you to specify a minimum similarity with the parent fragments, default=90. \n"; + helpString += "The mincov parameter allows you to specify minimum coverage by closest matches found in template. Default is 70, meaning 70%. \n"; + helpString += "The minbs parameter allows you to specify minimum bootstrap support for calling a sequence chimeric. Default is 90, meaning 90%. \n"; + helpString += "The minsnp parameter allows you to specify percent of SNPs to sample on each side of breakpoint for computing bootstrap support (default: 100) \n"; + helpString += "The search parameter allows you to specify search method for finding the closest parent. Choices are distance, blast, and kmer, default distance. \n"; + helpString += "The realign parameter allows you to realign the query to the potential parents. Choices are true or false, default false. \n"; + helpString += "The chimera.slayer command should be in the following format: \n"; + helpString += "chimera.slayer(fasta=yourFastaFile, reference=yourTemplate, search=yourSearch) \n"; + helpString += "Example: chimera.slayer(fasta=AD.align, reference=core_set_aligned.imputed.fasta, search=kmer) \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ChimeraSlayerCommand", "getRequiredParameters"); + m->errorOut(e, "ChimeraSlayerCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ChimeraSlayerCommand::getRequiredFiles(){ +ChimeraSlayerCommand::ChimeraSlayerCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["chimera"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + outputTypes["fasta"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ChimeraSlayerCommand", "getRequiredFiles"); + m->errorOut(e, "ChimeraSlayerCommand", "ChimeraSlayerCommand"); exit(1); } } @@ -70,10 +116,7 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta", "processors","name", "include","trim", "split","window", "template","numwanted", "ksize", "match","mismatch", - "divergence", "minsim","mincov","minbs", "minsnp","parents", "iters","outputdir","inputdir", "search","realign" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -97,8 +140,12 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", false); - if (fastafile == "not found") { fastafile = ""; m->mothurOut("[ERROR]: fasta is a required parameter for the chimera.slayer command."); m->mothurOutEndLine(); abort = true; } - else { + if (fastafile == "not found") { + //if there is a current fasta file, use it + string filename = m->getFastaFile(); + if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { m->splitAtDash(fastafile, fastaFileNames); //go through files and make sure they are good, if not, then disregard them @@ -216,22 +263,23 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { string path; - it = parameters.find("template"); + it = parameters.find("reference"); //user has given a template file if(it != parameters.end()){ if (it->second == "self") { templatefile = "self"; } else { path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. - if (path == "") { parameters["template"] = inputDir + it->second; } + if (path == "") { parameters["reference"] = inputDir + it->second; } - templatefile = validParameter.validFile(parameters, "template", true); + templatefile = validParameter.validFile(parameters, "reference", true); if (templatefile == "not open") { abort = true; } - else if (templatefile == "not found") { templatefile = ""; m->mothurOut("template is a required parameter for the chimera.slayer command."); m->mothurOutEndLine(); abort = true; } + else if (templatefile == "not found") { templatefile = ""; m->mothurOut("reference is a required parameter for the chimera.slayer command."); m->mothurOutEndLine(); abort = true; } } } - string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } + string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); includeAbunds = validParameter.validFile(parameters, "include", false); if (includeAbunds == "not found") { includeAbunds = "greater"; } @@ -295,54 +343,6 @@ ChimeraSlayerCommand::ChimeraSlayerCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ChimeraSlayerCommand::help(){ - try { - - m->mothurOut("The chimera.slayer command reads a fastafile and templatefile and outputs potentially chimeric sequences.\n"); - m->mothurOut("This command was modeled after the chimeraSlayer written by the Broad Institute.\n"); - m->mothurOut("The chimera.slayer command parameters are fasta, name, template, processors, trim, ksize, window, match, mismatch, divergence. minsim, mincov, minbs, minsnp, parents, search, iters, increment and numwanted.\n"); //realign, - m->mothurOut("The fasta parameter allows you to enter the fasta file containing your potentially chimeric sequences, and is required. \n"); - m->mothurOut("The name parameter allows you to provide a name file, if you are using template=self. \n"); - m->mothurOut("You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amazon.fasta \n"); - m->mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences, and is required. You may also set template=self, in this case the abundant sequences will be used as potential parents. \n"); - m->mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"); - #ifdef USE_MPI - m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n"); - #endif - m->mothurOut("The trim parameter allows you to output a new fasta file containing your sequences with the chimeric ones trimmed to include only their longest piece, default=F. \n"); - m->mothurOut("The split parameter allows you to check both pieces of non-chimeric sequence for chimeras, thus looking for trimeras and quadmeras. default=F. \n"); - m->mothurOut("The window parameter allows you to specify the window size for searching for chimeras, default=50. \n"); - m->mothurOut("The increment parameter allows you to specify how far you move each window while finding chimeric sequences, default=5.\n"); - m->mothurOut("The numwanted parameter allows you to specify how many sequences you would each query sequence compared with, default=15.\n"); - m->mothurOut("The ksize parameter allows you to input kmersize, default is 7, used if search is kmer. \n"); - m->mothurOut("The match parameter allows you to reward matched bases in blast search, default is 5. \n"); - m->mothurOut("The parents parameter allows you to select the number of potential parents to investigate from the numwanted best matches after rating them, default is 3. \n"); - m->mothurOut("The mismatch parameter allows you to penalize mismatched bases in blast search, default is -4. \n"); - m->mothurOut("The divergence parameter allows you to set a cutoff for chimera determination, default is 1.007. \n"); - m->mothurOut("The iters parameter allows you to specify the number of bootstrap iters to do with the chimeraslayer method, default=100.\n"); - m->mothurOut("The minsim parameter allows you to specify a minimum similarity with the parent fragments, default=90. \n"); - m->mothurOut("The mincov parameter allows you to specify minimum coverage by closest matches found in template. Default is 70, meaning 70%. \n"); - m->mothurOut("The minbs parameter allows you to specify minimum bootstrap support for calling a sequence chimeric. Default is 90, meaning 90%. \n"); - m->mothurOut("The minsnp parameter allows you to specify percent of SNPs to sample on each side of breakpoint for computing bootstrap support (default: 100) \n"); - m->mothurOut("The search parameter allows you to specify search method for finding the closest parent. Choices are distance, blast, and kmer, default distance. \n"); - m->mothurOut("The realign parameter allows you to realign the query to the potential parents. Choices are true or false, default false. \n"); - m->mothurOut("The chimera.slayer command should be in the following format: \n"); - m->mothurOut("chimera.slayer(fasta=yourFastaFile, template=yourTemplate, search=yourSearch) \n"); - m->mothurOut("Example: chimera.slayer(fasta=AD.align, template=core_set_aligned.imputed.fasta, search=kmer) \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ChimeraSlayerCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -ChimeraSlayerCommand::~ChimeraSlayerCommand(){ /* do nothing */ } - //*************************************************************************************************************** int ChimeraSlayerCommand::execute(){ diff --git a/chimeraslayercommand.h b/chimeraslayercommand.h index d201ccb..02ebe72 100644 --- a/chimeraslayercommand.h +++ b/chimeraslayercommand.h @@ -21,15 +21,16 @@ class ChimeraSlayerCommand : public Command { public: ChimeraSlayerCommand(string); ChimeraSlayerCommand(); - ~ChimeraSlayerCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ChimeraSlayerCommand() {} + + vector setParameters(); + string getCommandName() { return "chimera.slayer"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } - private: struct linePair { @@ -56,7 +57,6 @@ private: Chimera* chimera; vector outputNames; - map > outputTypes; vector fastaFileNames; vector nameFileNames; diff --git a/chopseqscommand.cpp b/chopseqscommand.cpp index a09ff65..8775d95 100644 --- a/chopseqscommand.cpp +++ b/chopseqscommand.cpp @@ -11,50 +11,58 @@ #include "sequence.hpp" //********************************************************************************************************************** -vector ChopSeqsCommand::getValidParameters(){ +vector ChopSeqsCommand::setParameters(){ try { - string AlignArray[] = {"fasta","short","numbases","countgaps","keep","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pnumbases("numbases", "Number", "", "0", "", "", "",false,true); parameters.push_back(pnumbases); + CommandParameter pcountgaps("countgaps", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pcountgaps); + CommandParameter pshort("short", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pshort); + CommandParameter pkeep("keep", "Multiple", "front-back", "front", "", "", "",false,false); parameters.push_back(pkeep); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ChopSeqsCommand", "getValidParameters"); + m->errorOut(e, "ChopSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ChopSeqsCommand::ChopSeqsCommand(){ +string ChopSeqsCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["accnos"] = tempOutNames; + string helpString = ""; + helpString += "The chop.seqs command reads a fasta file and outputs a .chop.fasta containing the trimmed sequences. Note: If a sequence is completely 'chopped', an accnos file will be created with the names of the sequences removed. \n"; + helpString += "The chop.seqs command parameters are fasta, numbases, countgaps and keep. fasta is required unless you have a valid current fasta file. numbases is required.\n"; + helpString += "The chop.seqs command should be in the following format: chop.seqs(fasta=yourFasta, numbases=yourNum, keep=yourKeep).\n"; + helpString += "The numbases parameter allows you to specify the number of bases you want to keep.\n"; + helpString += "The keep parameter allows you to specify whether you want to keep the front or the back of your sequence, default=front.\n"; + helpString += "The countgaps parameter allows you to specify whether you want to count gaps as bases, default=false.\n"; + helpString += "The short parameter allows you to specify you want to keep sequences that are too short to chop, default=false.\n"; + helpString += "For example, if you ran chop.seqs with numbases=200 and short=t, if a sequence had 100 bases mothur would keep the sequence rather than eliminate it.\n"; + helpString += "Example chop.seqs(fasta=amazon.fasta, numbases=200, keep=front).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ChopSeqsCommand", "ChopSeqsCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector ChopSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta","numbases"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ChopSeqsCommand", "getRequiredParameters"); + m->errorOut(e, "ChopSeqsCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector ChopSeqsCommand::getRequiredFiles(){ +ChopSeqsCommand::ChopSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ChopSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "ChopSeqsCommand", "ChopSeqsCommand"); exit(1); } } @@ -67,9 +75,7 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","numbases","countgaps","keep","short","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -104,7 +110,11 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { m->mothurOut("You must provide a fasta file."); m->mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { //if there is a current fasta file, use it + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(fastafile); } @@ -131,27 +141,6 @@ ChopSeqsCommand::ChopSeqsCommand(string option) { } //********************************************************************************************************************** -void ChopSeqsCommand::help(){ - try { - m->mothurOut("The chop.seqs command reads a fasta file and outputs a .chop.fasta containing the trimmed sequences. Note: If a sequence is completely 'chopped', an accnos file will be created with the names of the sequences removed. \n"); - m->mothurOut("The chop.seqs command parameters are fasta, numbases, countgaps and keep. fasta and numbases are required required.\n"); - m->mothurOut("The chop.seqs command should be in the following format: chop.seqs(fasta=yourFasta, numbases=yourNum, keep=yourKeep).\n"); - m->mothurOut("The numbases parameter allows you to specify the number of bases you want to keep.\n"); - m->mothurOut("The keep parameter allows you to specify whether you want to keep the front or the back of your sequence, default=front.\n"); - m->mothurOut("The countgaps parameter allows you to specify whether you want to count gaps as bases, default=false.\n"); - m->mothurOut("The short parameter allows you to specify you want to keep sequences that are too short to chop, default=false.\n"); - m->mothurOut("For example, if you ran chop.seqs with numbases=200 and short=t, if a sequence had 100 bases mothur would keep the sequence rather than eliminate it.\n"); - m->mothurOut("Example chop.seqs(fasta=amazon.fasta, numbases=200, keep=front).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ChopSeqsCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int ChopSeqsCommand::execute(){ try { diff --git a/chopseqscommand.h b/chopseqscommand.h index dbf4d23..92544ee 100644 --- a/chopseqscommand.h +++ b/chopseqscommand.h @@ -21,23 +21,22 @@ class ChopSeqsCommand : public Command { ChopSeqsCommand(string); ChopSeqsCommand(); ~ChopSeqsCommand(){}; - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + + vector setParameters(); + string getCommandName() { return "chop.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: string fastafile, outputDir, keep; bool abort, countGaps, Short; int numbases; vector outputNames; - map > outputTypes; string getChopped(Sequence); - - }; #endif diff --git a/classifyotucommand.cpp b/classifyotucommand.cpp index 8d9f177..a70be07 100644 --- a/classifyotucommand.cpp +++ b/classifyotucommand.cpp @@ -12,53 +12,71 @@ #include "phylosummary.h" //********************************************************************************************************************** -vector ClassifyOtuCommand::getValidParameters(){ +vector ClassifyOtuCommand::setParameters(){ try { - string AlignArray[] = {"list","label","name","taxonomy","basis","cutoff","probs","group","reftaxonomy","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptaxonomy); + CommandParameter preftaxonomy("reftaxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(preftaxonomy); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pbasis("basis", "Multiple", "otu-sequence", "otu", "", "", "",false,false); parameters.push_back(pbasis); + CommandParameter pcutoff("cutoff", "Number", "", "51", "", "", "",false,true); parameters.push_back(pcutoff); + CommandParameter pprobs("probs", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pprobs); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ClassifyOtuCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -ClassifyOtuCommand::ClassifyOtuCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["constaxonomy"] = tempOutNames; - outputTypes["taxsummary"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ClassifyOtuCommand", "ClassifyOtuCommand"); + m->errorOut(e, "ClassifyOtuCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ClassifyOtuCommand::getRequiredParameters(){ +string ClassifyOtuCommand::getHelpString(){ try { - string Array[] = {"list","taxonomy"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The classify.otu command parameters are list, taxonomy, reftaxonomy, name, group, cutoff, label, basis and probs. The taxonomy and list parameters are required unless you have a valid current file.\n"; + helpString += "The reftaxonomy parameter allows you give the name of the reference taxonomy file used when you classified your sequences. Providing it will keep the rankIDs in the summary file static.\n"; + helpString += "The name parameter allows you add a names file with your taxonomy file.\n"; + helpString += "The group parameter allows you provide a group file to use in creating the summary file breakdown.\n"; + helpString += "The basis parameter allows you indicate what you want the summary file to represent, options are otu and sequence. Default is otu.\n"; + helpString += "For example consider the following basis=sequence could give Clostridiales 3 105 16 43 46, where 105 is the total number of sequences whose otu classified to Clostridiales.\n"; + helpString += "16 is the number of sequences in the otus from groupA, 43 is the number of sequences in the otus from groupB, and 46 is the number of sequences in the otus from groupC.\n"; + helpString += "Now for basis=otu could give Clostridiales 3 7 6 1 2, where 7 is the number of otus that classified to Clostridiales.\n"; + helpString += "6 is the number of otus containing sequences from groupA, 1 is the number of otus containing sequences from groupB, and 2 is the number of otus containing sequences from groupC.\n"; + helpString += "The label parameter allows you to select what distance levels you would like a output files created for, and is separated by dashes.\n"; + helpString += "The default value for label is all labels in your inputfile.\n"; + helpString += "The cutoff parameter allows you to specify a consensus confidence threshold for your taxonomy. The default is 51, meaning 51%. Cutoff cannot be below 51.\n"; + helpString += "The probs parameter shuts off the outputting of the consensus confidence results. The default is true, meaning you want the confidence to be shown.\n"; + helpString += "The classify.otu command should be in the following format: classify.otu(taxonomy=yourTaxonomyFile, list=yourListFile, name=yourNamesFile, label=yourLabels).\n"; + helpString += "Example classify.otu(taxonomy=abrecovery.silva.full.taxonomy, list=abrecovery.fn.list, label=0.10).\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ClassifyOtuCommand", "getRequiredParameters"); + m->errorOut(e, "ClassifyOtuCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ClassifyOtuCommand::getRequiredFiles(){ +ClassifyOtuCommand::ClassifyOtuCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["constaxonomy"] = tempOutNames; + outputTypes["taxsummary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ClassifyOtuCommand", "getRequiredFiles"); + m->errorOut(e, "ClassifyOtuCommand", "ClassifyOtuCommand"); exit(1); } } + //********************************************************************************************************************** ClassifyOtuCommand::ClassifyOtuCommand(string option) { try{ @@ -70,9 +88,7 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { if (option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"list","label","name","taxonomy","cutoff","probs","basis","reftaxonomy","group","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -142,11 +158,20 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { //check for required parameters listfile = validParameter.validFile(parameters, "list", true); - if (listfile == "not found") { m->mothurOut("list is a required parameter for the classify.otu command."); m->mothurOutEndLine(); abort = true; } + if (listfile == "not found") { + //if there is a current list file, use it + listfile = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current listfile and the list parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (listfile == "not open") { abort = true; } taxfile = validParameter.validFile(parameters, "taxonomy", true); - if (taxfile == "not found") { m->mothurOut("taxonomy is a required parameter for the classify.otu command."); m->mothurOutEndLine(); abort = true; } + if (taxfile == "not found") { //if there is a current list file, use it + taxfile = m->getTaxonomyFile(); + if (taxfile != "") { m->mothurOut("Using " + taxfile + " as input file for the taxonomy parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current taxonomy file and the taxonomy parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (taxfile == "not open") { abort = true; } refTaxonomy = validParameter.validFile(parameters, "reftaxonomy", true); @@ -191,38 +216,6 @@ ClassifyOtuCommand::ClassifyOtuCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void ClassifyOtuCommand::help(){ - try { - m->mothurOut("The classify.otu command parameters are list, taxonomy, reftaxonomy, name, group, cutoff, label, basis and probs. The taxonomy and list parameters are required.\n"); - m->mothurOut("The reftaxonomy parameter allows you give the name of the reference taxonomy file used when you classified your sequences. Providing it will keep the rankIDs in the summary file static.\n"); - m->mothurOut("The name parameter allows you add a names file with your taxonomy file.\n"); - m->mothurOut("The group parameter allows you provide a group file to use in creating the summary file breakdown.\n"); - m->mothurOut("The basis parameter allows you indicate what you want the summary file to represent, options are otu and sequence. Default is otu.\n"); - m->mothurOut("For example consider the following basis=sequence could give Clostridiales 3 105 16 43 46, where 105 is the total number of sequences whose otu classified to Clostridiales.\n"); - m->mothurOut("16 is the number of sequences in the otus from groupA, 43 is the number of sequences in the otus from groupB, and 46 is the number of sequences in the otus from groupC.\n"); - m->mothurOut("Now for basis=otu could give Clostridiales 3 7 6 1 2, where 7 is the number of otus that classified to Clostridiales.\n"); - m->mothurOut("6 is the number of otus containing sequences from groupA, 1 is the number of otus containing sequences from groupB, and 2 is the number of otus containing sequences from groupC.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like a output files created for, and is separated by dashes.\n"); - m->mothurOut("The default value for label is all labels in your inputfile.\n"); - m->mothurOut("The cutoff parameter allows you to specify a consensus confidence threshold for your taxonomy. The default is 51, meaning 51%. Cutoff cannot be below 51.\n"); - m->mothurOut("The probs parameter shuts off the outputting of the consensus confidence results. The default is true, meaning you want the confidence to be shown.\n"); - m->mothurOut("The classify.otu command should be in the following format: classify.otu(taxonomy=yourTaxonomyFile, list=yourListFile, name=yourNamesFile, label=yourLabels).\n"); - m->mothurOut("Example classify.otu(taxonomy=abrecovery.silva.full.taxonomy, list=abrecovery.fn.list, label=0.10).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ClassifyOtuCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -ClassifyOtuCommand::~ClassifyOtuCommand(){} - //********************************************************************************************************************** int ClassifyOtuCommand::execute(){ diff --git a/classifyotucommand.h b/classifyotucommand.h index e81c246..7f15c71 100644 --- a/classifyotucommand.h +++ b/classifyotucommand.h @@ -20,13 +20,15 @@ class ClassifyOtuCommand : public Command { public: ClassifyOtuCommand(string); ClassifyOtuCommand(); - ~ClassifyOtuCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ClassifyOtuCommand() {} + + vector setParameters(); + string getCommandName() { return "classify.otu"; } + string getCommandCategory() { return "Phylotype Analysis"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: @@ -39,7 +41,6 @@ private: vector outputNames; map nameMap; map taxMap; - map > outputTypes; int readNamesFile(); int readTaxonomyFile(); diff --git a/classifyseqscommand.cpp b/classifyseqscommand.cpp index 6cfa332..6f8bc7e 100644 --- a/classifyseqscommand.cpp +++ b/classifyseqscommand.cpp @@ -16,51 +16,86 @@ //********************************************************************************************************************** -vector ClassifySeqsCommand::getValidParameters(){ +vector ClassifySeqsCommand::setParameters(){ try { - string AlignArray[] = {"template","fasta","name","group","search","ksize","method","processors","taxonomy","match","mismatch","gapopen","gapextend","numwanted","cutoff","probs","iters", "outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptaxonomy); + CommandParameter ptemplate("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptemplate); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter psearch("search", "Multiple", "kmer-blast-suffix-distance", "kmer", "", "", "",false,false); parameters.push_back(psearch); + CommandParameter pksize("ksize", "Number", "", "8", "", "", "",false,false); parameters.push_back(pksize); + CommandParameter pmethod("method", "Multiple", "bayesian-knn", "bayesian", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pmatch("match", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pmatch); + CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pmismatch); + CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "",false,false); parameters.push_back(pgapopen); + CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pgapextend); + CommandParameter pcutoff("cutoff", "Number", "", "0", "", "", "",false,true); parameters.push_back(pcutoff); + CommandParameter pprobs("probs", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pprobs); + CommandParameter piters("iters", "Number", "", "100", "", "", "",false,true); parameters.push_back(piters); + CommandParameter pnumwanted("numwanted", "Number", "", "10", "", "", "",false,true); parameters.push_back(pnumwanted); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ClassifySeqsCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -ClassifySeqsCommand::ClassifySeqsCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["taxonomy"] = tempOutNames; - outputTypes["taxsummary"] = tempOutNames; - outputTypes["matchdist"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand"); + m->errorOut(e, "ClassifySeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ClassifySeqsCommand::getRequiredParameters(){ +string ClassifySeqsCommand::getHelpString(){ try { - string Array[] = {"fasta","template","taxonomy"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The classify.seqs command reads a fasta file containing sequences and creates a .taxonomy file and a .tax.summary file.\n"; + helpString += "The classify.seqs command parameters are reference, fasta, name, search, ksize, method, taxonomy, processors, match, mismatch, gapopen, gapextend, numwanted and probs.\n"; + helpString += "The reference, fasta and taxonomy parameters are required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"; + helpString += "The search parameter allows you to specify the method to find most similar template. Your options are: suffix, kmer, blast and distance. The default is kmer.\n"; + helpString += "The name parameter allows you add a names file with your fasta file, if you enter multiple fasta files, you must enter matching names files for them.\n"; + helpString += "The group parameter allows you add a group file so you can have the summary totals broken up by group.\n"; + helpString += "The method parameter allows you to specify classification method to use. Your options are: bayesian and knn. The default is bayesian.\n"; + helpString += "The ksize parameter allows you to specify the kmer size for finding most similar template to candidate. The default is 8.\n"; + helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n"; +#ifdef USE_MPI + helpString += "When using MPI, the processors parameter is set to the number of MPI processes running. \n"; +#endif + helpString += "The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n"; + helpString += "The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n"; + helpString += "The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n"; + helpString += "The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n"; + helpString += "The numwanted parameter allows you to specify the number of sequence matches you want with the knn method. The default is 10.\n"; + helpString += "The cutoff parameter allows you to specify a bootstrap confidence threshold for your taxonomy. The default is 0.\n"; + helpString += "The probs parameter shuts off the bootstrapping results for the bayesian method. The default is true, meaning you want the bootstrapping to be shown.\n"; + helpString += "The iters parameter allows you to specify how many iterations to do when calculating the bootstrap confidence score for your taxonomy with the bayesian method. The default is 100.\n"; + helpString += "The classify.seqs command should be in the following format: \n"; + helpString += "classify.seqs(reference=yourTemplateFile, fasta=yourFastaFile, method=yourClassificationMethod, search=yourSearchmethod, ksize=yourKmerSize, taxonomy=yourTaxonomyFile, processors=yourProcessors) \n"; + helpString += "Example classify.seqs(fasta=amazon.fasta, reference=core.filtered, method=knn, search=gotoh, ksize=8, processors=2)\n"; + helpString += "The .taxonomy file consists of 2 columns: 1 = your sequence name, 2 = the taxonomy for your sequence. \n"; + helpString += "The .tax.summary is a summary of the different taxonomies represented in your fasta file. \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ClassifySeqsCommand", "getRequiredParameters"); + m->errorOut(e, "ClassifySeqsCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ClassifySeqsCommand::getRequiredFiles(){ +ClassifySeqsCommand::ClassifySeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["taxonomy"] = tempOutNames; + outputTypes["taxsummary"] = tempOutNames; + outputTypes["matchdist"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ClassifySeqsCommand", "getRequiredFiles"); + m->errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand"); exit(1); } } @@ -73,10 +108,7 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - - //valid paramters for this command - string AlignArray[] = {"template","fasta","name","group","search","ksize","method","processors","taxonomy","match","mismatch","gapopen","gapextend","numwanted","cutoff","probs","iters", "outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -103,12 +135,12 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { if (inputDir == "not found"){ inputDir = ""; } else { string path; - it = parameters.find("template"); + it = parameters.find("reference"); //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["template"] = inputDir + it->second; } + if (path == "") { parameters["reference"] = inputDir + it->second; } } it = parameters.find("taxonomy"); @@ -129,9 +161,9 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { } //check for required parameters - templateFileName = validParameter.validFile(parameters, "template", true); + templateFileName = validParameter.validFile(parameters, "reference", true); if (templateFileName == "not found") { - m->mothurOut("template is a required parameter for the classify.seqs command."); + m->mothurOut("reference is a required parameter for the classify.seqs command."); m->mothurOutEndLine(); abort = true; } @@ -139,7 +171,12 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { fastaFileName = validParameter.validFile(parameters, "fasta", false); - if (fastaFileName == "not found") { m->mothurOut("fasta is a required parameter for the classify.seqs command."); m->mothurOutEndLine(); abort = true; } + if (fastaFileName == "not found") { + //if there is a current fasta file, use it + string filename = m->getFastaFile(); + if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } else { m->splitAtDash(fastaFileName, fastaFileNames); @@ -323,7 +360,8 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { temp = validParameter.validFile(parameters, "ksize", false); if (temp == "not found"){ temp = "8"; } convert(temp, kmerSize); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); search = validParameter.validFile(parameters, "search", false); if (search == "not found"){ search = "kmer"; } @@ -370,52 +408,11 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option) { } //********************************************************************************************************************** - ClassifySeqsCommand::~ClassifySeqsCommand(){ - if (abort == false) { for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); } } - -//********************************************************************************************************************** - -void ClassifySeqsCommand::help(){ - try { - m->mothurOut("The classify.seqs command reads a fasta file containing sequences and creates a .taxonomy file and a .tax.summary file.\n"); - m->mothurOut("The classify.seqs command parameters are template, fasta, name, search, ksize, method, taxonomy, processors, match, mismatch, gapopen, gapextend, numwanted and probs.\n"); - m->mothurOut("The template, fasta and taxonomy parameters are required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"); - m->mothurOut("The search parameter allows you to specify the method to find most similar template. Your options are: suffix, kmer, blast and distance. The default is kmer.\n"); - m->mothurOut("The name parameter allows you add a names file with your fasta file, if you enter multiple fasta files, you must enter matching names files for them.\n"); - m->mothurOut("The group parameter allows you add a group file so you can have the summary totals broken up by group.\n"); - m->mothurOut("The method parameter allows you to specify classification method to use. Your options are: bayesian and knn. The default is bayesian.\n"); - m->mothurOut("The ksize parameter allows you to specify the kmer size for finding most similar template to candidate. The default is 8.\n"); - m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); - #ifdef USE_MPI - m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n"); - #endif - m->mothurOut("The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n"); - m->mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n"); - m->mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n"); - m->mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n"); - m->mothurOut("The numwanted parameter allows you to specify the number of sequence matches you want with the knn method. The default is 10.\n"); - m->mothurOut("The cutoff parameter allows you to specify a bootstrap confidence threshold for your taxonomy. The default is 0.\n"); - m->mothurOut("The probs parameter shuts off the bootstrapping results for the bayesian method. The default is true, meaning you want the bootstrapping to be shown.\n"); - m->mothurOut("The iters parameter allows you to specify how many iterations to do when calculating the bootstrap confidence score for your taxonomy with the bayesian method. The default is 100.\n"); - m->mothurOut("The classify.seqs command should be in the following format: \n"); - m->mothurOut("classify.seqs(template=yourTemplateFile, fasta=yourFastaFile, method=yourClassificationMethod, search=yourSearchmethod, ksize=yourKmerSize, taxonomy=yourTaxonomyFile, processors=yourProcessors) \n"); - m->mothurOut("Example classify.seqs(fasta=amazon.fasta, template=core.filtered, method=knn, search=gotoh, ksize=8, processors=2)\n"); - m->mothurOut("The .taxonomy file consists of 2 columns: 1 = your sequence name, 2 = the taxonomy for your sequence. \n"); - m->mothurOut("The .tax.summary is a summary of the different taxonomies represented in your fasta file. \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ClassifySeqsCommand", "help"); - exit(1); - } -} - - //********************************************************************************************************************** int ClassifySeqsCommand::execute(){ diff --git a/classifyseqscommand.h b/classifyseqscommand.h index 1654913..115360f 100644 --- a/classifyseqscommand.h +++ b/classifyseqscommand.h @@ -12,7 +12,6 @@ #include "mothur.h" #include "command.hpp" -//#include "alignment.hpp" #include "classify.h" //KNN and Bayesian methods modeled from algorithms in @@ -31,12 +30,16 @@ public: ClassifySeqsCommand(string); ClassifySeqsCommand(); ~ClassifySeqsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + + vector setParameters(); + string getCommandName() { return "classify.seqs"; } + string getCommandCategory() { return "Phylotype Analysis"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } + + private: struct linePair { @@ -53,7 +56,6 @@ private: vector outputNames; map > nameMap; map >::iterator itNames; - map > outputTypes; Classify* classify; diff --git a/clearcutcommand.cpp b/clearcutcommand.cpp index 7fd8c13..afb2159 100644 --- a/clearcutcommand.cpp +++ b/clearcutcommand.cpp @@ -15,51 +15,89 @@ extern "C" { #ifdef __cplusplus } #endif + //********************************************************************************************************************** -vector ClearcutCommand::getValidParameters(){ +vector ClearcutCommand::setParameters(){ try { - string AlignArray[] = {"fasta","phylip","version","verbose","quiet","seed","norandom","shuffle","neighbor","expblen", - "expdist","ntrees","matrixout","stdout","kimura","jukes","protein","DNA","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter pphylip("phylip", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none",false,false); parameters.push_back(pphylip); + CommandParameter pfasta("fasta", "InputTypes", "", "", "FastaPhylip", "FastaPhylip", "none",false,false); parameters.push_back(pfasta); + CommandParameter pverbose("verbose", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pverbose); + CommandParameter pquiet("quiet", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pquiet); + CommandParameter pversion("version", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pversion); + CommandParameter pseed("seed", "String", "", "", "*", "", "",false,false); parameters.push_back(pseed); + CommandParameter pnorandom("norandom", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pnorandom); + CommandParameter pshuffle("shuffle", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pshuffle); + CommandParameter pneighbor("neighbor", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pneighbor); + CommandParameter pexpblen("expblen", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pexpblen); + CommandParameter pexpdist("expdist", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pexpdist); + CommandParameter pDNA("DNA", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pDNA); + CommandParameter pprotein("protein", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pprotein); + CommandParameter pjukes("jukes", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pjukes); + CommandParameter pkimura("kimura", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pkimura); + CommandParameter pstdout("stdout", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pstdout); + CommandParameter pntrees("ntrees", "Number", "", "1", "", "", "",false,false); parameters.push_back(pntrees); + CommandParameter pmatrixout("matrixout", "String", "", "", "", "", "",false,false); parameters.push_back(pmatrixout); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ClearcutCommand", "getValidParameters"); + m->errorOut(e, "ClearcutCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ClearcutCommand::ClearcutCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["tree"] = tempOutNames; - outputTypes["matrixout"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ClearcutCommand", "ClearcutCommand"); - exit(1); - } -}//********************************************************************************************************************** -vector ClearcutCommand::getRequiredParameters(){ +string ClearcutCommand::getHelpString(){ try { - string Array[] = {"fasta","phylip","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The clearcut command interfaces mothur with the clearcut program written by Initiative for Bioinformatics and Evolutionary Studies (IBEST) at the University of Idaho.\n"; + helpString += "For more information about clearcut refer to http://bioinformatics.hungry.com/clearcut/ \n"; + helpString += "The clearcut command parameters are phylip, fasta, version, verbose, quiet, seed, norandom, shuffle, neighbor, expblen, expdist, ntrees, matrixout, stdout, kimura, jukes, protein, DNA. \n"; + helpString += "The phylip parameter allows you to enter your phylip formatted distance matrix. \n"; + helpString += "The fasta parameter allows you to enter your aligned fasta file, if you enter a fastafile you specify if the sequences are DNA or protein using the DNA or protein parameters. \n"; + + helpString += "The version parameter prints out the version of clearcut you are using, default=F. \n"; + helpString += "The verbose parameter prints out more output from clearcut, default=F. \n"; + helpString += "The quiet parameter turns on silent operation mode, default=F. \n"; + helpString += "The seed parameter allows you to explicitly set the PRNG seed to a specific value. \n"; + helpString += "The norandom parameter allows you to attempt joins deterministically, default=F. \n"; + helpString += "The shuffle parameter allows you to randomly shuffle the distance matrix, default=F. \n"; + helpString += "The neighbor parameter allows you to use traditional Neighbor-Joining algorithm, default=T. \n"; + + helpString += "The DNA parameter allows you to indicate your fasta file contains DNA sequences, default=F. \n"; + helpString += "The protein parameter allows you to indicate your fasta file contains protein sequences, default=F. \n"; + + helpString += "The stdout parameter outputs your tree to STDOUT, default=F. \n"; + helpString += "The matrixout parameter allows you to specify a filename to output a distance matrix to. \n"; + helpString += "The ntrees parameter allows you to specify the number of output trees, default=1. \n"; + helpString += "The expblen parameter allows you to use exponential notation for branch lengths, default=F. \n"; + helpString += "The expdist parameter allows you to use exponential notation for distance outputs, default=F. \n"; + + helpString += "The clearcut command should be in the following format: \n"; + helpString += "clearcut(phylip=yourDistanceFile) \n"; + helpString += "Example: clearcut(phylip=abrecovery.phylip.dist) \n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ClearcutCommand", "getRequiredParameters"); + m->errorOut(e, "ClearcutCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector ClearcutCommand::getRequiredFiles(){ +ClearcutCommand::ClearcutCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + outputTypes["matrixout"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ClearcutCommand", "getRequiredFiles"); + m->errorOut(e, "ClearcutCommand", "ClearcutCommand"); exit(1); } } @@ -72,10 +110,7 @@ ClearcutCommand::ClearcutCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","phylip","version","verbose","quiet","seed","norandom","shuffle","neighbor","expblen", - "expdist","ntrees","matrixout","stdout","kimura","jukes","protein","DNA","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -126,7 +161,20 @@ ClearcutCommand::ClearcutCommand(string option) { else if (phylipfile == "not found") { phylipfile = ""; } else { inputFile = phylipfile; } - if ((phylipfile == "") && (fastafile == "")) { m->mothurOut("You must provide either a phylip formatted distance matrix or an aligned fasta file."); m->mothurOutEndLine(); abort=true; } + if ((phylipfile == "") && (fastafile == "")) { + //is there are current file available for either of these? + //give priority to phylip, then fasta + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a phylip or fasta file before you can use the clearcut command."); m->mothurOutEndLine(); + abort = true; + } + } + } if ((phylipfile != "") && (fastafile != "")) { m->mothurOut("You must provide either a phylip formatted distance matrix or an aligned fasta file, not BOTH."); m->mothurOutEndLine(); abort=true; } @@ -188,44 +236,6 @@ ClearcutCommand::ClearcutCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ClearcutCommand::help(){ - try { - m->mothurOut("The clearcut command interfaces mothur with the clearcut program written by Initiative for Bioinformatics and Evolutionary Studies (IBEST) at the University of Idaho.\n"); - m->mothurOut("For more information about clearcut refer to http://bioinformatics.hungry.com/clearcut/ \n"); - m->mothurOut("The clearcut command parameters are phylip, fasta, version, verbose, quiet, seed, norandom, shuffle, neighbor, expblen, expdist, ntrees, matrixout, stdout, kimura, jukes, protein, DNA. \n"); - m->mothurOut("The phylip parameter allows you to enter your phylip formatted distance matrix. \n"); - m->mothurOut("The fasta parameter allows you to enter your aligned fasta file, if you enter a fastafile you specify if the sequences are DNA or protein using the DNA or protein parameters. \n"); - - m->mothurOut("The version parameter prints out the version of clearcut you are using, default=F. \n"); - m->mothurOut("The verbose parameter prints out more output from clearcut, default=F. \n"); - m->mothurOut("The quiet parameter turns on silent operation mode, default=F. \n"); - m->mothurOut("The seed parameter allows you to explicitly set the PRNG seed to a specific value. \n"); - m->mothurOut("The norandom parameter allows you to attempt joins deterministically, default=F. \n"); - m->mothurOut("The shuffle parameter allows you to randomly shuffle the distance matrix, default=F. \n"); - m->mothurOut("The neighbor parameter allows you to use traditional Neighbor-Joining algorithm, default=T. \n"); - - m->mothurOut("The DNA parameter allows you to indicate your fasta file contains DNA sequences, default=F. \n"); - m->mothurOut("The protein parameter allows you to indicate your fasta file contains protein sequences, default=F. \n"); - - m->mothurOut("The stdout parameter outputs your tree to STDOUT, default=F. \n"); - m->mothurOut("The matrixout parameter allows you to specify a filename to output a distance matrix to. \n"); - m->mothurOut("The ntrees parameter allows you to specify the number of output trees, default=1. \n"); - m->mothurOut("The expblen parameter allows you to use exponential notation for branch lengths, default=F. \n"); - m->mothurOut("The expdist parameter allows you to use exponential notation for distance outputs, default=F. \n"); - - m->mothurOut("The clearcut command should be in the following format: \n"); - m->mothurOut("clearcut(phylip=yourDistanceFile) \n"); - m->mothurOut("Example: clearcut(phylip=abrecovery.phylip.dist) \n"); - - } - catch(exception& e) { - m->errorOut(e, "ClearcutCommand", "help"); - exit(1); - } -} - /**************************************************************************************/ int ClearcutCommand::execute() { try { diff --git a/clearcutcommand.h b/clearcutcommand.h index ea6e279..af45656 100644 --- a/clearcutcommand.h +++ b/clearcutcommand.h @@ -26,20 +26,22 @@ class ClearcutCommand : public Command { public: ClearcutCommand(string); ClearcutCommand(); - ~ClearcutCommand() {}; - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ClearcutCommand() {} + + vector setParameters(); + string getCommandName() { return "clearcut"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: string outputDir, phylipfile, fastafile, matrixout, inputFile, seed, ntrees; bool version, verbose, quiet, norandom, shuffle, neighbor, expblen, expdist, stdoutWanted, kimura, jukes, protein, DNA; bool abort; vector outputNames; - map > outputTypes; + }; /****************************************************************************/ diff --git a/clusterclassic.cpp b/clusterclassic.cpp index 7f6e97e..0048dc6 100644 --- a/clusterclassic.cpp +++ b/clusterclassic.cpp @@ -11,7 +11,7 @@ #include "progress.hpp" /***********************************************************************/ -ClusterClassic::ClusterClassic(float c, string f) : method(f), smallDist(1e6), nseqs(0) { +ClusterClassic::ClusterClassic(float c, string f, bool s) : method(f), smallDist(1e6), nseqs(0), sim(s) { try { mapWanted = false; //set to true by mgcluster to speed up overlap merge @@ -19,7 +19,6 @@ ClusterClassic::ClusterClassic(float c, string f) : method(f), smallDist(1e6), n cutoff = c; aboveCutoff = cutoff + 10000.0; m = MothurOut::getInstance(); - globaldata = GlobalData::getInstance(); } catch(exception& e) { m->errorOut(e, "ClusterClassic", "ClusterClassic"); @@ -102,7 +101,7 @@ int ClusterClassic::readPhylipFile(string filename, NameAssignment* nameMap) { fileHandle >> distance; if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. //if(distance < cutoff){ dMatrix[i][j] = distance; @@ -124,7 +123,7 @@ int ClusterClassic::readPhylipFile(string filename, NameAssignment* nameMap) { if (m->control_pressed) { delete reading; fileHandle.close(); return 0; } if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. //if(distance < cutoff){ if (distance < smallDist) { smallDist = distance; } @@ -162,7 +161,7 @@ int ClusterClassic::readPhylipFile(string filename, NameAssignment* nameMap) { if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(j < i){ if (distance < smallDist) { smallDist = distance; } @@ -185,7 +184,7 @@ int ClusterClassic::readPhylipFile(string filename, NameAssignment* nameMap) { if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(j < i){ if (distance < smallDist) { smallDist = distance; } diff --git a/clusterclassic.h b/clusterclassic.h index 9a896f2..110c040 100644 --- a/clusterclassic.h +++ b/clusterclassic.h @@ -5,8 +5,8 @@ #include "mothur.h" #include "mothurout.h" #include "listvector.hpp" -#include "globaldata.hpp" #include "rabundvector.hpp" +#include "nameassignment.hpp" /* * clusterclassic.h @@ -21,7 +21,7 @@ class ClusterClassic { public: - ClusterClassic(float, string); + ClusterClassic(float, string, bool); int readPhylipFile(string, NameAssignment*); void update(double&); double getSmallDist() { return smallDist; } @@ -54,13 +54,12 @@ private: int smallRow; int smallCol, nseqs; double smallDist; - bool mapWanted; + bool mapWanted, sim; double cutoff, aboveCutoff; map seq2Bin; string method; MothurOut* m; - GlobalData* globaldata; }; #endif diff --git a/clustercommand.cpp b/clustercommand.cpp index 391b20a..9b0fcfd 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -8,53 +8,62 @@ */ #include "clustercommand.h" +#include "readphylip.h" +#include "readcolumn.h" +#include "readmatrix.hpp" //********************************************************************************************************************** -vector ClusterCommand::getValidParameters(){ +vector ClusterCommand::setParameters(){ try { - string AlignArray[] = {"cutoff","precision","method","showabund","timing","hard","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "furthest", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pshowabund); + CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptiming); + CommandParameter psim("sim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psim); + CommandParameter phard("hard", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(phard); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ClusterCommand", "getValidParameters"); + m->errorOut(e, "ClusterCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ClusterCommand::ClusterCommand(){ +string ClusterCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["list"] = tempOutNames; - outputTypes["rabund"] = tempOutNames; - outputTypes["sabund"] = tempOutNames; + string helpString = ""; + helpString += "The cluster command parameter options are phylip, column, name, method, cuttoff, hard, precision, sim, showabund and timing. Phylip or column and name are required, unless you have a valid current file.\n"; + helpString += "The cluster command should be in the following format: \n"; + helpString += "cluster(method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"; + helpString += "The acceptable cluster methods are furthest, nearest, average and weighted. If no method is provided then furthest is assumed.\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ClusterCommand", "ClusterCommand"); + m->errorOut(e, "ClusterCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ClusterCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ClusterCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ClusterCommand::getRequiredFiles(){ +ClusterCommand::ClusterCommand(){ try { - string Array[] = {"phylip","column","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ClusterCommand", "getRequiredFiles"); + m->errorOut(e, "ClusterCommand", "ClusterCommand"); exit(1); } } @@ -62,25 +71,22 @@ vector ClusterCommand::getRequiredFiles(){ //This function checks to make sure the cluster command has no errors and then clusters based on the method chosen. ClusterCommand::ClusterCommand(string option) { try{ - globaldata = GlobalData::getInstance(); - abort = false; calledHelp = false; //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"cutoff","precision","method","showabund","timing","hard","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } @@ -95,12 +101,77 @@ ClusterCommand::ClusterCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } - //error checking to make sure they read a distance file - if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) { - m->mothurOut("Before you use the cluster command, you first need to read in a distance matrix."); m->mothurOutEndLine(); - abort = true; - } - + 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; } + } + } + + //check for required parameters + phylipfile = validParameter.validFile(parameters, "phylip", true); + if (phylipfile == "not open") { phylipfile = ""; abort = true; } + else if (phylipfile == "not found") { phylipfile = ""; } + else { distfile = phylipfile; format = "phylip"; } + + columnfile = validParameter.validFile(parameters, "column", true); + if (columnfile == "not open") { columnfile = ""; abort = true; } + else if (columnfile == "not found") { columnfile = ""; } + else { distfile = columnfile; format = "column"; } + + namefile = validParameter.validFile(parameters, "name", true); + if (namefile == "not open") { abort = true; } + else if (namefile == "not found") { namefile = ""; } + + if ((phylipfile == "") && (columnfile == "")) { + //is there are current file available for either of these? + //give priority to column, then phylip + columnfile = m->getColumnFile(); + if (columnfile != "") { m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); } + else { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a phylip or column file before you can use the cluster command."); m->mothurOutEndLine(); + abort = true; + } + } + } + else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When executing a cluster command you must enter ONLY ONE of the following: phylip or column."); m->mothurOutEndLine(); abort = true; } + + if (columnfile != "") { + if (namefile == "") { + namefile = m->getNameFile(); + if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); + 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 @@ -114,6 +185,9 @@ ClusterCommand::ClusterCommand(string option) { temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "F"; } hard = m->isTrue(temp); + temp = validParameter.validFile(parameters, "sim", false); if (temp == "not found") { temp = "F"; } + sim = m->isTrue(temp); + temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "10"; } convert(temp, cutoff); @@ -131,68 +205,15 @@ ClusterCommand::ClusterCommand(string option) { timing = validParameter.validFile(parameters, "timing", false); if (timing == "not found") { timing = "F"; } - if (abort == false) { - - - //get matrix, list and rabund for execute - if(globaldata->gSparseMatrix != NULL) { matrix = globaldata->gSparseMatrix; } - - if(globaldata->gListVector != NULL){ - list = globaldata->gListVector; - rabund = new RAbundVector(list->getRAbundVector()); - } - - //create cluster - if (method == "furthest") { cluster = new CompleteLinkage(rabund, list, matrix, cutoff, method); } - else if(method == "nearest"){ cluster = new SingleLinkage(rabund, list, matrix, cutoff, method); } - else if(method == "average"){ cluster = new AverageLinkage(rabund, list, matrix, cutoff, method); } - else if(method == "weighted"){ cluster = new WeightedLinkage(rabund, list, matrix, cutoff, method); } - tag = cluster->getTag(); - - if (outputDir == "") { outputDir += m->hasPath(globaldata->inputFileName); } - fileroot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); - - 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"); } - } } catch(exception& e) { m->errorOut(e, "ClusterCommand", "ClusterCommand"); exit(1); } } - //********************************************************************************************************************** - -void ClusterCommand::help(){ - try { - m->mothurOut("The cluster command can only be executed after a successful read.dist command.\n"); - m->mothurOut("The cluster command parameter options are method, cuttoff, hard, precision, showabund and timing. No parameters are required.\n"); - m->mothurOut("The cluster command should be in the following format: \n"); - m->mothurOut("cluster(method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"); - m->mothurOut("The acceptable cluster methods are furthest, nearest and average. If no method is provided then furthest is assumed.\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ClusterCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -ClusterCommand::~ClusterCommand(){ - if (abort == false) { - delete cluster; - delete rabund; - } -} - +ClusterCommand::~ClusterCommand(){} //********************************************************************************************************************** int ClusterCommand::execute(){ @@ -200,8 +221,51 @@ int ClusterCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } + ReadMatrix* read; + if (format == "column") { read = new ReadColumnMatrix(columnfile, sim); } //sim indicates whether its a similarity matrix + else if (format == "phylip") { read = new ReadPhylipMatrix(phylipfile, sim); } + + read->setCutoff(cutoff); + + NameAssignment* nameMap = NULL; + if(namefile != ""){ + nameMap = new NameAssignment(namefile); + nameMap->readMap(); + } + + read->read(nameMap); + list = read->getListVector(); + matrix = read->getMatrix(); + rabund = new RAbundVector(list->getRAbundVector()); + delete read; + + if (m->control_pressed) { //clean up + delete list; delete matrix; delete rabund; + sabundFile.close();rabundFile.close();listFile.close(); + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + return 0; + } + + //create cluster + if (method == "furthest") { cluster = new CompleteLinkage(rabund, list, matrix, cutoff, method); } + else if(method == "nearest"){ cluster = new SingleLinkage(rabund, list, matrix, cutoff, method); } + else if(method == "average"){ cluster = new AverageLinkage(rabund, list, matrix, cutoff, method); } + else if(method == "weighted"){ cluster = new WeightedLinkage(rabund, list, matrix, cutoff, method); } + tag = cluster->getTag(); + + 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); + + 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"); + + time_t estart = time(NULL); - //int ndist = matrix->getNNodes(); float previousDist = 0.00000; float rndPreviousDist = 0.00000; oldRAbund = *rabund; @@ -215,10 +279,7 @@ int ClusterCommand::execute(){ while (matrix->getSmallDist() < cutoff && matrix->getNNodes() > 0){ if (m->control_pressed) { //clean up - delete globaldata->gSparseMatrix; globaldata->gSparseMatrix = NULL; - delete globaldata->gListVector; globaldata->gListVector = NULL; - if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); } - else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); } + delete list; delete matrix; delete rabund; delete cluster; sabundFile.close();rabundFile.close();listFile.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; @@ -271,17 +332,10 @@ int ClusterCommand::execute(){ printData(toString(rndPreviousDist, length-1)); } - //delete globaldata's copy of the sparsematrix and listvector to free up memory - delete globaldata->gSparseMatrix; globaldata->gSparseMatrix = NULL; - delete globaldata->gListVector; globaldata->gListVector = NULL; - - //saves .list file so you can do the collect, rarefaction and summary commands without doing a read.list - if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); } - else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); } - - globaldata->setListFile(fileroot+ tag + ".list"); - globaldata->setNameFile(""); - globaldata->setFormat("list"); + delete matrix; + delete list; + delete rabund; + delete cluster; sabundFile.close(); rabundFile.close(); diff --git a/clustercommand.h b/clustercommand.h index 787f835..368760a 100644 --- a/clustercommand.h +++ b/clustercommand.h @@ -10,7 +10,6 @@ */ #include "command.hpp" -#include "globaldata.hpp" #include "rabundvector.hpp" #include "sabundvector.hpp" #include "listvector.hpp" @@ -18,7 +17,6 @@ #include "sparsematrix.hpp" /* The cluster() command: - The cluster command can only be executed after a successful read.phylip or read.column command. The cluster command outputs a .list , .rabund and .sabund files. The cluster command parameter options are method, cuttoff and precision. No parameters are required. The cluster command should be in the following format: cluster(method=yourMethod, cutoff=yourCutoff, precision=yourPrecision). @@ -32,15 +30,16 @@ public: ClusterCommand(string); ClusterCommand(); ~ClusterCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "cluster"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; Cluster* cluster; SparseMatrix* matrix; ListVector* list; @@ -48,9 +47,9 @@ private: RAbundVector oldRAbund; ListVector oldList; - bool abort, hard; + bool abort, hard, sim; - string method, fileroot, tag, outputDir; + string method, fileroot, tag, outputDir, phylipfile, columnfile, namefile, format, distfile; double cutoff; string showabund, timing; int precision, length; @@ -62,7 +61,6 @@ private: void printData(string label); vector outputNames; - map > outputTypes; }; #endif diff --git a/clusterdoturcommand.cpp b/clusterdoturcommand.cpp index 5bcfe03..a9d3214 100644 --- a/clusterdoturcommand.cpp +++ b/clusterdoturcommand.cpp @@ -11,51 +11,55 @@ #include "clusterclassic.h" //********************************************************************************************************************** -vector ClusterDoturCommand::getValidParameters(){ +vector ClusterDoturCommand::setParameters(){ try { - string AlignArray[] = {"phylip","name","hard","cutoff","precision","method","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "furthest", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter phard("hard", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(phard); + CommandParameter psim("sim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psim); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "getValidParameters"); + m->errorOut(e, "ClusterDoturCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ClusterDoturCommand::ClusterDoturCommand(){ +string ClusterDoturCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["list"] = tempOutNames; - outputTypes["rabund"] = tempOutNames; - outputTypes["sabund"] = tempOutNames; + string helpString = ""; + helpString += "The cluster.classic command clusters using the algorithm from dotur. \n"; + helpString += "The cluster.classic command parameter options are phylip, name, method, cuttoff, hard, sim, precision. Phylip is required, unless you have a valid current file.\n"; + helpString += "The cluster.classic command should be in the following format: \n"; + helpString += "cluster.classic(phylip=yourDistanceMatrix, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"; + helpString += "The acceptable cluster methods are furthest, nearest, weighted and average. If no method is provided then furthest is assumed.\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "ClusterCommand"); + m->errorOut(e, "ClusterDoturCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ClusterDoturCommand::getRequiredParameters(){ - try { - string Array[] = {"phylip"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ClusterDoturCommand::getRequiredFiles(){ +ClusterDoturCommand::ClusterDoturCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "getRequiredFiles"); + m->errorOut(e, "ClusterDoturCommand", "ClusterCommand"); exit(1); } } @@ -70,9 +74,7 @@ ClusterDoturCommand::ClusterDoturCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"phylip","name","cutoff","hard","precision","method","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -122,7 +124,14 @@ ClusterDoturCommand::ClusterDoturCommand(string option) { //check for required parameters phylipfile = validParameter.validFile(parameters, "phylip", true); if (phylipfile == "not open") { abort = true; } - else if (phylipfile == "not found") { phylipfile = ""; m->mothurOut("When executing the cluster.dotur command you must enter a phylip file."); m->mothurOutEndLine(); abort = true; } + else if (phylipfile == "not found") { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a phylip file with the cluster.classic command."); m->mothurOutEndLine(); + abort = true; + } + } //check for optional parameter and set defaults @@ -145,6 +154,9 @@ ClusterDoturCommand::ClusterDoturCommand(string option) { temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "F"; } hard = m->isTrue(temp); + temp = validParameter.validFile(parameters, "sim", false); if (temp == "not found") { temp = "F"; } + sim = m->isTrue(temp); + method = validParameter.validFile(parameters, "method", false); if (method == "not found") { method = "furthest"; } @@ -161,28 +173,6 @@ ClusterDoturCommand::ClusterDoturCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void ClusterDoturCommand::help(){ - try { - m->mothurOut("The cluster.classic command clusters using the algorithm from dotur. \n"); - m->mothurOut("The cluster.classic command parameter options are phylip, name, method, cuttoff, hard, precision. Phylip is required.\n"); - m->mothurOut("The cluster.classic command should be in the following format: \n"); - m->mothurOut("cluster.classic(phylip=yourDistanceMatrix, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"); - m->mothurOut("The acceptable cluster methods are furthest, nearest, weighted and average. If no method is provided then furthest is assumed.\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -ClusterDoturCommand::~ClusterDoturCommand(){} - //********************************************************************************************************************** int ClusterDoturCommand::execute(){ @@ -198,7 +188,7 @@ int ClusterDoturCommand::execute(){ } //reads phylip file storing data in 2D vector, also fills list and rabund - ClusterClassic* cluster = new ClusterClassic(cutoff, method); + ClusterClassic* cluster = new ClusterClassic(cutoff, method, sim); cluster->readPhylipFile(phylipfile, nameMap); if (m->control_pressed) { delete cluster; delete list; delete rabund; return 0; } diff --git a/clusterdoturcommand.h b/clusterdoturcommand.h index da2f4a7..5358488 100644 --- a/clusterdoturcommand.h +++ b/clusterdoturcommand.h @@ -12,7 +12,6 @@ #include "command.hpp" #include "nameassignment.hpp" -#include "globaldata.hpp" #include "rabundvector.hpp" #include "sabundvector.hpp" #include "listvector.hpp" @@ -23,16 +22,18 @@ class ClusterDoturCommand : public Command { public: ClusterDoturCommand(string); ClusterDoturCommand(); - ~ClusterDoturCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ClusterDoturCommand(){} + + vector setParameters(); + string getCommandName() { return "cluster.classic"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - bool abort, hard; + bool abort, hard, sim; string method, fileroot, tag, outputDir, phylipfile, namefile; double cutoff; int precision, length; @@ -45,7 +46,6 @@ private: void printData(string label); vector outputNames; - map > outputTypes; }; #endif diff --git a/clusterfragmentscommand.cpp b/clusterfragmentscommand.cpp index be78e76..baea496 100644 --- a/clusterfragmentscommand.cpp +++ b/clusterfragmentscommand.cpp @@ -26,50 +26,57 @@ inline bool comparePriority(seqRNode first, seqRNode second) { return better; } //********************************************************************************************************************** -vector ClusterFragmentsCommand::getValidParameters(){ +vector ClusterFragmentsCommand::setParameters(){ try { - string AlignArray[] = {"fasta","name","diffs","percent","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pdiffs("diffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pdiffs); + CommandParameter ppercent("percent", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppercent); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ClusterFragmentsCommand", "getValidParameters"); + m->errorOut(e, "ClusterFragmentsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ClusterFragmentsCommand::ClusterFragmentsCommand(){ +string ClusterFragmentsCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["name"] = tempOutNames; + string helpString = ""; + helpString += "The cluster.fragments command groups sequences that are part of a larger sequence.\n"; + helpString += "The cluster.fragments command outputs a new fasta and name file.\n"; + helpString += "The cluster.fragments command parameters are fasta, name, diffs and percent. The fasta parameter is required, unless you have a valid current file. \n"; + helpString += "The names parameter allows you to give a list of seqs that are identical. This file is 2 columns, first column is name or representative sequence, second column is a list of its identical sequences separated by commas.\n"; + helpString += "The diffs parameter allows you to set the number of differences allowed, default=0. \n"; + helpString += "The percent parameter allows you to set percentage of differences allowed, default=0. percent=2 means if the number of difference is less than or equal to two percent of the length of the fragment, then cluster.\n"; + helpString += "You may use diffs and percent at the same time to say something like: If the number or differences is greater than 1 or more than 2% of the fragment length, don't merge. \n"; + helpString += "The cluster.fragments command should be in the following format: \n"; + helpString += "cluster.fragments(fasta=yourFastaFile, names=yourNamesFile) \n"; + helpString += "Example cluster.fragments(fasta=amazon.fasta).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ClusterFragmentsCommand", "ClusterFragmentsCommand"); + m->errorOut(e, "ClusterFragmentsCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ClusterFragmentsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ClusterFragmentsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ClusterFragmentsCommand::getRequiredFiles(){ +ClusterFragmentsCommand::ClusterFragmentsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ClusterFragmentsCommand", "getRequiredFiles"); + m->errorOut(e, "ClusterFragmentsCommand", "ClusterFragmentsCommand"); exit(1); } } @@ -82,9 +89,7 @@ ClusterFragmentsCommand::ClusterFragmentsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name","diffs","percent","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -126,8 +131,12 @@ ClusterFragmentsCommand::ClusterFragmentsCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the cluster.fragments command."); m->mothurOutEndLine(); abort = true; } - else if (fastafile == "not open") { abort = true; } + if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } + else if (fastafile == "not open") { fastafile = ""; 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(fastafile); } @@ -154,29 +163,6 @@ ClusterFragmentsCommand::ClusterFragmentsCommand(string option) { exit(1); } } - -//********************************************************************************************************************** -ClusterFragmentsCommand::~ClusterFragmentsCommand(){} -//********************************************************************************************************************** -void ClusterFragmentsCommand::help(){ - try { - m->mothurOut("The cluster.fragments command groups sequences that are part of a larger sequence.\n"); - m->mothurOut("The cluster.fragments command outputs a new fasta and name file.\n"); - m->mothurOut("The cluster.fragments command parameters are fasta, name, diffs and percent. The fasta parameter is required. \n"); - m->mothurOut("The names parameter allows you to give a list of seqs that are identical. This file is 2 columns, first column is name or representative sequence, second column is a list of its identical sequences separated by commas.\n"); - m->mothurOut("The diffs parameter allows you to set the number of differences allowed, default=0. \n"); - m->mothurOut("The percent parameter allows you to set percentage of differences allowed, default=0. percent=2 means if the number of difference is less than or equal to two percent of the length of the fragment, then cluster.\n"); - m->mothurOut("You may use diffs and percent at the same time to say something like: If the number or differences is greater than 1 or more than 2% of the fragment length, don't merge. \n"); - m->mothurOut("The cluster.fragments command should be in the following format: \n"); - m->mothurOut("cluster.fragments(fasta=yourFastaFile, names=yourNamesFile) \n"); - m->mothurOut("Example cluster.fragments(fasta=amazon.fasta).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ClusterFragmentsCommand", "help"); - exit(1); - } -} //********************************************************************************************************************** int ClusterFragmentsCommand::execute(){ try { diff --git a/clusterfragmentscommand.h b/clusterfragmentscommand.h index 01f38e4..882ab33 100644 --- a/clusterfragmentscommand.h +++ b/clusterfragmentscommand.h @@ -32,13 +32,15 @@ class ClusterFragmentsCommand : public Command { public: ClusterFragmentsCommand(string); ClusterFragmentsCommand(); - ~ClusterFragmentsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ClusterFragmentsCommand() {} + + vector setParameters(); + string getCommandName() { return "cluster.fragments"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: bool abort; @@ -49,7 +51,6 @@ private: map sizes; //this map a seq name to the number of identical seqs in the names file map::iterator itSize; vector outputNames; - map > outputTypes; int readFASTA(); void readNameFile(); diff --git a/clustersplitcommand.cpp b/clustersplitcommand.cpp index f9d3822..6d908c6 100644 --- a/clustersplitcommand.cpp +++ b/clustersplitcommand.cpp @@ -17,14 +17,66 @@ //********************************************************************************************************************** -vector ClusterSplitCommand::getValidParameters(){ +vector ClusterSplitCommand::setParameters(){ try { - string AlignArray[] = {"fasta","phylip","column","name","cutoff","precision","method","splitmethod","taxonomy","taxlevel","large","showabund","timing","hard","processors","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "FastaTaxName",false,false); parameters.push_back(ptaxonomy); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnFasta", "PhylipColumnFasta", "none",false,false); parameters.push_back(pphylip); + CommandParameter pfasta("fasta", "InputTypes", "", "", "PhylipColumnFasta", "PhylipColumnFasta", "FastaTaxName",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName-FastaTaxName",false,false); parameters.push_back(pname); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnFasta", "PhylipColumnFasta", "ColumnName",false,false); parameters.push_back(pcolumn); + CommandParameter ptaxlevel("taxlevel", "Number", "", "1", "", "", "",false,false); parameters.push_back(ptaxlevel); + CommandParameter psplitmethod("splitmethod", "Multiple", "classify-fasta-distance", "distance", "", "", "",false,false); parameters.push_back(psplitmethod); + CommandParameter plarge("large", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(plarge); + CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pshowabund); + CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptiming); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "furthest", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter phard("hard", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(phard); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ClusterSplitCommand", "getValidParameters"); + m->errorOut(e, "ClusterSplitCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string ClusterSplitCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The cluster.split command parameter options are fasta, phylip, column, name, cutoff, precision, method, splitmethod, taxonomy, taxlevel, showabund, timing, hard, large, processors. Fasta or Phylip or column and name are required.\n"; + helpString += "The cluster.split command can split your files in 3 ways. Splitting by distance file, by classification, or by classification also using a fasta file. \n"; + helpString += "For the distance file method, you need only provide your distance file and mothur will split the file into distinct groups. \n"; + helpString += "For the classification method, you need to provide your distance file and taxonomy file, and set the splitmethod to classify. \n"; + helpString += "You will also need to set the taxlevel you want to split by. mothur will split the sequences into distinct taxonomy groups, and split the distance file based on those groups. \n"; + helpString += "For the classification method using a fasta file, you need to provide your fasta file, names file and taxonomy file. \n"; + helpString += "You will also need to set the taxlevel you want to split by. mothur will split the sequence into distinct taxonomy groups, and create distance files for each grouping. \n"; + helpString += "The phylip and column parameter allow you to enter your distance file. \n"; + helpString += "The fasta parameter allows you to enter your aligned fasta file. \n"; + helpString += "The name parameter allows you to enter your name file and is required if your distance file is in column format. \n"; + helpString += "The cutoff parameter allow you to set the distance you want to cluster to, default is 10.0. \n"; + helpString += "The precision parameter allows you specify the precision of the precision of the distances outputted, default=100, meaning 2 decimal places. \n"; + helpString += "The method allows you to specify what clustering algorythm you want to use, default=furthest, option furthest, nearest, or average. \n"; + helpString += "The splitmethod parameter allows you to specify how you want to split your distance file before you cluster, default=distance, options distance, classify or fasta. \n"; + helpString += "The taxonomy parameter allows you to enter the taxonomy file for your sequences, this is only valid if you are using splitmethod=classify. Be sure your taxonomy file does not include the probability scores. \n"; + helpString += "The taxlevel parameter allows you to specify the taxonomy level you want to use to split the distance file, default=1, meaning use the first taxon in each list. \n"; + helpString += "The large parameter allows you to indicate that your distance matrix is too large to fit in RAM. The default value is false.\n"; +#ifdef USE_MPI + helpString += "When using MPI, the processors parameter is set to the number of MPI processes running. \n"; +#endif + helpString += "The cluster.split command should be in the following format: \n"; + helpString += "cluster.split(column=youDistanceFile, name=yourNameFile, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision, splitmethod=yourSplitmethod, taxonomy=yourTaxonomyfile, taxlevel=yourtaxlevel) \n"; + helpString += "Example: cluster.split(column=abrecovery.dist, name=abrecovery.names, method=furthest, cutoff=0.10, precision=1000, splitmethod=classify, taxonomy=abrecovery.silva.slv.taxonomy, taxlevel=5) \n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "ClusterSplitCommand", "getHelpString"); exit(1); } } @@ -32,6 +84,7 @@ vector ClusterSplitCommand::getValidParameters(){ ClusterSplitCommand::ClusterSplitCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["list"] = tempOutNames; outputTypes["rabund"] = tempOutNames; @@ -44,33 +97,9 @@ ClusterSplitCommand::ClusterSplitCommand(){ } } //********************************************************************************************************************** -vector ClusterSplitCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta","phylip","column","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ClusterSplitCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ClusterSplitCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ClusterSplitCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** //This function checks to make sure the cluster command has no errors and then clusters based on the method chosen. ClusterSplitCommand::ClusterSplitCommand(string option) { try{ - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; format = ""; @@ -78,9 +107,7 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","phylip","column","name","cutoff","precision","method","splitmethod","taxonomy","taxlevel","large","showabund","timing","hard","processors","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -102,8 +129,6 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { outputTypes["sabund"] = tempOutNames; outputTypes["column"] = tempOutNames; - globaldata->newRead(); - //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 = ""; } @@ -177,16 +202,55 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { if (taxFile == "not open") { abort = true; } else if (taxFile == "not found") { taxFile = ""; } - if ((phylipfile == "") && (columnfile == "") && (fastafile == "")) { m->mothurOut("When executing a cluster.split command you must enter a phylip or a column or fastafile."); m->mothurOutEndLine(); abort = true; } + if ((phylipfile == "") && (columnfile == "") && (fastafile == "")) { + //is there are current file available for either of these? + //give priority to column, then phylip, then fasta + columnfile = m->getColumnFile(); + if (columnfile != "") { m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); } + else { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. When executing a cluster.split command you must enter a phylip or a column or fastafile."); m->mothurOutEndLine(); + abort = true; + } + } + } + } else if ((phylipfile != "") && (columnfile != "") && (fastafile != "")) { m->mothurOut("When executing a cluster.split command you must enter ONLY ONE of the following: fasta, phylip or column."); m->mothurOutEndLine(); abort = true; } if (columnfile != "") { - if (namefile == "") { m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); abort = true; } + if (namefile == "") { + namefile = m->getNameFile(); + if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); + abort = true; + } + } } if (fastafile != "") { - if (taxFile == "") { m->mothurOut("You need to provide a taxonomy file if you are using a fasta file to generate the split."); m->mothurOutEndLine(); abort = true; } - if (namefile == "") { m->mothurOut("You need to provide a names file if you are using a fasta file to generate the split."); m->mothurOutEndLine(); abort = true; } + if (taxFile == "") { + taxFile = m->getTaxonomyFile(); + if (taxFile != "") { m->mothurOut("Using " + taxFile + " as input file for the taxonomy parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a taxonomy file if you are if you are using a fasta file to generate the split."); m->mothurOutEndLine(); + abort = true; + } + } + + if (namefile == "") { + namefile = m->getNameFile(); + if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a namefile if you are if you are using a fasta file to generate the split."); m->mothurOutEndLine(); + abort = true; + } + } } //check for optional parameter and set defaults @@ -205,8 +269,9 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { temp = validParameter.validFile(parameters, "large", false); if (temp == "not found") { temp = "F"; } large = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } - convert(temp, processors); + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); temp = validParameter.validFile(parameters, "splitmethod", false); if (splitmethod != "fasta") { @@ -247,45 +312,6 @@ ClusterSplitCommand::ClusterSplitCommand(string option) { //********************************************************************************************************************** -void ClusterSplitCommand::help(){ - try { - m->mothurOut("The cluster.split command parameter options are fasta, phylip, column, name, cutoff, precision, method, splitmethod, taxonomy, taxlevel, showabund, timing, hard, large, processors. Fasta or Phylip or column and name are required.\n"); - m->mothurOut("The cluster.split command can split your files in 3 ways. Splitting by distance file, by classification, or by classification also using a fasta file. \n"); - m->mothurOut("For the distance file method, you need only provide your distance file and mothur will split the file into distinct groups. \n"); - m->mothurOut("For the classification method, you need to provide your distance file and taxonomy file, and set the splitmethod to classify. \n"); - m->mothurOut("You will also need to set the taxlevel you want to split by. mothur will split the sequences into distinct taxonomy groups, and split the distance file based on those groups. \n"); - m->mothurOut("For the classification method using a fasta file, you need to provide your fasta file, names file and taxonomy file. \n"); - m->mothurOut("You will also need to set the taxlevel you want to split by. mothur will split the sequence into distinct taxonomy groups, and create distance files for each grouping. \n"); - m->mothurOut("The phylip and column parameter allow you to enter your distance file. \n"); - m->mothurOut("The fasta parameter allows you to enter your aligned fasta file. \n"); - m->mothurOut("The name parameter allows you to enter your name file and is required if your distance file is in column format. \n"); - m->mothurOut("The cutoff parameter allow you to set the distance you want to cluster to, default is 10.0. \n"); - m->mothurOut("The precision parameter allows you specify the precision of the precision of the distances outputted, default=100, meaning 2 decimal places. \n"); - m->mothurOut("The method allows you to specify what clustering algorythm you want to use, default=furthest, option furthest, nearest, or average. \n"); - m->mothurOut("The splitmethod parameter allows you to specify how you want to split your distance file before you cluster, default=distance, options distance, classify or fasta. \n"); - m->mothurOut("The taxonomy parameter allows you to enter the taxonomy file for your sequences, this is only valid if you are using splitmethod=classify. Be sure your taxonomy file does not include the probability scores. \n"); - m->mothurOut("The taxlevel parameter allows you to specify the taxonomy level you want to use to split the distance file, default=1, meaning use the first taxon in each list. \n"); - m->mothurOut("The large parameter allows you to indicate that your distance matrix is too large to fit in RAM. The default value is false.\n"); - #ifdef USE_MPI - m->mothurOut("When using MPI, the processors parameter is set to the number of MPI processes running. \n"); - #endif - m->mothurOut("The cluster.split command should be in the following format: \n"); - m->mothurOut("cluster.split(column=youDistanceFile, name=yourNameFile, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision, splitmethod=yourSplitmethod, taxonomy=yourTaxonomyfile, taxlevel=yourtaxlevel) \n"); - m->mothurOut("Example: cluster.split(column=abrecovery.dist, name=abrecovery.names, method=furthest, cutoff=0.10, precision=1000, splitmethod=classify, taxonomy=abrecovery.silva.slv.taxonomy, taxlevel=5) \n"); - - } - catch(exception& e) { - m->errorOut(e, "ClusterSplitCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -ClusterSplitCommand::~ClusterSplitCommand(){} - -//********************************************************************************************************************** - int ClusterSplitCommand::execute(){ try { @@ -949,11 +975,7 @@ vector ClusterSplitCommand::cluster(vector< map > distNa string thisNamefile = distNames[i].begin()->second; string thisDistFile = distNames[i].begin()->first; - - //read in distance file - globaldata->setNameFile(thisNamefile); - globaldata->setColumnFile(thisDistFile); globaldata->setFormat("column"); - + #ifdef USE_MPI int pid; MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are diff --git a/clustersplitcommand.h b/clustersplitcommand.h index 9bce099..28c7d23 100644 --- a/clustersplitcommand.h +++ b/clustersplitcommand.h @@ -16,7 +16,6 @@ #include "listvector.hpp" #include "cluster.hpp" #include "sparsematrix.hpp" -#include "globaldata.hpp" class ClusterSplitCommand : public Command { @@ -24,20 +23,20 @@ class ClusterSplitCommand : public Command { public: ClusterSplitCommand(string); ClusterSplitCommand(); - ~ClusterSplitCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ClusterSplitCommand() {} + vector setParameters(); + string getCommandName() { return "cluster.split"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; vector processIDS; //processid vector outputNames; - map > outputTypes; - + string method, fileroot, tag, outputDir, phylipfile, columnfile, namefile, distfile, format, showabund, timing, splitmethod, taxFile, fastafile; double cutoff, splitcutoff; int precision, length, processors, taxLevelCutoff; diff --git a/collect.cpp b/collect.cpp index ec5366b..8db4a28 100644 --- a/collect.cpp +++ b/collect.cpp @@ -70,17 +70,15 @@ int Collect::getCurve(float percentFreq = 0.01){ /***********************************************************************/ int Collect::getSharedCurve(float percentFreq = 0.01){ try { - globaldata = GlobalData::getInstance(); vector lookup; vector subset; //create and initialize vector of sharedvectors, one for each group - for (int i = 0; i < globaldata->Groups.size(); i++) { + for (int i = 0; i < m->Groups.size(); i++) { SharedRAbundVector* temp = new SharedRAbundVector(sharedorder->getNumBins()); temp->setLabel(sharedorder->getLabel()); - temp->setGroup(globaldata->Groups[i]); - temp->setGroupIndex(globaldata->gGroupmap->groupIndex[globaldata->Groups[i]]); - lookup.push_back(temp); + temp->setGroup(m->Groups[i]); + lookup.push_back(temp); } SharedCollectorsCurveData* ccd = new SharedCollectorsCurveData(); @@ -144,13 +142,13 @@ try { if ((w != k) && (w != l)) { subset.push_back(lookup[w]); } } - ccd->updateSharedData(subset, i+1, globaldata->Groups.size(), pair); + ccd->updateSharedData(subset, i+1, m->Groups.size(), pair); } n++; } //if this is a calculator that can do multiples then do them pair = false; - ccd->updateSharedData(lookup, i+1, globaldata->Groups.size(), pair); + ccd->updateSharedData(lookup, i+1, m->Groups.size(), pair); } totalNumSeq = i+1; } @@ -171,13 +169,13 @@ try { if ((w != k) && (w != l)) { subset.push_back(lookup[w]); } } - ccd->updateSharedData(subset, totalNumSeq, globaldata->Groups.size(), pair); + ccd->updateSharedData(subset, totalNumSeq, m->Groups.size(), pair); } n++; } //if this is a calculator that can do multiples then do them pair = false; - ccd->updateSharedData(lookup, totalNumSeq, globaldata->Groups.size(), pair); + ccd->updateSharedData(lookup, totalNumSeq, m->Groups.size(), pair); } //resets output files @@ -208,9 +206,9 @@ void Collect::getGroupComb() { numGroupComb = 0; int n = 1; - for (int i = 0; i < (globaldata->Groups.size() - 1); i++) { - for (int l = n; l < globaldata->Groups.size(); l++) { - group = globaldata->Groups[i] + globaldata->Groups[l]; + for (int i = 0; i < (m->Groups.size() - 1); i++) { + for (int l = n; l < m->Groups.size(); l++) { + group = m->Groups[i] + m->Groups[l]; groupComb.push_back(group); numGroupComb++; } diff --git a/collect.h b/collect.h index 79f88fb..5171233 100644 --- a/collect.h +++ b/collect.h @@ -8,7 +8,6 @@ #include "rabundvector.hpp" #include "sharedordervector.h" #include "datavector.hpp" -#include "globaldata.hpp" #include "mothurout.h" /***********************************************************************/ @@ -27,7 +26,6 @@ public: private: SharedOrderVector* sharedorder; - GlobalData* globaldata; OrderVector* order; vector displays; int numSeqs, numGroupComb, totalNumSeq; diff --git a/collectcommand.cpp b/collectcommand.cpp index 4b59296..adaff9b 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -34,38 +34,48 @@ #include "shen.h" #include "coverage.h" + //********************************************************************************************************************** -vector CollectCommand::getValidParameters(){ - try { - string AlignArray[] = {"freq","label","calc","abund","size","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "CollectCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector CollectCommand::getRequiredParameters(){ +vector CollectCommand::setParameters(){ try { + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); + CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-np_shannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap-geometric-qstat-logseries-bergerparker-bstick-goodscoverage-efron-boneh-solow-shen", "sobs-chao-ace-jack-shannon-npshannon-simpson", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund); + CommandParameter psize("size", "Number", "", "0", "", "", "",false,false); parameters.push_back(psize); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "CollectCommand", "getRequiredParameters"); + m->errorOut(e, "CollectCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector CollectCommand::getRequiredFiles(){ +string CollectCommand::getHelpString(){ try { - string AlignArray[] = {"shared","list","rabund","sabund","or"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The collect.single command parameters are list, sabund, rabund, shared, label, freq, calc and abund. list, sabund, rabund or shared is required unless you have a valid current file. \n"; + helpString += "The collect.single command should be in the following format: \n"; + helpString += "The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"; + helpString += "collect.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n"; + helpString += "Example collect(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-chao-ace-jack).\n"; + helpString += "The default values for freq is 100, and calc are sobs-chao-ace-jack-shannon-npshannon-simpson.\n"; + helpString += validCalculator->printCalc("single"); + helpString += "The label parameter is used to analyze specific labels in your input.\n"; + helpString += "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "CollectCommand", "getRequiredFiles"); + m->errorOut(e, "CollectCommand", "getHelpString"); exit(1); } } @@ -73,6 +83,7 @@ vector CollectCommand::getRequiredFiles(){ CollectCommand::CollectCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["sobs"] = tempOutNames; outputTypes["chao"] = tempOutNames; @@ -108,30 +119,26 @@ CollectCommand::CollectCommand(){ //********************************************************************************************************************** CollectCommand::CollectCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Estimators.clear(); //allow user to run help if(option == "help") { validCalculator = new ValidCalculators(); help(); delete validCalculator; abort = true; } else { - //valid paramters for this command - string Array[] = {"freq","label","calc","abund","size","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + //initialize outputTypes vector tempOutNames; outputTypes["sobs"] = tempOutNames; @@ -160,11 +167,92 @@ CollectCommand::CollectCommand(string option) { outputTypes["solow"] = tempOutNames; outputTypes["shen"] = 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 = ""; } + else { + string path; + 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("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("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("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; } + } + } + + //check for required parameters + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { listfile = ""; abort = true; } + else if (listfile == "not found") { listfile = ""; } + else { format = "list"; inputfile = listfile; } + + sabundfile = validParameter.validFile(parameters, "sabund", true); + if (sabundfile == "not open") { sabundfile = ""; abort = true; } + else if (sabundfile == "not found") { sabundfile = ""; } + else { format = "sabund"; inputfile = sabundfile; } + + rabundfile = validParameter.validFile(parameters, "rabund", true); + if (rabundfile == "not open") { rabundfile = ""; abort = true; } + else if (rabundfile == "not found") { rabundfile = ""; } + else { format = "rabund"; inputfile = rabundfile; } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { format = "sharedfile"; inputfile = sharedfile; } + + //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 = ""; } - //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund, rabund or shared file before you can use the collect.single command."); m->mothurOutEndLine(); abort = true; } + if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + rabundfile = m->getRabundFile(); + if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } + else { + sabundfile = m->getSabundFile(); + if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list, sabund, rabund or shared file before you can use the collect.single command."); m->mothurOutEndLine(); + abort = true; + } + } + } + } + } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -175,12 +263,7 @@ CollectCommand::CollectCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - + //NOTE: if you add new calc options, don't forget to add them to the parameter initialize in setParameters or the gui won't be able to use them calc = validParameter.validFile(parameters, "calc", false); if (calc == "not found") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; } else { @@ -207,48 +290,21 @@ CollectCommand::CollectCommand(string option) { } //********************************************************************************************************************** -void CollectCommand::help(){ - try { - m->mothurOut("The collect.single command can only be executed after a successful read.otu command. WITH ONE EXECEPTION. \n"); - m->mothurOut("The collect.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster.\n"); - m->mothurOut("The collect.single command parameters are label, freq, calc and abund. No parameters are required. \n"); - m->mothurOut("The collect.single command should be in the following format: \n"); - m->mothurOut("The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"); - m->mothurOut("collect.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n"); - m->mothurOut("Example collect(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-chao-ace-jack).\n"); - m->mothurOut("The default values for freq is 100, and calc are sobs-chao-ace-jack-shannon-npshannon-simpson.\n"); - validCalculator->printCalc("single", cout); - m->mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "CollectCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -CollectCommand::~CollectCommand(){} - -//********************************************************************************************************************** - int CollectCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - - string hadShared = ""; - if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } - else { hadShared = globaldata->getSharedFile(); inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } + + if ((format != "sharedfile")) { inputFileNames.push_back(inputfile); } + else { inputFileNames = parseSharedFile(sharedfile); format = "rabund"; } for (int p = 0; p < inputFileNames.size(); p++) { - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } m->Groups.clear(); return 0; } if (outputDir == "") { outputDir += m->hasPath(inputFileNames[p]); } string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])); - globaldata->inputFileName = inputFileNames[p]; + //globaldata->inputFileName = inputFileNames[p]; if (inputFileNames.size() > 1) { m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); @@ -338,14 +394,11 @@ int CollectCommand::execute(){ } //if the users entered no valid calculators don't execute command - if (cDisplays.size() == 0) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } + if (cDisplays.size() == 0) { return 0; } - read = new ReadOTUFile(inputFileNames[p]); - read->read(&*globaldata); - - order = globaldata->gorder; + input = new InputData(inputFileNames[p], format); + order = input->getOrderVector(); string lastLabel = order->getLabel(); - input = globaldata->ginput; //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -354,12 +407,10 @@ int CollectCommand::execute(){ if (m->control_pressed) { for(int i=0;iginput = NULL; - delete read; - delete order; globaldata->gorder = NULL; + delete input; + delete order; delete validCalculator; - globaldata->Groups.clear(); - if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } + m->Groups.clear(); return 0; } @@ -369,12 +420,10 @@ int CollectCommand::execute(){ if (m->control_pressed) { for(int i=0;iginput = NULL; - delete read; - delete order; globaldata->gorder = NULL; + delete input; + delete order; delete validCalculator; - globaldata->Groups.clear(); - if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } + m->Groups.clear(); return 0; } @@ -421,11 +470,9 @@ int CollectCommand::execute(){ if (m->control_pressed) { for(int i=0;iginput = NULL; - delete read; + delete input; delete validCalculator; - globaldata->Groups.clear(); - if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } + m->Groups.clear(); return 0; } @@ -456,12 +503,10 @@ int CollectCommand::execute(){ if (m->control_pressed) { for(int i=0;iginput = NULL; - delete read; - delete order; globaldata->gorder = NULL; + delete input; + delete order; delete validCalculator; - globaldata->Groups.clear(); - if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } + m->Groups.clear(); return 0; } delete order; @@ -469,15 +514,10 @@ int CollectCommand::execute(){ for(int i=0;iginput = NULL; - delete read; - globaldata->gorder = NULL; + delete input; delete validCalculator; } - //return to shared mode if you changed above - if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } m->mothurOutEndLine(); @@ -501,13 +541,8 @@ vector CollectCommand::parseSharedFile(string filename) { map filehandles; map::iterator it3; - - - //read first line - read = new ReadOTUFile(filename); - read->read(&*globaldata); - - input = globaldata->ginput; + + input = new InputData(filename, "sharedfile"); vector lookup = input->getSharedRAbundVectors(); string sharedFileRoot = m->getRootName(filename); @@ -542,9 +577,8 @@ vector CollectCommand::parseSharedFile(string filename) { for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - delete read; + delete input; - globaldata->ginput = NULL; return filenames; } diff --git a/collectcommand.h b/collectcommand.h index 20c863b..1884d04 100644 --- a/collectcommand.h +++ b/collectcommand.h @@ -12,16 +12,12 @@ #include "command.hpp" #include "ordervector.hpp" #include "inputdata.h" -#include "groupmap.h" #include "collect.h" #include "display.h" -#include "readotu.h" #include "validcalculator.h" /*The collect() command: The collect command generates a collector's curve from the given file. - The collect command can only be executed after a successful read.list, read.sabund or read.rabund command, with one exception. - The collect command can be executed after a successful cluster command. It will use the .list file from the output of the cluster. The collect command outputs a file for each estimator you choose to use. The collect command parameters are label, freq, single, abund. No parameters are required. The collect command should be in the following format: collect(label=yourLabel, freq=yourFreq, single=yourEstimators, abund=yourAbund). @@ -31,25 +27,23 @@ The label parameter is used to analyze specific labels in your input. */ - -class GlobalData; - class CollectCommand : public Command { public: CollectCommand(string); CollectCommand(); - ~CollectCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~CollectCommand(){} + + vector setParameters(); + string getCommandName() { return "collect.single"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; - ReadOTUFile* read; OrderVector* order; InputData* input; Collect* cCurve; @@ -58,11 +52,10 @@ private: int abund, size; float freq; vector outputNames; - map > outputTypes; bool abort, allLines; set labels; //holds labels to be used - string label, calc, outputDir; + string label, calc, outputDir, sharedfile, listfile, rabundfile, sabundfile, format, inputfile; vector Estimators; vector inputFileNames; vector groups; diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index 21695e3..0fe4d0f 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -50,38 +50,50 @@ #include "memeuclidean.h" #include "mempearson.h" + //********************************************************************************************************************** -vector CollectSharedCommand::getValidParameters(){ - try { - string AlignArray[] = {"freq","label","calc","groups","all","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "CollectSharedCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector CollectSharedCommand::getRequiredParameters(){ +vector CollectSharedCommand::setParameters(){ try { + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); + CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-skulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter pall("all", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pall); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "CollectSharedCommand", "getRequiredParameters"); + m->errorOut(e, "CollectSharedCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector CollectSharedCommand::getRequiredFiles(){ +string CollectSharedCommand::getHelpString(){ try { - string AlignArray[] = {"shared"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + string helpString = ""; + ValidCalculators validCalculator; + helpString += "The collect.shared command parameters are shared, label, freq, calc and groups. shared is required if there is no current sharedfile. \n"; + helpString += "The collect.shared command should be in the following format: \n"; + helpString += "collect.shared(label=yourLabel, freq=yourFreq, calc=yourEstimators, groups=yourGroups).\n"; + helpString += "Example collect.shared(label=unique-.01-.03, freq=10, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan).\n"; + helpString += "The default values for freq is 100 and calc are sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan.\n"; + helpString += "The default value for groups is all the groups in your groupfile.\n"; + helpString += "The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"; + helpString += validCalculator.printCalc("shared"); + helpString += "The label parameter is used to analyze specific labels in your input.\n"; + helpString += "The all parameter is used to specify if you want the estimate of all your groups together. This estimate can only be made for sharedsobs and sharedchao calculators. The default is false.\n"; + helpString += "If you use sharedchao and run into memory issues, set all to false. \n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "CollectSharedCommand", "getRequiredFiles"); + m->errorOut(e, "CollectSharedCommand", "getHelpString"); exit(1); } } @@ -89,6 +101,7 @@ vector CollectSharedCommand::getRequiredFiles(){ CollectSharedCommand::CollectSharedCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["sharedchao"] = tempOutNames; outputTypes["sharedsobs"] = tempOutNames; @@ -139,31 +152,26 @@ CollectSharedCommand::CollectSharedCommand(){ //********************************************************************************************************************** CollectSharedCommand::CollectSharedCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Estimators.clear(); - Groups.clear(); //allow user to run help - if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; calledHelp = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"freq","label","calc","groups","all","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters=parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - + //initialize outputTypes vector tempOutNames; outputTypes["sharedchao"] = tempOutNames; @@ -206,16 +214,34 @@ CollectSharedCommand::CollectSharedCommand(string option) { outputTypes["memeuclidean"] = tempOutNames; outputTypes["mempearson"] = 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 = ""; } - - //make sure the user has already run the read.otu command - if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); m->mothurOutEndLine(); abort = true; } - else if (globaldata->getGroupFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); m->mothurOutEndLine(); 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("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; } + } } - + + //get shared file + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current sharedfile and the shared 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(sharedfile); } //check for optional parameter and set defaults // ...at some point should added some additional type checking.. @@ -226,12 +252,6 @@ CollectSharedCommand::CollectSharedCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if(label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - calc = validParameter.validFile(parameters, "calc", false); if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; } else { @@ -244,7 +264,7 @@ CollectSharedCommand::CollectSharedCommand(string option) { else { m->splitAtDash(groups, Groups); } - globaldata->Groups = Groups; + m->Groups = Groups; string temp; temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; } @@ -255,16 +275,12 @@ CollectSharedCommand::CollectSharedCommand(string option) { if (abort == false) { - if (outputDir == "") { outputDir += m->hasPath(globaldata->inputFileName); } - string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); - format = globaldata->getFormat(); - int i; + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(sharedfile)); - validCalculator = new ValidCalculators(); - util = new SharedUtil(); + ValidCalculators validCalculator; - for (i=0; iisValidCalculator("shared", Estimators[i]) == true) { + for (int i=0; imothurOut("The collect.shared command can only be executed after a successful read.otu command.\n"); - m->mothurOut("The collect.shared command parameters are label, freq, calc and groups. No parameters are required \n"); - m->mothurOut("The collect.shared command should be in the following format: \n"); - m->mothurOut("collect.shared(label=yourLabel, freq=yourFreq, calc=yourEstimators, groups=yourGroups).\n"); - m->mothurOut("Example collect.shared(label=unique-.01-.03, freq=10, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan).\n"); - m->mothurOut("The default values for freq is 100 and calc are sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan.\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile.\n"); - m->mothurOut("The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"); - validCalculator->printCalc("shared", cout); - m->mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - m->mothurOut("The all parameter is used to specify if you want the estimate of all your groups together. This estimate can only be made for sharedsobs and sharedchao calculators. The default is false.\n"); - m->mothurOut("If you use sharedchao and run into memory issues, set all to false. \n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "CollectSharedCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -CollectSharedCommand::~CollectSharedCommand(){ - if (abort == false) { - delete input; globaldata->ginput = NULL; - delete read; - delete util; - delete validCalculator; - globaldata->gorder = NULL; - } -} - +CollectSharedCommand::~CollectSharedCommand(){} //********************************************************************************************************************** int CollectSharedCommand::execute(){ @@ -444,10 +424,7 @@ int CollectSharedCommand::execute(){ if (cDisplays.size() == 0) { return 0; } for(int i=0;isetAll(all); } - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - - input = globaldata->ginput; + input = new InputData(sharedfile, "sharedfile"); order = input->getSharedOrderVector(); string lastLabel = order->getLabel(); @@ -456,15 +433,16 @@ int CollectSharedCommand::execute(){ set userLabels = labels; //set users groups - util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect"); - util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex); + SharedUtil* util = new SharedUtil(); + util->setGroups(m->Groups, m->namesOfGroups, "collect"); + delete util; while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); for(int i=0;iGroups.clear(); + delete order; delete input; + m->Groups.clear(); return 0; } @@ -511,7 +489,8 @@ int CollectSharedCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); for(int i=0;iGroups.clear(); + m->Groups.clear(); + delete input; return 0; } @@ -542,7 +521,8 @@ int CollectSharedCommand::execute(){ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); for(int i=0;iGroups.clear(); + delete input; + m->Groups.clear(); return 0; } @@ -552,7 +532,8 @@ int CollectSharedCommand::execute(){ for(int i=0;iGroups.clear(); + m->Groups.clear(); + delete input; m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); diff --git a/collectsharedcommand.h b/collectsharedcommand.h index 327ce5d..d7f2f8f 100644 --- a/collectsharedcommand.h +++ b/collectsharedcommand.h @@ -12,16 +12,12 @@ #include "command.hpp" #include "sharedordervector.h" -#include "sharedlistvector.h" #include "inputdata.h" -#include "groupmap.h" #include "collect.h" #include "display.h" -#include "readotu.h" #include "validcalculator.h" #include "sharedutilities.h" -class GlobalData; class CollectSharedCommand : public Command { @@ -29,34 +25,27 @@ public: CollectSharedCommand(string); CollectSharedCommand(); ~CollectSharedCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "collect.shared"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; - SharedUtil* util; - GroupMap* groupmap; - SharedListVector* SharedList; - ReadOTUFile* read; SharedOrderVector* order; InputData* input; - ValidCalculators* validCalculator; Collect* cCurve; vector cDisplays; float freq; - string format; bool abort, allLines, all; set labels; //holds labels to be used - string label, calc, groups, outputDir; + string label, calc, groups, outputDir, sharedfile; vector Estimators, Groups, outputNames; - map > outputTypes; - - }; #endif diff --git a/command.hpp b/command.hpp index 93669ba..fd80ad1 100644 --- a/command.hpp +++ b/command.hpp @@ -17,22 +17,33 @@ #include "optionparser.h" #include "validparameter.h" #include "mothurout.h" +#include "commandparameter.h" class Command { public: Command() { m = MothurOut::getInstance(); } - virtual vector getValidParameters() = 0; - virtual vector getRequiredParameters() = 0; //adding "or" as the last element indicates one of the previous is needed - virtual vector getRequiredFiles() = 0; //adding "or" as the last element indicates one of the previous is needed - virtual map > getOutputFiles() = 0; //file type to names + + //needed by gui + virtual string getCommandName() = 0; + virtual string getCommandCategory() = 0; + virtual string getHelpString() = 0; + + virtual map > getOutputFiles() { return outputTypes; } + virtual vector setParameters() = 0; //to fill parameters + virtual vector getParameters() { return parameters; } + virtual int execute() = 0; virtual void help() = 0; virtual ~Command() { } + protected: MothurOut* m; bool calledHelp; + + map > outputTypes; + vector parameters; map >::iterator itTypes; }; diff --git a/commandfactory.cpp b/commandfactory.cpp index e18e6ac..a04ee16 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -8,9 +8,9 @@ */ #include "command.hpp" -#include "readdistcommand.h" -#include "readtreecommand.h" -#include "readotucommand.h" +//#include "readdistcommand.h" +//#include "readtreecommand.h" +//#include "readotucommand.h" #include "clustercommand.h" #include "collectcommand.h" #include "collectsharedcommand.h" @@ -48,7 +48,6 @@ #include "reversecommand.h" #include "trimseqscommand.h" #include "mergefilecommand.h" -#include "chimeraseqscommand.h" #include "listseqscommand.h" #include "getseqscommand.h" #include "removeseqscommand.h" @@ -116,6 +115,7 @@ #include "anosimcommand.h" #include "getcurrentcommand.h" #include "setcurrentcommand.h" +#include "sharedcommand.h" /*******************************************************/ @@ -148,9 +148,10 @@ 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["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"; commands["cluster"] = "cluster"; @@ -241,7 +242,6 @@ CommandFactory::CommandFactory(){ commands["dist.seqs"] = "MPIEnabled"; commands["filter.seqs"] = "MPIEnabled"; commands["align.seqs"] = "MPIEnabled"; - commands["chimera.seqs"] = "chimera.seqs"; commands["chimera.ccode"] = "MPIEnabled"; commands["chimera.check"] = "MPIEnabled"; commands["chimera.slayer"] = "MPIEnabled"; @@ -297,10 +297,10 @@ 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 == "read.dist") { command = new ReadDistCommand(optionString); } + //else if(commandName == "read.otu") { command = new ReadOtuCommand(optionString); } + //else if(commandName == "read.tree") { command = new ReadTreeCommand(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); } @@ -336,7 +336,6 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ else if(commandName == "trim.seqs") { command = new TrimSeqsCommand(optionString); } else if(commandName == "trim.flows") { command = new TrimFlowsCommand(optionString); } else if(commandName == "shhh.seqs") { command = new ShhherCommand(optionString); } - else if(commandName == "chimera.seqs") { command = new ChimeraSeqsCommand(optionString); } else if(commandName == "list.seqs") { command = new ListSeqsCommand(optionString); } else if(commandName == "get.seqs") { command = new GetSeqsCommand(optionString); } else if(commandName == "remove.seqs") { command = new RemoveSeqsCommand(optionString); } @@ -403,6 +402,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ else if(commandName == "get.current") { command = new GetCurrentCommand(optionString); } else if(commandName == "set.current") { command = new SetCurrentCommand(optionString); } else if(commandName == "anosim") { command = new AnosimCommand(optionString); } + else if(commandName == "make.shared") { command = new SharedCommand(optionString); } else { command = new NoCommand(optionString); } return command; @@ -432,10 +432,10 @@ 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 == "read.dist") { pipecommand = new ReadDistCommand(optionString); } + //else if(commandName == "read.otu") { pipecommand = new ReadOtuCommand(optionString); } + //else if(commandName == "read.tree") { pipecommand = new ReadTreeCommand(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); } @@ -471,7 +471,6 @@ Command* CommandFactory::getCommand(string commandName, string optionString, str else if(commandName == "trim.seqs") { pipecommand = new TrimSeqsCommand(optionString); } else if(commandName == "trim.flows") { pipecommand = new TrimFlowsCommand(optionString); } else if(commandName == "shhh.seqs") { pipecommand = new ShhherCommand(optionString); } - else if(commandName == "chimera.seqs") { pipecommand = new ChimeraSeqsCommand(optionString); } else if(commandName == "list.seqs") { pipecommand = new ListSeqsCommand(optionString); } else if(commandName == "get.seqs") { pipecommand = new GetSeqsCommand(optionString); } else if(commandName == "remove.seqs") { pipecommand = new RemoveSeqsCommand(optionString); } @@ -537,6 +536,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString, str else if(commandName == "make.fastq") { pipecommand = new MakeFastQCommand(optionString); } else if(commandName == "get.current") { pipecommand = new GetCurrentCommand(optionString); } else if(commandName == "set.current") { pipecommand = new SetCurrentCommand(optionString); } + else if(commandName == "make.shared") { pipecommand = new SharedCommand(optionString); } else { pipecommand = new NoCommand(optionString); } return pipecommand; @@ -554,10 +554,10 @@ 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 == "read.dist") { shellcommand = new ReadDistCommand(); } + //else if(commandName == "read.otu") { shellcommand = new ReadOtuCommand(); } + //else if(commandName == "read.tree") { shellcommand = new ReadTreeCommand(); } + 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(); } @@ -593,7 +593,6 @@ Command* CommandFactory::getCommand(string commandName){ else if(commandName == "trim.seqs") { shellcommand = new TrimSeqsCommand(); } else if(commandName == "trim.flows") { shellcommand = new TrimFlowsCommand(); } else if(commandName == "shhh.seqs") { shellcommand = new ShhherCommand(); } - else if(commandName == "chimera.seqs") { shellcommand = new ChimeraSeqsCommand(); } else if(commandName == "list.seqs") { shellcommand = new ListSeqsCommand(); } else if(commandName == "get.seqs") { shellcommand = new GetSeqsCommand(); } else if(commandName == "remove.seqs") { shellcommand = new RemoveSeqsCommand(); } @@ -659,6 +658,7 @@ Command* CommandFactory::getCommand(string commandName){ else if(commandName == "make.fastq") { shellcommand = new MakeFastQCommand(); } else if(commandName == "get.current") { shellcommand = new GetCurrentCommand(); } else if(commandName == "set.current") { shellcommand = new SetCurrentCommand(); } + else if(commandName == "make.shared") { shellcommand = new SharedCommand(); } else { shellcommand = new NoCommand(); } return shellcommand; diff --git a/commandoptionparser.cpp b/commandoptionparser.cpp index df216da..c5e000b 100644 --- a/commandoptionparser.cpp +++ b/commandoptionparser.cpp @@ -27,8 +27,8 @@ CommandOptionParser::CommandOptionParser(string input){ commandString = input.substr(0, openParen); //commandString contains everything before "(" optionString = input.substr((openParen+1), (closeParen-openParen-1)); //optionString contains everything between "(" and ")". } - else if (openParen == -1) { m->mothurOut("You are missing ("); m->mothurOutEndLine(); } - else if (closeParen == -1) { m->mothurOut("You are missing )"); m->mothurOutEndLine(); } + else if (openParen == -1) { m->mothurOut("[ERROR]: You are missing ("); m->mothurOutEndLine(); } + else if (closeParen == -1) { m->mothurOut("[ERROR]:You are missing )"); m->mothurOutEndLine(); } //GlobalData* globaldata = GlobalData::getInstance(); //globaldata->parseGlobalData(commandString, optionString); //parser to separate and check options diff --git a/consensuscommand.cpp b/consensuscommand.cpp index d64dc93..75c6a3c 100644 --- a/consensuscommand.cpp +++ b/consensuscommand.cpp @@ -10,36 +10,33 @@ #include "consensuscommand.h" //********************************************************************************************************************** -vector ConcensusCommand::getValidParameters(){ +vector ConcensusCommand::setParameters(){ try { - vector myArray; + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ConcensusCommand", "getValidParameters"); + m->errorOut(e, "ConcensusCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ConcensusCommand::getRequiredParameters(){ +string ConcensusCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The consensus command can only be executed after a successful read.tree command.\n"; + helpString += "The consensus command has no parameters.\n"; + helpString += "The consensus command should be in the following format: consensus().\n"; + helpString += "The consensus command output two files: .consensus.tre and .consensuspairs.\n"; + helpString += "The .consensus.tre file contains the consensus tree of the trees in your input file.\n"; + helpString += "The branch lengths are the percentage of trees in your input file that had the given pair.\n"; + helpString += "The .consensuspairs file contains a list of the internal nodes in your tree. For each node, the pair that was used in the consensus tree \n"; + helpString += "is reported with its percentage, as well as the other pairs that were seen for that node but not used and their percentages.\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ConcensusCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ConcensusCommand::getRequiredFiles(){ - try { - string AlignArray[] = {"tree","group"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ConcensusCommand", "getRequiredFiles"); + m->errorOut(e, "ConcensusCommand", "getHelpString"); exit(1); } } @@ -47,6 +44,7 @@ vector ConcensusCommand::getRequiredFiles(){ ConcensusCommand::ConcensusCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["tree"] = tempOutNames; outputTypes["nodepairs"] = tempOutNames; @@ -60,17 +58,16 @@ ConcensusCommand::ConcensusCommand(){ ConcensusCommand::ConcensusCommand(string fileroot) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; + setParameters(); + //initialize outputTypes vector tempOutNames; outputTypes["tree"] = tempOutNames; outputTypes["nodepairs"] = tempOutNames; filename = fileroot; - - t = globaldata->gTree; } catch(exception& e) { @@ -78,40 +75,19 @@ ConcensusCommand::ConcensusCommand(string fileroot) { exit(1); } } - -//********************************************************************************************************************** - -void ConcensusCommand::help(){ - try { - m->mothurOut("The consensus command can only be executed after a successful read.tree command.\n"); - m->mothurOut("The consensus command has no parameters.\n"); - m->mothurOut("The consensus command should be in the following format: consensus().\n"); - m->mothurOut("The consensus command output two files: .consensus.tre and .consensuspairs.\n"); - m->mothurOut("The .consensus.tre file contains the consensus tree of the trees in your input file.\n"); - m->mothurOut("The branch lengths are the percentage of trees in your input file that had the given pair.\n"); - m->mothurOut("The .consensuspairs file contains a list of the internal nodes in your tree. For each node, the pair that was used in the consensus tree \n"); - m->mothurOut("is reported with its percentage, as well as the other pairs that were seen for that node but not used and their percentages.\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ConcensusCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -ConcensusCommand::~ConcensusCommand(){} - //********************************************************************************************************************** int ConcensusCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - else { - numNodes = t[0]->getNumNodes(); - numLeaves = t[0]->getNumLeaves(); - } + + m->mothurOut("This command is not currently in use."); m->mothurOutEndLine(); + /* + t = globaldata->gTree; + numNodes = t[0]->getNumNodes(); + numLeaves = t[0]->getNumLeaves(); + //get the possible pairings getSets(); @@ -217,7 +193,7 @@ int ConcensusCommand::execute(){ if (itTypes != outputTypes.end()) { if ((itTypes->second).size() != 0) { currentTree = (itTypes->second)[0]; m->setTreeFile(currentTree); } } - + */ return 0; } catch(exception& e) { diff --git a/consensuscommand.h b/consensuscommand.h index d5072da..6bd5d3e 100644 --- a/consensuscommand.h +++ b/consensuscommand.h @@ -13,24 +13,24 @@ #include "tree.h" #include "treemap.h" #include "sharedutilities.h" - -class GlobalData; class ConcensusCommand : public Command { public: ConcensusCommand(string); ConcensusCommand(); - ~ConcensusCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ConcensusCommand() {} + + vector setParameters(); + string getCommandName() { return "concensus"; } + string getCommandCategory() { return "Hidden"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; SharedUtil* util; vector t; Tree* consensusTree; @@ -49,7 +49,6 @@ private: ofstream out, out2; int numNodes, numLeaves, count; //count is the next available spot in the tree vector vector outputNames; - map > outputTypes; int getSets(); int getSubgroupRating(vector); diff --git a/consensusseqscommand.cpp b/consensusseqscommand.cpp index 482bac5..bc47d8c 100644 --- a/consensusseqscommand.cpp +++ b/consensusseqscommand.cpp @@ -12,51 +12,58 @@ #include "inputdata.h" //********************************************************************************************************************** -vector ConsensusSeqsCommand::getValidParameters(){ +vector ConsensusSeqsCommand::setParameters(){ try { - string Array[] = {"fasta", "list", "name", "label","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plist); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ConsensusSeqsCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -ConsensusSeqsCommand::ConsensusSeqsCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["name"] = tempOutNames; - outputTypes["summary"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ConsensusSeqsCommand", "ConsensusSeqsCommand"); + m->errorOut(e, "ConsensusSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ConsensusSeqsCommand::getRequiredParameters(){ +string ConsensusSeqsCommand::getHelpString(){ try { - string Array[] = {"fasta", "list"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The consensus.seqs command can be used in 2 ways: create a consensus sequence from a fastafile, or with a listfile create a consensus sequence for each otu. Sequences must be aligned.\n"; + helpString += "The consensus.seqs command parameters are fasta, list, name and label.\n"; + helpString += "The fasta parameter allows you to enter the fasta file containing your sequences, and is required, unless you have a valid current fasta file. \n"; + helpString += "The list parameter allows you to enter a your list file. \n"; + helpString += "The name parameter allows you to enter a names file associated with the fasta file. \n"; + helpString += "The label parameter allows you to select what distance levels you would like output files for, and are separated by dashes.\n"; + helpString += "The consensus.seqs command should be in the following format: \n"; + helpString += "consensus.seqs(fasta=yourFastaFile, list=yourListFile) \n"; + helpString += "Example: consensus.seqs(fasta=abrecovery.align, list=abrecovery.fn.list) \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ConsensusSeqsCommand", "getRequiredParameters"); + m->errorOut(e, "ConsensusSeqsCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector ConsensusSeqsCommand::getRequiredFiles(){ +ConsensusSeqsCommand::ConsensusSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; + outputTypes["summary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "DegapSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "ConsensusSeqsCommand", "ConsensusSeqsCommand"); exit(1); } } @@ -70,9 +77,8 @@ ConsensusSeqsCommand::ConsensusSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","list","name","label", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -126,7 +132,11 @@ ConsensusSeqsCommand::ConsensusSeqsCommand(string option) { //check for parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the consensus.seqs command."); m->mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { abort = true; } @@ -153,31 +163,6 @@ ConsensusSeqsCommand::ConsensusSeqsCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ConsensusSeqsCommand::help(){ - try { - m->mothurOut("The consensus.seqs command can be used in 2 ways: create a consensus sequence from a fastafile, or with a listfile create a consensus sequence for each otu. Sequences must be aligned.\n"); - m->mothurOut("The consensus.seqs command parameters are fasta, list, name and label.\n"); - m->mothurOut("The fasta parameter allows you to enter the fasta file containing your sequences, and is required. \n"); - m->mothurOut("The list parameter allows you to enter a your list file. \n"); - m->mothurOut("The name parameter allows you to enter a names file associated with the fasta file. \n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like output files for, and are separated by dashes.\n"); - m->mothurOut("The consensus.seqs command should be in the following format: \n"); - m->mothurOut("consensus.seqs(fasta=yourFastaFile, list=yourListFile) \n"); - m->mothurOut("Example: consensus.seqs(fasta=abrecovery.align, list=abrecovery.fn.list) \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ConsensusSeqsCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -ConsensusSeqsCommand::~ConsensusSeqsCommand(){ /* do nothing */ } - //*************************************************************************************************************** int ConsensusSeqsCommand::execute(){ diff --git a/consensusseqscommand.h b/consensusseqscommand.h index 555b62c..07a4c08 100644 --- a/consensusseqscommand.h +++ b/consensusseqscommand.h @@ -18,13 +18,15 @@ class ConsensusSeqsCommand : public Command { public: ConsensusSeqsCommand(string); ConsensusSeqsCommand(); - ~ConsensusSeqsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ConsensusSeqsCommand(){} + + vector setParameters(); + string getCommandName() { return "consensus.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: @@ -32,7 +34,6 @@ private: string fastafile, listfile, namefile, label, outputDir; set labels; vector outputNames; - map > outputTypes; map fastaMap; map nameMap; map nameFileMap; diff --git a/corraxescommand.cpp b/corraxescommand.cpp index ae6ee3a..82cfa36 100644 --- a/corraxescommand.cpp +++ b/corraxescommand.cpp @@ -11,26 +11,46 @@ #include "sharedutilities.h" //********************************************************************************************************************** -vector CorrAxesCommand::getValidParameters(){ +vector CorrAxesCommand::setParameters(){ try { - string Array[] = {"axes","shared","relabund","numaxes","label","groups","method","metadata","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter paxes("axes", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paxes); + CommandParameter pshared("shared", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none",false,false); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none",false,false); parameters.push_back(prelabund); + CommandParameter pmetadata("metadata", "InputTypes", "", "", "SharedRelMeta", "SharedRelMeta", "none",false,false); parameters.push_back(pmetadata); + CommandParameter pnumaxes("numaxes", "Number", "", "3", "", "", "",false,false); parameters.push_back(pnumaxes); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pmethod("method", "Multiple", "pearson-spearman-kendall", "pearson", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "CorrAxesCommand", "getValidParameters"); + m->errorOut(e, "CorrAxesCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector CorrAxesCommand::getRequiredParameters(){ +string CorrAxesCommand::getHelpString(){ try { - string Array[] = {"axes"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The corr.axes command reads a shared, relabund or metadata file as well as an axes file and calculates the correlation coefficient.\n"; + helpString += "The corr.axes command parameters are shared, relabund, axes, metadata, groups, method, numaxes and label. The shared, relabund or metadata and axes parameters are required. If shared is given the relative abundance is calculated.\n"; + helpString += "The groups parameter allows you to specify which of the groups you would like included. The group names are separated by dashes.\n"; + helpString += "The label parameter allows you to select what distance level you would like used, if none is given the first distance is used.\n"; + helpString += "The method parameter allows you to select what method you would like to use. Options are pearson, spearman and kendall. Default=pearson.\n"; + helpString += "The numaxes parameter allows you to select the number of axes you would like to use. Default=3.\n"; + helpString += "The corr.axes command should be in the following format: corr.axes(axes=yourPcoaFile, shared=yourSharedFile, method=yourMethod).\n"; + helpString += "Example corr.axes(axes=genus.pool.thetayc.genus.lt.pcoa, shared=genus.pool.shared, method=kendall).\n"; + helpString += "The corr.axes command outputs a .corr.axes file.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "CorrAxesCommand", "getRequiredParameters"); + m->errorOut(e, "CorrAxesCommand", "getHelpString"); exit(1); } } @@ -38,6 +58,7 @@ vector CorrAxesCommand::getRequiredParameters(){ CorrAxesCommand::CorrAxesCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["corr.axes"] = tempOutNames; } @@ -46,31 +67,16 @@ CorrAxesCommand::CorrAxesCommand(){ exit(1); } } - -//********************************************************************************************************************** -vector CorrAxesCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "CorrAxesCommand", "getRequiredFiles"); - exit(1); - } -} //********************************************************************************************************************** CorrAxesCommand::CorrAxesCommand(string option) { try { abort = false; calledHelp = false; - globaldata = GlobalData::getInstance(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"axes","shared","relabund","numaxes","label","groups","method","metadata","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -151,14 +157,27 @@ CorrAxesCommand::CorrAxesCommand(string option) { pickedGroups = true; m->splitAtDash(groups, Groups); } - globaldata->Groups = Groups; + m->Groups = Groups; outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(inputFileName); } label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; m->mothurOut("You did not provide a label, I will use the first label in your inputfile."); m->mothurOutEndLine(); label=""; } - if ((relabundfile == "") && (sharedfile == "") && (metadatafile == "")) { m->mothurOut("You must provide either a shared, relabund, or metadata file."); m->mothurOutEndLine(); abort = true; } + if ((relabundfile == "") && (sharedfile == "") && (metadatafile == "")) { + //is there are current file available for any of these? + //give priority to shared, then relabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputFileName = sharedfile; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + relabundfile = m->getRelAbundFile(); + if (relabundfile != "") { inputFileName = relabundfile; m->mothurOut("Using " + relabundfile + " as input file for the relabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You must provide either a shared, relabund, or metadata file."); m->mothurOutEndLine(); abort = true; + } + } + } if (metadatafile != "") { if ((relabundfile != "") || (sharedfile != "")) { m->mothurOut("You may only use one of the following : shared, relabund or metadata file."); m->mothurOutEndLine(); abort = true; } @@ -182,31 +201,6 @@ CorrAxesCommand::CorrAxesCommand(string option) { } //********************************************************************************************************************** -void CorrAxesCommand::help(){ - try { - m->mothurOut("The corr.axes command reads a shared, relabund or metadata file as well as an axes file and calculates the correlation coefficient.\n"); - m->mothurOut("The corr.axes command parameters are shared, relabund, axes, metadata, groups, method, numaxes and label. The shared, relabund or metadata and axes parameters are required. If shared is given the relative abundance is calculated.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups you would like included. The group names are separated by dashes.\n"); - m->mothurOut("The label parameter allows you to select what distance level you would like used, if none is given the first distance is used.\n"); - m->mothurOut("The method parameter allows you to select what method you would like to use. Options are pearson, spearman and kendall. Default=pearson.\n"); - m->mothurOut("The numaxes parameter allows you to select the number of axes you would like to use. Default=3.\n"); - m->mothurOut("The corr.axes command should be in the following format: corr.axes(axes=yourPcoaFile, shared=yourSharedFile, method=yourMethod).\n"); - m->mothurOut("Example corr.axes(axes=genus.pool.thetayc.genus.lt.pcoa, shared=genus.pool.shared, method=kendall).\n"); - m->mothurOut("The corr.axes command outputs a .corr.axes file.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "CorrAxesCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -CorrAxesCommand::~CorrAxesCommand(){} - -//********************************************************************************************************************** - int CorrAxesCommand::execute(){ try { @@ -906,11 +900,11 @@ int CorrAxesCommand::getMetadata(){ SharedUtil* util; util = new SharedUtil(); - util->setGroups(globaldata->Groups, groupNames); + util->setGroups(m->Groups, groupNames); for (int i = 0; i < lookupFloat.size(); i++) { //if this sharedrabund is not from a group the user wants then delete it. - if (util->isValidGroup(lookupFloat[i]->getGroup(), globaldata->Groups) == false) { + if (util->isValidGroup(lookupFloat[i]->getGroup(), m->Groups) == false) { delete lookupFloat[i]; lookupFloat[i] = NULL; lookupFloat.erase(lookupFloat.begin()+i); i--; diff --git a/corraxescommand.h b/corraxescommand.h index bbe87ab..5f04c6a 100644 --- a/corraxescommand.h +++ b/corraxescommand.h @@ -19,25 +19,23 @@ class CorrAxesCommand : public Command { public: CorrAxesCommand(string); CorrAxesCommand(); - ~CorrAxesCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - -private: + ~CorrAxesCommand(){} + vector setParameters(); + string getCommandName() { return "corr.axes"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); - GlobalData* globaldata; + int execute(); + void help() { m->mothurOut(getHelpString()); } +private: + string axesfile, sharedfile, relabundfile, metadatafile, groups, label, inputFileName, outputDir, method; bool abort, pickedGroups; int numaxes; set names; vector outputNames, Groups; - map > outputTypes; vector lookupFloat; vector metadataLabels; diff --git a/datavector.hpp b/datavector.hpp index 3ecd407..734ace5 100644 --- a/datavector.hpp +++ b/datavector.hpp @@ -17,6 +17,7 @@ class SharedOrderVector; class SharedSAbundVector; class SharedRAbundVector; class SharedRAbundFloatVector; +class GroupMap; class DataVector { @@ -25,6 +26,7 @@ public: DataVector(string l) : label(l) {}; DataVector(const DataVector& dv) : label(dv.label){};//, maxRank(dv.maxRank), numBins(dv.numBins), numSeqs(dv.numSeqs) {}; DataVector(ifstream&); + DataVector(ifstream&, GroupMap*); virtual ~DataVector(){}; // virtual int getNumBins() { return numBins; } diff --git a/decalc.cpp b/decalc.cpp index 8d90a78..9894adb 100644 --- a/decalc.cpp +++ b/decalc.cpp @@ -952,7 +952,7 @@ map DeCalculator::trimSeqs(Sequence* query, vector topMatch map trimmedPos; //check to make sure that is not whole seq if ((rearPos - frontPos - 1) <= 0) { - m->mothurOut("[ERROR]: when I trim " + query->getName() + ", the entire sequence is trimmed. Skipping."); m->mothurOutEndLine(); + //m->mothurOut("[ERROR]: when I trim " + query->getName() + ", the entire sequence is trimmed. Skipping."); m->mothurOutEndLine(); query->setAligned(""); //trim topMatches for (int i = 0; i < topMatches.size(); i++) { diff --git a/deconvolutecommand.cpp b/deconvolutecommand.cpp index 62daa61..33e51ff 100644 --- a/deconvolutecommand.cpp +++ b/deconvolutecommand.cpp @@ -10,50 +10,50 @@ #include "deconvolutecommand.h" //********************************************************************************************************************** -vector DeconvoluteCommand::getValidParameters(){ +vector DeconvoluteCommand::setParameters(){ try { - string Array[] = {"fasta", "name","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter 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, "DeconvoluteCommand", "getValidParameters"); + m->errorOut(e, "DeconvoluteCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -DeconvoluteCommand::DeconvoluteCommand(){ +string DeconvoluteCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["name"] = tempOutNames; + string helpString = ""; + helpString += "The unique.seqs command reads a fastafile and creates a namesfile.\n"; + helpString += "It creates a file where the first column is the groupname and the second column is a list of sequence names who have the same sequence. \n"; + helpString += "If the sequence is unique the second column will just contain its name. \n"; + helpString += "The unique.seqs command parameters are fasta and name. fasta is required, unless there is a valid current fasta file.\n"; + helpString += "The unique.seqs command should be in the following format: \n"; + helpString += "unique.seqs(fasta=yourFastaFile) \n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "DeconvoluteCommand", "DeconvoluteCommand"); + m->errorOut(e, "DeconvoluteCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector DeconvoluteCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "DeconvoluteCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector DeconvoluteCommand::getRequiredFiles(){ +DeconvoluteCommand::DeconvoluteCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "DeconvoluteCommand", "getRequiredFiles"); + m->errorOut(e, "DeconvoluteCommand", "DeconvoluteCommand"); exit(1); } } @@ -66,9 +66,7 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta", "name","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -112,7 +110,11 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { //check for required parameters inFastaName = validParameter.validFile(parameters, "fasta", true); if (inFastaName == "not open") { abort = true; } - else if (inFastaName == "not found") { inFastaName = ""; m->mothurOut("fasta is a required parameter for the unique.seqs command."); m->mothurOutEndLine(); abort = true; } + else if (inFastaName == "not found") { + inFastaName = m->getFastaFile(); + if (inFastaName != "") { m->mothurOut("Using " + inFastaName + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } //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"){ @@ -131,23 +133,6 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void DeconvoluteCommand::help(){ - try { - m->mothurOut("The unique.seqs command reads a fastafile and creates a namesfile.\n"); - m->mothurOut("It creates a file where the first column is the groupname and the second column is a list of sequence names who have the same sequence. \n"); - m->mothurOut("If the sequence is unique the second column will just contain its name. \n"); - m->mothurOut("The unique.seqs command parameter is fasta and it is required.\n"); - m->mothurOut("The unique.seqs command should be in the following format: \n"); - m->mothurOut("unique.seqs(fasta=yourFastaFile) \n"); - } - catch(exception& e) { - m->errorOut(e, "DeconvoluteCommand", "help"); - exit(1); - } -} - /**************************************************************************************/ int DeconvoluteCommand::execute() { try { diff --git a/deconvolutecommand.h b/deconvolutecommand.h index 88b7a38..8a1cb87 100644 --- a/deconvolutecommand.h +++ b/deconvolutecommand.h @@ -22,17 +22,19 @@ public: DeconvoluteCommand(string); DeconvoluteCommand(); ~DeconvoluteCommand() {} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "unique.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: string inFastaName, oldNameMapFName, outputDir; vector outputNames; - map > outputTypes; bool abort; }; diff --git a/degapseqscommand.cpp b/degapseqscommand.cpp index 7fd2803..81002c8 100644 --- a/degapseqscommand.cpp +++ b/degapseqscommand.cpp @@ -11,49 +11,50 @@ #include "sequence.hpp" //********************************************************************************************************************** -vector DegapSeqsCommand::getValidParameters(){ +vector DegapSeqsCommand::setParameters(){ try { - string Array[] = {"fasta", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "DegapSeqsCommand", "getValidParameters"); + m->errorOut(e, "DegapSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -DegapSeqsCommand::DegapSeqsCommand(){ +string DegapSeqsCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; + string helpString = ""; + helpString += "The degap.seqs command reads a fastafile and removes all gap characters.\n"; + helpString += "The degap.seqs command parameter is fasta.\n"; + helpString += "The fasta parameter allows you to enter the fasta file containing your sequences, and is required unless you have a valid current fasta file. \n"; + helpString += "You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"; + helpString += "The degap.seqs command should be in the following format: \n"; + helpString += "degap.seqs(fasta=yourFastaFile) \n"; + helpString += "Example: degap.seqs(fasta=abrecovery.align) \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "DegapSeqsCommand", "DegapSeqsCommand"); + m->errorOut(e, "DegapSeqsCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector DegapSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "DegapSeqsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector DegapSeqsCommand::getRequiredFiles(){ +DegapSeqsCommand::DegapSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "DegapSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "DegapSeqsCommand", "DegapSeqsCommand"); exit(1); } } @@ -66,9 +67,7 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -92,7 +91,11 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", false); - if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the degap.seqs command."); m->mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { fastaFileNames.push_back(fastafile); m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } else { m->splitAtDash(fastafile, fastaFileNames); @@ -159,32 +162,7 @@ DegapSeqsCommand::DegapSeqsCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void DegapSeqsCommand::help(){ - try { - m->mothurOut("The degap.seqs command reads a fastafile and removes all gap characters.\n"); - m->mothurOut("The degap.seqs command parameter is fasta.\n"); - m->mothurOut("The fasta parameter allows you to enter the fasta file containing your sequences, and is required. \n"); - m->mothurOut("You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"); - m->mothurOut("The degap.seqs command should be in the following format: \n"); - m->mothurOut("degap.seqs(fasta=yourFastaFile) \n"); - m->mothurOut("Example: degap.seqs(fasta=abrecovery.align) \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "DegapSeqsCommand", "help"); - exit(1); - } -} - //*************************************************************************************************************** - -DegapSeqsCommand::~DegapSeqsCommand(){ /* do nothing */ } - -//*************************************************************************************************************** - - int DegapSeqsCommand::execute(){ try{ diff --git a/degapseqscommand.h b/degapseqscommand.h index 5501d49..db93b02 100644 --- a/degapseqscommand.h +++ b/degapseqscommand.h @@ -17,13 +17,15 @@ class DegapSeqsCommand : public Command { public: DegapSeqsCommand(string); DegapSeqsCommand(); - ~DegapSeqsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~DegapSeqsCommand(){} + + vector setParameters(); + string getCommandName() { return "degap.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: @@ -31,7 +33,7 @@ private: string fastafile, outputDir; vector outputNames; vector fastaFileNames; - map > outputTypes; + }; #endif diff --git a/deuniqueseqscommand.cpp b/deuniqueseqscommand.cpp index 1d87204..fb02764 100644 --- a/deuniqueseqscommand.cpp +++ b/deuniqueseqscommand.cpp @@ -11,49 +11,49 @@ #include "sequence.hpp" //********************************************************************************************************************** -vector DeUniqueSeqsCommand::getValidParameters(){ +vector DeUniqueSeqsCommand::setParameters(){ try { - string Array[] = {"fasta", "name","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pname); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "DeUniqueSeqsCommand", "getValidParameters"); + m->errorOut(e, "DeUniqueSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -DeUniqueSeqsCommand::DeUniqueSeqsCommand(){ +string DeUniqueSeqsCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; + string helpString = ""; + helpString += "The deunique.seqs command reads a fastafile and namefile, and creates a fastafile containing all the sequences.\n"; + helpString += "The deunique.seqs command parameters are fasta and name, both are required, unless you have valid current name and fasta files.\n"; + helpString += "The deunique.seqs command should be in the following format: \n"; + helpString += "deunique.seqs(fasta=yourFastaFile, name=yourNameFile) \n"; + helpString += "Example deunique.seqs(fasta=abrecovery.unique.fasta, name=abrecovery.names).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "DeUniqueSeqsCommand", "DeconvoluteCommand"); + m->errorOut(e, "DeUniqueSeqsCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector DeUniqueSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta","name"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "DeUniqueSeqsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector DeUniqueSeqsCommand::getRequiredFiles(){ +DeUniqueSeqsCommand::DeUniqueSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "DeUniqueSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "DeUniqueSeqsCommand", "DeconvoluteCommand"); exit(1); } } @@ -66,9 +66,7 @@ DeUniqueSeqsCommand::DeUniqueSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta", "name","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -111,7 +109,11 @@ DeUniqueSeqsCommand::DeUniqueSeqsCommand(string option) { //check for required parameters fastaFile = validParameter.validFile(parameters, "fasta", true); if (fastaFile == "not open") { abort = true; } - else if (fastaFile == "not found") { fastaFile = ""; m->mothurOut("fasta is a required parameter for the deunique.seqs command."); m->mothurOutEndLine(); abort = true; } + else if (fastaFile == "not found") { + fastaFile = m->getFastaFile(); + if (fastaFile != "") { m->mothurOut("Using " + fastaFile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } //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"){ @@ -121,7 +123,11 @@ DeUniqueSeqsCommand::DeUniqueSeqsCommand(string option) { nameFile = validParameter.validFile(parameters, "name", true); if (nameFile == "not open") { abort = true; } - else if (nameFile == "not found"){ nameFile = ""; m->mothurOut("name is a required parameter for the deunique.seqs command."); m->mothurOutEndLine(); abort = true; } + else if (nameFile == "not found"){ + nameFile = m->getNameFile(); + if (nameFile != "") { m->mothurOut("Using " + nameFile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current namefile and the name parameter is required."); m->mothurOutEndLine(); abort = true; } + } } } @@ -130,24 +136,6 @@ DeUniqueSeqsCommand::DeUniqueSeqsCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void DeUniqueSeqsCommand::help(){ - try { - m->mothurOut("The deunique.seqs command reads a fastafile and namefile, and creates a fastafile containing all the sequences.\n"); - m->mothurOut("The deunique.seqs command parameters are fasta and name, both are required.\n"); - m->mothurOut("The deunique.seqs command should be in the following format: \n"); - m->mothurOut("deunique.seqs(fasta=yourFastaFile, name=yourNameFile) \n"); - m->mothurOut("Example deunique.seqs(fasta=abrecovery.unique.fasta, name=abrecovery.names).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "DeUniqueSeqsCommand", "help"); - exit(1); - } -} - /**************************************************************************************/ int DeUniqueSeqsCommand::execute() { try { diff --git a/deuniqueseqscommand.h b/deuniqueseqscommand.h index 13176a8..96ed29b 100644 --- a/deuniqueseqscommand.h +++ b/deuniqueseqscommand.h @@ -19,18 +19,20 @@ public: DeUniqueSeqsCommand(string); DeUniqueSeqsCommand(); ~DeUniqueSeqsCommand() {} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "deunique.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: string fastaFile, nameFile, outputDir; vector outputNames; - map > outputTypes; bool abort; map nameMap; diff --git a/distancecommand.cpp b/distancecommand.cpp index 5ffe0da..029b581 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -14,52 +14,66 @@ #include "onegapdist.h" #include "onegapignore.h" - //********************************************************************************************************************** -vector DistanceCommand::getValidParameters(){ +vector DistanceCommand::setParameters(){ try { - string Array[] = {"fasta","oldfasta","column", "output", "calc", "countends", "cutoff", "processors", "outputdir","inputdir","compress"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "OldFastaColumn",false,false); parameters.push_back(pcolumn); + CommandParameter poldfasta("oldfasta", "InputTypes", "", "", "none", "none", "OldFastaColumn",false,false); parameters.push_back(poldfasta); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter poutput("output", "Multiple", "column-lt-square", "column", "", "", "",false,false); parameters.push_back(poutput); + CommandParameter pcalc("calc", "Multiple", "nogaps-eachgap-onegap", "onegap", "", "", "",false,false); parameters.push_back(pcalc); + CommandParameter pcountends("countends", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pcountends); + CommandParameter pcompress("compress", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pcompress); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pcutoff("cutoff", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "DistanceCommand", "getValidParameters"); + m->errorOut(e, "DistanceCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -DistanceCommand::DistanceCommand(){ +string DistanceCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["phylip"] = tempOutNames; - outputTypes["column"] = tempOutNames; + string helpString = ""; + helpString += "The dist.seqs command reads a file containing sequences and creates a distance file.\n"; + helpString += "The dist.seqs command parameters are fasta, oldfasta, column, calc, countends, output, compress, cutoff and processors. \n"; + helpString += "The fasta parameter is required, unless you have a valid current fasta file.\n"; + helpString += "The oldfasta and column parameters allow you to append the distances calculated to the column file.\n"; + helpString += "The calc parameter allows you to specify the method of calculating the distances. Your options are: nogaps, onegap or eachgap. The default is onegap.\n"; + helpString += "The countends parameter allows you to specify whether to include terminal gaps in distance. Your options are: T or F. The default is T.\n"; + helpString += "The cutoff parameter allows you to specify maximum distance to keep. The default is 1.0.\n"; + helpString += "The output parameter allows you to specify format of your distance matrix. Options are column, lt, and square. The default is column.\n"; + helpString += "The processors parameter allows you to specify number of processors to use. The default is 1.\n"; + helpString += "The compress parameter allows you to indicate that you want the resulting distance file compressed. The default is false.\n"; + helpString += "The dist.seqs command should be in the following format: \n"; + helpString += "dist.seqs(fasta=yourFastaFile, calc=yourCalc, countends=yourEnds, cutoff= yourCutOff, processors=yourProcessors) \n"; + helpString += "Example dist.seqs(fasta=amazon.fasta, calc=eachgap, countends=F, cutoff= 2.0, processors=3).\n"; + helpString += "Note: No spaces between parameter labels (i.e. calc), '=' and parameters (i.e.yourCalc).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "DistanceCommand", "DistanceCommand"); + m->errorOut(e, "DistanceCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector DistanceCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "DistanceCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector DistanceCommand::getRequiredFiles(){ +DistanceCommand::DistanceCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["phylip"] = tempOutNames; + outputTypes["column"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "DistanceCommand", "getRequiredFiles"); + m->errorOut(e, "DistanceCommand", "DistanceCommand"); exit(1); } } @@ -73,10 +87,7 @@ DistanceCommand::DistanceCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","oldfasta","column", "output", "calc", "countends", "cutoff", "processors", "outputdir","inputdir","compress"}; - - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -126,8 +137,15 @@ DistanceCommand::DistanceCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the dist.seqs command."); m->mothurOutEndLine(); abort = true; } - else if (fastafile == "not open") { abort = true; } + if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); + ifstream inFASTA; + m->openInputFile(fastafile, inFASTA); + alignDB = SequenceDB(inFASTA); + inFASTA.close(); + }else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + }else if (fastafile == "not open") { abort = true; } else{ ifstream inFASTA; m->openInputFile(fastafile, inFASTA); @@ -165,8 +183,9 @@ DistanceCommand::DistanceCommand(string option) { temp = validParameter.validFile(parameters, "cutoff", false); if(temp == "not found"){ temp = "1.0"; } convert(temp, cutoff); - temp = validParameter.validFile(parameters, "processors", false); if(temp == "not found"){ temp = "1"; } - convert(temp, processors); + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); temp = validParameter.validFile(parameters, "compress", false); if(temp == "not found"){ temp = "F"; } convert(temp, compress); @@ -207,35 +226,6 @@ DistanceCommand::DistanceCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -DistanceCommand::~DistanceCommand(){} - -//********************************************************************************************************************** - -void DistanceCommand::help(){ - try { - m->mothurOut("The dist.seqs command reads a file containing sequences and creates a distance file.\n"); - m->mothurOut("The dist.seqs command parameters are fasta, oldfasta, column, calc, countends, output, compress, cutoff and processors. \n"); - m->mothurOut("The fasta parameter is required.\n"); - m->mothurOut("The oldfasta and column parameters allow you to append the distances calculated to the column file.\n"); - m->mothurOut("The calc parameter allows you to specify the method of calculating the distances. Your options are: nogaps, onegap or eachgap. The default is onegap.\n"); - m->mothurOut("The countends parameter allows you to specify whether to include terminal gaps in distance. Your options are: T or F. The default is T.\n"); - m->mothurOut("The cutoff parameter allows you to specify maximum distance to keep. The default is 1.0.\n"); - m->mothurOut("The output parameter allows you to specify format of your distance matrix. Options are column, lt, and square. The default is column.\n"); - m->mothurOut("The processors parameter allows you to specify number of processors to use. The default is 1.\n"); - m->mothurOut("The compress parameter allows you to indicate that you want the resulting distance file compressed. The default is false.\n"); - m->mothurOut("The dist.seqs command should be in the following format: \n"); - m->mothurOut("dist.seqs(fasta=yourFastaFile, calc=yourCalc, countends=yourEnds, cutoff= yourCutOff, processors=yourProcessors) \n"); - m->mothurOut("Example dist.seqs(fasta=amazon.fasta, calc=eachgap, countends=F, cutoff= 2.0, processors=3).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. calc), '=' and parameters (i.e.yourCalc).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "DistanceCommand", "help"); - exit(1); - } -} //********************************************************************************************************************** int DistanceCommand::execute(){ diff --git a/distancecommand.h b/distancecommand.h index 595483d..23cc6a5 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -22,13 +22,16 @@ class DistanceCommand : public Command { public: DistanceCommand(string); DistanceCommand(); - ~DistanceCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~DistanceCommand() {} + + vector setParameters(); + string getCommandName() { return "dist.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: struct distlinePair { @@ -49,7 +52,6 @@ private: bool abort; vector Estimators, outputNames; //holds estimators to be used - map > outputTypes; //void m->appendFiles(string, string); void createProcesses(string); diff --git a/engine.cpp b/engine.cpp index 5419717..dbdcc36 100644 --- a/engine.cpp +++ b/engine.cpp @@ -95,14 +95,13 @@ string Engine::findMothursPath(){ InteractEngine::InteractEngine(string path){ - globaldata = GlobalData::getInstance(); string temppath = path.substr(0, (path.find_last_of("othur")-5)); //this will happen if you set the path variable to contain mothur's exe location if (temppath == "") { path = findMothursPath(); } - globaldata->argv = path; + mout->argv = path; } /***********************************************************************/ @@ -250,7 +249,6 @@ string Engine::getCommand() { //This function opens the batchfile to be used by BatchEngine::getInput. BatchEngine::BatchEngine(string path, string batchFileName){ try { - globaldata = GlobalData::getInstance(); openedBatch = mout->openInputFile(batchFileName, inputBatchFile); @@ -259,7 +257,7 @@ BatchEngine::BatchEngine(string path, string batchFileName){ //this will happen if you set the path variable to contain mothur's exe location if (temppath == "") { path = findMothursPath(); } - globaldata->argv = path; + mout->argv = path; } catch(exception& e) { @@ -406,7 +404,6 @@ string BatchEngine::getNextCommand(ifstream& inputBatchFile) { //This function opens the batchfile to be used by BatchEngine::getInput. ScriptEngine::ScriptEngine(string path, string commandString){ try { - globaldata = GlobalData::getInstance(); //remove quotes listOfCommands = commandString.substr(1, (commandString.length()-1)); @@ -416,7 +413,7 @@ ScriptEngine::ScriptEngine(string path, string commandString){ //this will happen if you set the path variable to contain mothur's exe location if (temppath == "") { path = findMothursPath(); } - globaldata->argv = path; + mout->argv = path; } catch(exception& e) { diff --git a/engine.hpp b/engine.hpp index d5846ba..5311da9 100644 --- a/engine.hpp +++ b/engine.hpp @@ -13,14 +13,11 @@ #include "mothur.h" -#include "globaldata.hpp" #include "commandoptionparser.hpp" #include "command.hpp" #include "commandfactory.hpp" #include "mothurout.h" -class GlobalData; - class Engine { public: Engine(); @@ -48,7 +45,6 @@ public: virtual bool getInput(); int openedBatch; private: - GlobalData* globaldata; ifstream inputBatchFile; string getNextCommand(ifstream&); @@ -62,7 +58,7 @@ public: ~InteractEngine(); virtual bool getInput(); private: - GlobalData* globaldata; + }; @@ -73,7 +69,6 @@ public: virtual bool getInput(); int openedBatch; private: - GlobalData* globaldata; string listOfCommands; string getNextCommand(string&); diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index cb0b131..02bc192 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -10,51 +10,63 @@ #include "filterseqscommand.h" #include "sequence.hpp" + //********************************************************************************************************************** -vector FilterSeqsCommand::getValidParameters(){ +vector FilterSeqsCommand::setParameters(){ try { - string Array[] = {"fasta", "trump", "soft", "hard", "vertical", "outputdir","inputdir", "processors"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter phard("hard", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(phard); + CommandParameter ptrump("trump", "String", "", "*", "", "", "",false,false); parameters.push_back(ptrump); + CommandParameter psoft("soft", "Number", "", "0", "", "", "",false,false); parameters.push_back(psoft); + CommandParameter pvertical("vertical", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pvertical); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "FilterSeqsCommand", "getValidParameters"); + m->errorOut(e, "FilterSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -FilterSeqsCommand::FilterSeqsCommand(){ +string FilterSeqsCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["filter"] = tempOutNames; + string helpString = ""; + helpString += "The filter.seqs command reads a file containing sequences and creates a .filter and .filter.fasta file.\n"; + helpString += "The filter.seqs command parameters are fasta, trump, soft, hard, processors and vertical. \n"; + helpString += "The fasta parameter is required, unless you have a valid current fasta file. You may enter several fasta files to build the filter from and filter, by separating their names with -'s.\n"; + helpString += "For example: fasta=abrecovery.fasta-amazon.fasta \n"; + helpString += "The trump option will remove a column if the trump character is found at that position in any sequence of the alignment. Default=*, meaning no trump. \n"; + helpString += "A soft mask removes any column where the dominant base (i.e. A, T, G, C, or U) does not occur in at least a designated percentage of sequences. Default=0.\n"; + helpString += "The hard parameter allows you to enter a file containing the filter you want to use.\n"; + helpString += "The vertical parameter removes columns where all sequences contain a gap character. The default is T.\n"; + helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n"; + helpString += "The filter.seqs command should be in the following format: \n"; + helpString += "filter.seqs(fasta=yourFastaFile, trump=yourTrump) \n"; + helpString += "Example filter.seqs(fasta=abrecovery.fasta, trump=.).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "FilterSeqsCommand", "FilterSeqsCommand"); + m->errorOut(e, "FilterSeqsCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector FilterSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "FilterSeqsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector FilterSeqsCommand::getRequiredFiles(){ +FilterSeqsCommand::FilterSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["filter"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "FilterSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "FilterSeqsCommand", "FilterSeqsCommand"); exit(1); } } @@ -68,9 +80,7 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta", "trump", "soft", "hard", "vertical", "outputdir","inputdir", "processors"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -112,7 +122,11 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { //check for required parameters fasta = validParameter.validFile(parameters, "fasta", false); - if (fasta == "not found") { m->mothurOut("fasta is a required parameter for the filter.seqs command."); m->mothurOutEndLine(); abort = true; } + if (fasta == "not found") { + fasta = m->getFastaFile(); + if (fasta != "") { fastafileNames.push_back(fasta); m->mothurOut("Using " + fasta + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } else { m->splitAtDash(fasta, fastafileNames); @@ -189,7 +203,8 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { temp = validParameter.validFile(parameters, "soft", false); if (temp == "not found") { soft = 0; } else { soft = (float)atoi(temp.c_str()) / 100.0; } - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); vertical = validParameter.validFile(parameters, "vertical", false); @@ -207,33 +222,6 @@ FilterSeqsCommand::FilterSeqsCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void FilterSeqsCommand::help(){ - try { - - m->mothurOut("The filter.seqs command reads a file containing sequences and creates a .filter and .filter.fasta file.\n"); - m->mothurOut("The filter.seqs command parameters are fasta, trump, soft, hard, processors and vertical. \n"); - m->mothurOut("The fasta parameter is required. You may enter several fasta files to build the filter from and filter, by separating their names with -'s.\n"); - m->mothurOut("For example: fasta=abrecovery.fasta-amazon.fasta \n"); - m->mothurOut("The trump parameter .... The default is ...\n"); - m->mothurOut("The soft parameter .... The default is ....\n"); - m->mothurOut("The hard parameter allows you to enter a file containing the filter you want to use.\n"); - m->mothurOut("The vertical parameter removes columns where all sequences contain a gap character. The default is T.\n"); - m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); - m->mothurOut("The filter.seqs command should be in the following format: \n"); - m->mothurOut("filter.seqs(fasta=yourFastaFile, trump=yourTrump) \n"); - m->mothurOut("Example filter.seqs(fasta=abrecovery.fasta, trump=.).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "FilterSeqsCommand", "help"); - exit(1); - } -} - /**************************************************************************************/ int FilterSeqsCommand::execute() { diff --git a/filterseqscommand.h b/filterseqscommand.h index c670f37..75e7895 100644 --- a/filterseqscommand.h +++ b/filterseqscommand.h @@ -20,12 +20,14 @@ public: FilterSeqsCommand(string); FilterSeqsCommand(); ~FilterSeqsCommand() {}; - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "filter.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: struct linePair { @@ -42,7 +44,6 @@ private: int alignmentLength, processors; vector bufferSizes; vector outputNames; - map > outputTypes; char trump; bool abort; diff --git a/fullmatrix.cpp b/fullmatrix.cpp index fe61307..4451d66 100644 --- a/fullmatrix.cpp +++ b/fullmatrix.cpp @@ -11,11 +11,9 @@ /**************************************************************************/ //This constructor reads a distance matrix file and stores the data in the matrix. -FullMatrix::FullMatrix(ifstream& filehandle) { +FullMatrix::FullMatrix(ifstream& filehandle, GroupMap* g, bool s) : groupmap(g), sim(s) { try{ m = MothurOut::getInstance(); - globaldata = GlobalData::getInstance(); - groupmap = globaldata->gGroupmap; string name, group; @@ -45,7 +43,7 @@ FullMatrix::FullMatrix(ifstream& filehandle) { for(int i=0;i> matrix[0][i]; - if (globaldata->sim) { matrix[0][i] = 1.0 - matrix[0][i]; } + if (sim) { matrix[0][i] = 1.0 - matrix[0][i]; } } break; } @@ -95,7 +93,7 @@ int FullMatrix::readSquareMatrix(ifstream& filehandle) { if (m->control_pressed) { delete reading; return 0; } filehandle >> matrix[i][j]; - if (globaldata->sim) { matrix[i][j] = 1.0 - matrix[i][j]; } + if (sim) { matrix[i][j] = 1.0 - matrix[i][j]; } count++; reading->update(count); @@ -139,7 +137,7 @@ int FullMatrix::readLTMatrix(ifstream& filehandle) { if (m->control_pressed) { delete reading; return 0; } filehandle >> distance; - if (globaldata->sim) { distance = 1.0 - distance; } + if (sim) { distance = 1.0 - distance; } matrix[i][j] = distance; matrix[j][i] = distance; diff --git a/fullmatrix.h b/fullmatrix.h index e2c0e31..9de7ead 100644 --- a/fullmatrix.h +++ b/fullmatrix.h @@ -11,7 +11,6 @@ #include "mothur.h" #include "groupmap.h" -#include "globaldata.hpp" #include "progress.hpp" @@ -23,8 +22,8 @@ struct Names { class FullMatrix { public: - FullMatrix(){ m = MothurOut::getInstance(); } - FullMatrix(ifstream&); + //FullMatrix(){ m = MothurOut::getInstance(); } + FullMatrix(ifstream&, GroupMap*, bool); ~FullMatrix(){}; int getNumSeqs(); @@ -52,7 +51,7 @@ private: int numSeqs; int numGroups; int numUserGroups; - GlobalData* globaldata; + bool sim; MothurOut* m; }; diff --git a/getcurrentcommand.cpp b/getcurrentcommand.cpp index bd7539a..7bfae20 100644 --- a/getcurrentcommand.cpp +++ b/getcurrentcommand.cpp @@ -9,48 +9,46 @@ #include "getcurrentcommand.h" - //********************************************************************************************************************** -vector GetCurrentCommand::getValidParameters(){ +vector GetCurrentCommand::setParameters(){ try { - string Array[] = {"outputdir","inputdir","clear"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pclear("clear", "String", "", "", "", "", "",false,false); parameters.push_back(pclear); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetCurrentCommand", "getValidParameters"); + m->errorOut(e, "GetCurrentCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -GetCurrentCommand::GetCurrentCommand(){ +string GetCurrentCommand::getHelpString(){ try { - abort = true; calledHelp = true; + string helpString = ""; + helpString += "The get.current command outputs the current files saved by mothur.\n"; + helpString += "The get.current command has one parameter: clear.\n"; + helpString += "The clear paramter is used to indicate which file types you would like to clear values for, multiple types can be separated by dashes.\n"; + helpString += "The get.current command should be in the following format: \n"; + helpString += "get.current() or get.current(clear=fasta-name-accnos)\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand"); + m->errorOut(e, "GetCurrentCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector GetCurrentCommand::getRequiredParameters(){ +GetCurrentCommand::GetCurrentCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); } catch(exception& e) { - m->errorOut(e, "GetCurrentCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector GetCurrentCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetCurrentCommand", "getRequiredFiles"); + m->errorOut(e, "GetCurrentCommand", "GetCurrentCommand"); exit(1); } } @@ -63,9 +61,7 @@ GetCurrentCommand::GetCurrentCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"outputdir","inputdir","clear"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -89,25 +85,6 @@ GetCurrentCommand::GetCurrentCommand(string option) { } //********************************************************************************************************************** -void GetCurrentCommand::help(){ - try { - m->mothurOut("The get.current command outputs the current files saved by mothur.\n"); - m->mothurOut("The get.current command has one parameter: clear.\n"); - m->mothurOut("The clear paramter is used to indicate which file types you would like to clear values for, multiple types can be separated by dashes.\n"); - m->mothurOut("The get.current command should be in the following format: \n"); - m->mothurOut("get.current() or get.current(clear=fasta-name-accnos)\n"); - - } - catch(exception& e) { - m->errorOut(e, "GetCurrentCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** -GetCurrentCommand::~GetCurrentCommand(){} -//********************************************************************************************************************** - int GetCurrentCommand::execute(){ try { diff --git a/getcurrentcommand.h b/getcurrentcommand.h index c36b6a5..aa4f8f4 100644 --- a/getcurrentcommand.h +++ b/getcurrentcommand.h @@ -17,18 +17,20 @@ class GetCurrentCommand : public Command { public: GetCurrentCommand(string); GetCurrentCommand(); - ~GetCurrentCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + ~GetCurrentCommand() {} + + vector setParameters(); + string getCommandName() { return "get.current"; } + string getCommandCategory() { return "General"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + + private: vector outputNames; - map > outputTypes; bool abort; string clearTypes; diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index ab3ccfa..ce3cf73 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -10,56 +10,54 @@ #include "getgroupcommand.h" //********************************************************************************************************************** -vector GetgroupCommand::getValidParameters(){ +vector GetgroupCommand::setParameters(){ try { - string Array[] = {"outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetgroupCommand", "getValidParameters"); + m->errorOut(e, "GetgroupCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -GetgroupCommand::GetgroupCommand(){ +string GetgroupCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["bootgroup"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector GetgroupCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; + 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"; + helpString += "Example get.group().\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetgroupCommand", "getRequiredParameters"); + m->errorOut(e, "GetgroupCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector GetgroupCommand::getRequiredFiles(){ +GetgroupCommand::GetgroupCommand(){ try { - string Array[] = {"shared"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["bootgroup"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "GetgroupCommand", "getRequiredFiles"); + m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); exit(1); } } //********************************************************************************************************************** GetgroupCommand::GetgroupCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; //allow user to run help @@ -72,10 +70,11 @@ GetgroupCommand::GetgroupCommand(string option) { OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } @@ -83,22 +82,33 @@ GetgroupCommand::GetgroupCommand(string option) { vector tempOutNames; outputTypes["bootgroup"] = tempOutNames; - //if the user changes the output directory command factory will send this info to us in the output parameter - string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } + //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("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; } + } + } - if ((globaldata->getSharedFile() == "")) { m->mothurOut("You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command."); m->mothurOutEndLine(); abort = true; } - - if (abort == false) { - //open shared file - sharedfile = globaldata->getSharedFile(); - m->openInputFile(sharedfile, in); - - //open output file - if (outputDir == "") { outputDir += m->hasPath(sharedfile); } - outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "bootGroups"; - m->openOutputFile(outputFile, out); - + //get shared file + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current sharedfile and the shared 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(sharedfile); } } } catch(exception& e) { @@ -108,34 +118,18 @@ GetgroupCommand::GetgroupCommand(string option) { } //********************************************************************************************************************** -void GetgroupCommand::help(){ - try { - m->mothurOut("The get.group command can only be executed after a successful read.otu command.\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"); - m->mothurOut("You may not use any parameters with the get.group command.\n"); - m->mothurOut("The get.group command should be in the following format: \n"); - m->mothurOut("get.group()\n"); - m->mothurOut("Example get.group().\n"); - - } - catch(exception& e) { - m->errorOut(e, "GetgroupCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -GetgroupCommand::~GetgroupCommand(){ -} - -//********************************************************************************************************************** - int GetgroupCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - + + //open shared file + m->openInputFile(sharedfile, in); + + //open output file + outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "bootGroups"; + m->openOutputFile(outputFile, out); + int num, inputData, count; count = 0; string holdLabel, nextLabel, groupN, label; diff --git a/getgroupcommand.h b/getgroupcommand.h index fb3e810..79dd805 100644 --- a/getgroupcommand.h +++ b/getgroupcommand.h @@ -11,26 +11,26 @@ */ #include "command.hpp" -#include "globaldata.hpp" class GetgroupCommand : public Command { public: GetgroupCommand(string); GetgroupCommand(); - ~GetgroupCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~GetgroupCommand() {} + + vector setParameters(); + string getCommandName() { return "get.group"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; - GroupMap* groupMap; - string outputFile, sharedfile; + + string outputFile, sharedfile, outputDir; vector outputNames; - map > outputTypes; ofstream out; ifstream in; bool abort; diff --git a/getgroupscommand.cpp b/getgroupscommand.cpp index 84b168a..aae7488 100644 --- a/getgroupscommand.cpp +++ b/getgroupscommand.cpp @@ -13,21 +13,52 @@ #include "sharedutilities.h" //********************************************************************************************************************** -vector GetGroupsCommand::getValidParameters(){ +vector GetGroupsCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "accnos", "groups","list","taxonomy","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetGroupsCommand", "getValidParameters"); + m->errorOut(e, "GetGroupsCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string GetGroupsCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The get.groups command selects sequences from a specfic group or set of groups from the following file types: fasta, name, group, list, taxonomy.\n"; + helpString += "It outputs a file containing the sequences in the those specified groups.\n"; + helpString += "The get.groups command parameters are accnos, fasta, name, group, list, taxonomy and groups. The group parameter is required, unless you have a current group file.\n"; + helpString += "You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n"; + helpString += "The get.groups command should be in the following format: get.groups(accnos=yourAccnos, fasta=yourFasta, group=yourGroupFile).\n"; + helpString += "Example get.groups(accnos=amazon.accnos, fasta=amazon.fasta, group=amazon.groups).\n"; + helpString += "or get.groups(groups=pasture, fasta=amazon.fasta, group=amazon.groups).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "GetGroupsCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** GetGroupsCommand::GetGroupsCommand(){ try { - abort = true; calledHelp = true; + abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["taxonomy"] = tempOutNames; @@ -41,29 +72,6 @@ GetGroupsCommand::GetGroupsCommand(){ } } //********************************************************************************************************************** -vector GetGroupsCommand::getRequiredParameters(){ - try { - string Array[] = {"group"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetGroupsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector GetGroupsCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetGroupsCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** GetGroupsCommand::GetGroupsCommand(string option) { try { abort = false; calledHelp = false; @@ -72,9 +80,7 @@ GetGroupsCommand::GetGroupsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name", "group", "accnos", "groups", "list","taxonomy","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -169,7 +175,12 @@ GetGroupsCommand::GetGroupsCommand(string option) { groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; m->mothurOut("You must provide a group file."); m->mothurOutEndLine(); abort = true; } + else if (groupfile == "not found") { + //if there is a current group file, use it + groupfile = m->getGroupFile(); + if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current groupfile and the group parameter is required."); m->mothurOutEndLine(); abort = true; } + } listfile = validParameter.validFile(parameters, "list", true); if (listfile == "not open") { abort = true; } @@ -180,10 +191,9 @@ GetGroupsCommand::GetGroupsCommand(string option) { else if (taxfile == "not found") { taxfile = ""; } groups = validParameter.validFile(parameters, "groups", false); - if (groups == "not found") { groups = ""; } - else { - m->splitAtDash(groups, Groups); - } + if (groups == "not found") { groups = "all"; } + m->splitAtDash(groups, Groups); + if ((accnosfile == "") && (Groups.size() == 0)) { m->mothurOut("You must provide an accnos file or specify groups using the groups parameter."); m->mothurOutEndLine(); abort = true; } @@ -198,26 +208,6 @@ GetGroupsCommand::GetGroupsCommand(string option) { } //********************************************************************************************************************** -void GetGroupsCommand::help(){ - try { - m->mothurOut("The get.groups command selects sequences from a specfic group or set of groups from the following file types: fasta, name, group, list, taxonomy.\n"); - m->mothurOut("It outputs a file containing the sequences in the those specified groups.\n"); - m->mothurOut("The get.groups command parameters are accnos, fasta, name, group, list, taxonomy and groups. The group parameter is required.\n"); - m->mothurOut("You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n"); - m->mothurOut("The get.groups command should be in the following format: get.groups(accnos=yourAccnos, fasta=yourFasta, group=yourGroupFile).\n"); - m->mothurOut("Example get.groups(accnos=amazon.accnos, fasta=amazon.fasta, group=amazon.groups).\n"); - m->mothurOut("or get.groups(groups=pasture, fasta=amazon.fasta, group=amazon.groups).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "GetGroupsCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int GetGroupsCommand::execute(){ try { diff --git a/getgroupscommand.h b/getgroupscommand.h index 7c4c92f..955de62 100644 --- a/getgroupscommand.h +++ b/getgroupscommand.h @@ -21,19 +21,21 @@ public: GetGroupsCommand(string); GetGroupsCommand(); ~GetGroupsCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "get.groups"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: set names; string accnosfile, fastafile, namefile, groupfile, listfile, taxfile, outputDir, groups; bool abort; vector outputNames, Groups; - map > outputTypes; GroupMap* groupMap; int readFasta(); diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp index 3191d5d..236eef2 100644 --- a/getlabelcommand.cpp +++ b/getlabelcommand.cpp @@ -9,38 +9,49 @@ #include "getlabelcommand.h" + //********************************************************************************************************************** -vector GetlabelCommand::getValidParameters(){ +vector GetlabelCommand::setParameters(){ try { - string Array[] = {"outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); + CommandParameter 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, "GetlabelCommand", "getValidParameters"); + m->errorOut(e, "GetlabelCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector GetlabelCommand::getRequiredParameters(){ +GetlabelCommand::GetlabelCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); } catch(exception& e) { - m->errorOut(e, "GetlabelCommand", "getRequiredParameters"); + m->errorOut(e, "GetlabelCommand", "CollectCommand"); exit(1); } } //********************************************************************************************************************** -vector GetlabelCommand::getRequiredFiles(){ +string GetlabelCommand::getHelpString(){ try { - string Array[] = {"list","rabund","sabund", "or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The get.label command parameters are list, sabund, rabund and shared file. \n"; + helpString += "The get.label command should be in the following format: \n"; + helpString += "get.label()\n"; + helpString += "Example get.label().\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetlabelCommand", "getRequiredFiles"); + m->errorOut(e, "GetlabelCommand", "getHelpString"); exit(1); } } @@ -48,14 +59,108 @@ vector GetlabelCommand::getRequiredFiles(){ GetlabelCommand::GetlabelCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund or rabund before you can use the get.label command."); m->mothurOutEndLine(); abort = true; } + vector myArray = setParameters(); + + OptionParser parser(option); + map parameters = parser.getParameters(); + map::iterator it; + + ValidParameters validParameter; + + //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("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("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("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("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; } + } + } + + //check for required parameters + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { listfile = ""; abort = true; } + else if (listfile == "not found") { listfile = ""; } + else { format = "list"; inputfile = listfile; } + + sabundfile = validParameter.validFile(parameters, "sabund", true); + if (sabundfile == "not open") { sabundfile = ""; abort = true; } + else if (sabundfile == "not found") { sabundfile = ""; } + else { format = "sabund"; inputfile = sabundfile; } + + rabundfile = validParameter.validFile(parameters, "rabund", true); + if (rabundfile == "not open") { rabundfile = ""; abort = true; } + else if (rabundfile == "not found") { rabundfile = ""; } + else { format = "rabund"; inputfile = rabundfile; } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { format = "sharedfile"; inputfile = sharedfile; } + + if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + rabundfile = m->getRabundFile(); + if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } + else { + sabundfile = m->getSabundFile(); + if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list, sabund, rabund or shared file before you can use the collect.single command."); m->mothurOutEndLine(); + abort = true; + } + } + } + } + } + } } @@ -66,53 +171,29 @@ GetlabelCommand::GetlabelCommand(string option) { } //********************************************************************************************************************** -void GetlabelCommand::help(){ - try { - m->mothurOut("The get.label command can only be executed after a successful read.otu command.\n"); - m->mothurOut("You may not use any parameters with the get.label command.\n"); - m->mothurOut("The get.label command should be in the following format: \n"); - m->mothurOut("get.label()\n"); - m->mothurOut("Example get.label().\n"); - } - catch(exception& e) { - m->errorOut(e, "GetlabelCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -GetlabelCommand::~GetlabelCommand(){ -} - -//********************************************************************************************************************** - int GetlabelCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - filename = globaldata->inputFileName; - ifstream in; - m->openInputFile(filename, in); - string label; - int numBins = 0; - int count = -1; - while(in.good()) { + InputData* input = new InputData(inputfile, format); + OrderVector* order = input->getOrderVector(); + string label = order->getLabel(); + + while (order != NULL) { - if (m->control_pressed) { in.close(); return 0; } + if (m->control_pressed) { delete input; delete order; return 0; } - if(count > numBins) - count = 0; - if(count == 0) { - m->mothurOut(label); m->mothurOutEndLine(); - in >> numBins; - } - in >> label; - count++; - } + m->mothurOut(label); m->mothurOutEndLine(); + + label = order->getLabel(); + + delete order; + order = input->getOrderVector(); + } + + delete input; - in.close(); return 0; } @@ -121,4 +202,6 @@ int GetlabelCommand::execute(){ exit(1); } } +//********************************************************************************************************************** + diff --git a/getlabelcommand.h b/getlabelcommand.h index 00945e1..3aaa92d 100644 --- a/getlabelcommand.h +++ b/getlabelcommand.h @@ -11,28 +11,29 @@ */ #include "command.hpp" -#include "readmatrix.hpp" +#include "ordervector.hpp" +#include "inputdata.h" -class GlobalData; class GetlabelCommand : public Command { public: GetlabelCommand(string); - GetlabelCommand(){} - ~GetlabelCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + GetlabelCommand(); + ~GetlabelCommand(){} + + vector setParameters(); + string getCommandName() { return "get.label"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; - string filename; + string inputfile, listfile, rabundfile, sabundfile, sharedfile, format; bool abort; vector outputNames; - map > outputTypes; }; #endif diff --git a/getlineagecommand.cpp b/getlineagecommand.cpp index 7950680..5e35449 100644 --- a/getlineagecommand.cpp +++ b/getlineagecommand.cpp @@ -11,23 +11,58 @@ #include "sequence.hpp" #include "listvector.hpp" - //********************************************************************************************************************** -vector GetLineageCommand::getValidParameters(){ +vector GetLineageCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "alignreport", "taxon", "dups", "list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport); + CommandParameter ptaxon("taxon", "String", "", "", "", "", "",false,true); parameters.push_back(ptaxon); + CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetLineageCommand", "getValidParameters"); + m->errorOut(e, "GetLineageCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string GetLineageCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The get.lineage command reads a taxonomy file and any of the following file types: fasta, name, group, list or alignreport file.\n"; + helpString += "It outputs a file containing only the sequences from the taxonomy file that are from the taxon requested.\n"; + helpString += "The get.lineage command parameters are taxon, fasta, name, group, list, taxonomy, alignreport and dups. You must provide taxonomy unless you have a valid current taxonomy file.\n"; + helpString += "The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n"; + helpString += "The taxon parameter allows you to select the taxons you would like to get and is required.\n"; + helpString += "You may enter your taxons with confidence scores, doing so will get only those sequences that belong to the taxonomy and whose cofidence scores is above the scores you give.\n"; + helpString += "If they belong to the taxonomy and have confidences below those you provide the sequence will not be selected.\n"; + helpString += "The get.lineage command should be in the following format: get.lineage(taxonomy=yourTaxonomyFile, taxon=yourTaxons).\n"; + helpString += "Example get.lineage(taxonomy=amazon.silva.taxonomy, taxon=Bacteria;Firmicutes;Bacilli;Lactobacillales;).\n"; + helpString += "Note: If you are running mothur in script mode you must wrap the taxon in ' characters so mothur will ignore the ; in the taxon.\n"; + helpString += "Example get.lineage(taxonomy=amazon.silva.taxonomy, taxon='Bacteria;Firmicutes;Bacilli;Lactobacillales;').\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "GetLineageCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** GetLineageCommand::GetLineageCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["taxonomy"] = tempOutNames; @@ -42,29 +77,6 @@ GetLineageCommand::GetLineageCommand(){ } } //********************************************************************************************************************** -vector GetLineageCommand::getRequiredParameters(){ - try { - string Array[] = {"taxonomy","taxon"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetLineageCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector GetLineageCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetLineageCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** GetLineageCommand::GetLineageCommand(string option) { try { abort = false; calledHelp = false; @@ -73,9 +85,7 @@ GetLineageCommand::GetLineageCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name", "group", "alignreport", "taxon", "dups", "list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -178,7 +188,11 @@ GetLineageCommand::GetLineageCommand(string option) { taxfile = validParameter.validFile(parameters, "taxonomy", true); if (taxfile == "not open") { abort = true; } - else if (taxfile == "not found") { taxfile = ""; m->mothurOut("The taxonomy parameter is required for the get.lineage command."); m->mothurOutEndLine(); abort = true; } + else if (taxfile == "not found") { + taxfile = m->getTaxonomyFile(); + if (taxfile != "") { m->mothurOut("Using " + taxfile + " as input file for the taxonomy parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current taxonomy file and the taxonomy parameter is required."); m->mothurOutEndLine(); abort = true; } + } string usedDups = "true"; string temp = validParameter.validFile(parameters, "dups", false); @@ -198,9 +212,6 @@ GetLineageCommand::GetLineageCommand(string option) { if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport, taxonomy or listfile."); m->mothurOutEndLine(); abort = true; } - - if ((usedDups != "") && (namefile == "")) { m->mothurOut("You may only use dups with the name option."); m->mothurOutEndLine(); abort = true; } - } } @@ -211,29 +222,6 @@ GetLineageCommand::GetLineageCommand(string option) { } //********************************************************************************************************************** -void GetLineageCommand::help(){ - try { - m->mothurOut("The get.lineage command reads a taxonomy file and any of the following file types: fasta, name, group, list or alignreport file.\n"); - m->mothurOut("It outputs a file containing only the sequences from the taxonomy file that are from the taxon requested.\n"); - m->mothurOut("The get.lineage command parameters are taxon, fasta, name, group, list, taxonomy, alignreport and dups. You must provide taxonomy and taxon.\n"); - m->mothurOut("The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n"); - m->mothurOut("The taxon parameter allows you to select the taxons you would like to get.\n"); - m->mothurOut("You may enter your taxons with confidence scores, doing so will get only those sequences that belong to the taxonomy and whose cofidence scores is above the scores you give.\n"); - m->mothurOut("If they belong to the taxonomy and have confidences below those you provide the sequence will not be selected.\n"); - m->mothurOut("The get.lineage command should be in the following format: get.lineage(taxonomy=yourTaxonomyFile, taxon=yourTaxons).\n"); - m->mothurOut("Example get.lineage(taxonomy=amazon.silva.taxonomy, taxon=Bacteria;Firmicutes;Bacilli;Lactobacillales;).\n"); - m->mothurOut("Note: If you are running mothur in script mode you must wrap the taxon in ' characters so mothur will ignore the ; in the taxon.\n"); - m->mothurOut("Example get.lineage(taxonomy=amazon.silva.taxonomy, taxon='Bacteria;Firmicutes;Bacilli;Lactobacillales;').\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "GetLineageCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int GetLineageCommand::execute(){ try { diff --git a/getlineagecommand.h b/getlineagecommand.h index 5b7c43e..6375b94 100644 --- a/getlineagecommand.h +++ b/getlineagecommand.h @@ -18,20 +18,22 @@ class GetLineageCommand : public Command { GetLineageCommand(string); GetLineageCommand(); - ~GetLineageCommand(){}; - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + ~GetLineageCommand(){} + + vector setParameters(); + string getCommandName() { return "get.lineage"; } + string getCommandCategory() { return "Phylotype Analysis"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + + private: set names; vector outputNames; string fastafile, namefile, groupfile, alignfile, listfile, taxfile, outputDir, taxons; bool abort, dups; - map > outputTypes; int readFasta(); int readName(); diff --git a/getlistcountcommand.cpp b/getlistcountcommand.cpp index 78f2604..404d353 100644 --- a/getlistcountcommand.cpp +++ b/getlistcountcommand.cpp @@ -10,67 +10,68 @@ #include "getlistcountcommand.h" //********************************************************************************************************************** -vector GetListCountCommand::getValidParameters(){ +vector GetListCountCommand::setParameters(){ try { - string Array[] = {"list","label","sort","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter parasort("sort", "Multiple", "name-otu", "otu", "", "", "",false,false); parameters.push_back(parasort); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetListCountCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -GetListCountCommand::GetListCountCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["otu"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "GetListCountCommand", "GetListCountCommand"); + m->errorOut(e, "GetListCountCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector GetListCountCommand::getRequiredParameters(){ +string GetListCountCommand::getHelpString(){ try { - string Array[] = {"list"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The get.otulist command parameters are list, sort and label. list is required, unless you have a valid current list file.\n"; + helpString += "The label parameter allows you to select what distance levels you would like a output files created for, and are separated by dashes.\n"; + helpString += "The sort parameter allows you to select how you want the output displayed. Options are otu and name.\n"; + helpString += "If otu is selected the output will be otu number followed by the list of names in that otu.\n"; + helpString += "If name is selected the output will be a sequence name followed by its otu number.\n"; + helpString += "The get.otulist command should be in the following format: get.otulist(list=yourlistFile, label=yourLabels).\n"; + helpString += "Example get.otulist(list=amazon.fn.list, label=0.10).\n"; + helpString += "The default value for label is all lines in your inputfile.\n"; + helpString += "The get.otulist command outputs a .otu file for each distance you specify listing the bin number and the names of the sequences in that bin.\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetListCountCommand", "getRequiredParameters"); + m->errorOut(e, "GetListCountCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector GetListCountCommand::getRequiredFiles(){ +GetListCountCommand::GetListCountCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["otu"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "GetListCountCommand", "getRequiredFiles"); + m->errorOut(e, "GetListCountCommand", "GetListCountCommand"); exit(1); } } //********************************************************************************************************************** GetListCountCommand::GetListCountCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"list","label","sort","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -86,8 +87,6 @@ GetListCountCommand::GetListCountCommand(string option) { //initialize outputTypes vector tempOutNames; outputTypes["otu"] = tempOutNames; - - string ranRead = globaldata->getListFile(); //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); @@ -108,10 +107,13 @@ GetListCountCommand::GetListCountCommand(string option) { //check for required parameters listfile = validParameter.validFile(parameters, "list", true); - if ((listfile == "not found") && (globaldata->getListFile() == "")) { m->mothurOut("You must read a listfile before running the get.listcount command."); m->mothurOutEndLine(); abort = true; } - else if ((listfile == "not found") && (globaldata->getListFile() != "")) { listfile = globaldata->getListFile(); } + if (listfile == "not found") { + listfile = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (listfile == "not open") { abort = true; } - else { globaldata->setListFile(listfile); } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -124,12 +126,6 @@ GetListCountCommand::GetListCountCommand(string option) { if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } - - //if the user has not specified any labels use the ones from read.otu - if ((label == "") && (ranRead != "")) { - allLines = globaldata->allLines; - labels = globaldata->labels; - } } } catch(exception& e) { @@ -139,58 +135,19 @@ GetListCountCommand::GetListCountCommand(string option) { } //********************************************************************************************************************** -void GetListCountCommand::help(){ - try { - m->mothurOut("The get.otulist command can only be executed after a successful read.otu command of a listfile or providing a list file using the list parameter.\n"); - m->mothurOut("The get.otulist command parameters are list, sort and label. No parameters are required.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like a output files created for, and are separated by dashes.\n"); - m->mothurOut("The sort parameter allows you to select how you want the output displayed. Options are otu and name.\n"); - m->mothurOut("If otu is selected the output will be otu number followed by the list of names in that otu.\n"); - m->mothurOut("If name is selected the output will be a sequence name followed by its otu number.\n"); - m->mothurOut("The get.otulist command should be in the following format: get.otulist(list=yourlistFile, label=yourLabels).\n"); - m->mothurOut("Example get.otulist(list=amazon.fn.list, label=0.10).\n"); - m->mothurOut("The default value for label is all lines in your inputfile.\n"); - m->mothurOut("The get.otulist command outputs a .otu file for each distance you specify listing the bin number and the names of the sequences in that bin.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "GetListCountCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -GetListCountCommand::~GetListCountCommand(){} - -//********************************************************************************************************************** - int GetListCountCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - - globaldata->setFormat("list"); - - //read list file - read = new ReadOTUFile(listfile); - read->read(&*globaldata); - input = globaldata->ginput; - list = globaldata->gListVector; + input = new InputData(listfile, "list"); + list = input->getListVector(); string lastLabel = list->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; - if (m->control_pressed) { - delete read; - delete input; - delete list; - globaldata->gListVector = NULL; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } - return 0; - } + if (m->control_pressed) { delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { @@ -198,14 +155,7 @@ int GetListCountCommand::execute(){ process(list); - if (m->control_pressed) { - delete read; - delete input; - delete list; - globaldata->gListVector = NULL; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - return 0; - } + if (m->control_pressed) { delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -219,14 +169,8 @@ int GetListCountCommand::execute(){ process(list); - if (m->control_pressed) { - delete read; - delete input; - delete list; - globaldata->gListVector = NULL; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - return 0; - } + if (m->control_pressed) { delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -262,21 +206,12 @@ int GetListCountCommand::execute(){ process(list); - if (m->control_pressed) { - delete read; - delete input; - delete list; - globaldata->gListVector = NULL; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - return 0; - } + if (m->control_pressed) { delete input; delete list; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } delete list; } - delete read; delete input; - globaldata->gListVector = NULL; m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); diff --git a/getlistcountcommand.h b/getlistcountcommand.h index 60d28cc..40ff7d0 100644 --- a/getlistcountcommand.h +++ b/getlistcountcommand.h @@ -12,9 +12,6 @@ #include "command.hpp" #include "inputdata.h" #include "listvector.hpp" -#include "readotu.h" - -class GlobalData; /**********************************************************/ @@ -23,18 +20,20 @@ class GetListCountCommand : public Command { public: GetListCountCommand(string); GetListCountCommand(); - ~GetListCountCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~GetListCountCommand(){} + + vector setParameters(); + string getCommandName() { return "get.otulist"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; ListVector* list; - ReadOTUFile* read; InputData* input; bool abort, allLines; @@ -42,8 +41,7 @@ private: string label, listfile, outputDir, sort; ofstream out; vector outputNames; - map > outputTypes; - + void process(ListVector*); }; /**********************************************************/ diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 78c39f7..0ab12ab 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -35,69 +35,90 @@ inline bool compareSize(repStruct left, repStruct right){ inline bool compareGroup(repStruct left, repStruct right){ return (left.group < right.group); } + //********************************************************************************************************************** -GetOTURepCommand::GetOTURepCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["name"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "GetOTURepCommand", "GetOTURepCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector GetOTURepCommand::getValidParameters(){ +vector GetOTURepCommand::setParameters(){ try { - string Array[] = {"fasta","list","label","name", "group", "weighted","sorted", "phylip","column","large","cutoff","precision","groups","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); + CommandParameter pweighted("weighted", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pweighted); + CommandParameter psorted("sorted", "Multiple", "none-name-bin-size-group", "none", "", "", "",false,false); parameters.push_back(psorted); + CommandParameter plarge("large", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(plarge); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetOTURepCommand", "getValidParameters"); + m->errorOut(e, "GetOTURepCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector GetOTURepCommand::getRequiredParameters(){ +string GetOTURepCommand::getHelpString(){ try { - string Array[] = {"fasta","list"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The get.oturep command parameters are phylip, column, list, fasta, name, group, large, weighted, cutoff, precision, groups, sorted and label. The fasta and list parameters are required, as well as phylip or column and name, unless you have valid current files.\n"; + helpString += "The label parameter allows you to select what distance levels you would like a output files created for, and is separated by dashes.\n"; + helpString += "The phylip or column parameter is required, but only one may be used. If you use a column file the name filename is required. \n"; + helpString += "If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.\n"; + helpString += "The get.oturep command should be in the following format: get.oturep(phylip=yourDistanceMatrix, fasta=yourFastaFile, list=yourListFile, name=yourNamesFile, group=yourGroupFile, label=yourLabels).\n"; + helpString += "Example get.oturep(phylip=amazon.dist, fasta=amazon.fasta, list=amazon.fn.list, group=amazon.groups).\n"; + helpString += "The default value for label is all labels in your inputfile.\n"; + helpString += "The sorted parameter allows you to indicate you want the output sorted. You can sort by sequence name, bin number, bin size or group. The default is no sorting, but your options are name, number, size, or group.\n"; + helpString += "The large parameter allows you to indicate that your distance matrix is too large to fit in RAM. The default value is false.\n"; + helpString += "The weighted parameter allows you to indicate that want to find the weighted representative. You must provide a namesfile to set weighted to true. The default value is false.\n"; + helpString += "The representative is found by selecting the sequence that has the smallest total distance to all other sequences in the OTU. If a tie occurs the smallest average distance is used.\n"; + helpString += "For weighted = false, mothur assumes the distance file contains only unique sequences, the list file may contain all sequences, but only the uniques are considered to become the representative. If your distance file contains all the sequences it would become weighted=true.\n"; + helpString += "For weighted = true, mothur assumes the distance file contains only unique sequences, the list file must contain all sequences, all sequences are considered to become the representative, but unique name will be used in the output for consistency.\n"; + helpString += "If your distance file contains all the sequence and you do not provide a name file, the weighted representative will be given, unless your listfile is unique. If you provide a namefile, then you can select weighted or unweighted.\n"; + helpString += "The group parameter allows you provide a group file.\n"; + helpString += "The groups parameter allows you to indicate that you want representative sequences for each group specified for each OTU, group name should be separated by dashes. ex. groups=A-B-C.\n"; + helpString += "The get.oturep command outputs a .fastarep and .rep.names file for each distance you specify, selecting one OTU representative for each bin.\n"; + helpString += "If you provide a groupfile, then it also appends the names of the groups present in that bin.\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetOTURepCommand", "getRequiredParameters"); + m->errorOut(e, "GetOTURepCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector GetOTURepCommand::getRequiredFiles(){ +GetOTURepCommand::GetOTURepCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "GetOTURepCommand", "getRequiredFiles"); + m->errorOut(e, "GetOTURepCommand", "GetOTURepCommand"); exit(1); } } //********************************************************************************************************************** GetOTURepCommand::GetOTURepCommand(string option) { try{ - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); //allow user to run help if (option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","list","label","name","weighted", "group", "sorted", "phylip","column","large","cutoff","precision","groups","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -175,11 +196,19 @@ GetOTURepCommand::GetOTURepCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the get.oturep command."); m->mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (fastafile == "not open") { abort = true; } listfile = validParameter.validFile(parameters, "list", true); - if (listfile == "not found") { m->mothurOut("list is a required parameter for the get.oturep command."); m->mothurOutEndLine(); abort = true; } + if (listfile == "not found") { + listfile = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (listfile == "not open") { abort = true; } phylipfile = validParameter.validFile(parameters, "phylip", true); @@ -196,10 +225,30 @@ GetOTURepCommand::GetOTURepCommand(string option) { if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } - if ((phylipfile == "") && (columnfile == "")) { m->mothurOut("When executing a get.oturep command you must enter a phylip or a column."); m->mothurOutEndLine(); abort = true; } - else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When executing a get.oturep 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; } } + if ((phylipfile == "") && (columnfile == "")) { //is there are current file available for either of these? + //give priority to column, then phylip + columnfile = m->getColumnFile(); + if (columnfile != "") { m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); } + else { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a phylip or column file before you can use the get.oturep command."); m->mothurOutEndLine(); + abort = true; + } + } + }else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When executing a get.oturep command you must enter ONLY ONE of the following: phylip or column."); m->mothurOutEndLine(); abort = true; } + + if (columnfile != "") { + if (namefile == "") { + namefile = m->getNameFile(); + if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); + abort = true; + } + } + } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -215,6 +264,7 @@ GetOTURepCommand::GetOTURepCommand(string option) { else if (groupfile == "not found") { groupfile = ""; } sorted = validParameter.validFile(parameters, "sorted", false); if (sorted == "not found"){ sorted = ""; } + if (sorted == "none") { sorted=""; } if ((sorted != "") && (sorted != "name") && (sorted != "bin") && (sorted != "size") && (sorted != "group")) { m->mothurOut(sorted + " is not a valid option for the sorted parameter. The only options are: name, bin, size and group. I will not sort."); m->mothurOutEndLine(); sorted = ""; @@ -235,12 +285,12 @@ GetOTURepCommand::GetOTURepCommand(string option) { m->splitAtDash(groups, Groups); } } - globaldata->Groups = Groups; + m->Groups = Groups; string temp = validParameter.validFile(parameters, "large", false); if (temp == "not found") { temp = "F"; } large = m->isTrue(temp); - temp = validParameter.validFile(parameters, "weighted", false); if (temp == "not found") { if (namefile == "") { temp = "F"; } else { temp = "t"; } } + temp = validParameter.validFile(parameters, "weighted", false); if (temp == "not found") { temp = "f"; } weighted = m->isTrue(temp); if ((weighted) && (namefile == "")) { m->mothurOut("You cannot set weighted to true unless you provide a namesfile."); m->mothurOutEndLine(); abort = true; } @@ -261,45 +311,12 @@ GetOTURepCommand::GetOTURepCommand(string option) { //********************************************************************************************************************** -void GetOTURepCommand::help(){ - try { - m->mothurOut("The get.oturep command parameters are phylip, column, list, fasta, name, group, large, weighted, cutoff, precision, groups, sorted and label. The fasta and list parameters are required, as well as phylip or column and name.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like a output files created for, and is separated by dashes.\n"); - m->mothurOut("The phylip or column parameter is required, but only one may be used. If you use a column file the name filename is required. \n"); - m->mothurOut("If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.\n"); - m->mothurOut("The get.oturep command should be in the following format: get.oturep(phylip=yourDistanceMatrix, fasta=yourFastaFile, list=yourListFile, name=yourNamesFile, group=yourGroupFile, label=yourLabels).\n"); - m->mothurOut("Example get.oturep(phylip=amazon.dist, fasta=amazon.fasta, list=amazon.fn.list, group=amazon.groups).\n"); - m->mothurOut("The default value for label is all labels in your inputfile.\n"); - m->mothurOut("The sorted parameter allows you to indicate you want the output sorted. You can sort by sequence name, bin number, bin size or group. The default is no sorting, but your options are name, number, size, or group.\n"); - m->mothurOut("The large parameter allows you to indicate that your distance matrix is too large to fit in RAM. The default value is false.\n"); - m->mothurOut("The weighted parameter allows you to indicate that want to find the weighted representative. You must provide a namesfile to set weighted to true. The default value is false with no namesfile and true when a name file is provided.\n"); - m->mothurOut("The representative is found by selecting the sequence that has the smallest total distance to all other sequences in the OTU. If a tie occurs the smallest average distance is used.\n"); - m->mothurOut("For weighted = false, mothur assumes the distance file contains only unique sequences, the list file may contain all sequences, but only the uniques are considered to become the representative. If your distance file contains all the sequences it would become weighted=true.\n"); - m->mothurOut("For weighted = true, mothur assumes the distance file contains only unique sequences, the list file must contain all sequences, all sequences are considered to become the representative, but unique name will be used in the output for consistency.\n"); - m->mothurOut("If your distance file contains all the sequence and you do not provide a name file, the weighted representative will be given, unless your listfile is unique. If you provide a namefile, then you can select weighted or unweighted.\n"); - m->mothurOut("The group parameter allows you provide a group file.\n"); - m->mothurOut("The groups parameter allows you to indicate that you want representative sequences for each group specified for each OTU, group name should be separated by dashes. ex. groups=A-B-C.\n"); - m->mothurOut("The get.oturep command outputs a .fastarep and .rep.names file for each distance you specify, selecting one OTU representative for each bin.\n"); - m->mothurOut("If you provide a groupfile, then it also appends the names of the groups present in that bin.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "GetOTURepCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -GetOTURepCommand::~GetOTURepCommand(){} - -//********************************************************************************************************************** - int GetOTURepCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } int error; + list = NULL; if (!large) { //read distance files @@ -318,9 +335,7 @@ int GetOTURepCommand::execute(){ if (m->control_pressed) { delete readMatrix; return 0; } - //get matrix - if (globaldata->gListVector != NULL) { delete globaldata->gListVector; } - globaldata->gListVector = readMatrix->getListVector(); + list = readMatrix->getListVector(); SparseMatrix* matrix = readMatrix->getMatrix(); @@ -328,7 +343,7 @@ int GetOTURepCommand::execute(){ // It consists of a vector of distance maps, where each map contains // all distances of a certain sequence. Vector and maps are accessed // via the index of a sequence in the distance matrix - seqVec = vector(globaldata->gListVector->size()); + seqVec = vector(list->size()); for (MatData currentCell = matrix->begin(); currentCell != matrix->end(); currentCell++) { if (m->control_pressed) { delete readMatrix; return 0; } seqVec[currentCell->row][currentCell->column] = currentCell->dist; @@ -359,9 +374,7 @@ int GetOTURepCommand::execute(){ if (m->control_pressed) { delete formatMatrix; return 0; } - //get matrix - if (globaldata->gListVector != NULL) { delete globaldata->gListVector; } - globaldata->gListVector = formatMatrix->getListVector(); + list = formatMatrix->getListVector(); distFile = formatMatrix->getFormattedFileName(); @@ -380,14 +393,14 @@ int GetOTURepCommand::execute(){ } - //globaldata->gListVector bin 0 = first name read in distance matrix, globaldata->gListVector bin 1 = second name read in distance matrix - if (globaldata->gListVector != NULL) { + //list bin 0 = first name read in distance matrix, list bin 1 = second name read in distance matrix + if (list != NULL) { vector names; string binnames; //map names to rows in sparsematrix - for (int i = 0; i < globaldata->gListVector->size(); i++) { + for (int i = 0; i < list->size(); i++) { names.clear(); - binnames = globaldata->gListVector->get(i); + binnames = list->get(i); m->splitAtComma(binnames, names); @@ -415,16 +428,12 @@ int GetOTURepCommand::execute(){ delete util; } } - - //set format to list so input can get listvector - globaldata->setFormat("list"); - - //read list file - read = new ReadOTUFile(listfile); - read->read(&*globaldata); - input = globaldata->ginput; - list = globaldata->gListVector; + //done with listvector from matrix + if (list != NULL) { delete list; } + + input = new InputData(listfile, "list"); + list = input->getListVector(); string lastLabel = list->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -433,7 +442,7 @@ int GetOTURepCommand::execute(){ if (m->control_pressed) { if (large) { inRow.close(); remove(distFile.c_str()); } - delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; + delete input; delete list; return 0; } if ((!weighted) && (namefile != "")) { readNamesFile(weighted); } @@ -448,7 +457,7 @@ int GetOTURepCommand::execute(){ if (m->control_pressed) { if (large) { inRow.close(); remove(distFile.c_str()); } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; + delete input; delete list; return 0; } processedLabels.insert(list->getLabel()); @@ -467,7 +476,7 @@ int GetOTURepCommand::execute(){ if (m->control_pressed) { if (large) { inRow.close(); remove(distFile.c_str()); } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; + delete input; delete list; return 0; } processedLabels.insert(list->getLabel()); @@ -507,7 +516,7 @@ int GetOTURepCommand::execute(){ if (m->control_pressed) { if (large) { inRow.close(); remove(distFile.c_str()); } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - delete read; delete input; delete list; globaldata->gListVector = NULL; return 0; + delete input; delete list; return 0; } } @@ -517,9 +526,7 @@ int GetOTURepCommand::execute(){ remove(distFile.c_str()); } - globaldata->gListVector = NULL; - delete input; globaldata->ginput = NULL; - delete read; + delete input; if (!weighted) { nameFileMap.clear(); } @@ -537,9 +544,7 @@ int GetOTURepCommand::execute(){ } delete fasta; - if (groupfile != "") { - delete groupMap; globaldata->gGroupmap = NULL; - } + if (groupfile != "") { delete groupMap; } if (m->control_pressed) { return 0; } diff --git a/getoturepcommand.h b/getoturepcommand.h index 7a17c9d..d8f8f09 100644 --- a/getoturepcommand.h +++ b/getoturepcommand.h @@ -12,10 +12,8 @@ /* The get.oturep command outputs a .fastarep file for each distance you specify, selecting one OTU representative for each bin. */ #include "command.hpp" -#include "globaldata.hpp" #include "listvector.hpp" #include "inputdata.h" -#include "readotu.h" #include "fastamap.h" #include "groupmap.h" #include "readmatrix.hpp" @@ -40,18 +38,19 @@ class GetOTURepCommand : public Command { public: GetOTURepCommand(string); GetOTURepCommand(); - ~GetOTURepCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + ~GetOTURepCommand(){} + + vector setParameters(); + string getCommandName() { return "get.oturep"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + + private: - GlobalData* globaldata; ListVector* list; - ReadOTUFile* read; InputData* input; FastaMap* fasta; GroupMap* groupMap; @@ -72,7 +71,6 @@ private: vector seqVec; // contains maps with sequence index and distance // for all distances related to a certain sequence vector rowPositions; - map > outputTypes; void readNamesFile(); void readNamesFile(bool); @@ -80,8 +78,6 @@ private: SeqMap getMap(int); string findRep(vector); // returns the name of the "representative" sequence of given bin or subset of a bin, for groups int processNames(string, string); - - }; #endif diff --git a/getotuscommand.cpp b/getotuscommand.cpp index 15d2bcb..4a79d3a 100644 --- a/getotuscommand.cpp +++ b/getotuscommand.cpp @@ -13,50 +13,58 @@ //********************************************************************************************************************** -vector GetOtusCommand::getValidParameters(){ +vector GetOtusCommand::setParameters(){ try { - string Array[] = { "group", "accnos","label", "groups","list","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetOtusCommand", "getValidParameters"); + m->errorOut(e, "GetOtusCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -GetOtusCommand::GetOtusCommand(){ +string GetOtusCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["group"] = tempOutNames; - outputTypes["list"] = tempOutNames; + string helpString = ""; + helpString += "The get.otus command selects otus containing sequences from a specfic group or set of groups.\n"; + helpString += "It outputs a new list file containing the otus containing sequences from in the those specified groups.\n"; + helpString += "The get.otus command parameters are accnos, group, list, label and groups. The group and list parameters are required, unless you have valid current files.\n"; + helpString += "You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n"; + helpString += "The label parameter allows you to specify which distance you want to process.\n"; + helpString += "The get.otus command should be in the following format: get.otus(accnos=yourAccnos, list=yourListFile, group=yourGroupFile, label=yourLabel).\n"; + helpString += "Example get.otus(accnos=amazon.accnos, list=amazon.fn.list, group=amazon.groups, label=0.03).\n"; + helpString += "or get.otus(groups=pasture, list=amazon.fn.list, amazon.groups, label=0.03).\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetOtusCommand", "GetOtusCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector GetOtusCommand::getRequiredParameters(){ - try { - string Array[] = {"group","label", "list"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetOtusCommand", "getRequiredParameters"); + m->errorOut(e, "GetOtusCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector GetOtusCommand::getRequiredFiles(){ +GetOtusCommand::GetOtusCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["list"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "GetOtusCommand", "getRequiredFiles"); + m->errorOut(e, "GetOtusCommand", "GetOtusCommand"); exit(1); } } @@ -69,9 +77,7 @@ GetOtusCommand::GetOtusCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = { "group", "accnos","label", "groups", "list","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -131,11 +137,19 @@ GetOtusCommand::GetOtusCommand(string option) { groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; m->mothurOut("You must provide a group file."); m->mothurOutEndLine(); abort = true; } + else if (groupfile == "not found") { + groupfile = m->getGroupFile(); + if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current group file and the group parameter is required."); m->mothurOutEndLine(); abort = true; } + } listfile = validParameter.validFile(parameters, "list", true); if (listfile == "not open") { abort = true; } - else if (listfile == "not found") { listfile = ""; m->mothurOut("You must provide a list file."); m->mothurOutEndLine(); abort = true; } + else if (listfile == "not found") { + listfile = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; } + } groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } @@ -144,7 +158,7 @@ GetOtusCommand::GetOtusCommand(string option) { } label = validParameter.validFile(parameters, "label", false); - if (label == "not found") { label = ""; m->mothurOut("You must provide a label to process."); m->mothurOutEndLine(); abort = true; } + if (label == "not found") { label = ""; m->mothurOut("You did not provide a label, I will use the first label in your inputfile."); m->mothurOutEndLine(); label=""; } if ((accnosfile == "") && (Groups.size() == 0)) { m->mothurOut("You must provide an accnos file or specify groups using the groups parameter."); m->mothurOutEndLine(); abort = true; } } @@ -157,27 +171,6 @@ GetOtusCommand::GetOtusCommand(string option) { } //********************************************************************************************************************** -void GetOtusCommand::help(){ - try { - m->mothurOut("The get.otus command selects otus containing sequences from a specfic group or set of groups.\n"); - m->mothurOut("It outputs a new list file containing the otus containing sequences from in the those specified groups.\n"); - m->mothurOut("The get.otus command parameters are accnos, group, list, label and groups. The group, list and label parameters are required.\n"); - m->mothurOut("You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n"); - m->mothurOut("The label parameter allows you to specify which distance you want to process.\n"); - m->mothurOut("The get.otus command should be in the following format: get.otus(accnos=yourAccnos, list=yourListFile, group=yourGroupFile, label=yourLabel).\n"); - m->mothurOut("Example get.otus(accnos=amazon.accnos, list=amazon.fn.list, group=amazon.groups, label=0.03).\n"); - m->mothurOut("or get.otus(groups=pasture, list=amazon.fn.list, amazon.groups, label=0.03).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "GetOtusCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int GetOtusCommand::execute(){ try { @@ -250,6 +243,9 @@ int GetOtusCommand::readListGroup(){ ListVector* list = input->getListVector(); string lastLabel = list->getLabel(); + //using first label seen if none is provided + if (label == "") { label = lastLabel; } + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set labels; labels.insert(label); set processedLabels; diff --git a/getotuscommand.h b/getotuscommand.h index ec69acb..34562fe 100644 --- a/getotuscommand.h +++ b/getotuscommand.h @@ -23,18 +23,20 @@ public: GetOtusCommand(string); GetOtusCommand(); ~GetOtusCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "get.otus"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: string accnosfile, groupfile, listfile, outputDir, groups, label; bool abort; vector outputNames, Groups; - map > outputTypes; GroupMap* groupMap; void readAccnos(); diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index 3b03f36..570d64e 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -10,95 +10,121 @@ #include "getrabundcommand.h" //********************************************************************************************************************** -vector GetRAbundCommand::getValidParameters(){ +vector GetRAbundCommand::setParameters(){ try { - string Array[] = {"label","sorted","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); + CommandParameter psorted("sorted", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(psorted); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetRAbundCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -GetRAbundCommand::GetRAbundCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["rabund"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "GetRAbundCommand", "GetRAbundCommand"); + m->errorOut(e, "GetRAbundCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector GetRAbundCommand::getRequiredParameters(){ +string GetRAbundCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The get.rabund command parameters are list, sabund, label and sorted. list or sabund parameters are required, unless you have valid current files.\n"; + helpString += "The label parameter allows you to select what distance levels you would like included in your .rabund file, and are separated by dashes.\n"; + helpString += "The sorted parameters allows you to print the rabund results sorted by abundance or not. The default is sorted.\n"; + helpString += "The get.rabund command should be in the following format: get.rabund(label=yourLabels, sorted=yourSorted).\n"; + helpString += "Example get.rabund(sorted=F).\n"; + helpString += "The default value for label is all labels in your inputfile.\n"; + helpString += "The get.rabund command outputs a .rabund file containing the lines you selected.\n"; + helpString += "Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetRAbundCommand", "getRequiredParameters"); + m->errorOut(e, "GetRAbundCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector GetRAbundCommand::getRequiredFiles(){ +GetRAbundCommand::GetRAbundCommand(){ try { - string Array[] = {"list"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "GetRAbundCommand", "getRequiredFiles"); + m->errorOut(e, "GetRAbundCommand", "GetRAbundCommand"); exit(1); } } //********************************************************************************************************************** GetRAbundCommand::GetRAbundCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"label","sorted","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - //if the user changes the output directory command factory will send this info to us in the output parameter - string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ - outputDir = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it - } - //initialize outputTypes vector tempOutNames; outputTypes["rabund"] = tempOutNames; - //make sure the user has already run the read.otu command - if (globaldata->getListFile() == "") { m->mothurOut("You must read a listfile before you can use the get.rabund command."); m->mothurOutEndLine(); 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("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("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; } + } + } + + + //check for required parameters + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { listfile = ""; abort = true; } + else if (listfile == "not found") { listfile = ""; } + else { format = "list"; inputfile = listfile; } + + sabundfile = validParameter.validFile(parameters, "sabund", true); + if (sabundfile == "not open") { sabundfile = ""; abort = true; } + else if (sabundfile == "not found") { sabundfile = ""; } + else { format = "sabund"; inputfile = sabundfile; } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... - string temp; temp = validParameter.validFile(parameters, "sorted", false); if (temp == "not found") { temp = "T"; } sorted = m->isTrue(temp); @@ -110,17 +136,28 @@ GetRAbundCommand::GetRAbundCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if(label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - - if (abort == false) { - filename = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "rabund"; - m->openOutputFile(filename, out); + if ((listfile == "") && (sabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + sabundfile = m->getSabundFile(); + if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list or sabund file."); 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(inputfile); } + } + } catch(exception& e) { @@ -130,96 +167,66 @@ GetRAbundCommand::GetRAbundCommand(string option) { } //********************************************************************************************************************** -void GetRAbundCommand::help(){ - try { - m->mothurOut("The get.rabund command can only be executed after a successful read.otu of a listfile.\n"); - m->mothurOut("The get.rabund command parameters are label and sorted. No parameters are required.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like included in your .rabund file, and are separated by dashes.\n"); - m->mothurOut("The sorted parameters allows you to print the rabund results sorted by abundance or not. The default is sorted.\n"); - m->mothurOut("The get.rabund command should be in the following format: get.rabund(label=yourLabels, sorted=yourSorted).\n"); - m->mothurOut("Example get.rabund(sorted=F).\n"); - m->mothurOut("The default value for label is all labels in your inputfile.\n"); - m->mothurOut("The get.rabund command outputs a .rabund file containing the lines you selected.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "GetRAbundCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -GetRAbundCommand::~GetRAbundCommand(){} - -//********************************************************************************************************************** - int GetRAbundCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - //read first line - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - - input = globaldata->ginput; - list = globaldata->gListVector; - string lastLabel = list->getLabel(); + filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "rabund"; + m->openOutputFile(filename, out); + + input = new InputData(inputfile, format); + rabund = input->getRAbundVector(); + string lastLabel = rabund->getLabel(); //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete list; globaldata->gListVector = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete rabund; delete input; return 0; } - while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if(allLines == 1 || labels.count(list->getLabel()) == 1){ - m->mothurOut(list->getLabel()); m->mothurOutEndLine(); - rabund = new RAbundVector(); - *rabund = (list->getRAbundVector()); + if(allLines == 1 || labels.count(rabund->getLabel()) == 1){ + m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete list; delete rabund; globaldata->gListVector = NULL; return 0; } - + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete input; delete rabund; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } delete rabund; - processedLabels.insert(list->getLabel()); - userLabels.erase(list->getLabel()); + processedLabels.insert(rabund->getLabel()); + userLabels.erase(rabund->getLabel()); } - if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = list->getLabel(); + if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = rabund->getLabel(); - delete list; - list = input->getListVector(lastLabel); + delete rabund; + rabund = input->getRAbundVector(lastLabel); - m->mothurOut(list->getLabel()); m->mothurOutEndLine(); - rabund = new RAbundVector(); - *rabund = (list->getRAbundVector()); + m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete list; delete rabund; globaldata->gListVector = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete input; delete rabund; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } delete rabund; - processedLabels.insert(list->getLabel()); - userLabels.erase(list->getLabel()); + processedLabels.insert(rabund->getLabel()); + userLabels.erase(rabund->getLabel()); //restore real lastlabel to save below - list->setLabel(saveLabel); + rabund->setLabel(saveLabel); } - lastLabel = list->getLabel(); + lastLabel = rabund->getLabel(); - delete list; - list = input->getListVector(); + delete rabund; + rabund = input->getRAbundVector(); } //output error messages about any remaining user labels @@ -237,20 +244,17 @@ int GetRAbundCommand::execute(){ //run last label if you need to if (needToRun == true) { - if (list != NULL) { delete list; } - list = input->getListVector(lastLabel); + if (rabund != NULL) { delete rabund; } + rabund = input->getRAbundVector(lastLabel); - m->mothurOut(list->getLabel()); m->mothurOutEndLine(); - rabund = new RAbundVector(); - *rabund = (list->getRAbundVector()); - - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete list; delete rabund; globaldata->gListVector = NULL; return 0; } + m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); + + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete input; delete rabund; return 0; } if(sorted) { rabund->print(out); } else { rabund->nonSortedPrint(out); } delete rabund; - delete list; } m->mothurOutEndLine(); @@ -259,9 +263,7 @@ int GetRAbundCommand::execute(){ m->mothurOutEndLine(); out.close(); - - globaldata->gListVector = NULL; - + //set rabund file as new current rabundfile string current = ""; itTypes = outputTypes.find("rabund"); diff --git a/getrabundcommand.h b/getrabundcommand.h index e853ac5..dd0cefc 100644 --- a/getrabundcommand.h +++ b/getrabundcommand.h @@ -13,33 +13,31 @@ #include "command.hpp" #include "inputdata.h" -#include "readotu.h" #include "listvector.hpp" -class GlobalData; class GetRAbundCommand : public Command { public: GetRAbundCommand(string); GetRAbundCommand(); - ~GetRAbundCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~GetRAbundCommand(){} + + vector setParameters(); + string getCommandName() { return "get.rabund"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; - string filename; + + string filename, listfile, sabundfile, inputfile, format, outputDir; ofstream out; - ReadOTUFile* read; InputData* input; - ListVector* list; RAbundVector* rabund; vector outputNames; - map > outputTypes; bool abort, allLines, sorted; set labels; //holds labels to be used diff --git a/getrelabundcommand.cpp b/getrelabundcommand.cpp index e79ccc9..6397e35 100644 --- a/getrelabundcommand.cpp +++ b/getrelabundcommand.cpp @@ -10,92 +10,111 @@ #include "getrelabundcommand.h" //********************************************************************************************************************** -vector GetRelAbundCommand::getValidParameters(){ +vector GetRelAbundCommand::setParameters(){ try { - string Array[] = {"groups","label","scale","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pscale("scale", "Multiple", "totalgroup-totalotu-averagegroup-averageotu", "totalgroup", "", "", "",false,false); parameters.push_back(pscale); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetRelAbundCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -GetRelAbundCommand::GetRelAbundCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["relabund"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "GetRelAbundCommand", "GetRelAbundCommand"); + m->errorOut(e, "GetRelAbundCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector GetRelAbundCommand::getRequiredParameters(){ +string GetRelAbundCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The get.relabund command parameters are shared, groups, scale and label. shared is required, unless you have a valid current file.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n"; + helpString += "The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"; + helpString += "The scale parameter allows you to select what scale you would like to use. Choices are totalgroup, totalotu, averagegroup, averageotu, default is totalgroup.\n"; + helpString += "The get.relabund command should be in the following format: get.relabund(groups=yourGroups, label=yourLabels).\n"; + helpString += "Example get.relabund(groups=A-B-C, scale=averagegroup).\n"; + helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"; + helpString += "The get.relabund command outputs a .relabund file.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetRelAbundCommand", "getRequiredParameters"); + m->errorOut(e, "GetRelAbundCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector GetRelAbundCommand::getRequiredFiles(){ +GetRelAbundCommand::GetRelAbundCommand(){ try { - string Array[] = {"shared"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["relabund"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "GetRelAbundCommand", "getRequiredFiles"); + m->errorOut(e, "GetRelAbundCommand", "GetRelAbundCommand"); exit(1); } } //********************************************************************************************************************** GetRelAbundCommand::GetRelAbundCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); - + //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"groups","label","scale","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } //initialize outputTypes vector tempOutNames; outputTypes["relabund"] = 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 = ""; } + else { + string path; + 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; } + } + } - //if the user changes the output directory command factory will send this info to us in the output parameter - outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ - outputDir = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + //get shared file + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; } } - //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "")) { - m->mothurOut("You must read a list and a group, or a shared file before you can use the get.relabund command."); 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(sharedfile); } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -106,18 +125,12 @@ GetRelAbundCommand::GetRelAbundCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; pickedGroups = false; } else { pickedGroups = true; m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } scale = validParameter.validFile(parameters, "scale", false); if (scale == "not found") { scale = "totalgroup"; } @@ -133,34 +146,6 @@ GetRelAbundCommand::GetRelAbundCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void GetRelAbundCommand::help(){ - try { - m->mothurOut("The get.relabund command can only be executed after a successful read.otu command of a list and group or shared file.\n"); - m->mothurOut("The get.relabund command parameters are groups, scale and label. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"); - m->mothurOut("The scale parameter allows you to select what scale you would like to use. Choices are totalgroup, totalotu, averagegroup, averageotu, default is totalgroup.\n"); - m->mothurOut("The get.relabund command should be in the following format: get.relabund(groups=yourGroups, label=yourLabels).\n"); - m->mothurOut("Example get.relabund(groups=A-B-C, scale=averagegroup).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"); - m->mothurOut("The get.relabund command outputs a .relabund file.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "GetRelAbundCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -GetRelAbundCommand::~GetRelAbundCommand(){ -} - //********************************************************************************************************************** int GetRelAbundCommand::execute(){ @@ -168,14 +153,12 @@ int GetRelAbundCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "relabund"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "relabund"; ofstream out; m->openOutputFile(outputFileName, out); out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - input = globaldata->ginput; + input = new InputData(sharedfile, "sharedfile"); lookup = input->getSharedRAbundVectors(); string lastLabel = lookup[0]->getLabel(); @@ -186,7 +169,7 @@ int GetRelAbundCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); delete input; out.close(); remove(outputFileName.c_str()); return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -217,13 +200,13 @@ int GetRelAbundCommand::execute(){ //prevent memory leak for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); delete input; out.close(); remove(outputFileName.c_str()); return 0; } //get next line to process lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); delete input; out.close(); remove(outputFileName.c_str()); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -251,9 +234,8 @@ int GetRelAbundCommand::execute(){ } //reset groups parameter - globaldata->Groups.clear(); - delete input; globaldata->ginput = NULL; - delete read; + m->Groups.clear(); + delete input; out.close(); if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0;} diff --git a/getrelabundcommand.h b/getrelabundcommand.h index 90d5f9a..ab1896f 100644 --- a/getrelabundcommand.h +++ b/getrelabundcommand.h @@ -12,35 +12,32 @@ #include "command.hpp" #include "inputdata.h" -#include "readotu.h" #include "sharedrabundvector.h" -class GlobalData; class GetRelAbundCommand : public Command { public: GetRelAbundCommand(string); GetRelAbundCommand(); - ~GetRelAbundCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~GetRelAbundCommand(){} + + vector setParameters(); + string getCommandName() { return "get.relabund"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; - ReadOTUFile* read; InputData* input; vector lookup; bool abort, allLines, pickedGroups; set labels; //holds labels to be used - string groups, label, outputDir, scale; + string groups, label, outputDir, scale, sharedfile; vector Groups, outputNames; - map > outputTypes; int getRelAbundance(vector&, ofstream&); diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index 0533af3..98bdcb2 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -10,92 +10,118 @@ #include "getsabundcommand.h" //********************************************************************************************************************** -vector GetSAbundCommand::getValidParameters(){ +vector GetSAbundCommand::setParameters(){ try { - string Array[] = {"label","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetSAbundCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -GetSAbundCommand::GetSAbundCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["sabund"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "GetSAbundCommand", "GetSAbundCommand"); + m->errorOut(e, "GetSAbundCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector GetSAbundCommand::getRequiredParameters(){ +string GetSAbundCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The get.sabund command parameters is list, rabund and label. list or rabund is required unless a valid current file exists.\n"; + helpString += "The label parameter allows you to select what distance levels you would like included in your .sabund file, and are separated by dashes.\n"; + helpString += "The get.sabund command should be in the following format: get.sabund(label=yourLabels).\n"; + helpString += "Example get.sabund().\n"; + helpString += "The default value for label is all labels in your inputfile.\n"; + helpString += "The get.sabund command outputs a .sabund file containing the labels you selected.\n"; + helpString += "Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetSAbundCommand", "getRequiredParameters"); + m->errorOut(e, "GetSAbundCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector GetSAbundCommand::getRequiredFiles(){ +GetSAbundCommand::GetSAbundCommand(){ try { - string Array[] = {"list","rabund"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["sabund"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "GetSAbundCommand", "getRequiredFiles"); + m->errorOut(e, "GetSAbundCommand", "GetSAbundCommand"); exit(1); } } //********************************************************************************************************************** GetSAbundCommand::GetSAbundCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"label","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } //initialize outputTypes vector tempOutNames; outputTypes["sabund"] = tempOutNames; - - //if the user changes the output directory command factory will send this info to us in the output parameter - string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ - outputDir = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + + //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("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; } + } } - - //make sure the user has already run the read.otu command - if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "")) { m->mothurOut("You must read a list or rabund before you can use the get.sabund command."); m->mothurOutEndLine(); abort = true; } - //check for optional parameter and set defaults + + //check for required parameters + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { listfile = ""; abort = true; } + else if (listfile == "not found") { listfile = ""; } + else { format = "list"; inputfile = listfile; } + + rabundfile = validParameter.validFile(parameters, "rabund", true); + if (rabundfile == "not open") { rabundfile = ""; abort = true; } + else if (rabundfile == "not found") { rabundfile = ""; } + else { format = "rabund"; inputfile = rabundfile; } + + + //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 = ""; } @@ -104,16 +130,27 @@ GetSAbundCommand::GetSAbundCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if(label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - - if (abort == false) { - filename = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "sabund"; - m->openOutputFile(filename, out); + if ((listfile == "") && (rabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + rabundfile = m->getRabundFile(); + if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list or rabund file."); 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(inputfile); } + + } } @@ -124,91 +161,63 @@ GetSAbundCommand::GetSAbundCommand(string option) { } //********************************************************************************************************************** -void GetSAbundCommand::help(){ - try { - m->mothurOut("The get.sabund command can only be executed after a successful read.otu of a listfile or rabundfile.\n"); - m->mothurOut("The get.sabund command parameters is label. No parameters are required.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like included in your .sabund file, and are separated by dashes.\n"); - m->mothurOut("The get.sabund command should be in the following format: get.sabund(label=yourLabels).\n"); - m->mothurOut("Example get.sabund().\n"); - m->mothurOut("The default value for label is all labels in your inputfile.\n"); - m->mothurOut("The get.sabund command outputs a .sabund file containing the labels you selected.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "GetSAbundCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -GetSAbundCommand::~GetSAbundCommand(){ -} - -//********************************************************************************************************************** - int GetSAbundCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - - //using order vector so you don't have to distinguish between the list and rabund files - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); + filename = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "sabund"; + m->openOutputFile(filename, out); + + input = new InputData(inputfile, format); + sabund = input->getSAbundVector(); + string lastLabel = sabund->getLabel(); - order = globaldata->gorder; - string lastLabel = order->getLabel(); - input = globaldata->ginput; //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete sabund; delete input; return 0; } - while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { + while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if(allLines == 1 || labels.count(order->getLabel()) == 1){ - m->mothurOut(order->getLabel()); m->mothurOutEndLine(); - sabund = new SAbundVector(); - *sabund = (order->getSAbundVector()); + if(allLines == 1 || labels.count(sabund->getLabel()) == 1){ + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); + sabund->print(out); delete sabund; - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete sabund; delete input; return 0; } - processedLabels.insert(order->getLabel()); - userLabels.erase(order->getLabel()); + processedLabels.insert(sabund->getLabel()); + userLabels.erase(sabund->getLabel()); } - if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { - string saveLabel = order->getLabel(); + if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + string saveLabel = sabund->getLabel(); - delete order; - order = (input->getOrderVector(lastLabel)); + delete sabund; + sabund = (input->getSAbundVector(lastLabel)); - m->mothurOut(order->getLabel()); m->mothurOutEndLine(); - sabund = new SAbundVector(); - *sabund = (order->getSAbundVector()); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); sabund->print(out); delete sabund; - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete sabund; delete input; return 0; } - processedLabels.insert(order->getLabel()); - userLabels.erase(order->getLabel()); + processedLabels.insert(sabund->getLabel()); + userLabels.erase(sabund->getLabel()); //restore real lastlabel to save below - order->setLabel(saveLabel); + sabund->setLabel(saveLabel); } - lastLabel = order->getLabel(); + lastLabel = sabund->getLabel(); - delete order; - order = (input->getOrderVector()); + delete sabund; + sabund = (input->getSAbundVector()); } //output error messages about any remaining user labels @@ -226,22 +235,19 @@ int GetSAbundCommand::execute(){ //run last label if you need to if (needToRun == true) { - if (order != NULL) { delete order; } - order = (input->getOrderVector(lastLabel)); + if (sabund != NULL) { delete sabund; } + sabund = (input->getSAbundVector(lastLabel)); - m->mothurOut(order->getLabel()); m->mothurOutEndLine(); - sabund = new SAbundVector(); - *sabund = (order->getSAbundVector()); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); sabund->print(out); delete sabund; - if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete order; globaldata->gorder = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); out.close(); remove(filename.c_str()); delete input; return 0; } - delete order; } - globaldata->gorder = NULL; - + out.close(); + delete input; m->mothurOutEndLine(); m->mothurOut("Output File Name: "); m->mothurOutEndLine(); diff --git a/getsabundcommand.h b/getsabundcommand.h index b5363e1..d17574f 100644 --- a/getsabundcommand.h +++ b/getsabundcommand.h @@ -13,33 +13,28 @@ #include "command.hpp" #include "inputdata.h" -#include "readotu.h" #include "sabundvector.hpp" -class GlobalData; - class GetSAbundCommand : public Command { public: GetSAbundCommand(string); GetSAbundCommand(); - ~GetSAbundCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~GetSAbundCommand() {} + + vector setParameters(); + string getCommandName() { return "get.sabund"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; - string filename, format; + string filename, format, inputfile, listfile, rabundfile, outputDir; ofstream out; - ReadOTUFile* read; - OrderVector* order; InputData* input; SAbundVector* sabund; vector outputNames; - map > outputTypes; bool abort, allLines; set labels; //holds labels to be used diff --git a/getseqscommand.cpp b/getseqscommand.cpp index ce820fe..5db2888 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -12,21 +12,53 @@ #include "listvector.hpp" //********************************************************************************************************************** -vector GetSeqsCommand::getValidParameters(){ +vector GetSeqsCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "qfile","alignreport", "accnos", "accnos2","dups", "list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pqfile); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos); + CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetSeqsCommand", "getValidParameters"); + m->errorOut(e, "GetSeqsCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string GetSeqsCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The get.seqs command reads an .accnos file and any of the following file types: fasta, name, group, list, taxonomy, quality or alignreport file.\n"; + helpString += "It outputs a file containing only the sequences in the .accnos file.\n"; + helpString += "The get.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups. You must provide accnos unless you have a valid current accnos file, and at least one of the other parameters.\n"; + helpString += "The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n"; + helpString += "The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n"; + helpString += "Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "GetSeqsCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** GetSeqsCommand::GetSeqsCommand(){ try { - abort = true; calledHelp = true; + abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["taxonomy"] = tempOutNames; @@ -43,29 +75,6 @@ GetSeqsCommand::GetSeqsCommand(){ } } //********************************************************************************************************************** -vector GetSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"accnos"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetSeqsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector GetSeqsCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetSeqsCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** GetSeqsCommand::GetSeqsCommand(string option) { try { abort = false; calledHelp = false; @@ -74,9 +83,7 @@ GetSeqsCommand::GetSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name", "group", "alignreport", "qfile", "accnos", "accnos2","dups", "list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -185,7 +192,14 @@ GetSeqsCommand::GetSeqsCommand(string option) { //check for required parameters accnosfile = validParameter.validFile(parameters, "accnos", true); if (accnosfile == "not open") { abort = true; } - else if (accnosfile == "not found") { accnosfile = ""; m->mothurOut("You must provide an accnos file."); m->mothurOutEndLine(); abort = true; } + else if (accnosfile == "not found") { + accnosfile = m->getAccnosFile(); + if (accnosfile != "") { m->mothurOut("Using " + accnosfile + " as input file for the accnos parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You have no valid accnos file and accnos is required."); m->mothurOutEndLine(); + abort = true; + } + } if (accnosfile2 == "not found") { accnosfile2 = ""; } @@ -222,9 +236,6 @@ GetSeqsCommand::GetSeqsCommand(string option) { dups = m->isTrue(temp); if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == "") && (accnosfile2 == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport, taxonomy, quality or listfile."); m->mothurOutEndLine(); abort = true; } - - if ((usedDups != "") && (namefile == "")) { m->mothurOut("You may only use dups with the name option."); m->mothurOutEndLine(); abort = true; } - } } @@ -235,24 +246,6 @@ GetSeqsCommand::GetSeqsCommand(string option) { } //********************************************************************************************************************** -void GetSeqsCommand::help(){ - try { - m->mothurOut("The get.seqs command reads an .accnos file and any of the following file types: fasta, name, group, list, taxonomy, quality or alignreport file.\n"); - m->mothurOut("It outputs a file containing only the sequences in the .accnos file.\n"); - m->mothurOut("The get.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups. You must provide accnos and at least one of the other parameters.\n"); - m->mothurOut("The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n"); - m->mothurOut("The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n"); - m->mothurOut("Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "GetSeqsCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int GetSeqsCommand::execute(){ try { diff --git a/getseqscommand.h b/getseqscommand.h index aef789a..07d13d6 100644 --- a/getseqscommand.h +++ b/getseqscommand.h @@ -18,20 +18,22 @@ class GetSeqsCommand : public Command { GetSeqsCommand(string); GetSeqsCommand(); - ~GetSeqsCommand(){}; - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + ~GetSeqsCommand(){} + + vector setParameters(); + string getCommandName() { return "get.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + + private: set names; vector outputNames; string accnosfile, accnosfile2, fastafile, namefile, groupfile, alignfile, listfile, taxfile, qualfile, outputDir; bool abort, dups; - map > outputTypes; int readFasta(); int readName(); diff --git a/getsharedotucommand.cpp b/getsharedotucommand.cpp index 4fe711e..f12b1cd 100644 --- a/getsharedotucommand.cpp +++ b/getsharedotucommand.cpp @@ -9,53 +9,66 @@ #include "getsharedotucommand.h" - //********************************************************************************************************************** -vector GetSharedOTUCommand::getValidParameters(){ +vector GetSharedOTUCommand::setParameters(){ try { - string Array[] = {"label","unique","shared","fasta","list","group","output","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(plist); + CommandParameter poutput("output", "Multiple", "accnos-default", "default", "", "", "",false,false); parameters.push_back(poutput); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter punique("unique", "String", "", "", "", "", "",false,false); parameters.push_back(punique); + CommandParameter pshared("shared", "String", "", "", "", "", "",false,false); parameters.push_back(pshared); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "GetSharedOTUCommand", "getValidParameters"); + m->errorOut(e, "GetSharedOTUCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -GetSharedOTUCommand::GetSharedOTUCommand(){ +string GetSharedOTUCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["accnos"] = tempOutNames; - outputTypes["sharedseqs"] = tempOutNames; + string helpString = ""; + helpString += "The get.sharedseqs command parameters are list, group, label, unique, shared, output and fasta. The list and group parameters are required, unless you have valid current files.\n"; + helpString += "The label parameter allows you to select what distance levels you would like output files for, and are separated by dashes.\n"; + helpString += "The unique and shared parameters allow you to select groups you would like to know the shared info for, and are separated by dashes.\n"; + helpString += "If you enter your groups under the unique parameter mothur will return the otus that contain ONLY sequences from those groups.\n"; + helpString += "If you enter your groups under the shared parameter mothur will return the otus that contain sequences from those groups and may also contain sequences from other groups.\n"; + helpString += "If you do not enter any groups then the get.sharedseqs command will return sequences that are unique to all groups in your group file.\n"; + helpString += "The fasta parameter allows you to input a fasta file and outputs a fasta file for each distance level containing only the sequences that are in OTUs shared by the groups specified.\n"; + helpString += "The output parameter allows you to output the list of names without the group and bin number added. \n"; + helpString += "With this option you can use the names file as an input in get.seqs and remove.seqs commands. To do this enter output=accnos. \n"; + helpString += "The get.sharedseqs command outputs a .names file for each distance level containing a list of sequences in the OTUs shared by the groups specified.\n"; + helpString += "The get.sharedseqs command should be in the following format: get.sharedseqs(label=yourLabels, groups=yourGroups, fasta=yourFastafile, output=yourOutput).\n"; + helpString += "Example get.sharedseqs(list=amazon.fn.list, label=unique-0.01, group=forest-pasture, fasta=amazon.fasta, output=accnos).\n"; + helpString += "The output to the screen is the distance and the number of otus at that distance for the groups you specified.\n"; + helpString += "The default value for label is all labels in your inputfile. The default for groups is all groups in your file.\n"; + helpString += "Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "GetSharedOTUCommand", "GetSharedOTUCommand"); + m->errorOut(e, "GetSharedOTUCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector GetSharedOTUCommand::getRequiredParameters(){ - try { - string Array[] = {"list","group"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "GetSharedOTUCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector GetSharedOTUCommand::getRequiredFiles(){ +GetSharedOTUCommand::GetSharedOTUCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["accnos"] = tempOutNames; + outputTypes["sharedseqs"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "GetSharedOTUCommand", "getRequiredFiles"); + m->errorOut(e, "GetSharedOTUCommand", "GetSharedOTUCommand"); exit(1); } } @@ -63,19 +76,15 @@ vector GetSharedOTUCommand::getRequiredFiles(){ GetSharedOTUCommand::GetSharedOTUCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; unique = true; allLines = 1; - labels.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"label","unique","shared","fasta","list","group","output","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -131,12 +140,25 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { //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"); } + else if (listfile == "not found") { + listfile = m->getListFile(); + if (listfile != "") { format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current list file. You must provide a list file."); m->mothurOutEndLine(); + abort = true; + } + }else { format = "list"; } groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; } + else if (groupfile == "not found") { + groupfile = m->getGroupFile(); + if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current group file. You must provide a group file."); m->mothurOutEndLine(); + abort = true; + } + } if ((listfile == "") || (groupfile == "")) { m->mothurOut("The list and group parameters are required."); m->mothurOutEndLine(); abort = true; } @@ -151,13 +173,14 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { output = validParameter.validFile(parameters, "output", false); if (output == "not found") { output = ""; } + else if (output == "default") { output = ""; } groups = validParameter.validFile(parameters, "unique", false); if (groups == "not found") { groups = ""; } else { userGroups = "unique." + groups; m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } @@ -166,7 +189,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { else { userGroups = groups; m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; unique = false; } @@ -184,36 +207,6 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option) { } //********************************************************************************************************************** -void GetSharedOTUCommand::help(){ - try { - m->mothurOut("The get.sharedseqs command parameters are list, group, label, unique, shared, output and fasta. The list and group parameters are required.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like output files for, and are separated by dashes.\n"); - m->mothurOut("The unique and shared parameters allow you to select groups you would like to know the shared info for, and are separated by dashes.\n"); - m->mothurOut("If you enter your groups under the unique parameter mothur will return the otus that contain ONLY sequences from those groups.\n"); - m->mothurOut("If you enter your groups under the shared parameter mothur will return the otus that contain sequences from those groups and may also contain sequences from other groups.\n"); - m->mothurOut("If you do not enter any groups then the get.sharedseqs command will return sequences that are unique to all groups in your group file.\n"); - m->mothurOut("The fasta parameter allows you to input a fasta file and outputs a fasta file for each distance level containing only the sequences that are in OTUs shared by the groups specified.\n"); - m->mothurOut("The output parameter allows you to output the list of names without the group and bin number added. \n"); - m->mothurOut("With this option you can use the names file as an input in get.seqs and remove.seqs commands. To do this enter output=accnos. \n"); - m->mothurOut("The get.sharedseqs command outputs a .names file for each distance level containing a list of sequences in the OTUs shared by the groups specified.\n"); - m->mothurOut("The get.sharedseqs command should be in the following format: get.sharedseqs(label=yourLabels, groups=yourGroups, fasta=yourFastafile, output=yourOutput).\n"); - m->mothurOut("Example get.sharedseqs(list=amazon.fn.list, label=unique-0.01, group=forest-pasture, fasta=amazon.fasta, output=accnos).\n"); - m->mothurOut("The output to the screen is the distance and the number of otus at that distance for the groups you specified.\n"); - m->mothurOut("The default value for label is all labels in your inputfile. The default for groups is all groups in your file.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "GetSharedOTUCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -GetSharedOTUCommand::~GetSharedOTUCommand(){} - -//********************************************************************************************************************** - int GetSharedOTUCommand::execute(){ try { @@ -225,8 +218,6 @@ int GetSharedOTUCommand::execute(){ if (m->control_pressed) { delete groupMap; return 0; } - globaldata->gGroupmap = groupMap; - if (Groups.size() == 0) { Groups = groupMap->namesOfGroups; @@ -328,7 +319,7 @@ int GetSharedOTUCommand::execute(){ //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); if (lastlist != NULL) { delete lastlist; } diff --git a/getsharedotucommand.h b/getsharedotucommand.h index 0e25721..27a57b0 100644 --- a/getsharedotucommand.h +++ b/getsharedotucommand.h @@ -14,7 +14,6 @@ #include "listvector.hpp" #include "sequence.hpp" #include "groupmap.h" -#include "globaldata.hpp" //********************************************************************************************************************** class GetSharedOTUCommand : public Command { @@ -23,29 +22,31 @@ class GetSharedOTUCommand : public Command { GetSharedOTUCommand(string); GetSharedOTUCommand(); - ~GetSharedOTUCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~GetSharedOTUCommand() {} + + vector setParameters(); + string getCommandName() { return "get.sharedseqs"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getRequiredCommand() { return "none"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + + private: - - GlobalData* globaldata; ListVector* list; GroupMap* groupMap; set labels; - string fastafile, label, groups, listfile, groupfile, output, userGroups, outputDir; + string fastafile, label, groups, listfile, groupfile, output, userGroups, outputDir, format; bool abort, allLines, unique; vector Groups; map groupFinder; map::iterator it; vector seqs; vector outputNames; - map > outputTypes; int process(ListVector*); diff --git a/globaldata.cpp b/globaldata.cpp index b18324b..a0b80ec 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -1,5 +1,5 @@ - +/* #include "globaldata.hpp" #include "sharedlistvector.h" #include "inputdata.h" @@ -7,7 +7,7 @@ /*******************************************************/ -/******************************************************/ +/****************************************************** GlobalData* GlobalData::getInstance() { if( _uniqueInstance == 0) { _uniqueInstance = new GlobalData(); @@ -16,7 +16,7 @@ GlobalData* GlobalData::getInstance() { } /*******************************************************/ -/******************************************************/ +/****************************************************** // These functions give you the option parameters of the commands string GlobalData::getPhylipFile() { return phylipfile; } string GlobalData::getColumnFile() { return columnfile; } @@ -49,7 +49,7 @@ void GlobalData::setFormat(string Format) { format = Format; } /*******************************************************/ -/******************************************************/ +/****************************************************** GlobalData::GlobalData() { m = MothurOut::getInstance(); //option definitions should go here... @@ -71,7 +71,7 @@ GlobalData::GlobalData() { } /*******************************************************/ -/******************************************************/ +/****************************************************** void GlobalData::clear() { //option definitions should go here... phylipfile = ""; //do we need this? @@ -94,7 +94,7 @@ void GlobalData::clear() { /*******************************************************/ -/******************************************************/ +/****************************************************** void GlobalData::newRead() { try{ //remove old file names @@ -143,7 +143,7 @@ void GlobalData::newRead() { //******************************************************/ -/******************************************************/ +/***************************************************** GlobalData::~GlobalData() { _uniqueInstance = 0; try { diff --git a/globaldata.hpp b/globaldata.hpp index b5e8c7c..59bbac5 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -1,6 +1,6 @@ #ifndef GLOBALDATA_HPP #define GLOBALDATA_HPP - +/* #include "mothur.h" #include "groupmap.h" #include "treemap.h" @@ -29,8 +29,8 @@ class SequenceDB; class GlobalData { public: static GlobalData* getInstance(); - ListVector* gListVector; - SparseMatrix* gSparseMatrix; + /*ListVector* gListVector; + //SparseMatrix* gSparseMatrix; InputData* ginput; OrderVector* gorder; ListVector* glist; @@ -38,20 +38,21 @@ public: SharedListVector* gSharedList; SAbundVector* sabund; RAbundVector* rabund; - GroupMap* gGroupmap; + //GroupMap* gGroupmap; FullMatrix* gMatrix; TreeMap* gTreemap; SequenceDB* gSequenceDB; - string inputFileName, argv; - bool allLines, runParse, jumble, sim; - vector Estimators, Groups; //holds estimators to be used - set labels; //holds labels to be used + NameAssignment* nameMap; + string argv; //inputFileName, + bool runParse, jumble, sim; //allLines, + vector Estimators;//, Groups; //holds estimators to be used + //set labels; //holds labels to be used vector Treenames; map names; string saveNextLabel; - string getPhylipFile(); + /*string getPhylipFile(); string getColumnFile(); string getListFile(); string getRabundFile(); @@ -78,19 +79,19 @@ public: void setRelAbundFile(string); void setOrderFile(string file); void setOrderGroupFile(string file); - void setFormat(string); //do we need this? + void setFormat(string); //do we need this?*/ - NameAssignment* nameMap; - void clear(); - void clearLabels(); - void clearAbund(); - void newRead(); + //void clear(); + //void clearLabels(); + //void clearAbund(); + //void newRead(); + /* private: MothurOut* m; - string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, treefile, sharedfile, format, distfile, ordergroup, relAbundfile; + //string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, treefile, sharedfile, format, distfile, ordergroup, relAbundfile; static GlobalData* _uniqueInstance; GlobalData( const GlobalData& ); // Disable copy constructor @@ -99,6 +100,6 @@ private: ~GlobalData(); -}; +};*/ #endif diff --git a/groupmap.cpp b/groupmap.cpp index 9e99556..58e04c5 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -44,6 +44,7 @@ int GroupMap::readMap() { m->gobble(fileHandle); } fileHandle.close(); + m->namesOfGroups = namesOfGroups; return error; } /************************************************************/ @@ -69,6 +70,7 @@ int GroupMap::readDesignMap() { m->gobble(fileHandle); } fileHandle.close(); + m->namesOfGroups = namesOfGroups; return error; } diff --git a/hclustercommand.cpp b/hclustercommand.cpp index 128dee3..582fc45 100644 --- a/hclustercommand.cpp +++ b/hclustercommand.cpp @@ -10,51 +10,59 @@ #include "hclustercommand.h" //********************************************************************************************************************** -vector HClusterCommand::getValidParameters(){ +vector HClusterCommand::setParameters(){ try { - string Array[] = {"cutoff","hard","precision","method","phylip","column","name","sorted","showabund","timing","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "furthest", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter phard("hard", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(phard); + CommandParameter psorted("sorted", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psorted); + CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pshowabund); + CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptiming); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "HClusterCommand", "getValidParameters"); + m->errorOut(e, "HClusterCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -HClusterCommand::HClusterCommand(){ +string HClusterCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["list"] = tempOutNames; - outputTypes["rabund"] = tempOutNames; - outputTypes["sabund"] = tempOutNames; + string helpString = ""; + helpString += "The hcluster command parameter options are cutoff, precision, method, phylip, column, name, showabund, timing and sorted. Phylip or column and name are required, unless you have valid current files.\n"; + helpString += "The phylip and column parameter allow you to enter your distance file, and sorted indicates whether your column distance file is already sorted. \n"; + helpString += "The name parameter allows you to enter your name file and is required if your distance file is in column format. \n"; + helpString += "The hcluster command should be in the following format: \n"; + helpString += "hcluster(column=youDistanceFile, name=yourNameFile, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"; + helpString += "The acceptable hcluster methods are furthest, nearest, weighted and average.\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "HClusterCommand", "HClusterCommand"); + m->errorOut(e, "HClusterCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector HClusterCommand::getRequiredParameters(){ - try { - string Array[] = {"phylip","column","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "HClusterCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector HClusterCommand::getRequiredFiles(){ +HClusterCommand::HClusterCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "HClusterCommand", "getRequiredFiles"); + m->errorOut(e, "HClusterCommand", "HClusterCommand"); exit(1); } } @@ -62,7 +70,6 @@ vector HClusterCommand::getRequiredFiles(){ //This function checks to make sure the cluster command has no errors and then clusters based on the method chosen. HClusterCommand::HClusterCommand(string option) { try{ - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; //allow user to run help @@ -92,8 +99,6 @@ HClusterCommand::HClusterCommand(string option) { outputTypes["rabund"] = tempOutNames; outputTypes["sabund"] = 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 = ""; } @@ -142,11 +147,31 @@ HClusterCommand::HClusterCommand(string option) { if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } - if ((phylipfile == "") && (columnfile == "")) { m->mothurOut("When executing a hcluster command you must enter a phylip or a column."); m->mothurOutEndLine(); abort = true; } + if ((phylipfile == "") && (columnfile == "")) { + //is there are current file available for either of these? + //give priority to column, then phylip + columnfile = m->getColumnFile(); + if (columnfile != "") { m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); } + else { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a phylip or column file before you can use the hcluster command."); m->mothurOutEndLine(); + abort = true; + } + } + } else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When executing a hcluster 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; } + if (namefile == "") { + namefile = m->getNameFile(); + if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); + abort = true; + } + } } //check for optional parameter and set defaults @@ -212,45 +237,23 @@ HClusterCommand::HClusterCommand(string option) { //********************************************************************************************************************** -void HClusterCommand::help(){ - try { - m->mothurOut("The hcluster command parameter options are cutoff, precision, method, phylip, column, name, showabund, timing and sorted. Phylip or column and name are required.\n"); - m->mothurOut("The phylip and column parameter allow you to enter your distance file, and sorted indicates whether your column distance file is already sorted. \n"); - m->mothurOut("The name parameter allows you to enter your name file and is required if your distance file is in column format. \n"); - m->mothurOut("The hcluster command should be in the following format: \n"); - m->mothurOut("hcluster(column=youDistanceFile, name=yourNameFile, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"); - m->mothurOut("The acceptable hcluster methods are furthest, nearest, weighted and average.\n\n"); - } - catch(exception& e) { - m->errorOut(e, "HClusterCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -HClusterCommand::~HClusterCommand(){} - -//********************************************************************************************************************** - int HClusterCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } + NameAssignment* nameMap = NULL; if(namefile != ""){ - globaldata->nameMap = new NameAssignment(namefile); - globaldata->nameMap->readMap(); - }else{ - globaldata->nameMap = NULL; - } + nameMap = new NameAssignment(namefile); + nameMap->readMap(); + } time_t estart = time(NULL); if (!sorted) { read = new ReadCluster(distfile, cutoff, outputDir, true); read->setFormat(format); - read->read(globaldata->nameMap); + read->read(nameMap); if (m->control_pressed) { delete read; @@ -266,7 +269,7 @@ int HClusterCommand::execute(){ list = read->getListVector(); delete read; }else { - list = new ListVector(globaldata->nameMap->getListVector()); + list = new ListVector(nameMap->getListVector()); } if (m->control_pressed) { @@ -295,7 +298,7 @@ int HClusterCommand::execute(){ print_start = true; start = time(NULL); - cluster = new HCluster(rabund, list, method, distfile, globaldata->nameMap, cutoff); + cluster = new HCluster(rabund, list, method, distfile, nameMap, cutoff); vector seqs; seqs.resize(1); // to start loop if (m->control_pressed) { @@ -374,18 +377,7 @@ int HClusterCommand::execute(){ else if(rndPreviousDistgListVector; globaldata->gListVector = NULL; - - //saves .list file so you can do the collect, rarefaction and summary commands without doing a read.list - if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); } - else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); } - - globaldata->setListFile(fileroot+ tag + ".list"); - globaldata->setNameFile(""); - globaldata->setFormat("list"); - + sabundFile.close(); rabundFile.close(); listFile.close(); diff --git a/hclustercommand.h b/hclustercommand.h index fc03331..5fbdb3d 100644 --- a/hclustercommand.h +++ b/hclustercommand.h @@ -11,7 +11,6 @@ */ #include "command.hpp" -#include "globaldata.hpp" #include "hcluster.h" #include "rabundvector.hpp" #include "sabundvector.hpp" @@ -34,16 +33,18 @@ class HClusterCommand : public Command { public: HClusterCommand(string); HClusterCommand(); - ~HClusterCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~HClusterCommand(){} + + vector setParameters(); + string getCommandName() { return "hcluster"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; HCluster* cluster; ListVector* list; RAbundVector* rabund; @@ -59,7 +60,6 @@ private: time_t start; unsigned long loops; vector outputNames; - map > outputTypes; void printData(string label); }; diff --git a/heatmap.cpp b/heatmap.cpp index 7d6eeaa..36665ff 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -10,9 +10,8 @@ #include "heatmap.h" //********************************************************************************************************************** -HeatMap::HeatMap(string sort, string scale, int num, int fsize, string dir){ +HeatMap::HeatMap(string sort, string scale, int num, int fsize, string dir, string i){ try { - globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); // format = globaldata->getFormat(); sorted = sort; @@ -20,6 +19,7 @@ HeatMap::HeatMap(string sort, string scale, int num, int fsize, string dir){ outputDir = dir; numOTU = num; fontSize = fsize; + inputfile = i; } catch(exception& e) { m->errorOut(e, "HeatMap", "HeatMap"); @@ -70,7 +70,7 @@ string HeatMap::getPic(RAbundVector* rabund) { } - string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + rabund->getLabel() + ".heatmap.bin.svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + rabund->getLabel() + ".heatmap.bin.svg"; m->openOutputFile(filenamesvg, outsvg); //svg image @@ -156,7 +156,7 @@ string HeatMap::getPic(vector lookup) { } } - string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; m->openOutputFile(filenamesvg, outsvg); //svg image @@ -453,7 +453,7 @@ string HeatMap::getPic(vector lookup) { } } - string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + ".heatmap.bin.svg"; m->openOutputFile(filenamesvg, outsvg); //svg image diff --git a/heatmap.h b/heatmap.h index c291a4d..2b49176 100644 --- a/heatmap.h +++ b/heatmap.h @@ -13,7 +13,7 @@ #include "sharedrabundvector.h" #include "sharedrabundfloatvector.h" #include "datavector.hpp" -#include "globaldata.hpp" + /***********************************************************************/ struct binCount { @@ -43,7 +43,7 @@ inline bool comparebinFloatCounts(binCountFloat left, binCountFloat right){ class HeatMap { public: - HeatMap(string, string, int, int, string); + HeatMap(string, string, int, int, string, string); ~HeatMap(){}; string getPic(RAbundVector*); @@ -56,8 +56,7 @@ class HeatMap { int sortRabund(RAbundVector*&); void printLegend(int, float); - GlobalData* globaldata; - string format, sorted, groupComb, scaler, outputDir; + string format, sorted, groupComb, scaler, outputDir, inputfile; ofstream outsvg; MothurOut* m; int numOTU, fontSize; diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index 19a320a..10c15d8 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -10,49 +10,67 @@ #include "heatmapcommand.h" //********************************************************************************************************************** -vector HeatMapCommand::getValidParameters(){ +vector HeatMapCommand::setParameters(){ try { - string Array[] = {"groups","label","sorted","scale","fontsize","numotu","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pscale("scale", "Multiple", "log10-log2-linear", "log10", "", "", "",false,false); parameters.push_back(pscale); + CommandParameter psorted("sorted", "Multiple", "none-shared-topotu-topgroup", "shared", "", "", "",false,false); parameters.push_back(psorted); + CommandParameter pnumotu("numotu", "Number", "", "0", "", "", "",false,false); parameters.push_back(pnumotu); + CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "",false,false); parameters.push_back(pfontsize); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "HeatMapCommand", "getValidParameters"); + m->errorOut(e, "HeatMapCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -HeatMapCommand::HeatMapCommand(){ +string HeatMapCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["svg"] = tempOutNames; + string helpString = ""; + helpString += "The heatmap.bin command parameters are shared, relabund, list, rabund, sabund, groups, sorted, scale, numotu, fontsize and label. shared, relabund, list, rabund or sabund is required unless you have a valid current file.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n"; + helpString += "The sorted parameter allows you to order the otus displayed, default=shared, meaning display the shared otus first. Other options for sorted are none, meaning the exact representation of your otus, \n"; + helpString += "topotu, meaning the otus with the greatest abundance when totaled across groups, topgroup, meaning the top otus for each group. \n"; + helpString += "The scale parameter allows you to choose the range of color your bin information will be displayed with.\n"; + helpString += "The numotu parameter allows you to display only the top N otus, by default all the otus are displayed. You could choose to look at the top 10, by setting numotu=10. The default for sorted is topotu when numotu is used.\n"; + helpString += "The group names are separated by dashes. The label parameter allows you to select what distance levels you would like a heatmap created for, and are also separated by dashes.\n"; + helpString += "The fontsize parameter allows you to adjust the font size of the picture created, default=24.\n"; + helpString += "The heatmap.bin command should be in the following format: heatmap.bin(groups=yourGroups, sorted=yourSorted, label=yourLabels).\n"; + helpString += "Example heatmap.bin(groups=A-B-C, sorted=none, scale=log10).\n"; + helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"; + helpString += "The default value for scale is log10; your other options are log2 and linear.\n"; + helpString += "The heatmap.bin command outputs a .svg file for each label you specify.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "HeatMapCommand", "HeatMapCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector HeatMapCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "HeatMapCommand", "getRequiredParameters"); + m->errorOut(e, "HeatMapCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector HeatMapCommand::getRequiredFiles(){ +HeatMapCommand::HeatMapCommand(){ try { - string Array[] = {"list","sabund","rabund","shared","relabund","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["svg"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "HeatMapCommand", "getRequiredFiles"); + m->errorOut(e, "HeatMapCommand", "HeatMapCommand"); exit(1); } } @@ -60,26 +78,23 @@ vector HeatMapCommand::getRequiredFiles(){ HeatMapCommand::HeatMapCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"groups","label","sorted","scale","fontsize","numotu","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } @@ -87,17 +102,111 @@ HeatMapCommand::HeatMapCommand(string option) { vector tempOutNames; outputTypes["svg"] = 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 = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + //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("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("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("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("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("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; } + } } - //make sure the user has already run the read.otu command - if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "") && (globaldata->getSharedFile() == "") && (globaldata->getRelAbundFile() == "")) { - m->mothurOut("You must read a list, rabund, sabund, or a list and a group, shared, or relabund file before you can use the heatmap.bin command."); m->mothurOutEndLine(); abort = true; + //check for required parameters + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { listfile = ""; abort = true; } + else if (listfile == "not found") { listfile = ""; } + else { format = "list"; inputfile = listfile; } + + sabundfile = validParameter.validFile(parameters, "sabund", true); + if (sabundfile == "not open") { sabundfile = ""; abort = true; } + else if (sabundfile == "not found") { sabundfile = ""; } + else { format = "sabund"; inputfile = sabundfile; } + + rabundfile = validParameter.validFile(parameters, "rabund", true); + if (rabundfile == "not open") { rabundfile = ""; abort = true; } + else if (rabundfile == "not found") { rabundfile = ""; } + else { format = "rabund"; inputfile = rabundfile; } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { format = "sharedfile"; inputfile = sharedfile; } + + relabundfile = validParameter.validFile(parameters, "relabund", true); + if (relabundfile == "not open") { relabundfile = ""; abort = true; } + else if (relabundfile == "not found") { relabundfile = ""; } + else { format = "relabund"; inputfile = relabundfile; } + + + if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "") && (relabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + rabundfile = m->getRabundFile(); + if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } + else { + sabundfile = m->getSabundFile(); + if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } + else { + relabundfile = m->getRelAbundFile(); + if (relabundfile != "") { inputfile = relabundfile; format = "relabund"; m->mothurOut("Using " + relabundfile + " as input file for the relabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list, sabund, rabund, relabund or shared file."); 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(inputfile); } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... label = validParameter.validFile(parameters, "label", false); @@ -107,17 +216,12 @@ HeatMapCommand::HeatMapCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } string temp = validParameter.validFile(parameters, "numotu", false); if (temp == "not found") { temp = "0"; } @@ -144,39 +248,6 @@ HeatMapCommand::HeatMapCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void HeatMapCommand::help(){ - try { - m->mothurOut("The heatmap.bin command can only be executed after a successful read.otu command.\n"); - m->mothurOut("The heatmap.bin command parameters are groups, sorted, scale, numotu, fontsize and label. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n"); - m->mothurOut("The sorted parameter allows you to order the otus displayed, default=shared, meaning display the shared otus first. Other options for sorted are none, meaning the exact representation of your otus, \n"); - m->mothurOut("topotu, meaning the otus with the greatest abundance when totaled across groups, topgroup, meaning the top otus for each group. \n"); - m->mothurOut("The scale parameter allows you to choose the range of color your bin information will be displayed with.\n"); - m->mothurOut("The numotu parameter allows you to display only the top N otus, by default all the otus are displayed. You could choose to look at the top 10, by setting numotu=10. The default for sorted is topotu when numotu is used.\n"); - m->mothurOut("The group names are separated by dashes. The label parameter allows you to select what distance levels you would like a heatmap created for, and are also separated by dashes.\n"); - m->mothurOut("The fontsize parameter allows you to adjust the font size of the picture created, default=24.\n"); - m->mothurOut("The heatmap.bin command should be in the following format: heatmap.bin(groups=yourGroups, sorted=yourSorted, label=yourLabels).\n"); - m->mothurOut("Example heatmap.bin(groups=A-B-C, sorted=none, scale=log10).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"); - m->mothurOut("The default value for scale is log10; your other options are log2 and linear.\n"); - m->mothurOut("The heatmap.bin command outputs a .svg file for each label you specify.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "HeatMapCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -HeatMapCommand::~HeatMapCommand(){ -} - //********************************************************************************************************************** int HeatMapCommand::execute(){ @@ -184,14 +255,10 @@ int HeatMapCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - heatmap = new HeatMap(sorted, scale, numOTU, fontSize, outputDir); - format = globaldata->getFormat(); + heatmap = new HeatMap(sorted, scale, numOTU, fontSize, outputDir, inputfile); string lastLabel; - - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - input = globaldata->ginput; + input = new InputData(inputfile, format); if (format == "sharedfile") { //you have groups @@ -200,7 +267,7 @@ int HeatMapCommand::execute(){ }else if ((format == "list") || (format == "rabund") || (format == "sabund")) { //you are using just a list file and have only one group - rabund = globaldata->rabund; + rabund = input->getRAbundVector(); lastLabel = rabund->getLabel(); }else if (format == "relabund") { //you have groups @@ -219,8 +286,8 @@ int HeatMapCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); - globaldata->Groups.clear(); - delete read; delete heatmap; return 0; + m->Groups.clear(); + delete input; delete heatmap; return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -262,8 +329,8 @@ int HeatMapCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); - globaldata->Groups.clear(); - delete read; delete heatmap; return 0; + m->Groups.clear(); + delete input; delete heatmap; return 0; } //output error messages about any remaining user labels @@ -291,14 +358,14 @@ int HeatMapCommand::execute(){ } //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); }else if ((format == "list") || (format == "rabund") || (format == "sabund")) { while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); - delete rabund; delete read; delete heatmap; return 0; + delete rabund; delete input; delete heatmap; return 0; } if(allLines == 1 || labels.count(rabund->getLabel()) == 1){ @@ -337,7 +404,7 @@ int HeatMapCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); - delete read; delete heatmap; return 0; + delete input; delete heatmap; return 0; } //output error messages about any remaining user labels @@ -362,7 +429,7 @@ int HeatMapCommand::execute(){ string outputFileName = heatmap->getPic(rabund); outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName); - delete rabund; globaldata->rabund = NULL; + delete rabund; } }else { @@ -372,8 +439,8 @@ int HeatMapCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); - globaldata->Groups.clear(); - delete read; delete heatmap; return 0; + m->Groups.clear(); + delete input; delete heatmap; return 0; } if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){ @@ -414,8 +481,8 @@ int HeatMapCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); - globaldata->Groups.clear(); - delete read; delete heatmap; return 0; + m->Groups.clear(); + delete input; delete heatmap; return 0; } //output error messages about any remaining user labels @@ -443,25 +510,21 @@ int HeatMapCommand::execute(){ } //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); } - globaldata->rabund = NULL; - delete input; globaldata->ginput = NULL; + delete input; + delete heatmap; if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); - delete read; delete heatmap; return 0; + for (int i = 0; i < outputNames.size(); i++) { if (outputNames[i] != "control") { remove(outputNames[i].c_str()); } } outputTypes.clear(); return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } m->mothurOutEndLine(); - - delete read; - delete heatmap; return 0; } diff --git a/heatmapcommand.h b/heatmapcommand.h index a85d510..6fb5ff0 100644 --- a/heatmapcommand.h +++ b/heatmapcommand.h @@ -13,31 +13,29 @@ #include "command.hpp" #include "inputdata.h" -#include "readotu.h" #include "sharedlistvector.h" #include "heatmap.h" #include "rabundvector.hpp" -class GlobalData; class HeatMapCommand : public Command { public: HeatMapCommand(string); HeatMapCommand(); - ~HeatMapCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~HeatMapCommand(){} + + vector setParameters(); + string getCommandName() { return "heatmap.bin"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; - ReadOTUFile* read; InputData* input; - SharedListVector* SharedList; RAbundVector* rabund; vector lookup; vector lookupFloat; @@ -45,9 +43,8 @@ private: bool abort, allLines; set labels; //holds labels to be used - string format, groups, sorted, scale, label, outputDir; + string format, groups, sorted, scale, label, outputDir, sharedfile, relabundfile, listfile, rabundfile, sabundfile, inputfile; vector Groups, outputNames; - map > outputTypes; int numOTU, fontSize; diff --git a/heatmapsim.cpp b/heatmapsim.cpp index efe4140..9c5e780 100644 --- a/heatmapsim.cpp +++ b/heatmapsim.cpp @@ -20,8 +20,7 @@ #include "sharedbraycurtis.h" //********************************************************************************************************************** -HeatMapSim::HeatMapSim(string dir) : outputDir(dir) { - globaldata = GlobalData::getInstance(); +HeatMapSim::HeatMapSim(string dir, string i) : outputDir(dir), inputfile(i) { m = MothurOut::getInstance(); } //********************************************************************************************************************** @@ -36,7 +35,7 @@ vector HeatMapSim::getPic(vector lookup, vectorcontrol_pressed) { return outputNames; } - string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + calcs[k]->getName() + ".heatmap.sim.svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + calcs[k]->getName() + ".heatmap.sim.svg"; m->openOutputFile(filenamesvg, outsvg); outputNames.push_back(filenamesvg); @@ -114,7 +113,7 @@ string HeatMapSim::getPic(vector< vector > dists, vector groups) vector sims; - string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "heatmap.sim.svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "heatmap.sim.svg"; m->openOutputFile(filenamesvg, outsvg); //svg image @@ -123,7 +122,7 @@ string HeatMapSim::getPic(vector< vector > dists, vector groups) //white backround outsvg << ""; - outsvg << "Heatmap for " + globaldata->inputFileName + "\n"; + outsvg << "Heatmap for " + inputfile + "\n"; //column labels for (int h = 0; h < groups.size(); h++) { diff --git a/heatmapsim.h b/heatmapsim.h index bb78e42..a28995d 100644 --- a/heatmapsim.h +++ b/heatmapsim.h @@ -12,7 +12,6 @@ #include "sharedrabundvector.h" #include "datavector.hpp" -#include "globaldata.hpp" #include "calculator.h" /***********************************************************************/ @@ -20,7 +19,7 @@ class HeatMapSim { public: - HeatMapSim(string); + HeatMapSim(string, string); ~HeatMapSim(){}; vector getPic(vector, vector); @@ -29,8 +28,7 @@ class HeatMapSim { private: void printLegend(int, float); - GlobalData* globaldata; - string format, groupComb, outputDir; + string format, groupComb, outputDir, inputfile; ofstream outsvg; MothurOut* m; diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp index 28b0221..5a84391 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -19,49 +19,66 @@ #include "sharedmorisitahorn.h" #include "sharedbraycurtis.h" + //********************************************************************************************************************** -vector HeatMapSimCommand::getValidParameters(){ +vector HeatMapSimCommand::setParameters(){ try { - string Array[] = {"groups","label", "calc","phylip","column","name","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pcalc("calc", "Multiple", "jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-morisitahorn-braycurtis", "jest-thetayc", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter 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, "HeatMapSimCommand", "getValidParameters"); + m->errorOut(e, "HeatMapSimCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -HeatMapSimCommand::HeatMapSimCommand(){ +string HeatMapSimCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["svg"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector HeatMapSimCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The heatmap.sim command parameters are shared, phylip, column, name, groups, calc and label. shared or phylip or column and name are required unless valid current files exist.\n"; + helpString += "There are two ways to use the heatmap.sim command. The first is with the read.otu command. \n"; + helpString += "With the read.otu command you may use the groups, label and calc parameters. \n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n"; + helpString += "The group names are separated by dashes. The label parameter allows you to select what distance levels you would like a heatmap created for, and is also separated by dashes.\n"; + helpString += "The heatmap.sim command should be in the following format: heatmap.sim(groups=yourGroups, calc=yourCalc, label=yourLabels).\n"; + helpString += "Example heatmap.sim(groups=A-B-C, calc=jabund).\n"; + helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"; + helpString += validCalculator->printCalc("heat"); + helpString += "The default value for calc is jclass-thetayc.\n"; + helpString += "The heatmap.sim command outputs a .svg file for each calculator you choose at each label you specify.\n"; + helpString += "The second way to use the heatmap.sim command is with a distance file representing the distance bewteen your groups. \n"; + helpString += "Using the command this way, the phylip or column parameter are required, and only one may be used. If you use a column file the name filename is required. \n"; + helpString += "The heatmap.sim command should be in the following format: heatmap.sim(phylip=yourDistanceFile).\n"; + helpString += "Example heatmap.sim(phylip=amazonGroups.dist).\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "HeatMapSimCommand", "getRequiredParameters"); + m->errorOut(e, "HeatMapSimCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector HeatMapSimCommand::getRequiredFiles(){ +HeatMapSimCommand::HeatMapSimCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["svg"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "HeatMapSimCommand", "getRequiredFiles"); + m->errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand"); exit(1); } } @@ -69,20 +86,14 @@ vector HeatMapSimCommand::getRequiredFiles(){ HeatMapSimCommand::HeatMapSimCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Groups.clear(); - Estimators.clear(); //allow user to run help if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"groups","label", "calc","phylip","column","name","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -131,18 +142,31 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { //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("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; } + } } //required parameters phylipfile = validParameter.validFile(parameters, "phylip", true); if (phylipfile == "not open") { abort = true; } else if (phylipfile == "not found") { phylipfile = ""; } - else { format = "phylip"; if (outputDir == "") { outputDir += m->hasPath(phylipfile); } } + else { format = "phylip"; inputfile = phylipfile; if (outputDir == "") { outputDir += m->hasPath(phylipfile); } } columnfile = validParameter.validFile(parameters, "column", true); if (columnfile == "not open") { abort = true; } else if (columnfile == "not found") { columnfile = ""; } - else { format = "column"; if (outputDir == "") { outputDir += m->hasPath(columnfile); } } + else { format = "column"; inputfile = columnfile; if (outputDir == "") { outputDir += m->hasPath(columnfile); } } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { format = "shared"; inputfile = sharedfile; if (outputDir == "") { outputDir += m->hasPath(sharedfile); } } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { abort = true; } @@ -150,48 +174,62 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { //error checking on files - if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == ""))) { m->mothurOut("You must run the read.otu command or provide a distance file before running the heatmap.sim command."); m->mothurOutEndLine(); abort = true; } + if ((sharedfile == "") && ((phylipfile == "") && (columnfile == ""))) { + sharedfile = m->getSharedFile(); + if (sharedfile != "") { format = "shared"; inputfile = sharedfile; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + //is there are current file available for either of these? + //give priority to column, then phylip + columnfile = m->getColumnFile(); + if (columnfile != "") { format = "column"; inputfile = columnfile; m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); } + else { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { format = "phylip"; inputfile = phylipfile; m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a shared or phylip or column file."); m->mothurOutEndLine(); + abort = true; + } + } + } + } else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When running the heatmap.sim command with a distance file you may not use both the column and the phylip parameters."); m->mothurOutEndLine(); abort = true; } if (columnfile != "") { - if (namefile == "") { m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); abort = true; } + if (namefile == "") { + namefile = m->getNameFile(); + if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); + abort = true; + } + } } - if (format == "") { format = "shared"; } - //check for optional parameter and set defaults // ...at some point should added some additional type checking... - if (format == "shared") { - if (outputDir == "") { outputDir += m->hasPath(globaldata->getSharedFile()); } - - label = validParameter.validFile(parameters, "label", false); - if (label == "not found") { label = ""; } - else { - if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } - else { allLines = 1; } - } - - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } + + label = validParameter.validFile(parameters, "label", false); + if (label == "not found") { label = ""; } + else { + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } + else { allLines = 1; } + } - calc = validParameter.validFile(parameters, "calc", false); - if (calc == "not found") { calc = "jest-thetayc"; } - else { - if (calc == "default") { calc = "jest-thetayc"; } - } - m->splitAtDash(calc, Estimators); + calc = validParameter.validFile(parameters, "calc", false); + if (calc == "not found") { calc = "jest-thetayc"; } + else { + if (calc == "default") { calc = "jest-thetayc"; } + } + m->splitAtDash(calc, Estimators); - groups = validParameter.validFile(parameters, "groups", false); - if (groups == "not found") { groups = ""; } - else { - m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; - } + groups = validParameter.validFile(parameters, "groups", false); + if (groups == "not found") { groups = ""; } + else { + m->splitAtDash(groups, Groups); + m->Groups = Groups; } + if (abort == false) { validCalculator = new ValidCalculators(); @@ -233,40 +271,6 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void HeatMapSimCommand::help(){ - try { - m->mothurOut("The heatmap.sim command can only be executed after a successful read.otu command, or by providing a distance file.\n"); - m->mothurOut("The heatmap.sim command parameters are phylip, column, name, groups, calc and label. No parameters are required.\n"); - m->mothurOut("There are two ways to use the heatmap.sim command. The first is with the read.otu command. \n"); - m->mothurOut("With the read.otu command you may use the groups, label and calc parameters. \n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n"); - m->mothurOut("The group names are separated by dashes. The label parameter allows you to select what distance levels you would like a heatmap created for, and is also separated by dashes.\n"); - m->mothurOut("The heatmap.sim command should be in the following format: heatmap.sim(groups=yourGroups, calc=yourCalc, label=yourLabels).\n"); - m->mothurOut("Example heatmap.sim(groups=A-B-C, calc=jabund).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"); - validCalculator->printCalc("heat", cout); - m->mothurOut("The default value for calc is jclass-thetayc.\n"); - m->mothurOut("The heatmap.sim command outputs a .svg file for each calculator you choose at each label you specify.\n"); - m->mothurOut("The second way to use the heatmap.sim command is with a distance file representing the distance bewteen your groups. \n"); - m->mothurOut("Using the command this way, the phylip or column parameter are required, and only one may be used. If you use a column file the name filename is required. \n"); - m->mothurOut("The heatmap.sim command should be in the following format: heatmap.sim(phylip=yourDistanceFile).\n"); - m->mothurOut("Example heatmap.sim(phylip=amazonGroups.dist).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "HeatMapSimCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -HeatMapSimCommand::~HeatMapSimCommand(){} - //********************************************************************************************************************** int HeatMapSimCommand::execute(){ @@ -274,17 +278,11 @@ int HeatMapSimCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - heatmap = new HeatMapSim(outputDir); + heatmap = new HeatMapSim(outputDir, inputfile); if (format == "shared") { runCommandShared(); - }else if (format == "phylip") { - globaldata->inputFileName = phylipfile; - runCommandDist(); - }else if (format == "column") { - globaldata->inputFileName = columnfile; - runCommandDist(); - } + }else{ runCommandDist(); } delete heatmap; delete validCalculator; @@ -310,11 +308,7 @@ int HeatMapSimCommand::runCommandShared() { //if the users entered no valid calculators don't execute command if (heatCalculators.size() == 0) { m->mothurOut("No valid calculators."); m->mothurOutEndLine(); return 0; } - //you have groups - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - - input = globaldata->ginput; + input = new InputData(sharedfile, "sharedfile"); lookup = input->getSharedRAbundVectors(); string lastLabel = lookup[0]->getLabel(); @@ -324,12 +318,12 @@ int HeatMapSimCommand::runCommandShared() { set processedLabels; set userLabels = labels; - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); return 0; } //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -369,7 +363,7 @@ int HeatMapSimCommand::runCommandShared() { } - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { delete input; m->Groups.clear(); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -384,7 +378,7 @@ int HeatMapSimCommand::runCommandShared() { } } - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { delete input; m->Groups.clear(); return 0; } //run last label if you need to if (needToRun == true) { @@ -398,13 +392,12 @@ int HeatMapSimCommand::runCommandShared() { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { delete input; m->Groups.clear(); return 0; } //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); - delete input; globaldata->ginput = NULL; - delete read; + delete input; return 0; } diff --git a/heatmapsimcommand.h b/heatmapsimcommand.h index cd12c17..2a2c367 100644 --- a/heatmapsimcommand.h +++ b/heatmapsimcommand.h @@ -12,41 +12,37 @@ #include "command.hpp" #include "inputdata.h" -#include "readotu.h" #include "validcalculator.h" #include "heatmapsim.h" - -class GlobalData; +#include "nameassignment.hpp" class HeatMapSimCommand : public Command { public: HeatMapSimCommand(string); HeatMapSimCommand(); - ~HeatMapSimCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~HeatMapSimCommand(){} + + vector setParameters(); + string getCommandName() { return "heatmap.sim"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; - ReadOTUFile* read; InputData* input; vector lookup; vector heatCalculators; ValidCalculators* validCalculator; HeatMapSim* heatmap; OptionParser* parser; - map parameters; - map::iterator it; bool abort, allLines; set labels; //holds labels to be used - string format, groups, label, calc, phylipfile, columnfile, namefile, outputDir; + string format, groups, label, calc, sharedfile, phylipfile, columnfile, namefile, outputDir, inputfile; vector Estimators, Groups, outputNames; - map > outputTypes; int runCommandShared(); int runCommandDist(); diff --git a/helpcommand.cpp b/helpcommand.cpp index 3c799b0..47d04f9 100644 --- a/helpcommand.cpp +++ b/helpcommand.cpp @@ -9,54 +9,12 @@ #include "helpcommand.h" -//********************************************************************************************************************** -vector HelpCommand::getValidParameters(){ - try { - - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "HelpCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector HelpCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "HelpCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector HelpCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "HelpCommand", "getRequiredFiles"); - exit(1); - } -} //********************************************************************************************************************** -HelpCommand::HelpCommand(string option) { - - validCommands = CommandFactory::getInstance(); - +HelpCommand::HelpCommand(string option) { + validCommands = CommandFactory::getInstance(); } - //********************************************************************************************************************** - -HelpCommand::~HelpCommand(){} - -//********************************************************************************************************************** - int HelpCommand::execute(){ try { validCommands->printCommands(cout); @@ -71,5 +29,4 @@ int HelpCommand::execute(){ exit(1); } } - //**********************************************************************************************************************/ diff --git a/helpcommand.h b/helpcommand.h index d4e7b1f..4794a67 100644 --- a/helpcommand.h +++ b/helpcommand.h @@ -19,21 +19,20 @@ class HelpCommand : public Command { public: HelpCommand(string); HelpCommand() {} - ~HelpCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help() {}; + ~HelpCommand(){} -private: - CommandFactory* validCommands; - vector outputNames; - map > outputTypes; + vector setParameters() { return outputNames; } //dummy, doesn't really do anything + string getCommandName() { return "help"; } + string getCommandCategory() { return "General"; } + string getHelpString() { return "For more information about a specific command type 'commandName(help)' i.e. 'read.dist(help)'"; } + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: + CommandFactory* validCommands; + vector outputNames; }; diff --git a/homovacommand.cpp b/homovacommand.cpp index defccd3..9f74830 100644 --- a/homovacommand.cpp +++ b/homovacommand.cpp @@ -12,61 +12,58 @@ #include "readphylipvector.h" //********************************************************************************************************************** - -vector HomovaCommand::getValidParameters(){ +vector HomovaCommand::setParameters(){ try { - string Array[] = {"outputdir","iters","phylip","design","alpha", "inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter palpha("alpha", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(palpha); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "HomovaCommand", "getValidParameters"); - exit(1); - } -} - -//********************************************************************************************************************** - -HomovaCommand::HomovaCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["homova"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "HomovaCommand", "HomovaCommand"); + m->errorOut(e, "HomovaCommand", "setParameters"); exit(1); } } - //********************************************************************************************************************** - -vector HomovaCommand::getRequiredParameters(){ +string HomovaCommand::getHelpString(){ try { - string Array[] = {"design"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "Referenced: 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.\n"; + helpString += "The homova command outputs a .homova file. \n"; + helpString += "The homova command parameters are phylip, iters, and alpha. The phylip and design parameters are required, unless valid current files exist.\n"; + helpString += "The design parameter allows you to assign your samples to groups when you are running homova. It is required. \n"; + helpString += "The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the sample name and the second column is the group the sample belongs to.\n"; + helpString += "The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"; + helpString += "The homova command should be in the following format: homova(phylip=file.dist, design=file.design).\n"; + helpString += "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e. 1000).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "HomovaCommand", "getRequiredParameters"); + m->errorOut(e, "HomovaCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector HomovaCommand::getRequiredFiles(){ +HomovaCommand::HomovaCommand(){ try { - string Array[] = {}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["homova"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "HomovaCommand", "getRequiredFiles"); + m->errorOut(e, "HomovaCommand", "HomovaCommand"); exit(1); } } - //********************************************************************************************************************** HomovaCommand::HomovaCommand(string option) { @@ -77,9 +74,7 @@ HomovaCommand::HomovaCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"design","outputdir","iters","phylip","alpha", "inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -123,22 +118,22 @@ HomovaCommand::HomovaCommand(string option) { phylipFileName = validParameter.validFile(parameters, "phylip", true); if (phylipFileName == "not open") { phylipFileName = ""; abort = true; } - else if (phylipFileName == "not found") { phylipFileName = ""; } - else if (designFileName == "not found") { - designFileName = ""; - m->mothurOut("You must provide an phylip file."); - m->mothurOutEndLine(); - abort = true; + else if (phylipFileName == "not found") { + //if there is a current phylip file, use it + phylipFileName = m->getPhylipFile(); + if (phylipFileName != "") { m->mothurOut("Using " + phylipFileName + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current phylip file and the phylip parameter is required."); m->mothurOutEndLine(); abort = true; } + } //check for required parameters designFileName = validParameter.validFile(parameters, "design", true); if (designFileName == "not open") { abort = true; } else if (designFileName == "not found") { - designFileName = ""; - m->mothurOut("You must provide an design file."); - m->mothurOutEndLine(); - abort = true; + //if there is a current design file, use it + designFileName = m->getDesignFile(); + if (designFileName != "") { m->mothurOut("Using " + designFileName + " as input file for the design parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current design file and the design parameter is required."); m->mothurOutEndLine(); abort = true; } } string temp = validParameter.validFile(parameters, "iters", false); @@ -156,30 +151,6 @@ HomovaCommand::HomovaCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void HomovaCommand::help(){ - try { - m->mothurOut("Referenced: 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.\n"); - m->mothurOut("The homova command outputs a .homova file. \n"); - m->mothurOut("The homova command parameters are phylip, iters, and alpha. The phylip and design parameters are required.\n"); - m->mothurOut("The design parameter allows you to assign your samples to groups when you are running homova. It is required. \n"); - m->mothurOut("The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the sample name and the second column is the group the sample belongs to.\n"); - m->mothurOut("The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"); - m->mothurOut("The homova command should be in the following format: homova(phylip=file.dist, design=file.design).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e. 1000).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "HomovaCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -HomovaCommand::~HomovaCommand(){} - //********************************************************************************************************************** int HomovaCommand::execute(){ diff --git a/homovacommand.h b/homovacommand.h index 11f3c07..ec7a793 100644 --- a/homovacommand.h +++ b/homovacommand.h @@ -21,13 +21,15 @@ class HomovaCommand : public Command { public: HomovaCommand(string); HomovaCommand(); - ~HomovaCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + ~HomovaCommand(){} + + vector setParameters(); + string getCommandName() { return "homova"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } private: double runHOMOVA(ofstream& , map >, double); @@ -36,7 +38,6 @@ private: map > getRandomizedGroups(map >); bool abort; - map > outputTypes; vector outputNames; string outputDir, inputDir, designFileName, phylipFileName; diff --git a/indicatorcommand.cpp b/indicatorcommand.cpp index 654ec06..8e80d53 100644 --- a/indicatorcommand.cpp +++ b/indicatorcommand.cpp @@ -10,34 +10,54 @@ #include "indicatorcommand.h" #include "sharedutilities.h" + //********************************************************************************************************************** -vector IndicatorCommand::getValidParameters(){ +vector IndicatorCommand::setParameters(){ try { - string Array[] = {"tree","shared","relabund","design","label","groups","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pdesign); + CommandParameter pshared("shared", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "IndicatorCommand", "getValidParameters"); + m->errorOut(e, "IndicatorCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector IndicatorCommand::getRequiredParameters(){ +string IndicatorCommand::getHelpString(){ try { - string Array[] = {"tree"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The indicator command reads a shared or relabund file and a tree file, and outputs a .indicator.tre and .indicator.summary file. \n"; + helpString += "The new tree contains labels at each internal node. The label is the node number so you can relate the tree to the summary file.\n"; + helpString += "The summary file lists the indicator value for each OTU for each node.\n"; + helpString += "The indicator command parameters are tree, groups, shared, relabund, design and label. The tree parameter is required as well as either shared or relabund.\n"; + helpString += "The design parameter allows you to provide a design file to relate the tree to the shared or relabund file.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your shared or relabund you would like analyzed, or if you provide a design file the groups in your design file. The groups may be entered separated by dashes.\n"; + helpString += "The label parameter indicates at what distance your tree relates to the shared or relabund.\n"; + helpString += "The indicator command should be used in the following format: indicator(tree=test.tre, shared=test.shared, label=0.03)\n"; + helpString += "Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "IndicatorCommand", "getRequiredParameters"); + m->errorOut(e, "IndicatorCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** IndicatorCommand::IndicatorCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["tree"] = tempOutNames; outputTypes["summary"] = tempOutNames; @@ -47,31 +67,16 @@ IndicatorCommand::IndicatorCommand(){ exit(1); } } - -//********************************************************************************************************************** -vector IndicatorCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "IndicatorCommand", "getRequiredFiles"); - exit(1); - } -} //********************************************************************************************************************** IndicatorCommand::IndicatorCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"tree","shared","design","relabund","groups","label","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -84,7 +89,7 @@ IndicatorCommand::IndicatorCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - globaldata->newRead(); + m->runParse = true; vector tempOutNames; outputTypes["tree"] = tempOutNames; @@ -133,8 +138,11 @@ IndicatorCommand::IndicatorCommand(string option) { //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 indicator command."); m->mothurOutEndLine(); abort = true; } - else { globaldata->setTreeFile(treefile); globaldata->setFormat("tree"); } + else if (treefile == "not found") { //if there is a current design file, use it + treefile = m->getTreeFile(); + if (treefile != "") { m->mothurOut("Using " + treefile + " as input file for the tree parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current tree file and the tree parameter is required."); m->mothurOutEndLine(); abort = true; } + } sharedfile = validParameter.validFile(parameters, "shared", true); if (sharedfile == "not open") { abort = true; } @@ -153,12 +161,25 @@ IndicatorCommand::IndicatorCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; Groups.push_back("all"); } else { m->splitAtDash(groups, Groups); } - globaldata->Groups = Groups; + m->Groups = Groups; label = validParameter.validFile(parameters, "label", false); if (label == "not found") { label = ""; m->mothurOut("You did not provide a label, I will use the first label in your inputfile."); m->mothurOutEndLine(); label=""; } - if ((relabundfile == "") && (sharedfile == "")) { m->mothurOut("You must provide either a shared or relabund file."); m->mothurOutEndLine(); abort = true; } + if ((relabundfile == "") && (sharedfile == "")) { + //is there are current file available for either of these? + //give priority to shared, then relabund + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputFileName = sharedfile; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + relabundfile = m->getRelAbundFile(); + if (relabundfile != "") { inputFileName = relabundfile; m->mothurOut("Using " + relabundfile + " as input file for the relabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a shared or relabund."); m->mothurOutEndLine(); + abort = true; + } + } + } if ((relabundfile != "") && (sharedfile != "")) { m->mothurOut("You may not use both a shared and relabund file."); m->mothurOutEndLine(); abort = true; } @@ -171,30 +192,6 @@ IndicatorCommand::IndicatorCommand(string option) { } //********************************************************************************************************************** -void IndicatorCommand::help(){ - try { - m->mothurOut("The indicator command reads a shared or relabund file and a tree file, and outputs a .indicator.tre and .indicator.summary file. \n"); - m->mothurOut("The new tree contains labels at each internal node. The label is the node number so you can relate the tree to the summary file.\n"); - m->mothurOut("The summary file lists the indicator value for each OTU for each node.\n"); - m->mothurOut("The indicator command parameters are tree, groups, shared, relabund, design and label. The tree parameter is required as well as either shared or relabund.\n"); - m->mothurOut("The design parameter allows you to provide a design file to relate the tree to the shared or relabund file.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your shared or relabund you would like analyzed, or if you provide a design file the groups in your design file. The groups may be entered separated by dashes.\n"); - m->mothurOut("The label parameter indicates at what distance your tree relates to the shared or relabund.\n"); - m->mothurOut("The indicator command should be used in the following format: indicator(tree=test.tre, shared=test.shared, label=0.03)\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "IndicatorCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -IndicatorCommand::~IndicatorCommand(){} - -//********************************************************************************************************************** - int IndicatorCommand::execute(){ try { @@ -211,7 +208,7 @@ int IndicatorCommand::execute(){ delete util; //loop through the Groups and fill Globaldata's Groups with the design file info - globaldata->Groups = designMap->getNamesSeqs(Groups); + m->Groups = designMap->getNamesSeqs(Groups); } /***************************************************/ @@ -228,41 +225,39 @@ int IndicatorCommand::execute(){ } //reset Globaldatas groups if needed - if (designfile != "") { globaldata->Groups = Groups; } + if (designfile != "") { m->Groups = Groups; } /***************************************************/ // reading tree info // /***************************************************/ string groupfile = ""; Tree* tree = new Tree(treefile); delete tree; //extracts names from tree to make faked out groupmap - - globaldata->setGroupFile(groupfile); treeMap = new TreeMap(); bool mismatch = false; - for (int i = 0; i < globaldata->Treenames.size(); i++) { + for (int i = 0; i < m->Treenames.size(); i++) { //sanity check - is this a group that is not in the sharedfile? if (designfile == "") { - if (!(m->inUsersGroups(globaldata->Treenames[i], globaldata->gGroupmap->namesOfGroups))) { - m->mothurOut("[ERROR]: " + globaldata->Treenames[i] + " is not a group in your shared or relabund file."); m->mothurOutEndLine(); + if (!(m->inUsersGroups(m->Treenames[i], m->namesOfGroups))) { + m->mothurOut("[ERROR]: " + m->Treenames[i] + " is not a group in your shared or relabund file."); m->mothurOutEndLine(); mismatch = true; } - treeMap->addSeq(globaldata->Treenames[i], "Group1"); + treeMap->addSeq(m->Treenames[i], "Group1"); }else{ - vector myGroups; myGroups.push_back(globaldata->Treenames[i]); + vector myGroups; myGroups.push_back(m->Treenames[i]); vector myNames = designMap->getNamesSeqs(myGroups); for(int k = 0; k < myNames.size(); k++) { - if (!(m->inUsersGroups(myNames[k], globaldata->gGroupmap->namesOfGroups))) { + if (!(m->inUsersGroups(myNames[k], m->namesOfGroups))) { m->mothurOut("[ERROR]: " + myNames[k] + " is not a group in your shared or relabund file."); m->mothurOutEndLine(); mismatch = true; } } - treeMap->addSeq(globaldata->Treenames[i], "Group1"); + treeMap->addSeq(m->Treenames[i], "Group1"); } } - if ((designfile != "") && (globaldata->Treenames.size() != Groups.size())) { m->mothurOut("[ERROR]: You design file does not match your tree, aborting."); m->mothurOutEndLine(); mismatch = true; } + if ((designfile != "") && (m->Treenames.size() != Groups.size())) { m->mothurOut("[ERROR]: You design file does not match your tree, aborting."); m->mothurOutEndLine(); mismatch = true; } if (mismatch) { //cleanup and exit if (designfile != "") { delete designMap; } @@ -271,15 +266,13 @@ int IndicatorCommand::execute(){ delete treeMap; return 0; } - - globaldata->gTreemap = treeMap; read = new ReadNewickTree(treefile); - int readOk = read->read(); + int readOk = read->read(treeMap); - if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); globaldata->gTree.clear(); delete globaldata->gTreemap; delete read; return 0; } + if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); delete treeMap; delete read; return 0; } - vector T = globaldata->gTree; + vector T = read->getTrees(); delete read; @@ -287,7 +280,7 @@ int IndicatorCommand::execute(){ if (designfile != "") { delete designMap; } if (sharedfile != "") { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } else { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } } - for (int i = 0; i < T.size(); i++) { delete T[i]; } globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; + for (int i = 0; i < T.size(); i++) { delete T[i]; } delete treeMap; return 0; } T[0]->assembleTree(); @@ -295,20 +288,20 @@ int IndicatorCommand::execute(){ /***************************************************/ // create ouptut tree - respecting pickedGroups // /***************************************************/ - Tree* outputTree = new Tree(globaldata->Groups.size()); + Tree* outputTree = new Tree(m->Groups.size(), treeMap); - outputTree->getSubTree(T[0], globaldata->Groups); + outputTree->getSubTree(T[0], m->Groups); outputTree->assembleTree(); //no longer need original tree, we have output tree to use and label - for (int i = 0; i < T.size(); i++) { delete T[i]; } globaldata->gTree.clear(); + for (int i = 0; i < T.size(); i++) { delete T[i]; } if (m->control_pressed) { if (designfile != "") { delete designMap; } if (sharedfile != "") { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } else { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } } - delete outputTree; delete globaldata->gTreemap; return 0; + delete outputTree; delete treeMap; return 0; } /***************************************************/ @@ -317,13 +310,12 @@ int IndicatorCommand::execute(){ GetIndicatorSpecies(outputTree); if (designfile != "") { delete designMap; } + if (sharedfile != "") { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } + else { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } } + delete outputTree; delete treeMap; - if (m->control_pressed) { - if (sharedfile != "") { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - else { for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } } - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } - delete outputTree; delete globaldata->gTreemap; return 0; - } + + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //set tree file as new current treefile string current = ""; diff --git a/indicatorcommand.h b/indicatorcommand.h index ae74997..05db05c 100644 --- a/indicatorcommand.h +++ b/indicatorcommand.h @@ -13,7 +13,6 @@ #include "command.hpp" #include "readtree.h" #include "treemap.h" -#include "globaldata.hpp" #include "sharedrabundvector.h" #include "sharedrabundfloatvector.h" #include "inputdata.h" @@ -22,23 +21,23 @@ class IndicatorCommand : public Command { public: IndicatorCommand(string); IndicatorCommand(); - ~IndicatorCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + ~IndicatorCommand(){} + + vector setParameters(); + string getCommandName() { return "indicator"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; ReadTree* read; TreeMap* treeMap; GroupMap* designMap; string treefile, sharedfile, relabundfile, groups, label, inputFileName, outputDir, designfile; bool abort; vector outputNames, Groups; - map > outputTypes; vector lookup; vector lookupFloat; diff --git a/inputdata.cpp b/inputdata.cpp index 283fb7e..ec23955 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -16,21 +16,16 @@ InputData::InputData(string fName, string f) : format(f){ m = MothurOut::getInstance(); - globaldata = GlobalData::getInstance(); m->openInputFile(fName, fileHandle); filename = fName; + m->saveNextLabel = ""; } - /***********************************************************************/ - InputData::~InputData(){ fileHandle.close(); - globaldata = GlobalData::getInstance(); - globaldata->saveNextLabel = ""; -// delete output; - + m->saveNextLabel = ""; } /***********************************************************************/ @@ -38,7 +33,6 @@ InputData::~InputData(){ InputData::InputData(string fName, string orderFileName, string f) : format(f){ try { m = MothurOut::getInstance(); - globaldata = GlobalData::getInstance(); ifstream ofHandle; m->openInputFile(orderFileName, ofHandle); string name; @@ -431,6 +425,7 @@ vector InputData::getSharedRAbundVectors(){ } }else if (format == "shared") { SharedList = new SharedListVector(fileHandle); + if (SharedList != NULL) { return SharedList->getSharedRAbundVector(); } @@ -455,7 +450,7 @@ vector InputData::getSharedRAbundVectors(string label){ string thisLabel; m->openInputFile(filename, in); - globaldata->saveNextLabel = ""; + m->saveNextLabel = ""; if(in){ if (format == "sharedfile") { @@ -481,6 +476,7 @@ vector InputData::getSharedRAbundVectors(string label){ while (in.eof() != true) { SharedList = new SharedListVector(in); + if (SharedList != NULL) { thisLabel = SharedList->getLabel(); //if you are at the last label @@ -549,7 +545,7 @@ vector InputData::getSharedRAbundFloatVectors(string l string thisLabel; m->openInputFile(filename, in); - globaldata->saveNextLabel = ""; + m->saveNextLabel = ""; if(in){ if (format == "relabund") { diff --git a/inputdata.h b/inputdata.h index ccf3551..658b21d 100644 --- a/inputdata.h +++ b/inputdata.h @@ -46,7 +46,6 @@ private: map orderMap; string filename; MothurOut* m; - GlobalData* globaldata; }; diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp index 129c970..dd3a65d 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -18,77 +18,86 @@ #include "slibshuff.h" #include "dlibshuff.h" + + //********************************************************************************************************************** -vector LibShuffCommand::getValidParameters(){ +vector LibShuffCommand::setParameters(){ try { - string Array[] = {"iters","groups","step","form","cutoff","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter piters("iters", "Number", "", "10000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pstep("step", "Number", "", "0.01", "", "", "",false,false); parameters.push_back(pstep); + CommandParameter pcutoff("cutoff", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pform("form", "Multiple", "discrete-integral", "integral", "", "", "",false,false); parameters.push_back(pform); + CommandParameter psim("sim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psim); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "LibShuffCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -LibShuffCommand::LibShuffCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["coverage"] = tempOutNames; - outputTypes["libshuffsummary"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "LibShuffCommand", "LibShuffCommand"); + m->errorOut(e, "LibShuffCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector LibShuffCommand::getRequiredParameters(){ +string LibShuffCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The libshuff command parameters are phylip, group, sim, groups, iters, step, form and cutoff. phylip and group parameters are required, unless you have valid current files.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"; + helpString += "The group names are separated by dashes. The iters parameter allows you to specify how many random matrices you would like compared to your matrix.\n"; + helpString += "The step parameter allows you to specify change in distance you would like between each output if you are using the discrete form.\n"; + helpString += "The form parameter allows you to specify if you would like to analyze your matrix using the discrete or integral form. Your options are integral or discrete.\n"; + helpString += "The libshuff command should be in the following format: libshuff(groups=yourGroups, iters=yourIters, cutOff=yourCutOff, form=yourForm, step=yourStep).\n"; + helpString += "Example libshuff(groups=A-B-C, iters=500, form=discrete, step=0.01, cutOff=2.0).\n"; + helpString += "The default value for groups is all the groups in your groupfile, iters is 10000, cutoff is 1.0, form is integral and step is 0.01.\n"; + helpString += "The libshuff command output two files: .coverage and .slsummary their descriptions are in the manual.\n"; + helpString += "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "LibShuffCommand", "getRequiredParameters"); + m->errorOut(e, "LibShuffCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector LibShuffCommand::getRequiredFiles(){ +LibShuffCommand::LibShuffCommand(){ try { - string Array[] = {"phylip","group"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["coverage"] = tempOutNames; + outputTypes["libshuffsummary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "LibShuffCommand", "getRequiredFiles"); + m->errorOut(e, "LibShuffCommand", "LibShuffCommand"); exit(1); } } -//********************************************************************************************************************** +//********************************************************************************************************************** LibShuffCommand::LibShuffCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; - Groups.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"iters","groups","step","form","cutoff","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } @@ -97,15 +106,55 @@ LibShuffCommand::LibShuffCommand(string option) { outputTypes["coverage"] = tempOutNames; outputTypes["libshuffsummary"] = tempOutNames; + 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("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; } + } + } + + //check for required parameters + phylipfile = validParameter.validFile(parameters, "phylip", true); + if (phylipfile == "not open") { phylipfile = ""; abort = true; } + else if (phylipfile == "not found") { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You must provide a phylip file."); m->mothurOutEndLine(); + abort = true; + } + } + + //check for required parameters + groupfile = validParameter.validFile(parameters, "group", true); + if (groupfile == "not open") { groupfile = ""; abort = true; } + else if (groupfile == "not found") { + groupfile = m->getGroupFile(); + if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You must provide a group file."); 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 = ""; - outputDir += m->hasPath(globaldata->getPhylipFile()); //if user entered a file with a path then preserve it - } - - //make sure the user has already run the read.dist command - if ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL)) { - m->mothurOut("You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. "); m->mothurOutEndLine(); abort = true;; + outputDir += m->hasPath(phylipfile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -115,7 +164,7 @@ LibShuffCommand::LibShuffCommand(string option) { else { savegroups = groups; m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } string temp; @@ -127,31 +176,11 @@ LibShuffCommand::LibShuffCommand(string option) { temp = validParameter.validFile(parameters, "step", false); if (temp == "not found") { temp = "0.01"; } convert(temp, step); - - userform = validParameter.validFile(parameters, "form", false); if (userform == "not found") { userform = "integral"; } - if (abort == false) { - - matrix = globaldata->gMatrix; //get the distance matrix - setGroups(); //set the groups to be analyzed and sorts them - - /********************************************************************************************/ - //this is needed because when we read the matrix we sort it into groups in alphabetical order - //the rest of the command and the classes used in this command assume specific order - /********************************************************************************************/ - matrix->setGroups(globaldata->gGroupmap->namesOfGroups); - vector sizes; - for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) { sizes.push_back(globaldata->gGroupmap->getNumSeqs(globaldata->gGroupmap->namesOfGroups[i])); } - matrix->setSizes(sizes); + temp = validParameter.validFile(parameters, "sim", false); if (temp == "not found") { temp = "F"; } + sim = m->isTrue(temp); - - if(userform == "discrete"){ - form = new DLibshuff(matrix, iters, step, cutOff); - } - else{ - form = new SLibshuff(matrix, iters, cutOff); - } - } + userform = validParameter.validFile(parameters, "form", false); if (userform == "not found") { userform = "integral"; } } @@ -163,65 +192,106 @@ LibShuffCommand::LibShuffCommand(string option) { } //********************************************************************************************************************** -void LibShuffCommand::help(){ - try { - m->mothurOut("The libshuff command can only be executed after a successful read.dist command including a groupfile.\n"); - m->mothurOut("The libshuff command parameters are groups, iters, step, form and cutoff. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"); - m->mothurOut("The group names are separated by dashes. The iters parameter allows you to specify how many random matrices you would like compared to your matrix.\n"); - m->mothurOut("The step parameter allows you to specify change in distance you would like between each output if you are using the discrete form.\n"); - m->mothurOut("The form parameter allows you to specify if you would like to analyze your matrix using the discrete or integral form. Your options are integral or discrete.\n"); - m->mothurOut("The libshuff command should be in the following format: libshuff(groups=yourGroups, iters=yourIters, cutOff=yourCutOff, form=yourForm, step=yourStep).\n"); - m->mothurOut("Example libshuff(groups=A-B-C, iters=500, form=discrete, step=0.01, cutOff=2.0).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, iters is 10000, cutoff is 1.0, form is integral and step is 0.01.\n"); - m->mothurOut("The libshuff command output two files: .coverage and .slsummary their descriptions are in the manual.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "LibShuffCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int LibShuffCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } + + //read files + groupMap = new GroupMap(groupfile); + int error = groupMap->readMap(); + if (error == 1) { delete groupMap; return 0; } + + ifstream in; + m->openInputFile(phylipfile, in); + matrix = new FullMatrix(in, groupMap, sim); //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(); remove(newGroupFile.c_str()); 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; + groupfile = newGroupFile; + + groupMap = new GroupMap(groupfile); + groupMap->readMap(); + + if (m->control_pressed) { delete groupMap; delete matrix; remove(newGroupFile.c_str()); return 0; } + } + + + setGroups(); //set the groups to be analyzed and sorts them + + /********************************************************************************************/ + //this is needed because when we read the matrix we sort it into groups in alphabetical order + //the rest of the command and the classes used in this command assume specific order + /********************************************************************************************/ + matrix->setGroups(groupMap->namesOfGroups); + vector sizes; + for (int i = 0; i < groupMap->namesOfGroups.size(); i++) { sizes.push_back(groupMap->getNumSeqs(groupMap->namesOfGroups[i])); } + matrix->setSizes(sizes); + + + if(userform == "discrete"){ + form = new DLibshuff(matrix, iters, step, cutOff); + } + else{ + form = new SLibshuff(matrix, iters, cutOff); + } savedDXYValues = form->evaluateAll(); savedMinValues = form->getSavedMins(); - if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; } + if (m->control_pressed) { delete form; m->Groups.clear(); delete matrix; delete groupMap; return 0; } pValueCounts.resize(numGroups); for(int i=0;icontrol_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; return 0; } Progress* reading = new Progress(); for(int i=0;icontrol_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; delete reading; return 0; } reading->newLine(groupNames[i]+'-'+groupNames[j], iters); - int spoti = globaldata->gGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix - int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]]; + int spoti = groupMap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix + int spotj = groupMap->groupIndex[groupNames[j]]; for(int p=0;pcontrol_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; delete reading; return 0; } form->randomizeGroups(spoti,spotj); if(form->evaluatePair(spoti,spotj) >= savedDXYValues[spoti][spotj]) { pValueCounts[i][j]++; } if(form->evaluatePair(spotj,spoti) >= savedDXYValues[spotj][spoti]) { pValueCounts[j][i]++; } - if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; delete reading; return 0; } reading->update(p); } @@ -230,7 +300,7 @@ int LibShuffCommand::execute(){ } } - if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; } + if (m->control_pressed) { outputTypes.clear(); delete form; m->Groups.clear(); delete matrix; delete groupMap; delete reading; return 0; } reading->finish(); delete reading; @@ -240,15 +310,13 @@ int LibShuffCommand::execute(){ printCoverageFile(); //clear out users groups - globaldata->Groups.clear(); + m->Groups.clear(); delete form; - //delete globaldata's copy of the gmatrix to free up memory - delete globaldata->gMatrix; globaldata->gMatrix = NULL; + delete matrix; delete groupMap; if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } - m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } @@ -268,7 +336,7 @@ int LibShuffCommand::printCoverageFile() { try { ofstream outCov; - summaryFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage"; + summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "libshuff.coverage"; m->openOutputFile(summaryFile, outCov); outputNames.push_back(summaryFile); outputTypes["coverage"].push_back(summaryFile); outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint); @@ -286,8 +354,8 @@ int LibShuffCommand::printCoverageFile() { for(int j=0;jgGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix - int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]]; + int spoti = groupMap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix + int spotj = groupMap->groupIndex[groupNames[j]]; for(int k=0;kgetRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary"; + summaryFile = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "libshuff.summary"; m->openOutputFile(summaryFile, outSum); outputNames.push_back(summaryFile); outputTypes["libshuffsummary"].push_back(summaryFile); @@ -380,8 +448,8 @@ int LibShuffCommand::printSummaryFile() { for(int j=i+1;jcontrol_pressed) { outSum.close(); return 0; } - int spoti = globaldata->gGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix - int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]]; + int spoti = groupMap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix + int spotj = groupMap->groupIndex[groupNames[j]]; if(pValueCounts[i][j]){ cout << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[spoti][spotj] << '\t' << setprecision(precision) << pValueCounts[i][j]/(float)iters << endl; @@ -420,48 +488,48 @@ int LibShuffCommand::printSummaryFile() { void LibShuffCommand::setGroups() { try { //if the user has not entered specific groups to analyze then do them all - if (globaldata->Groups.size() == 0) { - numGroups = globaldata->gGroupmap->getNumGroups(); + if (m->Groups.size() == 0) { + numGroups = groupMap->getNumGroups(); for (int i=0; i < numGroups; i++) { - globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]); + m->Groups.push_back(groupMap->namesOfGroups[i]); } } else { if (savegroups != "all") { //check that groups are valid - for (int i = 0; i < globaldata->Groups.size(); i++) { - if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) { - m->mothurOut(globaldata->Groups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine(); + for (int i = 0; i < m->Groups.size(); i++) { + if (groupMap->isValidGroup(m->Groups[i]) != true) { + m->mothurOut(m->Groups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine(); // erase the invalid group from globaldata->Groups - globaldata->Groups.erase(globaldata->Groups.begin()+i); + m->Groups.erase(m->Groups.begin()+i); } } //if the user only entered invalid groups - if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) { - numGroups = globaldata->gGroupmap->getNumGroups(); + if ((m->Groups.size() == 0) || (m->Groups.size() == 1)) { + numGroups = groupMap->getNumGroups(); for (int i=0; i < numGroups; i++) { - globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]); + m->Groups.push_back(groupMap->namesOfGroups[i]); } m->mothurOut("When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine(); - } else { numGroups = globaldata->Groups.size(); } + } else { numGroups = m->Groups.size(); } } else { //users wants all groups - numGroups = globaldata->gGroupmap->getNumGroups(); - globaldata->Groups.clear(); + numGroups = groupMap->getNumGroups(); + m->Groups.clear(); for (int i=0; i < numGroups; i++) { - globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]); + m->Groups.push_back(groupMap->namesOfGroups[i]); } } } //sort so labels match - sort(globaldata->Groups.begin(), globaldata->Groups.end()); + sort(m->Groups.begin(), m->Groups.end()); //sort - sort(globaldata->gGroupmap->namesOfGroups.begin(), globaldata->gGroupmap->namesOfGroups.end()); + sort(groupMap->namesOfGroups.begin(), groupMap->namesOfGroups.end()); - for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) { globaldata->gGroupmap->groupIndex[globaldata->gGroupmap->namesOfGroups[i]] = i; } + for (int i = 0; i < groupMap->namesOfGroups.size(); i++) { groupMap->groupIndex[groupMap->namesOfGroups[i]] = i; } - groupNames = globaldata->Groups; + groupNames = m->Groups; } catch(exception& e) { diff --git a/libshuffcommand.h b/libshuffcommand.h index 3240860..97fcd1c 100644 --- a/libshuffcommand.h +++ b/libshuffcommand.h @@ -13,44 +13,44 @@ #include "command.hpp" #include "fullmatrix.h" #include "libshuff.h" +#include "groupmap.h" -class GlobalData; - class LibShuffCommand : public Command { public: LibShuffCommand(string); LibShuffCommand(); ~LibShuffCommand(){}; - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + + vector setParameters(); + string getCommandName() { return "libshuff"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + int execute(); - void help(); - + void help() { m->mothurOut(getHelpString()); } + private: vector groupNames; void setGroups(); int printCoverageFile(); int printSummaryFile(); - - GlobalData* globaldata; + + GroupMap* groupMap; FullMatrix* matrix; Libshuff* form; float cutOff, step; int numGroups, numComp, iters; - string coverageFile, summaryFile; + string coverageFile, summaryFile, phylipfile, groupfile; vector > pValueCounts; vector > savedDXYValues; vector > > savedMinValues; - bool abort; + bool abort, sim; string outputFile, groups, userform, savegroups, outputDir; vector Groups, outputNames; //holds groups to be used - map > outputTypes; }; #endif diff --git a/listseqscommand.cpp b/listseqscommand.cpp index a8a9d2b..b977304 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -11,50 +11,55 @@ #include "sequence.hpp" #include "listvector.hpp" + //********************************************************************************************************************** -vector ListSeqsCommand::getValidParameters(){ +vector ListSeqsCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "alignreport","list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "FNGLT", "FNGLT", "none",false,false); parameters.push_back(palignreport); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "getValidParameters"); + m->errorOut(e, "ListSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ListSeqsCommand::ListSeqsCommand(){ +string ListSeqsCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["accnos"] = tempOutNames; + string helpString = ""; + helpString += "The list.seqs command reads a fasta, name, group, list, taxonomy or alignreport file and outputs a .accnos file containing sequence names.\n"; + helpString += "The list.seqs command parameters are fasta, name, group, list, taxonomy and alignreport. You must provide one of these parameters.\n"; + helpString += "The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n"; + helpString += "Example list.seqs(fasta=amazon.fasta).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "ListSeqsCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector ListSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta","name", "group", "alignreport","list","taxonomy","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "getRequiredParameters"); + m->errorOut(e, "ListSeqsCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector ListSeqsCommand::getRequiredFiles(){ +ListSeqsCommand::ListSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["accnos"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "ListSeqsCommand", "ListSeqsCommand"); exit(1); } } @@ -68,9 +73,7 @@ ListSeqsCommand::ListSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name", "group", "alignreport","list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -186,22 +189,6 @@ ListSeqsCommand::ListSeqsCommand(string option) { } //********************************************************************************************************************** -void ListSeqsCommand::help(){ - try { - m->mothurOut("The list.seqs command reads a fasta, name, group, list, taxonomy or alignreport file and outputs a .accnos file containing sequence names.\n"); - m->mothurOut("The list.seqs command parameters are fasta, name, group, list, taxonomy and alignreport. You must provide one of these parameters.\n"); - m->mothurOut("The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n"); - m->mothurOut("Example list.seqs(fasta=amazon.fasta).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ListSeqsCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int ListSeqsCommand::execute(){ try { diff --git a/listseqscommand.h b/listseqscommand.h index 889b373..bd7beae 100644 --- a/listseqscommand.h +++ b/listseqscommand.h @@ -19,16 +19,18 @@ class ListSeqsCommand : public Command { ListSeqsCommand(string); ListSeqsCommand(); ~ListSeqsCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + + vector setParameters(); + string getCommandName() { return "get.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + + private: vector names, outputNames; - map > outputTypes; string fastafile, namefile, groupfile, alignfile, inputFileName, outputDir, listfile, taxfile; bool abort; diff --git a/makefastqcommand.cpp b/makefastqcommand.cpp index 18ca864..995dc66 100644 --- a/makefastqcommand.cpp +++ b/makefastqcommand.cpp @@ -12,49 +12,49 @@ #include "qualityscores.h" //********************************************************************************************************************** -vector MakeFastQCommand::getValidParameters(){ +vector MakeFastQCommand::setParameters(){ try { - string Array[] = {"fasta","qfile","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pqfile); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MakeFastQCommand", "getValidParameters"); + m->errorOut(e, "MakeFastQCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -MakeFastQCommand::MakeFastQCommand(){ +string MakeFastQCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fastq"] = tempOutNames; + string helpString = ""; + helpString += "The make.fastq command read a fasta and quality file and creates a fastq file.\n"; + helpString += "The make.fastq command parameters are fasta and qfile, both are required.\n"; + helpString += "You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"; + helpString += "The make.fastq command should be in the following format: make.fastq(qfile=yourQualityFile, fasta=yourFasta).\n"; + helpString += "Example make.fastq(fasta=amazon.fasta, qfile=amazon.qual).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MakeFastQCommand", "MakeFastQCommand"); + m->errorOut(e, "MakeFastQCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector MakeFastQCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta","qfile"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "MakeFastQCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector MakeFastQCommand::getRequiredFiles(){ +MakeFastQCommand::MakeFastQCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fastq"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "MakeFastQCommand", "getRequiredFiles"); + m->errorOut(e, "MakeFastQCommand", "MakeFastQCommand"); exit(1); } } @@ -67,9 +67,7 @@ MakeFastQCommand::MakeFastQCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","qfile", "outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -107,25 +105,25 @@ MakeFastQCommand::MakeFastQCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["qfile"] = inputDir + it->second; } } - - 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; } - } } //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; fastafile = ""; } - else if (fastafile == "not found") { fastafile = ""; m->mothurOut("You must provide a fasta file."); m->mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } qualfile = validParameter.validFile(parameters, "qfile", true); if (qualfile == "not open") { abort = true; qualfile = ""; } - else if (qualfile == "not found") { qualfile = ""; m->mothurOut("You must provide a quality file."); m->mothurOutEndLine(); abort = true; } + else if (qualfile == "not found") { + qualfile = m->getQualFile(); + if (qualfile != "") { m->mothurOut("Using " + qualfile + " as input file for the qfile parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current qualfile and the qfile 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(fastafile); } @@ -140,23 +138,6 @@ MakeFastQCommand::MakeFastQCommand(string option) { } //********************************************************************************************************************** -void MakeFastQCommand::help(){ - try { - m->mothurOut("The make.fastq command read a fasta and quality file and creates a fastq file.\n"); - m->mothurOut("The make.fastq command parameters are fasta and qfile, both are required.\n"); - m->mothurOut("You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"); - m->mothurOut("The make.fastq command should be in the following format: make.fastq(qfile=yourQualityFile, fasta=yourFasta).\n"); - m->mothurOut("Example make.fastq(fasta=amazon.fasta, qfile=amazon.qual).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "MakeFastQCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int MakeFastQCommand::execute(){ try { diff --git a/makefastqcommand.h b/makefastqcommand.h index fd893ad..946c990 100644 --- a/makefastqcommand.h +++ b/makefastqcommand.h @@ -20,19 +20,21 @@ public: MakeFastQCommand(string); MakeFastQCommand(); ~MakeFastQCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "make.fastq"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: string fastafile, qualfile, outputDir; bool abort; vector outputNames; - map > outputTypes; string convertQual(vector); diff --git a/makegroupcommand.cpp b/makegroupcommand.cpp index 8adfe09..6f640eb 100644 --- a/makegroupcommand.cpp +++ b/makegroupcommand.cpp @@ -10,53 +10,56 @@ #include "makegroupcommand.h" #include "sequence.hpp" + //********************************************************************************************************************** -vector MakeGroupCommand::getValidParameters(){ +vector MakeGroupCommand::setParameters(){ try { - string Array[] = {"fasta", "output","groups","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MakeGroupCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -MakeGroupCommand::MakeGroupCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["group"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "MakeGroupCommand", "MakeGroupCommand"); + m->errorOut(e, "MakeGroupCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector MakeGroupCommand::getRequiredParameters(){ +string MakeGroupCommand::getHelpString(){ try { - string Array[] = {"fasta","groups"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The make.group command reads a fasta file or series of fasta files and creates a groupfile.\n"; + helpString += "The make.group command parameters are fasta, groups and output. Fasta and group are required.\n"; + helpString += "The output parameter allows you to specify the name of groupfile created. \n"; + helpString += "The make.group command should be in the following format: \n"; + helpString += "make.group(fasta=yourFastaFiles, groups=yourGroups). \n"; + helpString += "Example make.group(fasta=seqs1.fasta-seq2.fasta-seqs3.fasta, groups=A-B-C)\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFiles).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MakeGroupCommand", "getRequiredParameters"); + m->errorOut(e, "MakeGroupCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector MakeGroupCommand::getRequiredFiles(){ +MakeGroupCommand::MakeGroupCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["group"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "MakeGroupCommand", "getRequiredFiles"); + m->errorOut(e, "MakeGroupCommand", "MakeGroupCommand"); exit(1); } } + //********************************************************************************************************************** MakeGroupCommand::MakeGroupCommand(string option) { @@ -68,10 +71,7 @@ MakeGroupCommand::MakeGroupCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - - //valid paramters for this command - string AlignArray[] = {"fasta","groups","output","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -93,8 +93,11 @@ MakeGroupCommand::MakeGroupCommand(string option) { if (inputDir == "not found"){ inputDir = ""; } fastaFileName = validParameter.validFile(parameters, "fasta", false); - if (fastaFileName == "not found") { m->mothurOut("fasta is a required parameter for the make.group command."); m->mothurOutEndLine(); abort = true; } - else { + if (fastaFileName == "not found") { //if there is a current fasta file, use it + string filename = m->getFastaFile(); + if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { m->splitAtDash(fastaFileName, fastaFileNames); //go through files and make sure they are good, if not, then disregard them @@ -162,37 +165,12 @@ MakeGroupCommand::MakeGroupCommand(string option) { if (groupsNames.size() != fastaFileNames.size()) { m->mothurOut("You do not have the same number of valid fastfile files as groups. This could be because we could not open a fastafile."); m->mothurOutEndLine(); abort = true; } } - cout << "here" << endl; } catch(exception& e) { m->errorOut(e, "MakeGroupCommand", "MakeGroupCommand"); exit(1); } } - -//********************************************************************************************************************** - -MakeGroupCommand::~MakeGroupCommand(){ } - -//********************************************************************************************************************** - -void MakeGroupCommand::help(){ - try { - m->mothurOut("The make.group command reads a fasta file or series of fasta files and creates a groupfile.\n"); - m->mothurOut("The make.group command parameters are fasta, groups and output. Fasta and group are required.\n"); - m->mothurOut("The output parameter allows you to specify the name of groupfile created. \n"); - m->mothurOut("The make.group command should be in the following format: \n"); - m->mothurOut("make.group(fasta=yourFastaFiles, groups=yourGroups). \n"); - m->mothurOut("Example make.group(fasta=seqs1.fasta-seq2.fasta-seqs3.fasta, groups=A-B-C)\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFiles).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "MakeGroupCommand", "help"); - exit(1); - } -} - - //********************************************************************************************************************** int MakeGroupCommand::execute(){ diff --git a/makegroupcommand.h b/makegroupcommand.h index e836d20..1206938 100644 --- a/makegroupcommand.h +++ b/makegroupcommand.h @@ -17,20 +17,21 @@ class MakeGroupCommand : public Command { public: MakeGroupCommand(string); MakeGroupCommand(); - ~MakeGroupCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + ~MakeGroupCommand(){} + + vector setParameters(); + string getCommandName() { return "make.group"; } + string getCommandCategory() { return "General"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } private: string fastaFileName, groups, outputDir, filename, output; vector fastaFileNames; vector groupsNames, outputNames; - map > outputTypes; bool abort; }; diff --git a/mantelcommand.cpp b/mantelcommand.cpp index a1f7b3b..c41cde3 100644 --- a/mantelcommand.cpp +++ b/mantelcommand.cpp @@ -10,34 +10,50 @@ #include "mantelcommand.h" #include "readphylipvector.h" + //********************************************************************************************************************** -vector MantelCommand::getValidParameters(){ +vector MantelCommand::setParameters(){ try { - string Array[] = {"phylip1","phylip2","method","iters","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pphylip1("phylip1", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip1); + CommandParameter pphylip2("phylip2", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip2); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pmethod("method", "Multiple", "pearson-spearman-kendall", "pearson", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MantelCommand", "getValidParameters"); + m->errorOut(e, "MantelCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector MantelCommand::getRequiredParameters(){ +string MantelCommand::getHelpString(){ try { - string Array[] = {"phylip1", "phylip2"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "Sokal, R. R., & Rohlf, F. J. (1995). Biometry, 3rd edn. New York: Freeman.\n"; + helpString += "The mantel command reads two distance matrices and calculates the mantel correlation coefficient.\n"; + helpString += "The mantel command parameters are phylip1, phylip2, iters and method. The phylip1 and phylip2 parameters are required. Matrices must be the same size and contain the same names.\n"; + helpString += "The method parameter allows you to select what method you would like to use. Options are pearson, spearman and kendall. Default=pearson.\n"; + helpString += "The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"; + helpString += "The mantel command should be in the following format: mantel(phylip1=veg.dist, phylip2=env.dist).\n"; + helpString += "The mantel command outputs a .mantel file.\n"; + helpString += "Note: No spaces between parameter labels (i.e. phylip1), '=' and parameters (i.e. veg.dist).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MantelCommand", "getRequiredParameters"); + m->errorOut(e, "MantelCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** MantelCommand::MantelCommand(){ try { - abort = true; calledHelp = true; + abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["mantel"] = tempOutNames; } @@ -46,18 +62,6 @@ MantelCommand::MantelCommand(){ exit(1); } } - -//********************************************************************************************************************** -vector MantelCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "MantelCommand", "getRequiredFiles"); - exit(1); - } -} //********************************************************************************************************************** MantelCommand::MantelCommand(string option) { try { @@ -67,9 +71,7 @@ MantelCommand::MantelCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"phylip1","phylip2","method","iters","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -134,29 +136,6 @@ MantelCommand::MantelCommand(string option) { } //********************************************************************************************************************** -void MantelCommand::help(){ - try { - m->mothurOut("Sokal, R. R., & Rohlf, F. J. (1995). Biometry, 3rd edn. New York: Freeman.\n"); - m->mothurOut("The mantel command reads two distance matrices and calculates the mantel correlation coefficient.\n"); - m->mothurOut("The mantel command parameters are phylip1, phylip2, iters and method. The phylip1 and phylip2 parameters are required. Matrices must be the same size and contain the same names.\n"); - m->mothurOut("The method parameter allows you to select what method you would like to use. Options are pearson, spearman and kendall. Default=pearson.\n"); - m->mothurOut("The iters parameter allows you to set number of randomization for the P value. The default is 1000. \n"); - m->mothurOut("The mantel command should be in the following format: mantel(phylip1=veg.dist, phylip2=env.dist).\n"); - m->mothurOut("The mantel command outputs a .mantel file.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. phylip1), '=' and parameters (i.e. veg.dist).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "MantelCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -MantelCommand::~MantelCommand(){} - -//********************************************************************************************************************** - int MantelCommand::execute(){ try { diff --git a/mantelcommand.h b/mantelcommand.h index 0646b29..224265b 100644 --- a/mantelcommand.h +++ b/mantelcommand.h @@ -17,13 +17,15 @@ class MantelCommand : public Command { public: MantelCommand(string); MantelCommand(); - ~MantelCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + ~MantelCommand(){} + + vector setParameters(); + string getCommandName() { return "mantel"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } private: @@ -32,7 +34,6 @@ private: int iters; vector outputNames; - map > outputTypes; }; diff --git a/matrixoutputcommand.cpp b/matrixoutputcommand.cpp index ef2c236..effc368 100644 --- a/matrixoutputcommand.cpp +++ b/matrixoutputcommand.cpp @@ -49,50 +49,59 @@ #include "memchord.h" #include "memeuclidean.h" #include "mempearson.h" + //********************************************************************************************************************** -vector MatrixOutputCommand::getValidParameters(){ +vector MatrixOutputCommand::setParameters(){ try { - string Array[] = {"label","calc","groups","outputdir","inputdir", "output"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pcalc("calc", "Multiple", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-whittaker-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-hamming-structchi2-gower-memchi2-memchord-memeuclidean-mempearson", "jclass-thetayc", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MatrixOutputCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -MatrixOutputCommand::MatrixOutputCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["phylip"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "MatrixOutputCommand", "MatrixOutputCommand"); + m->errorOut(e, "MatrixOutputCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector MatrixOutputCommand::getRequiredParameters(){ +string MatrixOutputCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The dist.shared command parameters are shared, groups, calc, output and label. shared is a required, unless you have a valid current file.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n"; + helpString += "The group names are separated by dashes. The label parameter allows you to select what distance levels you would like distance matrices created for, and is also separated by dashes.\n"; + helpString += "The dist.shared command should be in the following format: dist.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels).\n"; + helpString += "The output parameter allows you to specify format of your distance matrix. Options are lt, and square. The default is lt.\n"; + helpString += "Example dist.shared(groups=A-B-C, calc=jabund-sorabund).\n"; + helpString += "The default value for groups is all the groups in your groupfile.\n"; + helpString += "The default value for calc is jclass and thetayc.\n"; + helpString += validCalculator->printCalc("matrix"); + helpString += "The dist.shared command outputs a .dist file for each calculator you specify at each distance you choose.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MatrixOutputCommand", "getRequiredParameters"); + m->errorOut(e, "MatrixOutputCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector MatrixOutputCommand::getRequiredFiles(){ +MatrixOutputCommand::MatrixOutputCommand(){ try { - string Array[] = {"shared"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["phylip"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "MatrixOutputCommand", "getRequiredFiles"); + m->errorOut(e, "MatrixOutputCommand", "MatrixOutputCommand"); exit(1); } } @@ -100,28 +109,23 @@ vector MatrixOutputCommand::getRequiredFiles(){ MatrixOutputCommand::MatrixOutputCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Groups.clear(); - Estimators.clear(); - + //allow user to run help if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"label","calc","groups","outputdir","inputdir", "output"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } @@ -129,16 +133,32 @@ MatrixOutputCommand::MatrixOutputCommand(string option) { vector 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); + if (inputDir == "not found"){ inputDir = ""; } + else { + string path; + 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; } + } + } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not found") { + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; } + }else if (sharedfile == "not open") { sharedfile = ""; 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 = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it - } - - //make sure the user has already run the read.otu command - if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the dist.shared command."); m->mothurOutEndLine(); abort = true; } - else if (globaldata->getGroupFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the dist.shared command."); m->mothurOutEndLine(); abort = true; } + outputDir += m->hasPath(sharedfile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -153,17 +173,11 @@ MatrixOutputCommand::MatrixOutputCommand(string option) { output = validParameter.validFile(parameters, "output", false); if(output == "not found"){ output = "lt"; } if ((output != "lt") && (output != "square")) { m->mothurOut(output + " is not a valid output form. Options are lt and square. I will use lt."); m->mothurOutEndLine(); output = "lt"; } - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } calc = validParameter.validFile(parameters, "calc", false); @@ -272,36 +286,10 @@ MatrixOutputCommand::MatrixOutputCommand(string option) { } } -//********************************************************************************************************************** - -void MatrixOutputCommand::help(){ - try { - m->mothurOut("The dist.shared command can only be executed after a successful read.otu command.\n"); - m->mothurOut("The dist.shared command parameters are groups, calc, output and label. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n"); - m->mothurOut("The group names are separated by dashes. The label parameter allows you to select what distance levels you would like distance matrices created for, and is also separated by dashes.\n"); - m->mothurOut("The dist.shared command should be in the following format: dist.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels).\n"); - m->mothurOut("The output parameter allows you to specify format of your distance matrix. Options are lt, and square. The default is lt.\n"); - m->mothurOut("Example dist.shared(groups=A-B-C, calc=jabund-sorabund).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile.\n"); - m->mothurOut("The default value for calc is jclass and thetayc.\n"); - validCalculator->printCalc("matrix", cout); - m->mothurOut("The dist.shared command outputs a .dist file for each calculator you specify at each distance you choose.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "MatrixOutputCommand", "help"); - exit(1); - } -} - - //********************************************************************************************************************** MatrixOutputCommand::~MatrixOutputCommand(){ if (abort == false) { - delete input; globaldata->ginput = NULL; - delete read; delete validCalculator; } } @@ -315,12 +303,8 @@ int MatrixOutputCommand::execute(){ //if the users entered no valid calculators don't execute command if (matrixCalculators.size() == 0) { m->mothurOut("No valid calculators."); m->mothurOutEndLine(); return 0; } - - //you have groups - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - input = globaldata->ginput; + input = new InputData(sharedfile, "sharedfile"); lookup = input->getSharedRAbundVectors(); string lastLabel = lookup[0]->getLabel(); @@ -328,16 +312,16 @@ int MatrixOutputCommand::execute(){ set processedLabels; set userLabels = labels; - if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0;} + if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0;} numGroups = lookup.size(); - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); return 0; } //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } m->Groups.clear(); return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); @@ -370,7 +354,7 @@ int MatrixOutputCommand::execute(){ lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete input; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } m->Groups.clear(); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -385,7 +369,7 @@ int MatrixOutputCommand::execute(){ } } - if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete input; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } m->Groups.clear(); return 0; } //run last label if you need to if (needToRun == true) { @@ -397,10 +381,10 @@ int MatrixOutputCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - if (m->control_pressed) { outputTypes.clear(); delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { outputTypes.clear(); delete input; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } m->Groups.clear(); return 0; } //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); //set phylip file as new current phylipfile string current = ""; @@ -500,7 +484,7 @@ int MatrixOutputCommand::process(vector thisLookup){ } } - exportFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist"; + exportFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist"; m->openOutputFile(exportFileName, out); outputNames.push_back(exportFileName); outputTypes["phylip"].push_back(exportFileName); diff --git a/matrixoutputcommand.h b/matrixoutputcommand.h index 2a79081..40706b9 100644 --- a/matrixoutputcommand.h +++ b/matrixoutputcommand.h @@ -12,7 +12,6 @@ #include "command.hpp" #include "inputdata.h" #include "groupmap.h" -#include "readotu.h" #include "validcalculator.h" // aka. dist.shared() @@ -21,7 +20,6 @@ The user can select the labels they wish to use as well as the groups they would like included. They can also use as many or as few calculators as they wish. */ -class GlobalData; class MatrixOutputCommand : public Command { @@ -29,25 +27,25 @@ public: MatrixOutputCommand(string); MatrixOutputCommand(); ~MatrixOutputCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "dist.shared"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: void printSims(ostream&); int process(vector); - GlobalData* globaldata; - ReadOTUFile* read; vector matrixCalculators; vector< vector > simMatrix; InputData* input; ValidCalculators* validCalculator; vector lookup; - string exportFileName, output; + string exportFileName, output, sharedfile; int numGroups; ofstream out; @@ -55,9 +53,6 @@ private: set labels; //holds labels to be used string outputFile, calc, groups, label, outputDir; vector Estimators, Groups, outputNames; //holds estimators to be used - map > outputTypes; - - }; diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index 2b34a00..cb241c6 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -10,49 +10,48 @@ #include "mergefilecommand.h" //********************************************************************************************************************** -vector MergeFileCommand::getValidParameters(){ +vector MergeFileCommand::setParameters(){ try { - string Array[] = {"input", "output","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pinput("input", "String", "", "", "", "", "",false,true); parameters.push_back(pinput); + CommandParameter poutput("output", "String", "", "", "", "", "",false,true); parameters.push_back(poutput); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "getValidParameters"); + m->errorOut(e, "MergeFileCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -MergeFileCommand::MergeFileCommand(){ +string MergeFileCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["merge"] = tempOutNames; + string helpString = ""; + helpString += "The merge.file command takes a list of files separated by dashes and merges them into one file."; + helpString += "The merge.file command parameters are input and output."; + helpString += "Example merge.file(input=small.fasta-large.fasta, output=all.fasta)."; + helpString += "Note: No spaces between parameter labels (i.e. output), '=' and parameters (i.e.yourOutputFileName).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector MergeFileCommand::getRequiredParameters(){ - try { - string Array[] = {"input","output"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "getRequiredParameters"); + m->errorOut(e, "MergeFileCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector MergeFileCommand::getRequiredFiles(){ +MergeFileCommand::MergeFileCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["merge"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "getRequiredFiles"); + m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); exit(1); } } @@ -67,9 +66,7 @@ MergeFileCommand::MergeFileCommand(string option) { abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"input", "output","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -127,11 +124,6 @@ MergeFileCommand::MergeFileCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -MergeFileCommand::~MergeFileCommand() { /* do nothing */ } - //********************************************************************************************************************** int MergeFileCommand::execute(){ @@ -174,17 +166,4 @@ int MergeFileCommand::execute(){ exit(1); } } - -//********************************************************************************************************************** - -void MergeFileCommand::help(){ - try { - m->mothurOut("The merge.file command..."); m->mothurOutEndLine(); - } - catch(exception& e) { - m->errorOut(e, "MergeFileCommand", "help"); - exit(1); - } -} - //********************************************************************************************************************** diff --git a/mergefilecommand.h b/mergefilecommand.h index 56da315..1ecc3cb 100644 --- a/mergefilecommand.h +++ b/mergefilecommand.h @@ -17,17 +17,18 @@ class MergeFileCommand : public Command { public: MergeFileCommand(string); MergeFileCommand(); - ~MergeFileCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + ~MergeFileCommand(){} + + vector setParameters(); + string getCommandName() { return "merge.files"; } + string getCommandCategory() { return "General"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: vector fileNames, outputNames; - map > outputTypes; string outputFileName; int numInputFiles; bool abort; diff --git a/mergegroupscommand.cpp b/mergegroupscommand.cpp index 60b9c85..74bf0de 100644 --- a/mergegroupscommand.cpp +++ b/mergegroupscommand.cpp @@ -11,50 +11,56 @@ #include "sharedutilities.h" //********************************************************************************************************************** -vector MergeGroupsCommand::getValidParameters(){ +vector MergeGroupsCommand::setParameters(){ try { - string Array[] = {"shared","label","outputdir","design","groups","processors","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MergeGroupsCommand", "getValidParameters"); + m->errorOut(e, "MergeGroupsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -MergeGroupsCommand::MergeGroupsCommand(){ +string MergeGroupsCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["shared"] = tempOutNames; + string helpString = ""; + helpString += "The merge.groups command reads a shared file and a design file and merges the groups in the shared file that are in the same grouping in the design file.\n"; + helpString += "The merge.groups command outputs a .shared file. \n"; + helpString += "The merge.groups command parameters are shared, groups, label and design. The design and shared parameter are required.\n"; + helpString += "The design parameter allows you to assign your groups to sets. It is required. \n"; + helpString += "The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the group name and the second column is the set the group belongs to.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your shared you would like included. The group names are separated by dashes.\n"; + helpString += "The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"; + helpString += "The merge.groups command should be in the following format: merge.groups(design=yourDesignFile, shared=yourSharedFile).\n"; + helpString += "Example merge.groups(design=temp.design, groups=A-B-C, shared=temp.shared).\n"; + helpString += "The default value for groups is all the groups in your sharedfile, and all labels in your inputfile will be used.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MergeGroupsCommand", "MetaStatsCommand"); + m->errorOut(e, "MergeGroupsCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector MergeGroupsCommand::getRequiredParameters(){ - try { - string Array[] = {"design", "shared"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "MergeGroupsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector MergeGroupsCommand::getRequiredFiles(){ +MergeGroupsCommand::MergeGroupsCommand(){ try { - string Array[] = {}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["shared"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "MergeGroupsCommand", "getRequiredFiles"); + m->errorOut(e, "MergeGroupsCommand", "MetaStatsCommand"); exit(1); } } @@ -62,18 +68,14 @@ vector MergeGroupsCommand::getRequiredFiles(){ MergeGroupsCommand::MergeGroupsCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"groups","label","outputdir","shared","design","processors","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -118,12 +120,22 @@ MergeGroupsCommand::MergeGroupsCommand(string option) { //check for required parameters designfile = validParameter.validFile(parameters, "design", true); if (designfile == "not open") { abort = true; } - else if (designfile == "not found") { designfile = ""; m->mothurOut("You must provide a design file."); m->mothurOutEndLine(); abort = true; } + else if (designfile == "not found") { + //if there is a current shared file, use it + designfile = m->getDesignFile(); + if (designfile != "") { m->mothurOut("Using " + designfile + " as input file for the design parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current designfile and the design parameter is required."); m->mothurOutEndLine(); abort = true; } + } //make sure the user has already run the read.otu command sharedfile = validParameter.validFile(parameters, "shared", true); if (sharedfile == "not open") { abort = true; } - else if (sharedfile == "not found") { sharedfile = ""; m->mothurOut("You must provide a shared file."); m->mothurOutEndLine(); abort = true; } + else if (sharedfile == "not found") { + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; } + } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -137,7 +149,7 @@ MergeGroupsCommand::MergeGroupsCommand(string option) { groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = "all"; } m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } } @@ -146,34 +158,6 @@ MergeGroupsCommand::MergeGroupsCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void MergeGroupsCommand::help(){ - try { - m->mothurOut("The merge.groups command reads a shared file and a design file and merges the groups in the shared file that are in the same grouping in the design file.\n"); - m->mothurOut("The merge.groups command outputs a .shared file. \n"); - m->mothurOut("The merge.groups command parameters are shared, groups, label and design. The design and shared parameter are required.\n"); - m->mothurOut("The design parameter allows you to assign your groups to sets when you are running metastat. mothur will run all pairwise comparisons of the sets. It is required. \n"); - m->mothurOut("The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the group name and the second column is the set the group belongs to.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your shared you would like included. The group names are separated by dashes.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"); - m->mothurOut("The merge.groups command should be in the following format: merge.groups(design=yourDesignFile, shared=yourSharedFile).\n"); - m->mothurOut("Example merge.groups(design=temp.design, groups=A-B-C, shared=temp.shared).\n"); - m->mothurOut("The default value for groups is all the groups in your sharedfile, and all labels in your inputfile will be used.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "MergeGroupsCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -MergeGroupsCommand::~MergeGroupsCommand(){} - //********************************************************************************************************************** int MergeGroupsCommand::execute(){ @@ -202,7 +186,7 @@ int MergeGroupsCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { out.close(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { out.close(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -233,13 +217,13 @@ int MergeGroupsCommand::execute(){ //prevent memory leak for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - if (m->control_pressed) { out.close(); globaldata->Groups.clear(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { out.close(); m->Groups.clear(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //get next line to process lookup = input.getSharedRAbundVectors(); } - if (m->control_pressed) { out.close(); globaldata->Groups.clear(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { out.close(); m->Groups.clear(); delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //output error messages about any remaining user labels set::iterator it; @@ -268,7 +252,7 @@ int MergeGroupsCommand::execute(){ out.close(); //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); delete designMap; if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0;} diff --git a/mergegroupscommand.h b/mergegroupscommand.h index 62839ec..827f5a3 100644 --- a/mergegroupscommand.h +++ b/mergegroupscommand.h @@ -14,26 +14,24 @@ #include "inputdata.h" #include "sharedrabundvector.h" -class GlobalData; - class MergeGroupsCommand : public Command { public: MergeGroupsCommand(string); MergeGroupsCommand(); - ~MergeGroupsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~MergeGroupsCommand() {} + + vector setParameters(); + string getCommandName() { return "merge.groups"; } + string getCommandCategory() { return "General"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; GroupMap* designMap; vector lookup; - map > outputTypes; bool abort, allLines, pickedGroups; set labels; //holds labels to be used diff --git a/metastatscommand.cpp b/metastatscommand.cpp index e13e37c..4bb50ab 100644 --- a/metastatscommand.cpp +++ b/metastatscommand.cpp @@ -12,50 +12,64 @@ #include "sharedutilities.h" //********************************************************************************************************************** -vector MetaStatsCommand::getValidParameters(){ +vector MetaStatsCommand::setParameters(){ try { - string Array[] = {"groups","label","outputdir","iters","threshold","g","design","sets","processors","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pdesign); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pthreshold("threshold", "Number", "", "0.05", "", "", "",false,false); parameters.push_back(pthreshold); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter psets("sets", "String", "", "", "", "", "",false,false); parameters.push_back(psets); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MetaStatsCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -MetaStatsCommand::MetaStatsCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["metastats"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "MetaStatsCommand", "MetaStatsCommand"); + m->errorOut(e, "MetaStatsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector MetaStatsCommand::getRequiredParameters(){ +string MetaStatsCommand::getHelpString(){ try { - string Array[] = {"design"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "This command is based on the Metastats program, White, J.R., Nagarajan, N. & Pop, M. Statistical methods for detecting differentially abundant features in clinical metagenomic samples. PLoS Comput Biol 5, e1000352 (2009).\n"; + helpString += "The metastats command outputs a .metastats file. \n"; + helpString += "The metastats command parameters are shared, iters, threshold, groups, label, design, sets and processors. The shared and design parameters are required, unless you have valid current files.\n"; + helpString += "The design parameter allows you to assign your groups to sets when you are running metastat. mothur will run all pairwise comparisons of the sets. It is required. \n"; + helpString += "The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the group name and the second column is the set the group belongs to.\n"; + helpString += "The sets parameter allows you to specify which of the sets in your designfile you would like to analyze. The set names are separated by dashes. THe default is all sets in the designfile.\n"; + helpString += "The iters parameter allows you to set number of bootstrap permutations for estimating null distribution of t statistic. The default is 1000. \n"; + helpString += "The threshold parameter allows you to set the significance level to reject null hypotheses (default 0.05).\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n"; + helpString += "The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"; + helpString += "The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"; + helpString += "The metastats command should be in the following format: metastats(design=yourDesignFile).\n"; + helpString += "Example metastats(design=temp.design, groups=A-B-C).\n"; + helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MetaStatsCommand", "getRequiredParameters"); + m->errorOut(e, "MetaStatsCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector MetaStatsCommand::getRequiredFiles(){ +MetaStatsCommand::MetaStatsCommand(){ try { - string Array[] = {"shared"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["metastats"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "MetaStatsCommand", "getRequiredFiles"); + m->errorOut(e, "MetaStatsCommand", "MetaStatsCommand"); exit(1); } } @@ -63,18 +77,15 @@ vector MetaStatsCommand::getRequiredFiles(){ MetaStatsCommand::MetaStatsCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); + //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"groups","label","outputdir","iters","threshold","g","design","sets","processors","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -91,11 +102,6 @@ MetaStatsCommand::MetaStatsCommand(string option) { vector tempOutNames; outputTypes["metastats"] = 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 = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it - } //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); @@ -109,16 +115,40 @@ MetaStatsCommand::MetaStatsCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["design"] = 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; } + } + + } + + //check for required parameters + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { abort = true; } + else if (sharedfile == "not found") { //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; } } //check for required parameters designfile = validParameter.validFile(parameters, "design", true); if (designfile == "not open") { abort = true; } - else if (designfile == "not found") { designfile = ""; m->mothurOut("You must provide an design file."); m->mothurOutEndLine(); abort = true; } + else if (designfile == "not found") { + //if there is a current design file, use it + designfile = m->getDesignFile(); + if (designfile != "") { m->mothurOut("Using " + designfile + " as input file for the design parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current designfile and the design parameter is required."); m->mothurOutEndLine(); abort = true; } + } - //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "")) { - m->mothurOut("You must read a list and a group, or a shared file before you can use the metastats command."); 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 = ""; + outputDir += m->hasPath(sharedfile); //if user entered a file with a path then preserve it } //check for optional parameter and set defaults @@ -130,18 +160,12 @@ MetaStatsCommand::MetaStatsCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; pickedGroups = false; } else { pickedGroups = true; m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } sets = validParameter.validFile(parameters, "sets", false); @@ -157,8 +181,9 @@ MetaStatsCommand::MetaStatsCommand(string option) { temp = validParameter.validFile(parameters, "threshold", false); if (temp == "not found") { temp = "0.05"; } convert(temp, threshold); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } - convert(temp, processors); + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); } } @@ -167,39 +192,6 @@ MetaStatsCommand::MetaStatsCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void MetaStatsCommand::help(){ - try { - m->mothurOut("This command is based on the Metastats program, White, J.R., Nagarajan, N. & Pop, M. Statistical methods for detecting differentially abundant features in clinical metagenomic samples. PLoS Comput Biol 5, e1000352 (2009).\n"); - m->mothurOut("The metastats command can only be executed after a successful read.otu command of a list and group or shared file.\n"); - m->mothurOut("The metastats command outputs a .metastats file. \n"); - m->mothurOut("The metastats command parameters are iters, threshold, groups, label, design, sets and processors. The design parameter is required.\n"); - m->mothurOut("The design parameter allows you to assign your groups to sets when you are running metastat. mothur will run all pairwise comparisons of the sets. It is required. \n"); - m->mothurOut("The design file looks like the group file. It is a 2 column tab delimited file, where the first column is the group name and the second column is the set the group belongs to.\n"); - m->mothurOut("The sets parameter allows you to specify which of the sets in your designfile you would like to analyze. The set names are separated by dashes. THe default is all sets in the designfile.\n"); - m->mothurOut("The iters parameter allows you to set number of bootstrap permutations for estimating null distribution of t statistic. The default is 1000. \n"); - m->mothurOut("The threshold parameter allows you to set the significance level to reject null hypotheses (default 0.05).\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"); - m->mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"); - m->mothurOut("The metastats command should be in the following format: metastats(design=yourDesignFile).\n"); - m->mothurOut("Example metastats(design=temp.design, groups=A-B-C).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "MetaStatsCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -MetaStatsCommand::~MetaStatsCommand(){} - //********************************************************************************************************************** int MetaStatsCommand::execute(){ @@ -209,10 +201,8 @@ int MetaStatsCommand::execute(){ designMap = new GroupMap(designfile); designMap->readDesignMap(); - - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - input = globaldata->ginput; + + input = new InputData(sharedfile, "sharedfile"); lookup = input->getSharedRAbundVectors(); string lastLabel = lookup[0]->getLabel(); @@ -258,7 +248,7 @@ int MetaStatsCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); delete read; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -289,13 +279,13 @@ int MetaStatsCommand::execute(){ //prevent memory leak for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //get next line to process lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); delete input; delete designMap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //output error messages about any remaining user labels set::iterator it; @@ -323,9 +313,8 @@ int MetaStatsCommand::execute(){ } //reset groups parameter - globaldata->Groups.clear(); - delete input; globaldata->ginput = NULL; - delete read; + m->Groups.clear(); + delete input; delete designMap; if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0;} @@ -404,7 +393,7 @@ int MetaStatsCommand::driver(int start, int num, vector& th string setB = namesOfGroupCombos[c][1]; //get filename - string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + thisLookUp[0]->getLabel() + "." + setA + "-" + setB + ".metastats"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + thisLookUp[0]->getLabel() + "." + setA + "-" + setB + ".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 8c633b5..1380444 100644 --- a/metastatscommand.h +++ b/metastatscommand.h @@ -12,23 +12,22 @@ #include "command.hpp" #include "inputdata.h" -#include "readotu.h" #include "sharedrabundvector.h" -class GlobalData; - class MetaStatsCommand : public Command { public: MetaStatsCommand(string); MetaStatsCommand(); - ~MetaStatsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~MetaStatsCommand() {} + + vector setParameters(); + string getCommandName() { return "metastats"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: struct linePair { @@ -38,16 +37,13 @@ private: }; vector lines; - GlobalData* globaldata; GroupMap* designMap; - ReadOTUFile* read; InputData* input; vector lookup; - map > outputTypes; - + bool abort, allLines, pickedGroups; set labels; //holds labels to be used - string groups, label, outputDir, inputDir, designfile, sets; + string groups, label, outputDir, inputDir, designfile, sets, sharedfile; vector Groups, outputNames, Sets; vector< vector > namesOfGroupCombos; int iters, processors; diff --git a/mgclustercommand.cpp b/mgclustercommand.cpp index 23f359e..b6c4164 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -9,69 +9,82 @@ #include "mgclustercommand.h" - //********************************************************************************************************************** -vector MGClusterCommand::getValidParameters(){ +vector MGClusterCommand::setParameters(){ try { - string Array[] = {"blast", "method", "name", "hard", "cutoff", "precision", "length", "min", "penalty", "hcluster","merge","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pblast("blast", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pblast); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter plength("length", "Number", "", "5", "", "", "",false,false); parameters.push_back(plength); + CommandParameter ppenalty("penalty", "Number", "", "0.10", "", "", "",false,false); parameters.push_back(ppenalty); + CommandParameter pcutoff("cutoff", "Number", "", "0.70", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average", "furthest", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter phard("hard", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(phard); + CommandParameter pmin("min", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pmin); + CommandParameter pmerge("merge", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pmerge); + CommandParameter phcluster("hcluster", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(phcluster); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "MGClusterCommand", "getValidParameters"); + m->errorOut(e, "MGClusterCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -MGClusterCommand::MGClusterCommand(){ +string MGClusterCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["list"] = tempOutNames; - outputTypes["rabund"] = tempOutNames; - outputTypes["sabund"] = tempOutNames; + string helpString = ""; + helpString += "The mgcluster command parameter options are blast, name, cutoff, precision, hard, method, merge, min, length, penalty and hcluster. The blast parameter is required.\n"; + helpString += "The mgcluster command reads a blast and name file and clusters the sequences into OPF units similiar to the OTUs.\n"; + helpString += "This command outputs a .list, .rabund and .sabund file that can be used with mothur other commands to estimate richness.\n"; + helpString += "The cutoff parameter is used to specify the maximum distance you would like to cluster to. The default is 0.70.\n"; + helpString += "The precision parameter's default value is 100. \n"; + helpString += "The acceptable mgcluster methods are furthest, nearest and average. If no method is provided then furthest is assumed.\n\n"; + helpString += "The min parameter allows you to specify is you want the minimum or maximum blast score ratio used in calculating the distance. The default is true, meaning you want the minimum.\n"; + helpString += "The length parameter is used to specify the minimum overlap required. The default is 5.\n"; + helpString += "The penalty parameter is used to adjust the error rate. The default is 0.10.\n"; + helpString += "The merge parameter allows you to shut off merging based on overlaps and just cluster. By default merge is true, meaning you want to merge.\n"; + helpString += "The hcluster parameter allows you to use the hcluster algorithm when clustering. This may be neccessary if your file is too large to fit into RAM. The default is false.\n"; + helpString += "The mgcluster command should be in the following format: \n"; + helpString += "mgcluster(blast=yourBlastfile, name=yourNameFile, cutoff=yourCutOff).\n"; + helpString += "Note: No spaces between parameter labels (i.e. balst), '=' and parameters (i.e.yourBlastfile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "MGClusterCommand", "MGClusterCommand"); + m->errorOut(e, "MGClusterCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector MGClusterCommand::getRequiredParameters(){ - try { - string Array[] = {"blast"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "MGClusterCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector MGClusterCommand::getRequiredFiles(){ +MGClusterCommand::MGClusterCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "MGClusterCommand", "getRequiredFiles"); + m->errorOut(e, "MGClusterCommand", "MGClusterCommand"); exit(1); } } //********************************************************************************************************************** MGClusterCommand::MGClusterCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"blast", "method", "name", "hard", "cutoff", "precision", "length", "min", "penalty", "hcluster","merge","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -115,7 +128,7 @@ MGClusterCommand::MGClusterCommand(string option) { //check for required parameters blastfile = validParameter.validFile(parameters, "blast", true); - if (blastfile == "not open") { abort = true; } + if (blastfile == "not open") { blastfile = ""; abort = true; } else if (blastfile == "not found") { blastfile = ""; } //if the user changes the output directory command factory will send this info to us in the output parameter @@ -172,32 +185,6 @@ MGClusterCommand::MGClusterCommand(string option) { } } //********************************************************************************************************************** - -void MGClusterCommand::help(){ - try { - m->mothurOut("The mgcluster command parameter options are blast, name, cutoff, precision, method, merge, min, length, penalty and hcluster. The blast parameter is required.\n"); - m->mothurOut("The mgcluster command reads a blast and name file and clusters the sequences into OPF units similiar to the OTUs.\n"); - m->mothurOut("This command outputs a .list, .rabund and .sabund file that can be used with mothur other commands to estimate richness.\n"); - m->mothurOut("The cutoff parameter is used to specify the maximum distance you would like to cluster to. The default is 0.70.\n"); - m->mothurOut("The precision parameter's default value is 100. \n"); - m->mothurOut("The acceptable mgcluster methods are furthest, nearest and average. If no method is provided then furthest is assumed.\n\n"); - m->mothurOut("The min parameter allows you to specify is you want the minimum or maximum blast score ratio used in calculating the distance. The default is true, meaning you want the minimum.\n"); - m->mothurOut("The length parameter is used to specify the minimum overlap required. The default is 5.\n"); - m->mothurOut("The penalty parameter is used to adjust the error rate. The default is 0.10.\n"); - m->mothurOut("The merge parameter allows you to shut off merging based on overlaps and just cluster. By default merge is true, meaning you want to merge.\n"); - m->mothurOut("The hcluster parameter allows you to use the hcluster algorithm when clustering. This may be neccessary if your file is too large to fit into RAM. The default is false.\n"); - m->mothurOut("The mgcluster command should be in the following format: \n"); - m->mothurOut("mgcluster(blast=yourBlastfile, name=yourNameFile, cutoff=yourCutOff).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. balst), '=' and parameters (i.e.yourBlastfile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "MGClusterCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** -MGClusterCommand::~MGClusterCommand(){} -//********************************************************************************************************************** int MGClusterCommand::execute(){ try { @@ -488,14 +475,9 @@ int MGClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); - globaldata->setListFile(fileroot+ tag + ".list"); - globaldata->setFormat("list"); - if (m->control_pressed) { delete nameMap; listFile.close(); rabundFile.close(); sabundFile.close(); remove((fileroot+ tag + ".list").c_str()); remove((fileroot+ tag + ".rabund").c_str()); remove((fileroot+ tag + ".sabund").c_str()); - globaldata->setListFile(""); - globaldata->setFormat(""); outputTypes.clear(); return 0; } diff --git a/mgclustercommand.h b/mgclustercommand.h index f16a8f0..a51fec5 100644 --- a/mgclustercommand.h +++ b/mgclustercommand.h @@ -14,9 +14,10 @@ #include "readblast.h" #include "sparsematrix.hpp" #include "nameassignment.hpp" -#include "globaldata.hpp" #include "cluster.hpp" #include "hcluster.h" +#include "rabundvector.hpp" +#include "sabundvector.hpp" /**********************************************************************/ @@ -25,16 +26,18 @@ class MGClusterCommand : public Command { public: MGClusterCommand(string); MGClusterCommand(); - ~MGClusterCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~MGClusterCommand(){} + + vector setParameters(); + string getCommandName() { return "mgcluster"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; ReadBlast* read; NameAssignment* nameMap; Cluster* cluster; @@ -43,7 +46,6 @@ private: ListVector oldList; vector overlapMatrix; vector outputNames; - map > outputTypes; string blastfile, method, namefile, overlapFile, distFile, outputDir; ofstream sabundFile, rabundFile, listFile; diff --git a/mothur.cpp b/mothur.cpp index 9ed0dfc..74e7e73 100644 --- a/mothur.cpp +++ b/mothur.cpp @@ -14,7 +14,6 @@ /**************************************************************************************************/ -GlobalData* GlobalData::_uniqueInstance = 0; CommandFactory* CommandFactory::_uniqueInstance = 0; MothurOut* MothurOut::_uniqueInstance = 0; diff --git a/mothurout.cpp b/mothurout.cpp index 0c25f2a..59e4fdc 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -1730,7 +1730,6 @@ bool MothurOut::checkReleaseVersion(ifstream& file, string version) { exit(1); } } - /**************************************************************************************************/ diff --git a/mothurout.h b/mothurout.h index 3580532..6654455 100644 --- a/mothurout.h +++ b/mothurout.h @@ -35,6 +35,11 @@ class MothurOut { void setReleaseDate(string r) { releaseDate = r; } string getVersion() { return version; } void setVersion(string r) { version = r; } + vector Groups; + vector Treenames; + map names; + vector namesOfGroups; + string saveNextLabel, argv; //functions from mothur.h //file operations @@ -89,7 +94,7 @@ class MothurOut { unsigned int fromBase36(string); int control_pressed; - bool executing; + bool executing, runParse, jumble; //current files - if you add a new type you must edit optionParser->getParameters, get.current command and mothurOut->printCurrentFiles/clearCurrentFiles. string getPhylipFile() { return phylipfile; } @@ -111,6 +116,7 @@ class MothurOut { string getOligosFile() { return oligosfile; } string getAccnosFile() { return accnosfile; } string getTaxonomyFile() { return taxonomyfile; } + string getProcessors() { return processors; } void setListFile(string f) { listfile = getFullPathName(f); } void setTreeFile(string f) { treefile = getFullPathName(f); } @@ -131,6 +137,7 @@ class MothurOut { void setOligosFile(string f) { oligosfile = getFullPathName(f); } void setAccnosFile(string f) { accnosfile = getFullPathName(f); } void setTaxonomyFile(string f) { taxonomyfile = getFullPathName(f); } + void setProcessors(string p) { processors = p; } void printCurrentFiles(); void clearCurrentFiles(); @@ -160,6 +167,7 @@ class MothurOut { oligosfile = ""; accnosfile = ""; taxonomyfile = ""; + processors = "1"; }; ~MothurOut(); @@ -168,7 +176,7 @@ class MothurOut { string releaseDate, version; string accnosfile, phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, designfile, taxonomyfile; - string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile; + string orderfile, treefile, sharedfile, ordergroupfile, relabundfile, fastafile, qualfile, sfffile, oligosfile, processors; ofstream out; diff --git a/nmdscommand.cpp b/nmdscommand.cpp index aa1cd66..8fa0145 100644 --- a/nmdscommand.cpp +++ b/nmdscommand.cpp @@ -11,51 +11,61 @@ #include "readphylipvector.h" //********************************************************************************************************************** -vector NMDSCommand::getValidParameters(){ +vector NMDSCommand::setParameters(){ try { - string Array[] = {"phylip","axes","mindim","maxdim","iters","maxiters","epsilon","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter paxes("axes", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paxes); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); + CommandParameter pmaxdim("maxdim", "Number", "", "2", "", "", "",false,false); parameters.push_back(pmaxdim); + CommandParameter pmindim("mindim", "Number", "", "2", "", "", "",false,false); parameters.push_back(pmindim); + CommandParameter piters("iters", "Number", "", "10", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pmaxiters("maxiters", "Number", "", "500", "", "", "",false,false); parameters.push_back(pmaxiters); + CommandParameter pepsilon("epsilon", "Number", "", "0.000000000001", "", "", "",false,false); parameters.push_back(pepsilon); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "NMDSCommand", "getValidParameters"); + m->errorOut(e, "NMDSCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -NMDSCommand::NMDSCommand(){ +string NMDSCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["nmds"] = tempOutNames; - outputTypes["stress"] = tempOutNames; - outputTypes["iters"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "NMDSCommand", "NMDSCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector NMDSCommand::getRequiredParameters(){ - try { - string Array[] = {"phylip"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The nmds command is modelled after the nmds code written in R by Sarah Goslee, using Non-metric multidimensional scaling function using the majorization algorithm from Borg & Groenen 1997, Modern Multidimensional Scaling.\n"; + helpString += "The nmds command parameters are phylip, axes, mindim, maxdim, maxiters, iters and epsilon.\n"; + helpString += "The phylip parameter allows you to enter your distance file.\n"; + helpString += "The axes parameter allows you to enter a file containing a starting configuration.\n"; + helpString += "The maxdim parameter allows you to select the maximum dimensions to use. Default=2\n"; + helpString += "The mindim parameter allows you to select the minimum dimensions to use. Default=2\n"; + helpString += "The maxiters parameter allows you to select the maximum number of iters to try with each random configuration. Default=500\n"; + helpString += "The iters parameter allows you to select the number of random configuration to try. Default=10\n"; + helpString += "The epsilon parameter allows you to select set an acceptable stopping point. Default=1e-12.\n"; + helpString += "Example nmds(phylip=yourDistanceFile).\n"; + helpString += "Note: No spaces between parameter labels (i.e. phylip), '=' and parameters (i.e.yourDistanceFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "NMDSCommand", "getRequiredParameters"); + m->errorOut(e, "NMDSCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector NMDSCommand::getRequiredFiles(){ +NMDSCommand::NMDSCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["nmds"] = tempOutNames; + outputTypes["stress"] = tempOutNames; + outputTypes["iters"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "NMDSCommand", "getRequiredFiles"); + m->errorOut(e, "NMDSCommand", "NMDSCommand"); exit(1); } } @@ -69,9 +79,7 @@ NMDSCommand::NMDSCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"phylip","axes","mindim","maxdim","iters","maxiters","epsilon","outputdir", "inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser. getParameters(); @@ -114,7 +122,12 @@ NMDSCommand::NMDSCommand(string option) { //required parameters phylipfile = validParameter.validFile(parameters, "phylip", true); if (phylipfile == "not open") { phylipfile = ""; abort = true; } - else if (phylipfile == "not found") { phylipfile = ""; m->mothurOut("You must provide a distance file before running the nmds command."); m->mothurOutEndLine(); abort = true; } + else if (phylipfile == "not found") { + //if there is a current phylip file, use it + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current phylip file and the phylip parameter is required."); m->mothurOutEndLine(); abort = true; } + } axesfile = validParameter.validFile(parameters, "axes", true); if (axesfile == "not open") { axesfile = ""; abort = true; } @@ -152,28 +165,6 @@ NMDSCommand::NMDSCommand(string option) { } } //********************************************************************************************************************** -void NMDSCommand::help(){ - try { - m->mothurOut("The nmds command is modelled after the nmds code written in R by Sarah Goslee, using Non-metric multidimensional scaling function using the majorization algorithm from Borg & Groenen 1997, Modern Multidimensional Scaling."); m->mothurOutEndLine(); - m->mothurOut("The nmds command parameters are phylip, axes, mindim, maxdim, maxiters, iters and epsilon."); m->mothurOutEndLine(); - m->mothurOut("The phylip parameter allows you to enter your distance file."); m->mothurOutEndLine(); - m->mothurOut("The axes parameter allows you to enter a file containing a starting configuration."); m->mothurOutEndLine(); - m->mothurOut("The maxdim parameter allows you to select the maximum dimensions to use. Default=2"); m->mothurOutEndLine(); - m->mothurOut("The mindim parameter allows you to select the minimum dimensions to use. Default=2"); m->mothurOutEndLine(); - m->mothurOut("The maxiters parameter allows you to select the maximum number of iters to try with each random configuration. Default=500"); m->mothurOutEndLine(); - m->mothurOut("The iters parameter allows you to select the number of random configuration to try. Default=10"); m->mothurOutEndLine(); - m->mothurOut("The epsilon parameter allows you to select set an acceptable stopping point. Default=1e-12."); m->mothurOutEndLine(); - m->mothurOut("Example nmds(phylip=yourDistanceFile).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. phylip), '=' and parameters (i.e.yourDistanceFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "NMDSCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** -NMDSCommand::~NMDSCommand(){} -//********************************************************************************************************************** int NMDSCommand::execute(){ try { diff --git a/nmdscommand.h b/nmdscommand.h index 7979c67..861e8ea 100644 --- a/nmdscommand.h +++ b/nmdscommand.h @@ -32,13 +32,15 @@ class NMDSCommand : public Command { public: NMDSCommand(string); NMDSCommand(); - ~NMDSCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~NMDSCommand(){} + + vector setParameters(); + string getCommandName() { return "nmds"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: @@ -47,7 +49,6 @@ private: int maxdim, mindim, maxIters, iters; double epsilon; vector outputNames; - map > outputTypes; LinearAlgebra linearCalc; vector< vector > nmdsCalc(vector< vector >&, vector< vector >&, double&); diff --git a/nocommands.cpp b/nocommands.cpp index eab873b..9c223ee 100644 --- a/nocommands.cpp +++ b/nocommands.cpp @@ -9,49 +9,12 @@ #include "nocommands.h" -//********************************************************************************************************************** -vector NoCommand::getValidParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "NoCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector NoCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "NoCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector NoCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "NoCommand", "getRequiredFiles"); - exit(1); - } -} //********************************************************************************************************************** NoCommand::NoCommand(string option) {} //********************************************************************************************************************** -NoCommand::~NoCommand(){} - -//********************************************************************************************************************** - int NoCommand::execute(){ //Could choose to give more help here?fdsah cout << "Invalid command.\n"; diff --git a/nocommands.h b/nocommands.h index f11673f..12bfc4d 100644 --- a/nocommands.h +++ b/nocommands.h @@ -19,17 +19,19 @@ class NoCommand : public Command { public: NoCommand(string); NoCommand() {} - ~NoCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help() {} + ~NoCommand(){} + + vector setParameters() { return outputNames; } //dummy, doesn't really do anything + string getCommandName() { return "NoCommand"; } + string getCommandCategory() { return "Hidden"; } + string getHelpString() { return "No Command"; } + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: vector outputNames; - map > outputTypes; }; diff --git a/normalizesharedcommand.cpp b/normalizesharedcommand.cpp index 37cfb5d..8a6b4ad 100644 --- a/normalizesharedcommand.cpp +++ b/normalizesharedcommand.cpp @@ -10,49 +10,61 @@ #include "normalizesharedcommand.h" //********************************************************************************************************************** -vector NormalizeSharedCommand::getValidParameters(){ +vector NormalizeSharedCommand::setParameters(){ try { - string Array[] = {"groups","label","method","makerelabund","outputdir","inputdir","norm"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pmethod("method", "Multiple", "totalgroup-zscore", "totalgroup", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter pnorm("norm", "Number", "", "0", "", "", "",false,false); parameters.push_back(pnorm); + CommandParameter pmakerelabund("makerelabund", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pmakerelabund); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "NormalizeSharedCommand", "getValidParameters"); + m->errorOut(e, "NormalizeSharedCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -NormalizeSharedCommand::NormalizeSharedCommand(){ +string NormalizeSharedCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["shared"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector NormalizeSharedCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The normalize.shared command parameters are shared, relabund, groups, method, norm, makerelabund and label. shared or relabund is required, unless you have a valid current file.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n"; + helpString += "The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"; + helpString += "The method parameter allows you to select what method you would like to use to normalize. The options are totalgroup and zscore. We hope to add more ways to normalize in the future, suggestions are welcome!\n"; + helpString += "The makerelabund parameter allows you to convert a shared file to a relabund file before you normalize. default=f.\n"; + helpString += "The norm parameter allows you to number you would like to normalize to. By default this is set to the number of sequences in your smallest group.\n"; + helpString += "The normalize.shared command should be in the following format: normalize.shared(groups=yourGroups, label=yourLabels).\n"; + helpString += "Example normalize.shared(groups=A-B-C, scale=totalgroup).\n"; + helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"; + helpString += "The normalize.shared command outputs a .norm.shared file.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "NormalizeSharedCommand", "getRequiredParameters"); + m->errorOut(e, "NormalizeSharedCommand", "getHelpString"); exit(1); } } + + //********************************************************************************************************************** -vector NormalizeSharedCommand::getRequiredFiles(){ +NormalizeSharedCommand::NormalizeSharedCommand(){ try { - string Array[] = {"shared"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["shared"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "NormalizeSharedCommand", "getRequiredFiles"); + m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand"); exit(1); } } @@ -60,26 +72,23 @@ vector NormalizeSharedCommand::getRequiredFiles(){ NormalizeSharedCommand::NormalizeSharedCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"groups","label","method","makerelabund","outputdir","inputdir","norm"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } @@ -87,20 +96,59 @@ NormalizeSharedCommand::NormalizeSharedCommand(string option) { vector tempOutNames; outputTypes["shared"] = 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 = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + //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("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("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; } + } } - //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "") && (globaldata->getRelAbundFile() == "")) { - m->mothurOut("You must read a list and a group, shared or relabund file before you can use the normalize.shared command."); m->mothurOutEndLine(); abort = true; + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { format = "sharedfile"; inputfile = sharedfile; } + + relabundfile = validParameter.validFile(parameters, "relabund", true); + if (relabundfile == "not open") { relabundfile = ""; abort = true; } + else if (relabundfile == "not found") { relabundfile = ""; } + else { format = "relabund"; inputfile = relabundfile; } + + + if ((sharedfile == "") && (relabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + relabundfile = m->getRelAbundFile(); + if (relabundfile != "") { inputfile = relabundfile; format = "relabund"; m->mothurOut("Using " + relabundfile + " as input file for the relabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list, sabund, rabund, relabund or shared file."); m->mothurOutEndLine(); + abort = true; + } + } } - if ((globaldata->getSharedFile() != "") && (globaldata->getRelAbundFile() != "")) { - m->mothurOut("You may not use both a shared and relabund file as input for normalize.shared command."); 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(inputfile); } + //check for optional parameter and set defaults @@ -112,18 +160,12 @@ NormalizeSharedCommand::NormalizeSharedCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; pickedGroups = false; } else { pickedGroups = true; m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } method = validParameter.validFile(parameters, "method", false); if (method == "not found") { method = "totalgroup"; } @@ -139,9 +181,6 @@ NormalizeSharedCommand::NormalizeSharedCommand(string option) { temp = validParameter.validFile(parameters, "makerelabund", false); if (temp == "") { temp = "f"; } makeRelabund = m->isTrue(temp); - - if ((globaldata->getFormat() != "sharedfile") && makeRelabund) { m->mothurOut("makerelabund can only be used with a shared file."); m->mothurOutEndLine(); } - } } @@ -150,35 +189,6 @@ NormalizeSharedCommand::NormalizeSharedCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void NormalizeSharedCommand::help(){ - try { - m->mothurOut("The normalize.shared command can only be executed after a successful read.otu command of a list and group, shared or relabund file.\n"); - m->mothurOut("The normalize.shared command parameters are groups, method, norm, makerelabund and label. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"); - m->mothurOut("The method parameter allows you to select what method you would like to use to normalize. The options are totalgroup and zscore. We hope to add more ways to normalize in the future, suggestions are welcome!\n"); - m->mothurOut("The makerelabund parameter allows you to convert a shared file to a relabund file before you normalize. default=f.\n"); - m->mothurOut("The norm parameter allows you to number you would like to normalize to. By default this is set to the number of sequences in your smallest group.\n"); - m->mothurOut("The normalize.shared command should be in the following format: normalize.shared(groups=yourGroups, label=yourLabels).\n"); - m->mothurOut("Example normalize.shared(groups=A-B-C, scale=totalgroup).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"); - m->mothurOut("The normalize.shared command outputs a .norm.shared file.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "NormalizeSharedCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -NormalizeSharedCommand::~NormalizeSharedCommand(){} - //********************************************************************************************************************** int NormalizeSharedCommand::execute(){ @@ -186,18 +196,33 @@ int NormalizeSharedCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "norm.shared"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "norm.shared"; ofstream out; m->openOutputFile(outputFileName, out); - if (globaldata->getFormat() == "sharedfile") { input = new InputData(globaldata->inputFileName, "sharedfile"); } - else { input = new InputData(globaldata->inputFileName, "relabund"); } - + input = new InputData(inputfile, format); + //you are reading a sharedfile and you do not want to make relabund - if ((globaldata->getFormat() == "sharedfile") && (!makeRelabund)) { + if ((format == "sharedfile") && (!makeRelabund)) { lookup = input->getSharedRAbundVectors(); string lastLabel = lookup[0]->getLabel(); + //look for groups whose numseqs is below norm and remove them, warning the user + if (norm != 0) { + m->Groups.clear(); + vector temp; + for (int i = 0; i < lookup.size(); i++) { + if (lookup[i]->getNumSeqs() < norm) { + m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); + delete lookup[i]; + }else { + m->Groups.push_back(lookup[i]->getGroup()); + temp.push_back(lookup[i]); + } + } + lookup = temp; + } + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; @@ -217,7 +242,7 @@ int NormalizeSharedCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ @@ -248,13 +273,13 @@ int NormalizeSharedCommand::execute(){ //prevent memory leak for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } - if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } //get next line to process lookup = input->getSharedRAbundVectors(); } - if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -289,6 +314,22 @@ int NormalizeSharedCommand::execute(){ set processedLabels; set userLabels = labels; + //look for groups whose numseqs is below norm and remove them, warning the user + if (norm != 0) { + m->Groups.clear(); + vector temp; + for (int i = 0; i < lookupFloat.size(); i++) { + if (lookupFloat[i]->getNumSeqs() < norm) { + m->mothurOut(lookupFloat[i]->getGroup() + " contains " + toString(lookupFloat[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine(); + delete lookupFloat[i]; + }else { + m->Groups.push_back(lookupFloat[i]->getGroup()); + temp.push_back(lookupFloat[i]); + } + } + lookupFloat = temp; + } + //set norm to smallest group number if (method == "totalgroup") { if (norm == 0) { @@ -304,7 +345,7 @@ int NormalizeSharedCommand::execute(){ //as long as you are not at the end of the file or done wih the lines you want while((lookupFloat[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { - if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } globaldata->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } m->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){ @@ -335,13 +376,13 @@ int NormalizeSharedCommand::execute(){ //prevent memory leak for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; lookupFloat[i] = NULL; } - if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } //get next line to process lookupFloat = input->getSharedRAbundFloatVectors(); } - if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } + if (m->control_pressed) { outputTypes.clear(); m->Groups.clear(); out.close(); remove(outputFileName.c_str()); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -370,7 +411,7 @@ int NormalizeSharedCommand::execute(){ } //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); delete input; out.close(); diff --git a/normalizesharedcommand.h b/normalizesharedcommand.h index bedff43..26bc0e4 100644 --- a/normalizesharedcommand.h +++ b/normalizesharedcommand.h @@ -14,34 +14,33 @@ #include "inputdata.h" #include "sharedrabundvector.h" -class GlobalData; - class NormalizeSharedCommand : public Command { public: NormalizeSharedCommand(string); NormalizeSharedCommand(); - ~NormalizeSharedCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~NormalizeSharedCommand() {} + + vector setParameters(); + string getCommandName() { return "normalize.shared"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; InputData* input; vector lookup; vector lookupFloat; bool abort, allLines, pickedGroups, makeRelabund; set labels; //holds labels to be used - string groups, label, outputDir, method; + string groups, label, outputDir, method, sharedfile, relabundfile, format, inputfile; int norm; vector Groups, outputNames; - map > outputTypes; - + int normalize(vector&, ofstream&); int normalize(vector&, ofstream&); int eliminateZeroOTUS(vector&); diff --git a/optionparser.cpp b/optionparser.cpp index 0506da6..71714f1 100644 --- a/optionparser.cpp +++ b/optionparser.cpp @@ -21,11 +21,15 @@ OptionParser::OptionParser(string option) { 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; } } @@ -49,7 +53,7 @@ map OptionParser::getParameters() { if (it->second == "current") { //look for file types - if ((it->first == "fasta") || (it->first == "candidate")) { + if (it->first == "fasta") { it->second = m->getFastaFile(); }else if (it->first == "qfile") { it->second = m->getQualFile(); diff --git a/otuhierarchycommand.cpp b/otuhierarchycommand.cpp index b49af32..17e29d9 100644 --- a/otuhierarchycommand.cpp +++ b/otuhierarchycommand.cpp @@ -10,49 +10,53 @@ #include "otuhierarchycommand.h" //********************************************************************************************************************** -vector OtuHierarchyCommand::getValidParameters(){ +vector OtuHierarchyCommand::setParameters(){ try { - string Array[] = {"list","label","output","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter poutput("output", "Multiple", "name-number", "name", "", "", "",false,false); parameters.push_back(poutput); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "OtuHierarchyCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -OtuHierarchyCommand::OtuHierarchyCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["otuheirarchy"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "OtuHierarchyCommand", "OtuHierarchyCommand"); + m->errorOut(e, "OtuHierarchyCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector OtuHierarchyCommand::getRequiredParameters(){ +string OtuHierarchyCommand::getHelpString(){ try { - string Array[] = {"list","label"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The otu.hierarchy command is used to see how otus relate at two distances. \n"; + helpString += "The otu.hierarchy command parameters are list, label and output. list and label parameters are required. \n"; + helpString += "The output parameter allows you to output the names of the sequence in the OTUs or the OTU numbers. Options are name and number, default is name. \n"; + helpString += "The otu.hierarchy command should be in the following format: \n"; + helpString += "otu.hierarchy(list=yourListFile, label=yourLabels).\n"; + helpString += "Example otu.hierarchy(list=amazon.fn.list, label=0.01-0.03).\n"; + helpString += "The otu.hierarchy command outputs a .otu.hierarchy file which is described on the wiki.\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "OtuHierarchyCommand", "getRequiredParameters"); + m->errorOut(e, "OtuHierarchyCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector OtuHierarchyCommand::getRequiredFiles(){ +OtuHierarchyCommand::OtuHierarchyCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["otuheirarchy"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "OtuHierarchyCommand", "getRequiredFiles"); + m->errorOut(e, "OtuHierarchyCommand", "OtuHierarchyCommand"); exit(1); } } @@ -65,9 +69,7 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"list","label","output","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -99,8 +101,14 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option) { } listFile = validParameter.validFile(parameters, "list", true); - if (listFile == "not found") { m->mothurOut("list is a required parameter for the otu.hierarchy command."); m->mothurOutEndLine(); abort = true; } - else if (listFile == "not open") { abort = true; } + if (listFile == "not found") { + listFile = m->getListFile(); + if (listFile != "") { m->mothurOut("Using " + listFile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current list file. You must provide a list file."); m->mothurOutEndLine(); + abort = true; + } + }else if (listFile == "not open") { 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"){ @@ -130,29 +138,6 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option) { } //********************************************************************************************************************** -void OtuHierarchyCommand::help(){ - try { - m->mothurOut("The otu.hierarchy command is used to see how otus relate at two distances. \n"); - m->mothurOut("The otu.hierarchy command parameters are list, label and output. list and label parameters are required. \n"); - m->mothurOut("The output parameter allows you to output the names of the sequence in the OTUs or the OTU numbers. Options are name and number, default is name. \n"); - m->mothurOut("The otu.hierarchy command should be in the following format: \n"); - m->mothurOut("otu.hierarchy(list=yourListFile, label=yourLabels).\n"); - m->mothurOut("Example otu.hierarchy(list=amazon.fn.list, label=0.01-0.03).\n"); - m->mothurOut("The otu.hierarchy command outputs a .otu.hierarchy file which is described on the wiki.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "OtuHierarchyCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -OtuHierarchyCommand::~OtuHierarchyCommand(){} - -//********************************************************************************************************************** - int OtuHierarchyCommand::execute(){ try { diff --git a/otuhierarchycommand.h b/otuhierarchycommand.h index dd5f3a7..b82ee76 100644 --- a/otuhierarchycommand.h +++ b/otuhierarchycommand.h @@ -19,20 +19,22 @@ class OtuHierarchyCommand : public Command { public: OtuHierarchyCommand(string); OtuHierarchyCommand(); - ~OtuHierarchyCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~OtuHierarchyCommand(){} + + vector setParameters(); + string getCommandName() { return "otu.hierarchy"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: bool abort; set labels; //holds labels to be used string label, listFile, outputDir, output; vector outputNames; - map > outputTypes; vector getListVectors(); diff --git a/pairwiseseqscommand.cpp b/pairwiseseqscommand.cpp index 5c89040..0c9bcc5 100644 --- a/pairwiseseqscommand.cpp +++ b/pairwiseseqscommand.cpp @@ -23,44 +23,66 @@ //********************************************************************************************************************** -vector PairwiseSeqsCommand::getValidParameters(){ +vector PairwiseSeqsCommand::setParameters(){ try { - string AlignArray[] = {"fasta","align","match","mismatch","gapopen","gapextend", "processors","calc","compress","cutoff","countends","output","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "PairwiseSeqsCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector PairwiseSeqsCommand::getRequiredParameters(){ - try { - string AlignArray[] = {"fasta"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter palign("align", "Multiple", "needleman-gotoh-blast-noalign", "needleman", "", "", "",false,false); parameters.push_back(palign); + CommandParameter pmatch("match", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pmatch); + CommandParameter pmismatch("mismatch", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pmismatch); + CommandParameter pgapopen("gapopen", "Number", "", "-2.0", "", "", "",false,false); parameters.push_back(pgapopen); + CommandParameter pgapextend("gapextend", "Number", "", "-1.0", "", "", "",false,false); parameters.push_back(pgapextend); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter poutput("output", "Multiple", "column-lt-square", "column", "", "", "",false,false); parameters.push_back(poutput); + CommandParameter pcalc("calc", "Multiple", "nogaps-eachgap-onegap", "onegap", "", "", "",false,false); parameters.push_back(pcalc); + CommandParameter pcountends("countends", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pcountends); + CommandParameter pcompress("compress", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pcompress); + CommandParameter pcutoff("cutoff", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "PairwiseSeqsCommand", "getRequiredParameters"); + m->errorOut(e, "PairwiseSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector PairwiseSeqsCommand::getRequiredFiles(){ +string PairwiseSeqsCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The pairwise.seqs command reads a fasta file and creates distance matrix.\n"; + helpString += "The pairwise.seqs command parameters are fasta, align, match, mismatch, gapopen, gapextend, calc, output, cutoff and processors.\n"; + helpString += "The fasta parameter is required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"; + helpString += "The align parameter allows you to specify the alignment method to use. Your options are: gotoh, needleman, blast and noalign. The default is needleman.\n"; + helpString += "The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n"; + helpString += "The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n"; + helpString += "The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n"; + helpString += "The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n"; + helpString += "The calc parameter allows you to specify the method of calculating the distances. Your options are: nogaps, onegap or eachgap. The default is onegap.\n"; + helpString += "The countends parameter allows you to specify whether to include terminal gaps in distance. Your options are: T or F. The default is T.\n"; + helpString += "The cutoff parameter allows you to specify maximum distance to keep. The default is 1.0.\n"; + helpString += "The output parameter allows you to specify format of your distance matrix. Options are column, lt, and square. The default is column.\n"; + helpString += "The compress parameter allows you to indicate that you want the resulting distance file compressed. The default is false.\n"; + helpString += "The pairwise.seqs command should be in the following format: \n"; + helpString += "pairwise.seqs(fasta=yourfastaFile, align=yourAlignmentMethod) \n"; + helpString += "Example pairwise.seqs(fasta=candidate.fasta, align=blast)\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "PairwiseSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "PairwiseSeqsCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** PairwiseSeqsCommand::PairwiseSeqsCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["phylip"] = tempOutNames; outputTypes["column"] = tempOutNames; @@ -79,10 +101,7 @@ PairwiseSeqsCommand::PairwiseSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - - //valid paramters for this command - string AlignArray[] = {"fasta","align","match","mismatch","gapopen","gapextend", "processors","cutoff","compress","calc","countends","output","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -110,7 +129,12 @@ PairwiseSeqsCommand::PairwiseSeqsCommand(string option) { if (inputDir == "not found"){ inputDir = ""; } fastaFileName = validParameter.validFile(parameters, "fasta", false); - if (fastaFileName == "not found") { m->mothurOut("fasta is a required parameter for the pairwise.seqs command."); m->mothurOutEndLine(); abort = true; } + if (fastaFileName == "not found") { + //if there is a current fasta file, use it + string filename = m->getFastaFile(); + if (filename != "") { fastaFileNames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } else { m->splitAtDash(fastaFileName, fastaFileNames); @@ -181,8 +205,9 @@ PairwiseSeqsCommand::PairwiseSeqsCommand(string option) { temp = validParameter.validFile(parameters, "gapextend", false); if (temp == "not found"){ temp = "-1.0"; } convert(temp, gapExtend); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } - convert(temp, processors); + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); temp = validParameter.validFile(parameters, "cutoff", false); if(temp == "not found"){ temp = "1.0"; } convert(temp, cutoff); @@ -231,37 +256,6 @@ PairwiseSeqsCommand::PairwiseSeqsCommand(string option) { exit(1); } } -//********************************************************************************************************************** -PairwiseSeqsCommand::~PairwiseSeqsCommand(){} -//********************************************************************************************************************** - -void PairwiseSeqsCommand::help(){ - try { - m->mothurOut("The pairwise.seqs command reads a fasta file and creates distance matrix.\n"); - m->mothurOut("The pairwise.seqs command parameters are fasta, align, match, mismatch, gapopen, gapextend, calc, output, cutoff and processors.\n"); - m->mothurOut("The fasta parameter is required. You may enter multiple fasta files by separating their names with dashes. ie. fasta=abrecovery.fasta-amzon.fasta \n"); - m->mothurOut("The align parameter allows you to specify the alignment method to use. Your options are: gotoh, needleman, blast and noalign. The default is needleman.\n"); - m->mothurOut("The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n"); - m->mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n"); - m->mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n"); - m->mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n"); - m->mothurOut("The calc parameter allows you to specify the method of calculating the distances. Your options are: nogaps, onegap or eachgap. The default is onegap.\n"); - m->mothurOut("The countends parameter allows you to specify whether to include terminal gaps in distance. Your options are: T or F. The default is T.\n"); - m->mothurOut("The cutoff parameter allows you to specify maximum distance to keep. The default is 1.0.\n"); - m->mothurOut("The output parameter allows you to specify format of your distance matrix. Options are column, lt, and square. The default is column.\n"); - m->mothurOut("The compress parameter allows you to indicate that you want the resulting distance file compressed. The default is false.\n"); - m->mothurOut("The pairwise.seqs command should be in the following format: \n"); - m->mothurOut("pairwise.seqs(fasta=yourfastaFile, align=yourAlignmentMethod) \n"); - m->mothurOut("Example pairwise.seqs(fasta=candidate.fasta, align=blast)\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "PairwiseSeqsCommand", "help"); - exit(1); - } -} - - //********************************************************************************************************************** int PairwiseSeqsCommand::execute(){ diff --git a/pairwiseseqscommand.h b/pairwiseseqscommand.h index cf73f3e..52ba63d 100644 --- a/pairwiseseqscommand.h +++ b/pairwiseseqscommand.h @@ -23,13 +23,15 @@ class PairwiseSeqsCommand : public Command { public: PairwiseSeqsCommand(string); PairwiseSeqsCommand(); - ~PairwiseSeqsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + ~PairwiseSeqsCommand() {} + + vector setParameters(); + string getCommandName() { return "pairwise.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } private: struct distlinePair { @@ -37,10 +39,8 @@ private: int end; }; - vector processIDS; //end line, processid vector lines; - map > outputTypes; Alignment* alignment; Dist* distCalculator; diff --git a/parsefastaqcommand.cpp b/parsefastaqcommand.cpp index 87ec2d2..75d6fa0 100644 --- a/parsefastaqcommand.cpp +++ b/parsefastaqcommand.cpp @@ -11,50 +11,48 @@ #include "sequence.hpp" //********************************************************************************************************************** -vector ParseFastaQCommand::getValidParameters(){ +vector ParseFastaQCommand::setParameters(){ try { - string Array[] = {"fastq", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfastq("fastq", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfastq); + 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, "ParseFastaQCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -ParseFastaQCommand::ParseFastaQCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["qfile"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ParseFastaQCommand", "ParseFastaQCommand"); + m->errorOut(e, "ParseFastaQCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ParseFastaQCommand::getRequiredParameters(){ +string ParseFastaQCommand::getHelpString(){ try { - string Array[] = {"fastq"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The fastq.info command reads a fastq file and creates a fasta and quality file.\n"; + helpString += "The fastq.info command parameter is fastq, and it is required.\n"; + helpString += "The fastq.info command should be in the following format: fastq.info(fastaq=yourFastaQFile).\n"; + helpString += "Example fastq.info(fastaq=test.fastaq).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fastq), '=' and yourFastQFile.\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ParseFastaQCommand", "getRequiredParameters"); + m->errorOut(e, "ParseFastaQCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ParseFastaQCommand::getRequiredFiles(){ +ParseFastaQCommand::ParseFastaQCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["qfile"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ParseFastaQCommand", "getRequiredFiles"); + m->errorOut(e, "ParseFastaQCommand", "ParseFastaQCommand"); exit(1); } } @@ -66,9 +64,7 @@ ParseFastaQCommand::ParseFastaQCommand(string option){ if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fastq", "outputdir", "inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -117,26 +113,6 @@ ParseFastaQCommand::ParseFastaQCommand(string option){ } //********************************************************************************************************************** -void ParseFastaQCommand::help(){ - try { - m->mothurOut("The fastq.info command reads a fastq file and creates a fasta and quality file.\n"); - m->mothurOut("The fastq.info command parameter is fastq, and it is required.\n"); - m->mothurOut("The fastq.info command should be in the following format: fastq.info(fastaq=yourFastaQFile).\n"); - m->mothurOut("Example fastq.info(fastaq=test.fastaq).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fastq), '=' and yourFastQFile.\n"); - m->mothurOutEndLine(); - } - catch(exception& e) { - m->errorOut(e, "ParseFastaQCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** - -ParseFastaQCommand::~ParseFastaQCommand() { /* do nothing */ } - -//********************************************************************************************************************** - int ParseFastaQCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } diff --git a/parsefastaqcommand.h b/parsefastaqcommand.h index c45405f..fe77cf0 100644 --- a/parsefastaqcommand.h +++ b/parsefastaqcommand.h @@ -18,18 +18,18 @@ class ParseFastaQCommand : public Command { public: ParseFastaQCommand(string); ParseFastaQCommand(); - ~ParseFastaQCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ParseFastaQCommand() {} + vector setParameters(); + string getCommandName() { return "parse.fastq"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: vector outputNames; - map > outputTypes; string outputDir, fastaQFile; bool abort; diff --git a/parselistscommand.cpp b/parselistscommand.cpp index 2d26ef3..6e4082e 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -10,50 +10,51 @@ #include "parselistscommand.h" //********************************************************************************************************************** -vector ParseListCommand::getValidParameters(){ +vector ParseListCommand::setParameters(){ try { - string Array[] = {"list","group", "label", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ParseListCommand", "getValidParameters"); + m->errorOut(e, "ParseListCommand", "setParameters"); exit(1); } } - //********************************************************************************************************************** -ParseListCommand::ParseListCommand(){ +string ParseListCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["list"] = tempOutNames; + string helpString = ""; + helpString += "The parse.list command reads a list and group file and generates a list file for each group in the groupfile. \n"; + helpString += "The parse.list command parameters are list, group and label.\n"; + helpString += "The list and group parameters are required.\n"; + helpString += "The label parameter is used to read specific labels in your input you want to use.\n"; + helpString += "The parse.list command should be used in the following format: parse.list(list=yourListFile, group=yourGroupFile, label=yourLabels).\n"; + helpString += "Example: parse.list(list=abrecovery.fn.list, group=abrecovery.groups, label=0.03).\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ParseListCommand", "ParseListCommand"); + m->errorOut(e, "ParseListCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ParseListCommand::getRequiredParameters(){ - try { - string Array[] = {"list","group"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ParseListCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ParseListCommand::getRequiredFiles(){ +ParseListCommand::ParseListCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["list"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ParseListCommand", "getRequiredFiles"); + m->errorOut(e, "ParseListCommand", "ParseListCommand"); exit(1); } } @@ -67,9 +68,7 @@ ParseListCommand::ParseListCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"list","group", "label", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -115,12 +114,28 @@ ParseListCommand::ParseListCommand(string option) { //check for required parameters listfile = validParameter.validFile(parameters, "list", true); if (listfile == "not open") { abort = true; } - else if (listfile == "not found") { listfile = ""; } + else if (listfile == "not found") { + listfile = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current list file. You must provide a list file."); m->mothurOutEndLine(); + abort = true; + + } + } groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; } - else { + else if (groupfile == "not found") { + groupfile = m->getListFile(); + if (groupfile != "") { + m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); + groupMap = new GroupMap(groupfile); + + int error = groupMap->readMap(); + if (error == 1) { abort = true; } + }else { m->mothurOut("No valid current group file. You must provide a group file."); m->mothurOutEndLine(); abort = true; } + }else { groupMap = new GroupMap(groupfile); int error = groupMap->readMap(); @@ -147,25 +162,6 @@ ParseListCommand::ParseListCommand(string option) { } } //********************************************************************************************************************** -void ParseListCommand::help(){ - try { - m->mothurOut("The parse.list command reads a list and group file and generates a list file for each group in the groupfile. \n"); - m->mothurOut("The parse.list command parameters are list, group and label.\n"); - m->mothurOut("The list and group parameters are required.\n"); - m->mothurOut("The label parameter is used to read specific labels in your input you want to use.\n"); - m->mothurOut("The parse.list command should be used in the following format: parse.list(list=yourListFile, group=yourGroupFile, label=yourLabels).\n"); - m->mothurOut("Example: parse.list(list=abrecovery.fn.list, group=abrecovery.groups, label=0.03).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "ParseListCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** -ParseListCommand::~ParseListCommand(){} -//********************************************************************************************************************** int ParseListCommand::execute(){ try { diff --git a/parselistscommand.h b/parselistscommand.h index 5ecc7ab..065c499 100644 --- a/parselistscommand.h +++ b/parselistscommand.h @@ -21,13 +21,15 @@ class ParseListCommand : public Command { public: ParseListCommand(string); ParseListCommand(); - ~ParseListCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ParseListCommand() {} + + vector setParameters(); + string getCommandName() { return "parse.list"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: int parse(ListVector*); @@ -41,7 +43,6 @@ private: set labels; bool abort, allLines; vector outputNames; - map > outputTypes; map filehandles; map::iterator it3; diff --git a/parsimony.cpp b/parsimony.cpp index 11abb94..54a3ffd 100644 --- a/parsimony.cpp +++ b/parsimony.cpp @@ -13,12 +13,11 @@ EstOutput Parsimony::getValues(Tree* t, int p, string o) { try { - globaldata = GlobalData::getInstance(); processors = p; outputDir = o; //if the users enters no groups then give them the score of all groups - int numGroups = globaldata->Groups.size(); + int numGroups = m->Groups.size(); //calculate number of comparsions int numComp = 0; @@ -26,7 +25,7 @@ EstOutput Parsimony::getValues(Tree* t, int p, string o) { for (int r=0; r groups; groups.push_back(globaldata->Groups[r]); groups.push_back(globaldata->Groups[l]); + vector groups; groups.push_back(m->Groups[r]); groups.push_back(m->Groups[l]); //cout << globaldata->Groups[r] << '\t' << globaldata->Groups[l] << endl; namesOfGroupCombos.push_back(groups); } @@ -45,8 +44,8 @@ EstOutput Parsimony::getValues(Tree* t, int p, string o) { } namesOfGroupCombos.push_back(groups); }else { - for (int i = 0; i < globaldata->Groups.size(); i++) { - groups.push_back(globaldata->Groups[i]); + for (int i = 0; i < m->Groups.size(); i++) { + groups.push_back(m->Groups[i]); //cout << globaldata->Groups[i] << endl; } namesOfGroupCombos.push_back(groups); @@ -173,7 +172,7 @@ EstOutput Parsimony::driver(Tree* t, vector< vector > namesOfGroupCombos EstOutput results; results.resize(num); - Tree* copyTree = new Tree(); + Tree* copyTree = new Tree(tmap); int count = 0; for (int h = start; h < (start+num); h++) { diff --git a/parsimony.h b/parsimony.h index fc905f2..b116aa2 100644 --- a/parsimony.h +++ b/parsimony.h @@ -13,7 +13,6 @@ #include "treecalculator.h" #include "treemap.h" -#include "globaldata.hpp" /***********************************************************************/ @@ -33,7 +32,6 @@ class Parsimony : public TreeCalculator { }; vector lines; - GlobalData* globaldata; EstOutput data; TreeMap* tmap; int processors; diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index c0de504..a8c2d15 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -10,56 +10,65 @@ #include "parsimonycommand.h" //********************************************************************************************************************** -vector ParsimonyCommand::getValidParameters(){ +vector ParsimonyCommand::setParameters(){ try { - string Array[] = {"random","groups","iters","processors","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter prandom("random", "String", "", "", "", "", "",false,false); parameters.push_back(prandom); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ParsimonyCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -ParsimonyCommand::ParsimonyCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["parsimony"] = tempOutNames; - outputTypes["psummary"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "ParsimonyCommand", "ParsimonyCommand"); + m->errorOut(e, "ParsimonyCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector ParsimonyCommand::getRequiredParameters(){ +string ParsimonyCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The parsimony command parameters are tree, group, name, random, groups, processors and iters. tree parameter is required unless you have valid current tree file or are using random.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 1 valid group.\n"; + helpString += "The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n"; + helpString += "The parsimony command should be in the following format: parsimony(random=yourOutputFilename, groups=yourGroups, iters=yourIters).\n"; + helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n"; + helpString += "Example parsimony(random=out, iters=500).\n"; + helpString += "The default value for random is "" (meaning you want to use the trees in your inputfile, randomtree=out means you just want the random distribution of trees outputted to out.rd_parsimony),\n"; + helpString += "and iters is 1000. The parsimony command output two files: .parsimony and .psummary their descriptions are in the manual.\n"; + helpString += "Note: No spaces between parameter labels (i.e. random), '=' and parameters (i.e.yourOutputFilename).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ParsimonyCommand", "getRequiredParameters"); + m->errorOut(e, "ParsimonyCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector ParsimonyCommand::getRequiredFiles(){ +ParsimonyCommand::ParsimonyCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["parsimony"] = tempOutNames; + outputTypes["psummary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ParsimonyCommand", "getRequiredFiles"); + m->errorOut(e, "ParsimonyCommand", "ParsimonyCommand"); exit(1); } } /***********************************************************/ ParsimonyCommand::ParsimonyCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; Groups.clear(); @@ -67,17 +76,16 @@ ParsimonyCommand::ParsimonyCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"random","groups","processors","iters","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } @@ -86,69 +94,81 @@ ParsimonyCommand::ParsimonyCommand(string option) { outputTypes["parsimony"] = tempOutNames; outputTypes["psummary"] = 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 = ""; } + 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; } + } + } + + m->runParse = true; + + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } + randomtree = validParameter.validFile(parameters, "random", false); if (randomtree == "not found") { randomtree = ""; } //are you trying to use parsimony without reading a tree or saying you want random distribution if (randomtree == "") { - if (globaldata->gTree.size() == 0) { - m->mothurOut("You must read a treefile and a groupfile or set the randomtree parameter to the output filename you wish, before you may execute the parsimony command."); m->mothurOutEndLine(); abort = true; } + //check for required parameters + treefile = validParameter.validFile(parameters, "tree", true); + if (treefile == "not open") { abort = true; } + else if (treefile == "not found") { //if there is a current design file, use it + treefile = m->getTreeFile(); + if (treefile != "") { m->mothurOut("Using " + treefile + " as input file for the tree parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current tree file and the tree parameter is required."); m->mothurOutEndLine(); abort = true; } + } + + //check for required parameters + groupfile = validParameter.validFile(parameters, "group", true); + if (groupfile == "not open") { abort = true; } + else if (groupfile == "not found") { groupfile = ""; } + + namefile = validParameter.validFile(parameters, "name", true); + if (namefile == "not open") { abort = true; } + else if (namefile == "not found") { namefile = ""; } } //if the user changes the output directory command factory will send this info to us in the output parameter - string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; if (randomtree == "") { outputDir += m->hasPath(globaldata->inputFileName); } } + string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; if (randomtree == "") { outputDir += m->hasPath(treefile); } } //check for optional parameter and set defaults // ...at some point should added some additional type checking... groups = validParameter.validFile(parameters, "groups", false); - if (groups == "not found") { groups = ""; globaldata->Groups.clear(); } + if (groups == "not found") { groups = ""; m->Groups.clear(); } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } itersString = validParameter.validFile(parameters, "iters", false); if (itersString == "not found") { itersString = "1000"; } convert(itersString, iters); - string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } - convert(temp, processors); - - if (abort == false) { - //randomtree will tell us if user had their own treefile or if they just want the random distribution - //user has entered their own tree - if (randomtree == "") { - T = globaldata->gTree; - tmap = globaldata->gTreemap; - - if(outputDir == "") { outputDir += m->hasPath(globaldata->getTreeFile()); } - output = new ColumnFile(outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".parsimony", itersString); - outputNames.push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".parsimony"); - outputTypes["parsimony"].push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".parsimony"); - - sumFile = outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".psummary"; - m->openOutputFile(sumFile, outSum); - outputNames.push_back(sumFile); - outputTypes["psummary"].push_back(sumFile); - }else { //user wants random distribution - savetmap = globaldata->gTreemap; - getUserInput(); - - if(outputDir == "") { outputDir += m->hasPath(randomtree); } - output = new ColumnFile(outputDir+ m->getSimpleName(randomtree), itersString); - outputNames.push_back(outputDir+ m->getSimpleName(randomtree)); - outputTypes["parsimony"].push_back(outputDir+ m->getSimpleName(randomtree)); - } - - //set users groups to analyze - util = new SharedUtil(); - util->setGroups(globaldata->Groups, tmap->namesOfGroups, allGroups, numGroups, "parsimony"); //sets the groups the user wants to analyze - util->getCombos(groupComb, globaldata->Groups, numComp); - - if (numGroups == 1) { numComp++; groupComb.push_back(allGroups); } - - pars = new Parsimony(tmap); - counter = 0; - - } + string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); } @@ -158,43 +178,116 @@ ParsimonyCommand::ParsimonyCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void ParsimonyCommand::help(){ - try { - m->mothurOut("The parsimony command can only be executed after a successful read.tree command, unless you use the random parameter.\n"); - m->mothurOut("The parsimony command parameters are random, groups, processors and iters. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 1 valid group.\n"); - m->mothurOut("The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n"); - m->mothurOut("The parsimony command should be in the following format: parsimony(random=yourOutputFilename, groups=yourGroups, iters=yourIters).\n"); - m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); - m->mothurOut("Example parsimony(random=out, iters=500).\n"); - m->mothurOut("The default value for random is "" (meaning you want to use the trees in your inputfile, randomtree=out means you just want the random distribution of trees outputted to out.rd_parsimony),\n"); - m->mothurOut("and iters is 1000. The parsimony command output two files: .parsimony and .psummary their descriptions are in the manual.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. random), '=' and parameters (i.e.yourOutputFilename).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ParsimonyCommand", "help"); - exit(1); - } -} - - /***********************************************************/ int ParsimonyCommand::execute() { try { if (abort == true) { if (calledHelp) { return 0; } return 2; } + + + //randomtree will tell us if user had their own treefile or if they just want the random distribution + //user has entered their own tree + if (randomtree == "") { + if (groupfile != "") { + //read in group map info. + tmap = new TreeMap(groupfile); + tmap->readMap(); + }else{ //fake out by putting everyone in one group + Tree* tree = new Tree(treefile); delete tree; //extracts names from tree to make faked out groupmap + tmap = new TreeMap(); + + for (int i = 0; i < m->Treenames.size(); i++) { tmap->addSeq(m->Treenames[i], "Group1"); } + } + + if (namefile != "") { readNamesFile(); } + + read = new ReadNewickTree(treefile); + int readOk = read->read(tmap); + + if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); delete tmap; delete read; return 0; } + + read->AssembleTrees(); + T = read->getTrees(); + delete read; + + //make sure all files match + //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 == m->Treenames.size()) { numNamesInTree = nameMap.size(); } + else { numNamesInTree = m->Treenames.size(); } + }else { numNamesInTree = m->Treenames.size(); } + + + //output any names that are in group file but not in tree + if (numNamesInTree < tmap->getNumSeqs()) { + for (int i = 0; i < tmap->namesOfSeqs.size(); i++) { + //is that name in the tree? + int count = 0; + for (int j = 0; j < m->Treenames.size(); j++) { + if (tmap->namesOfSeqs[i] == m->Treenames[j]) { break; } //found it + count++; + } + + if (m->control_pressed) { + delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + m->Groups.clear(); + return 0; + } + + //then you did not find it so report it + if (count == m->Treenames.size()) { + //if it is in your namefile then don't remove + map::iterator it = nameMap.find(tmap->namesOfSeqs[i]); + + if (it == nameMap.end()) { + m->mothurOut(tmap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine(); + tmap->removeSeq(tmap->namesOfSeqs[i]); + i--; //need this because removeSeq removes name from namesOfSeqs + } + } + } + } + + 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"); + + sumFile = outputDir + m->getSimpleName(treefile) + ".psummary"; + m->openOutputFile(sumFile, outSum); + outputNames.push_back(sumFile); + outputTypes["psummary"].push_back(sumFile); + }else { //user wants random distribution + getUserInput(); + + if(outputDir == "") { outputDir += m->hasPath(randomtree); } + output = new ColumnFile(outputDir+ m->getSimpleName(randomtree), itersString); + outputNames.push_back(outputDir+ m->getSimpleName(randomtree)); + outputTypes["parsimony"].push_back(outputDir+ m->getSimpleName(randomtree)); + } + + //set users groups to analyze + util = new SharedUtil(); + util->setGroups(m->Groups, tmap->namesOfGroups, allGroups, numGroups, "parsimony"); //sets the groups the user wants to analyze + util->getCombos(groupComb, m->Groups, numComp); + delete util; + + if (numGroups == 1) { numComp++; groupComb.push_back(allGroups); } + + pars = new Parsimony(tmap); + counter = 0; Progress* reading; reading = new Progress("Comparing to random:", iters); if (m->control_pressed) { - delete reading; delete pars; delete util; delete output; + delete reading; delete pars; delete output; + delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (randomtree == "") { outSum.close(); } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - globaldata->Groups.clear(); + m->Groups.clear(); return 0; } @@ -215,10 +308,11 @@ int ParsimonyCommand::execute() { userData = pars->getValues(T[i], processors, outputDir); //data = AB, AC, BC, ABC. if (m->control_pressed) { - delete reading; delete pars; delete util; delete output; + delete reading; delete pars; delete output; + delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (randomtree == "") { outSum.close(); } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - globaldata->Groups.clear(); + m->Groups.clear(); return 0; } @@ -244,7 +338,7 @@ int ParsimonyCommand::execute() { for (int j = 0; j < iters; j++) { //create new tree with same num nodes and leaves as users - randT = new Tree(); + randT = new Tree(tmap); //create random relationships between nodes randT->assembleRandomTree(); @@ -253,10 +347,11 @@ int ParsimonyCommand::execute() { randomData = pars->getValues(randT, processors, outputDir); if (m->control_pressed) { - delete reading; delete pars; delete util; delete output; delete randT; + delete reading; delete pars; delete output; delete randT; if (randomtree == "") { outSum.close(); } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - globaldata->Groups.clear(); + delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + m->Groups.clear(); return 0; } @@ -284,16 +379,16 @@ int ParsimonyCommand::execute() { for (int j = 0; j < iters; j++) { //create new tree with same num nodes and leaves as users - randT = new Tree(); + randT = new Tree(tmap); //create random relationships between nodes randT->assembleRandomTree(); if (m->control_pressed) { - delete reading; delete pars; delete util; delete output; delete randT; - globaldata->gTreemap = savetmap; + delete reading; delete pars; delete output; delete randT; + delete tmap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - globaldata->Groups.clear(); + m->Groups.clear(); return 0; } @@ -302,10 +397,10 @@ int ParsimonyCommand::execute() { randomData = pars->getValues(randT, processors, outputDir); if (m->control_pressed) { - delete reading; delete pars; delete util; delete output; delete randT; - globaldata->gTreemap = savetmap; + delete reading; delete pars; delete output; delete randT; + delete tmap; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - globaldata->Groups.clear(); + m->Groups.clear(); return 0; } @@ -358,11 +453,11 @@ int ParsimonyCommand::execute() { } if (m->control_pressed) { - delete reading; delete pars; delete util; delete output; + delete reading; delete pars; delete output; + delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (randomtree == "") { outSum.close(); } - else { globaldata->gTreemap = savetmap; } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - globaldata->Groups.clear(); + m->Groups.clear(); return 0; } @@ -374,21 +469,13 @@ int ParsimonyCommand::execute() { printParsimonyFile(); if (randomtree == "") { printUSummaryFile(); } - //reset globaldata's treemap if you just did random distrib - if (randomtree != "") { - //memory leak prevention - //if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } - globaldata->gTreemap = savetmap; - } - //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); - if (m->control_pressed) { - delete pars; delete util; delete output; - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); - return 0; - } + delete pars; delete output; + delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0;} m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -509,11 +596,7 @@ void ParsimonyCommand::getUserInput() { string s; getline(cin, s); - //save tmap for later - //memory leak prevention - //if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } - globaldata->gTreemap = tmap; - globaldata->Treenames = tmap->namesOfSeqs; + m->Treenames = tmap->namesOfSeqs; } catch(exception& e) { @@ -521,7 +604,46 @@ void ParsimonyCommand::getUserInput() { exit(1); } } - +/*****************************************************************/ +int ParsimonyCommand::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 == m->names.end()) { + m->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)) { tmap->addSeq(dupNames[i], "Group1"); } + } + }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); m->names.clear(); namefile = ""; return 1; } + } + in.close(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "ParsimonyCommand", "readNamesFile"); + exit(1); + } +} /***********************************************************/ diff --git a/parsimonycommand.h b/parsimonycommand.h index 9e756b8..274cac4 100644 --- a/parsimonycommand.h +++ b/parsimonycommand.h @@ -15,25 +15,26 @@ #include "progress.hpp" #include "sharedutilities.h" #include "fileoutput.h" +#include "readtree.h" -class GlobalData; - class ParsimonyCommand : public Command { public: ParsimonyCommand(string); ParsimonyCommand(); - ~ParsimonyCommand() { if (abort == false) { delete pars; delete util; delete output; } } - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + ~ParsimonyCommand(){} + + vector setParameters(); + string getCommandName() { return "parsimony"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; + ReadTree* read; SharedUtil* util; FileOutput* output; vector T; //user trees @@ -43,8 +44,8 @@ private: TreeMap* savetmap; Parsimony* pars; vector groupComb; // AB. AC, BC... - string sumFile, randomtree, allGroups, outputDir; - int iters, numGroups, numComp, counter, processors; + string sumFile, randomtree, allGroups, outputDir, treefile, groupfile, namefile; + int iters, numGroups, numComp, counter, processors, numUniquesInName; vector numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib. vector< vector > userTreeScores; //scores for users trees for each comb. vector< vector > UScoreSig; //tree score signifigance when compared to random trees - percentage of random trees with that score or lower. @@ -57,16 +58,15 @@ private: vector< map > uCumul; //map -vector entry for each combination. ofstream outSum; - - bool abort; string groups, itersString; vector Groups, outputNames; //holds groups to be used - map > outputTypes; - + map nameMap; + void printParsimonyFile(); int printUSummaryFile(); void getUserInput(); + int readNamesFile(); }; diff --git a/pcacommand.cpp b/pcacommand.cpp index 23c066b..a91143b 100644 --- a/pcacommand.cpp +++ b/pcacommand.cpp @@ -11,50 +11,54 @@ #include "inputdata.h" //********************************************************************************************************************** -vector PCACommand::getValidParameters(){ +vector PCACommand::setParameters(){ try { - string Array[] = {"label", "groups","metric","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); + CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prelabund); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pmetric("metric", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pmetric); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "PCACommand", "getValidParameters"); + m->errorOut(e, "PCACommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -PCACommand::PCACommand(){ +string PCACommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["pca"] = tempOutNames; - outputTypes["loadings"] = tempOutNames; + string helpString = ""; + helpString += "The pca command parameters are shared, relabund, label, groups and metric. shared or relabund is required unless you have a valid current file."; + helpString += "The label parameter is used to analyze specific labels in your input. Default is the first label in your shared or relabund file. Multiple labels may be separated by dashes.\n"; + helpString += "The groups parameter allows you to specify which groups you would like analyzed. Groupnames are separated by dashes.\n"; + helpString += "The metric parameter allows indicate you if would like the pearson correlation coefficient calculated. Default=True"; + helpString += "Example pca(groups=yourGroups).\n"; + helpString += "Example pca(groups=A-B-C).\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "PCACommand", "PCACommand"); + m->errorOut(e, "PCACommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector PCACommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "PCACommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector PCACommand::getRequiredFiles(){ +PCACommand::PCACommand(){ try { - string Array[] = {"shared","relabund","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["pca"] = tempOutNames; + outputTypes["loadings"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "PCACommand", "getRequiredFiles"); + m->errorOut(e, "PCACommand", "PCACommand"); exit(1); } } @@ -64,15 +68,11 @@ PCACommand::PCACommand(string option) { try { abort = false; calledHelp = false; - globaldata = GlobalData::getInstance(); - //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"label","groups","metric","outputdir", "inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser. getParameters(); @@ -84,22 +84,62 @@ PCACommand::PCACommand(string option) { 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 = ""; } - + //initialize outputTypes vector tempOutNames; outputTypes["pca"] = tempOutNames; outputTypes["loadings"] = tempOutNames; - //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "") && (globaldata->getRelAbundFile() == "")) { - m->mothurOut("You must read a list and a group, shared or relabund file before you can use the pca command."); m->mothurOutEndLine(); 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("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("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 (globaldata->getSharedFile() != "") { mode = "shared"; inputFile = globaldata->getSharedFile(); } - if (globaldata->getRelAbundFile() != "") { mode = "relabund"; inputFile = globaldata->getRelAbundFile(); } + //check for required parameters + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { mode = "sharedfile"; inputFile = sharedfile; } + + relabundfile = validParameter.validFile(parameters, "relabund", true); + if (relabundfile == "not open") { relabundfile = ""; abort = true; } + else if (relabundfile == "not found") { relabundfile = ""; } + else { mode = "relabund"; inputFile = relabundfile; } + + if ((sharedfile == "") && (relabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputFile = sharedfile; mode = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + relabundfile = m->getRelAbundFile(); + if (relabundfile != "") { inputFile = relabundfile; mode = "relabund"; m->mothurOut("Using " + relabundfile + " as input file for the relabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a relabund or shared file."); 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 = ""; @@ -110,13 +150,13 @@ PCACommand::PCACommand(string option) { metric = m->isTrue(temp); label = validParameter.validFile(parameters, "label", false); - if (label == "not found") { label = ""; labels = globaldata->labels; if(labels.size() == 0) { m->mothurOut("You did not provide a label, I will use the first label in your inputfile."); m->mothurOutEndLine(); } } + if (label == "not found") { label = ""; if(labels.size() == 0) { m->mothurOut("You did not provide a label, I will use the first label in your inputfile."); m->mothurOutEndLine(); } } else { m->splitAtDash(label, labels); } groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); } - globaldata->Groups = Groups; + m->Groups = Groups; } @@ -127,25 +167,6 @@ PCACommand::PCACommand(string option) { } } //********************************************************************************************************************** -void PCACommand::help(){ - try { - m->mothurOut("The pca command can only be run after a successful read.otu command of a shared or relabund file."); m->mothurOutEndLine(); - m->mothurOut("The pca command parameters are label, groups and metric. No parameters are required."); m->mothurOutEndLine(); - m->mothurOut("The label parameter is used to analyze specific labels in your input. Default is the first label in your shared or relabund file. Multiple labels may be separated by dashes.\n"); - m->mothurOut("The groups parameter allows you to specify which groups you would like analyzed. Groupnames are separated by dashes.\n"); - m->mothurOut("The metric parameter allows indicate you if would like the pearson correlation coefficient calculated. Default=True"); m->mothurOutEndLine(); - m->mothurOut("Example pca(groups=yourGroups).\n"); - m->mothurOut("Example pca(groups=A-B-C).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "PCACommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** -PCACommand::~PCACommand(){} -//********************************************************************************************************************** int PCACommand::execute(){ try { @@ -344,7 +365,7 @@ int PCACommand::process(vector& lookupFloat){ string fbase = outputDir + m->getRootName(m->getSimpleName(inputFile)); string outputFileName = fbase + lookupFloat[0]->getLabel(); - output(outputFileName, globaldata->Groups, G, d); + output(outputFileName, m->Groups, G, d); if (metric) { diff --git a/pcacommand.h b/pcacommand.h index eedfcf3..379cf6e 100644 --- a/pcacommand.h +++ b/pcacommand.h @@ -12,8 +12,7 @@ #include "command.hpp" #include "linearalgebra.h" -#include "globaldata.hpp" - +#include "sharedrabundfloatvector.h" /*****************************************************************/ class PCACommand : public Command { @@ -21,22 +20,23 @@ class PCACommand : public Command { public: PCACommand(string); PCACommand(); - ~PCACommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~PCACommand() {} -private: - GlobalData* globaldata; + vector setParameters(); + string getCommandName() { return "pca"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + +private: + bool abort, metric; - string outputDir, mode, inputFile, label, groups; + string outputDir, mode, inputFile, label, groups, sharedfile, relabundfile; vector outputNames, Groups; set labels; - map > outputTypes; LinearAlgebra linearCalc; //vector< vector > createMatrix(vector); diff --git a/pcoacommand.cpp b/pcoacommand.cpp index 3cd844a..6ebf653 100644 --- a/pcoacommand.cpp +++ b/pcoacommand.cpp @@ -11,51 +11,53 @@ #include "pcoacommand.h" #include "readphylipvector.h" + //********************************************************************************************************************** -vector PCOACommand::getValidParameters(){ +vector PCOACommand::setParameters(){ try { - string Array[] = {"phylip", "metric","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); + CommandParameter pmetric("metric", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pmetric); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "PCOACommand", "getValidParameters"); + m->errorOut(e, "PCOACommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -PCOACommand::PCOACommand(){ +string PCOACommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["pcoa"] = tempOutNames; - outputTypes["loadings"] = tempOutNames; + string helpString = ""; + helpString += "The pcoa command parameters are phylip and metric"; + helpString += "The phylip parameter allows you to enter your distance file."; + helpString += "The metric parameter allows indicate you if would like the pearson correlation coefficient calculated. Default=True"; + helpString += "Example pcoa(phylip=yourDistanceFile).\n"; + helpString += "Note: No spaces between parameter labels (i.e. phylip), '=' and parameters (i.e.yourDistanceFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "PCOACommand", "PCOACommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector PCOACommand::getRequiredParameters(){ - try { - string Array[] = {"phylip"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "PCOACommand", "getRequiredParameters"); + m->errorOut(e, "PCOACommand", "getHelpString"); exit(1); } } + + //********************************************************************************************************************** -vector PCOACommand::getRequiredFiles(){ +PCOACommand::PCOACommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["pcoa"] = tempOutNames; + outputTypes["loadings"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "PCOACommand", "getRequiredFiles"); + m->errorOut(e, "PCOACommand", "PCOACommand"); exit(1); } } @@ -69,9 +71,7 @@ PCOACommand::PCOACommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"phylip","metric","outputdir", "inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser. getParameters(); @@ -105,8 +105,14 @@ PCOACommand::PCOACommand(string option) { //required parameters phylipfile = validParameter.validFile(parameters, "phylip", true); if (phylipfile == "not open") { abort = true; } - else if (phylipfile == "not found") { phylipfile = ""; abort = true; } - else { filename = phylipfile; } + else if (phylipfile == "not found") { + //if there is a current phylip file, use it + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current phylip file and the phylip parameter is required."); m->mothurOutEndLine(); abort = true; } + } + + filename = phylipfile; //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"){ @@ -114,9 +120,6 @@ PCOACommand::PCOACommand(string option) { outputDir += m->hasPath(phylipfile); //if user entered a file with a path then preserve it } - //error checking on files - if (phylipfile == "") { m->mothurOut("You must provide a distance file before running the pcoa command."); m->mothurOutEndLine(); abort = true; } - string temp = validParameter.validFile(parameters, "metric", false); if (temp == "not found"){ temp = "T"; } metric = m->isTrue(temp); } @@ -128,23 +131,6 @@ PCOACommand::PCOACommand(string option) { } } //********************************************************************************************************************** -void PCOACommand::help(){ - try { - - m->mothurOut("The pcoa command parameters are phylip and metric"); m->mothurOutEndLine(); - m->mothurOut("The phylip parameter allows you to enter your distance file."); m->mothurOutEndLine(); - m->mothurOut("The metric parameter allows indicate you if would like the pearson correlation coefficient calculated. Default=True"); m->mothurOutEndLine(); - m->mothurOut("Example pcoa(phylip=yourDistanceFile).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. phylip), '=' and parameters (i.e.yourDistanceFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "PCOACommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** -PCOACommand::~PCOACommand(){} -//********************************************************************************************************************** int PCOACommand::execute(){ try { diff --git a/pcoacommand.h b/pcoacommand.h index d923006..ea4d2b3 100644 --- a/pcoacommand.h +++ b/pcoacommand.h @@ -20,20 +20,21 @@ class PCOACommand : public Command { public: PCOACommand(string); PCOACommand(); - ~PCOACommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~PCOACommand(){} + + vector setParameters(); + string getCommandName() { return "pcoa"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: bool abort, metric; string phylipfile, filename, fbase, outputDir; vector outputNames; - map > outputTypes; LinearAlgebra linearCalc; void get_comment(istream&, char, char); diff --git a/phylodiversity.h b/phylodiversity.h index 5e02595..a789efa 100644 --- a/phylodiversity.h +++ b/phylodiversity.h @@ -12,7 +12,6 @@ */ #include "treemap.h" -#include "globaldata.hpp" #include "mothurout.h" @@ -21,14 +20,13 @@ class PhyloDiversity { public: - PhyloDiversity(TreeMap* t) : tmap(t) { globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); } + PhyloDiversity(TreeMap* t) : tmap(t) { m = MothurOut::getInstance(); } ~PhyloDiversity() {}; //int getValues(Tree*, vector, vector< vector< float> >&); private: - GlobalData* globaldata; MothurOut* m; TreeMap* tmap; }; diff --git a/phylodiversitycommand.cpp b/phylodiversitycommand.cpp index a987594..0822582 100644 --- a/phylodiversitycommand.cpp +++ b/phylodiversitycommand.cpp @@ -10,70 +10,87 @@ #include "phylodiversitycommand.h" //********************************************************************************************************************** -vector PhyloDiversityCommand::getValidParameters(){ +vector PhyloDiversityCommand::setParameters(){ try { - string Array[] = {"freq","rarefy","iters","groups","processors","summary","collect","scale","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter prarefy("rarefy", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(prarefy); + CommandParameter psummary("summary", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(psummary); + CommandParameter pcollect("collect", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pcollect); + CommandParameter pscale("scale", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pscale); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "PhyloDiversityCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -PhyloDiversityCommand::PhyloDiversityCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["phylodiv"] = tempOutNames; - outputTypes["rarefy"] = tempOutNames; - outputTypes["summary"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "PhyloDiversityCommand", "PhyloDiversityCommand"); + m->errorOut(e, "PhyloDiversityCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector PhyloDiversityCommand::getRequiredParameters(){ +string PhyloDiversityCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The phylo.diversity command parameters are tree, group, name, groups, iters, freq, processors, scale, rarefy, collect and summary. tree and group are required, unless you have valid current files.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. The group names are separated by dashes. By default all groups are used.\n"; + helpString += "The iters parameter allows you to specify the number of randomizations to preform, by default iters=1000, if you set rarefy to true.\n"; + helpString += "The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"; + helpString += "The scale parameter is used indicate that you want your output scaled to the number of sequences sampled, default = false. \n"; + helpString += "The rarefy parameter allows you to create a rarefaction curve. The default is false.\n"; + helpString += "The collect parameter allows you to create a collectors curve. The default is false.\n"; + helpString += "The summary parameter allows you to create a .summary file. The default is true.\n"; + helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n"; + helpString += "The phylo.diversity command should be in the following format: phylo.diversity(groups=yourGroups, rarefy=yourRarefy, iters=yourIters).\n"; + helpString += "Example phylo.diversity(groups=A-B-C, rarefy=T, iters=500).\n"; + helpString += "The phylo.diversity command output two files: .phylo.diversity and if rarefy=T, .rarefaction.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "PhyloDiversityCommand", "getRequiredParameters"); + m->errorOut(e, "PhyloDiversityCommand", "getHelpString"); exit(1); } } + + //********************************************************************************************************************** -vector PhyloDiversityCommand::getRequiredFiles(){ +PhyloDiversityCommand::PhyloDiversityCommand(){ try { - string Array[] = {"tree","group"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["phylodiv"] = tempOutNames; + outputTypes["rarefy"] = tempOutNames; + outputTypes["summary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "PhyloDiversityCommand", "getRequiredFiles"); + m->errorOut(e, "PhyloDiversityCommand", "PhyloDiversityCommand"); exit(1); } } //********************************************************************************************************************** PhyloDiversityCommand::PhyloDiversityCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"freq","rarefy","iters","groups","processors","summary","collect","scale","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters();; OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; @@ -88,12 +105,64 @@ PhyloDiversityCommand::PhyloDiversityCommand(string option) { outputTypes["rarefy"] = tempOutNames; outputTypes["summary"] = 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 = m->hasPath(globaldata->getTreeFile()); } + //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; } + } + } + + m->runParse = true; + + //check for required parameters + treefile = validParameter.validFile(parameters, "tree", true); + if (treefile == "not open") { abort = true; } + else if (treefile == "not found") { + //if there is a current design file, use it + treefile = m->getTreeFile(); + if (treefile != "") { m->mothurOut("Using " + treefile + " as input file for the tree parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current tree file and the tree parameter is required."); m->mothurOutEndLine(); abort = true; } + } + + //check for required parameters + groupfile = validParameter.validFile(parameters, "group", true); + if (groupfile == "not open") { abort = true; } + else if (groupfile == "not found") { + //if there is a current design file, use it + groupfile = m->getGroupFile(); + if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current group file and the group parameter is required."); m->mothurOutEndLine(); abort = true; } + } + + namefile = validParameter.validFile(parameters, "name", true); + if (namefile == "not open") { abort = true; } + else if (namefile == "not found") { namefile = ""; } + + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(treefile); } - if (globaldata->gTree.size() == 0) {//no trees were read - m->mothurOut("You must execute the read.tree command, before you may execute the phylo.diversity command."); m->mothurOutEndLine(); abort = true; } - string temp; temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; } convert(temp, freq); @@ -114,14 +183,15 @@ PhyloDiversityCommand::PhyloDiversityCommand(string option) { temp = validParameter.validFile(parameters, "collect", false); if (temp == "not found") { temp = "F"; } collect = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); groups = validParameter.validFile(parameters, "groups", false); - if (groups == "not found") { groups = ""; Groups = globaldata->gTreemap->namesOfGroups; globaldata->Groups = Groups; } + if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } if ((!collect) && (!rarefy) && (!summary)) { m->mothurOut("No outputs selected. You must set either collect, rarefy or summary to true, summary=T by default."); m->mothurOutEndLine(); abort=true; } @@ -135,57 +205,84 @@ PhyloDiversityCommand::PhyloDiversityCommand(string option) { } //********************************************************************************************************************** -void PhyloDiversityCommand::help(){ - try { - m->mothurOut("The phylo.diversity command can only be executed after a successful read.tree command.\n"); - m->mothurOut("The phylo.diversity command parameters are groups, iters, freq, processors, scale, rarefy, collect and summary. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. The group names are separated by dashes. By default all groups are used.\n"); - m->mothurOut("The iters parameter allows you to specify the number of randomizations to preform, by default iters=1000, if you set rarefy to true.\n"); - m->mothurOut("The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"); - m->mothurOut("The scale parameter is used indicate that you want your ouptut scaled to the number of sequences sampled, default = false. \n"); - m->mothurOut("The rarefy parameter allows you to create a rarefaction curve. The default is false.\n"); - m->mothurOut("The collect parameter allows you to create a collectors curve. The default is false.\n"); - m->mothurOut("The summary parameter allows you to create a .summary file. The default is true.\n"); - m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); - m->mothurOut("The phylo.diversity command should be in the following format: phylo.diversity(groups=yourGroups, rarefy=yourRarefy, iters=yourIters).\n"); - m->mothurOut("Example phylo.diversity(groups=A-B-C, rarefy=T, iters=500).\n"); - m->mothurOut("The phylo.diversity command output two files: .phylo.diversity and if rarefy=T, .rarefaction.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "PhyloDiversityCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -PhyloDiversityCommand::~PhyloDiversityCommand(){} - -//********************************************************************************************************************** - int PhyloDiversityCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } + //read in group map info. + tmap = new TreeMap(groupfile); + tmap->readMap(); + + if (namefile != "") { readNamesFile(); } + + read = new ReadNewickTree(treefile); + int readOk = read->read(tmap); + + if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); delete tmap; delete read; return 0; } + + read->AssembleTrees(); + vector trees = read->getTrees(); + delete read; + + //make sure all files match + //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 == m->Treenames.size()) { numNamesInTree = nameMap.size(); } + else { numNamesInTree = m->Treenames.size(); } + }else { numNamesInTree = m->Treenames.size(); } + + + //output any names that are in group file but not in tree + if (numNamesInTree < tmap->getNumSeqs()) { + for (int i = 0; i < tmap->namesOfSeqs.size(); i++) { + //is that name in the tree? + int count = 0; + for (int j = 0; j < m->Treenames.size(); j++) { + if (tmap->namesOfSeqs[i] == m->Treenames[j]) { break; } //found it + count++; + } + + if (m->control_pressed) { + delete tmap; for (int i = 0; i < trees.size(); i++) { delete trees[i]; } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + m->Groups.clear(); + return 0; + } + + //then you did not find it so report it + if (count == m->Treenames.size()) { + //if it is in your namefile then don't remove + map::iterator it = nameMap.find(tmap->namesOfSeqs[i]); + + if (it == nameMap.end()) { + m->mothurOut(tmap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine(); + tmap->removeSeq(tmap->namesOfSeqs[i]); + i--; //need this because removeSeq removes name from namesOfSeqs + } + } + } + } + + SharedUtil* util = new SharedUtil(); + util->setGroups(m->Groups, tmap->namesOfGroups, "treegroup"); //sets the groups the user wants to analyze + delete util; + //incase the user had some mismatches between the tree and group files we don't want group xxx to be analyzed - for (int i = 0; i < globaldata->Groups.size(); i++) { if (globaldata->Groups[i] == "xxx") { globaldata->Groups.erase(globaldata->Groups.begin()+i); break; } } + for (int i = 0; i < m->Groups.size(); i++) { if (m->Groups[i] == "xxx") { m->Groups.erase(m->Groups.begin()+i); break; } } vector outputNames; - - vector trees = globaldata->gTree; //for each of the users trees for(int i = 0; i < trees.size(); i++) { - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + 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++) { remove(outputNames[j].c_str()); } return 0; } ofstream outSum, outRare, outCollect; - string outSumFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv.summary"; - string outRareFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv.rarefaction"; - string outCollectFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getTreeFile())) + toString(i+1) + ".phylodiv"; + 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"; 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); } @@ -196,7 +293,7 @@ int PhyloDiversityCommand::execute(){ //create a vector containing indexes of leaf nodes, randomize it, select nodes to send to calculator vector randomLeaf; for (int j = 0; j < numLeafNodes; j++) { - if (m->inUsersGroups(trees[i]->tree[j].getGroup(), globaldata->Groups) == true) { //is this a node from the group the user selected. + if (m->inUsersGroups(trees[i]->tree[j].getGroup(), m->Groups) == true) { //is this a node from the group the user selected. randomLeaf.push_back(j); } } @@ -211,15 +308,15 @@ int PhyloDiversityCommand::execute(){ //find largest group total int largestGroup = 0; - for (int j = 0; j < globaldata->Groups.size(); j++) { - if (globaldata->gTreemap->seqsPerGroup[globaldata->Groups[j]] > largestGroup) { largestGroup = globaldata->gTreemap->seqsPerGroup[globaldata->Groups[j]]; } + for (int j = 0; j < m->Groups.size(); j++) { + if (tmap->seqsPerGroup[m->Groups[j]] > largestGroup) { largestGroup = tmap->seqsPerGroup[m->Groups[j]]; } //initialize diversity - diversity[globaldata->Groups[j]].resize(globaldata->gTreemap->seqsPerGroup[globaldata->Groups[j]]+1, 0.0); //numSampled + diversity[m->Groups[j]].resize(tmap->seqsPerGroup[m->Groups[j]]+1, 0.0); //numSampled //groupA 0.0 0.0 //initialize sumDiversity - sumDiversity[globaldata->Groups[j]].resize(globaldata->gTreemap->seqsPerGroup[globaldata->Groups[j]]+1, 0.0); + sumDiversity[m->Groups[j]].resize(tmap->seqsPerGroup[m->Groups[j]]+1, 0.0); } //convert freq percentage to number @@ -233,8 +330,8 @@ int PhyloDiversityCommand::execute(){ if(largestGroup % increment != 0){ numSampledList.insert(largestGroup); } //add other groups ending points - for (int j = 0; j < globaldata->Groups.size(); j++) { - if (numSampledList.count(diversity[globaldata->Groups[j]].size()-1) == 0) { numSampledList.insert(diversity[globaldata->Groups[j]].size()-1); } + for (int j = 0; j < m->Groups.size(); j++) { + if (numSampledList.count(diversity[m->Groups[j]].size()-1) == 0) { numSampledList.insert(diversity[m->Groups[j]].size()-1); } } #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) @@ -293,8 +390,6 @@ int PhyloDiversityCommand::createProcesses(vector& procIters, Tree* t, map< vector processIDS; map< string, vector >::iterator itSum; - EstOutput results; - //loop through and create all the processes you want while (process != processors) { int pid = fork(); @@ -385,7 +480,7 @@ int PhyloDiversityCommand::driver(Tree* t, map< string, vector >& div, ma //initialize counts map counts; map< string, set > countedBranch; - for (int j = 0; j < globaldata->Groups.size(); j++) { counts[globaldata->Groups[j]] = 0; countedBranch[globaldata->Groups[j]].insert(-2); } //add dummy index to initialize countedBranch sets + for (int j = 0; j < m->Groups.size(); j++) { counts[m->Groups[j]] = 0; countedBranch[m->Groups[j]].insert(-2); } //add dummy index to initialize countedBranch sets for(int k = 0; k < numLeafNodes; k++){ @@ -416,9 +511,9 @@ int PhyloDiversityCommand::driver(Tree* t, map< string, vector >& div, ma if (rarefy) { //add this diversity to the sum - for (int j = 0; j < globaldata->Groups.size(); j++) { - for (int g = 0; g < div[globaldata->Groups[j]].size(); g++) { - sumDiv[globaldata->Groups[j]][g] += div[globaldata->Groups[j]][g]; + for (int j = 0; j < m->Groups.size(); j++) { + for (int g = 0; g < div[m->Groups[j]].size(); g++) { + sumDiv[m->Groups[j]][g] += div[m->Groups[j]][g]; } } } @@ -445,14 +540,14 @@ void PhyloDiversityCommand::printSumData(map< string, vector >& div, ofst out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); - for (int j = 0; j < globaldata->Groups.size(); j++) { - int numSampled = (div[globaldata->Groups[j]].size()-1); - out << globaldata->Groups[j] << '\t' << numSampled << '\t'; + for (int j = 0; j < m->Groups.size(); j++) { + int numSampled = (div[m->Groups[j]].size()-1); + out << m->Groups[j] << '\t' << numSampled << '\t'; float score; - if (scale) { score = (div[globaldata->Groups[j]][numSampled] / (float)numIters) / (float)numSampled; } - else { score = div[globaldata->Groups[j]][numSampled] / (float)numIters; } + if (scale) { score = (div[m->Groups[j]][numSampled] / (float)numIters) / (float)numSampled; } + else { score = div[m->Groups[j]][numSampled] / (float)numIters; } out << setprecision(4) << score << endl; } @@ -471,7 +566,7 @@ void PhyloDiversityCommand::printData(set& num, map< string, vector try { out << "numSampled\t"; - for (int i = 0; i < globaldata->Groups.size(); i++) { out << globaldata->Groups[i] << '\t'; } + for (int i = 0; i < m->Groups.size(); i++) { out << m->Groups[i] << '\t'; } out << endl; out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); @@ -481,11 +576,11 @@ void PhyloDiversityCommand::printData(set& num, map< string, vector out << numSampled << '\t'; - for (int j = 0; j < globaldata->Groups.size(); j++) { - if (numSampled < div[globaldata->Groups[j]].size()) { + for (int j = 0; j < m->Groups.size(); j++) { + if (numSampled < div[m->Groups[j]].size()) { float score; - if (scale) { score = (div[globaldata->Groups[j]][numSampled] / (float)numIters) / (float)numSampled; } - else { score = div[globaldata->Groups[j]][numSampled] / (float)numIters; } + if (scale) { score = (div[m->Groups[j]][numSampled] / (float)numIters) / (float)numSampled; } + else { score = div[m->Groups[j]][numSampled] / (float)numIters; } out << setprecision(4) << score << '\t'; }else { out << "NA" << '\t'; } @@ -594,6 +689,47 @@ vector PhyloDiversityCommand::calcBranchLength(Tree* t, int leaf, map< st exit(1); } } +/*****************************************************************/ +int PhyloDiversityCommand::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 == m->names.end()) { + m->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)) { tmap->addSeq(dupNames[i], "Group1"); } + } + }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); m->names.clear(); namefile = ""; return 1; } + } + in.close(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "PhyloDiversityCommand", "readNamesFile"); + exit(1); + } +} + //********************************************************************************************************************** diff --git a/phylodiversitycommand.h b/phylodiversitycommand.h index f5e205c..df04b35 100644 --- a/phylodiversitycommand.h +++ b/phylodiversitycommand.h @@ -12,31 +12,35 @@ #include "command.hpp" #include "treemap.h" -#include "globaldata.hpp" +#include "readtree.h" +#include "sharedutilities.h" + class PhyloDiversityCommand : public Command { public: PhyloDiversityCommand(string); PhyloDiversityCommand(); - ~PhyloDiversityCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~PhyloDiversityCommand(){} - private: - GlobalData* globaldata; - + vector setParameters(); + string getCommandName() { return "phylo.diversity"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } +private: + ReadTree* read; + TreeMap* tmap; float freq; - int iters, processors; + int iters, processors, numUniquesInName; bool abort, rarefy, summary, collect, scale; - string groups, outputDir; + string groups, outputDir, treefile, groupfile, namefile; vector Groups, outputNames; //holds groups to be used, and outputFile names - map > outputTypes; + map nameMap; + int readNamesFile(); void printData(set&, map< string, vector >&, ofstream&, int); void printSumData(map< string, vector >&, ofstream&, int); vector calcBranchLength(Tree*, int, map< string, set >&); diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index c3aee47..e7d1296 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -14,51 +14,58 @@ #include "sabundvector.hpp" //********************************************************************************************************************** -vector PhylotypeCommand::getValidParameters(){ +vector PhylotypeCommand::setParameters(){ try { - string Array[] = {"taxonomy","cutoff","label","name","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptaxonomy); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pcutoff("cutoff", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "PhylotypeCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -PhylotypeCommand::PhylotypeCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["list"] = tempOutNames; - outputTypes["sabund"] = tempOutNames; - outputTypes["rabund"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "PhylotypeCommand", "PhylotypeCommand"); + m->errorOut(e, "PhylotypeCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector PhylotypeCommand::getRequiredParameters(){ +string PhylotypeCommand::getHelpString(){ try { - string Array[] = {"taxonomy"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The phylotype command reads a taxonomy file and outputs a .list, .rabund and .sabund file. \n"; + helpString += "The phylotype command parameter options are taxonomy, cutoff and label. The taxonomy parameter is required.\n"; + helpString += "The cutoff parameter allows you to specify the level you want to stop at. The default is the highest level in your taxonomy file. \n"; + helpString += "For example: taxonomy = Bacteria;Bacteroidetes-Chlorobi;Bacteroidetes; - cutoff=2, would truncate the taxonomy to Bacteria;Bacteroidetes-Chlorobi; \n"; + helpString += "For the cutoff parameter levels count up from the root of the phylotree. This enables you to look at the grouping down to a specific resolution, say the genus level.\n"; + helpString += "The label parameter allows you to specify which level you would like, and are separated by dashes. The default all levels in your taxonomy file. \n"; + helpString += "For the label parameter, levels count down from the root to keep the output similiar to mothur's other commands which report information from finer resolution to coarser resolutions.\n"; + helpString += "The phylotype command should be in the following format: \n"; + helpString += "phylotype(taxonomy=yourTaxonomyFile, cutoff=yourCutoff, label=yourLabels) \n"; + helpString += "Eaxample: phylotype(taxonomy=amazon.taxonomy, cutoff=5, label=1-3-5).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "PhylotypeCommand", "getRequiredParameters"); + m->errorOut(e, "PhylotypeCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector PhylotypeCommand::getRequiredFiles(){ +PhylotypeCommand::PhylotypeCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "PhylotypeCommand", "getRequiredFiles"); + m->errorOut(e, "PhylotypeCommand", "PhylotypeCommand"); exit(1); } } @@ -71,10 +78,7 @@ PhylotypeCommand::PhylotypeCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - - //valid paramters for this command - string AlignArray[] = {"taxonomy","cutoff","label","name","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -117,9 +121,12 @@ PhylotypeCommand::PhylotypeCommand(string option) { taxonomyFileName = validParameter.validFile(parameters, "taxonomy", true); if (taxonomyFileName == "not found") { - m->mothurOut("taxonomy is a required parameter for the phylotype command."); - m->mothurOutEndLine(); - abort = true; + taxonomyFileName = m->getTaxonomyFile(); + if (taxonomyFileName != "") { m->mothurOut("Using " + taxonomyFileName + " as input file for the taxonomy parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. taxonomy is a required parameter."); m->mothurOutEndLine(); + abort = true; + } }else if (taxonomyFileName == "not open") { abort = true; } namefile = validParameter.validFile(parameters, "name", true); @@ -153,30 +160,6 @@ PhylotypeCommand::PhylotypeCommand(string option) { } /**********************************************************************************************************************/ -void PhylotypeCommand::help(){ - try { - m->mothurOut("The phylotype command reads a taxonomy file and outputs a .list, .rabund and .sabund file. \n"); - m->mothurOut("The phylotype command parameter options are taxonomy, cutoff and label. The taxonomy parameter is required.\n"); - m->mothurOut("The cutoff parameter allows you to specify the level you want to stop at. The default is the highest level in your taxonomy file. \n"); - m->mothurOut("For example: taxonomy = Bacteria;Bacteroidetes-Chlorobi;Bacteroidetes; - cutoff=2, would truncate the taxonomy to Bacteria;Bacteroidetes-Chlorobi; \n"); - m->mothurOut("For the cutoff parameter levels count up from the root of the phylotree. This enables you to look at the grouping down to a specific resolution, say the genus level.\n"); - m->mothurOut("The label parameter allows you to specify which level you would like, and are separated by dashes. The default all levels in your taxonomy file. \n"); - m->mothurOut("For the label parameter, levels count down from the root to keep the output similiar to mothur's other commands which report information from finer resolution to coarser resolutions.\n"); - m->mothurOut("The phylotype command should be in the following format: \n"); - m->mothurOut("phylotype(taxonomy=yourTaxonomyFile, cutoff=yourCutoff, label=yourLabels) \n"); - m->mothurOut("Eaxample: phylotype(taxonomy=amazon.taxonomy, cutoff=5, label=1-3-5).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "PhylotypeCommand", "help"); - exit(1); - } -} -/**********************************************************************************************************************/ - -PhylotypeCommand::~PhylotypeCommand(){} - -/**********************************************************************************************************************/ - int PhylotypeCommand::execute(){ try { diff --git a/phylotypecommand.h b/phylotypecommand.h index e45e21b..36e679f 100644 --- a/phylotypecommand.h +++ b/phylotypecommand.h @@ -21,13 +21,15 @@ class PhylotypeCommand : public Command { public: PhylotypeCommand(string); PhylotypeCommand(); - ~PhylotypeCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~PhylotypeCommand(){} + + vector setParameters(); + string getCommandName() { return "phylotype"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: bool abort, allLines; diff --git a/pipelinepdscommand.cpp b/pipelinepdscommand.cpp index 84282dc..19e7886 100644 --- a/pipelinepdscommand.cpp +++ b/pipelinepdscommand.cpp @@ -12,39 +12,80 @@ #include "commandoptionparser.hpp" //********************************************************************************************************************** -vector PipelineCommand::getValidParameters(){ - try { - string Array[] = {"sff","oligos","align","chimera","classify","taxonomy","pipeline","processors","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "PipelineCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector PipelineCommand::getRequiredParameters(){ +vector PipelineCommand::setParameters(){ try { + CommandParameter psff("sff", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(psff); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(poligos); + CommandParameter palign("align", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(palign); + CommandParameter pchimera("chimera", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(pchimera); + CommandParameter pclassify("classify", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(pclassify); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "oneRequired", "pipe",false,false); parameters.push_back(ptaxonomy); + CommandParameter ppipeline("pipeline", "InputTypes", "", "", "none", "oneRequired", "none",false,false); parameters.push_back(ppipeline); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "PipelineCommand", "getRequiredParameters"); + m->errorOut(e, "PipelineCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector PipelineCommand::getRequiredFiles(){ +string PipelineCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The pipeline.pds command is designed to guide you through your analysis using mothur.\n"; + helpString += "The pipeline.pds command parameters are pipeline, sff, oligos, align, chimera, classify, taxonomy and processors.\n"; + helpString += "The sff parameter allows you to enter your sff file. It is required, if not using pipeline parameter.\n"; + helpString += "The oligos parameter allows you to enter your oligos file. It is required, if not using pipeline parameter.\n"; + helpString += "The align parameter allows you to enter a template to use with the aligner. It is required, if not using pipeline parameter.\n"; + helpString += "The chimera parameter allows you to enter a template to use for chimera detection. It is required, if not using pipeline parameter.\n"; + helpString += "The classify parameter allows you to enter a template to use for classification. It is required, if not using pipeline parameter.\n"; + helpString += "The taxonomy parameter allows you to enter a taxonomy file for the classify template to use for classification. It is required, if not using pipeline parameter.\n"; + helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n"; + helpString += "The pipeline parameter allows you to enter your own pipeline file. This file should look like a mothur batchfile, but where you would be using a mothur generated file, you can use current instead.\n"; + helpString += "Example: trim.seqs(processors=8, allfiles=T, maxambig=0, maxhomop=8, flip=T, bdiffs=1, pdiffs=2, qwindowaverage=35, qwindowsize=50, fasta=may1.v13.fasta, oligos=may1.v13.oligos, qfile=may1.v13.qual)\n"; + helpString += "then, you could enter unique.seqs(fasta=current), and mothur would use the .trim.fasta file from the trim.seqs command. \n"; + helpString += "then you could enter align.seqs(candidate=current, template=silva.v13.align, processors=8). , and mothur would use the .trim.unique.fasta file from the unique.seqs command. \n"; + helpString += "If no pipeline file is given then mothur will use Pat's pipeline. \n\n"; + helpString += "Here is a list of the commands used in Pat's pipeline.\n"; + helpString += "All paralellized commands will use the processors you entered.\n"; + helpString += "The sffinfo command takes your sff file and extracts the fasta and quality files.\n"; + helpString += "The trim.seqs command uses your oligos file and the quality and fasta files generated by sffinfo.\n"; + helpString += "The trim.seqs command sets the following parameters: allfiles=T, maxambig=0, maxhomop=8, flip=T, bdiffs=1, pdiffs=2, qwindowaverage=35, qwindowsize=50.\n"; + helpString += "The unique.seqs command uses the trimmed fasta file and removes redundant sequences, don't worry the names file generated by unique.seqs will be used in the pipeline to make sure they are included.\n"; + helpString += "The align.seqs command aligns the unique sequences using the aligners default options. \n"; + helpString += "The screen.seqs command screens the sequences using optimize=end-minlength. \n"; + helpString += "The pipeline uses chimera.slayer to detect chimeras using the default options. \n"; + helpString += "The pipeline removes all sequences determined to be chimeric by chimera.slayer. \n"; + helpString += "The filter.seqs command filters the sequences using vertical=T, trump=. \n"; + helpString += "The unique.seqs command uses the filtered fasta file and name file to remove sequences that have become redundant after filtering.\n"; + helpString += "The pre.cluster command clusters sequences that have no more than 2 differences.\n"; + helpString += "The dist.seqs command is used to generate a column and phylip formatted distance matrix using cutoff=0.20 for column.\n"; + helpString += "The pipeline uses cluster with method=average, hard=T. \n"; + helpString += "The classify.seqs command is used to classify the sequences using the bayesian method with a cutoff of 80.\n"; + helpString += "The phylotype command is used to cluster the sequences based on their classification.\n"; + helpString += "The clearcut command is used to generate a tree using neighbor=T. \n"; + helpString += "The summary.single and summary.shared commands are run on the otu files from cluster and phylotype commands. \n"; + helpString += "The summary.shared command uses calc=sharednseqs-sharedsobs-sharedchao-sharedace-anderberg-jclass-jest-kulczynski-kulczynskicody-lennon-ochiai-sorclass-sorest-whittaker-braycurtis-jabund-morisitahorn-sorabund-thetan-thetayc. \n"; + helpString += "The summary.single command uses calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson. \n"; + helpString += "The classify.otu command is used to get the concensus taxonomy for otu files from cluster and phylotype commands. \n"; + helpString += "The phylo.diversity command run on the tree generated by clearcut with rarefy=T, iters=100. \n"; + helpString += "The unifrac commands are also run on the tree generated by clearcut with random=F, distance=T. \n"; + helpString += "\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "PipelineCommand", "getRequiredFiles"); + m->errorOut(e, "PipelineCommand", "getHelpString"); exit(1); } } + + //********************************************************************************************************************** PipelineCommand::PipelineCommand(string option) { try { @@ -55,10 +96,7 @@ PipelineCommand::PipelineCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - - //valid paramters for this command - string AlignArray[] = {"sff","oligos","align","chimera","classify","taxonomy","pipeline","processors","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -139,8 +177,9 @@ PipelineCommand::PipelineCommand(string option) { if (pipeFilename == "not found") { pipeFilename = ""; } else if (pipeFilename == "not open") { pipeFilename = ""; abort = true; } - string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } - convert(temp, processors); + string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); if (pipeFilename != "") { abort = readUsersPipeline(); @@ -179,60 +218,6 @@ PipelineCommand::PipelineCommand(string option) { } //********************************************************************************************************************** -void PipelineCommand::help(){ - try { - m->mothurOut("The pipeline command is designed to guide you through your analysis using mothur.\n"); - m->mothurOut("The pipeline command parameters are pipeline, sff, oligos, align, chimera, classify, taxonomy and processors.\n"); - m->mothurOut("The sff parameter allows you to enter your sff file. It is required, if not using pipeline parameter.\n"); - m->mothurOut("The oligos parameter allows you to enter your oligos file. It is required, if not using pipeline parameter.\n"); - m->mothurOut("The align parameter allows you to enter a template to use with the aligner. It is required, if not using pipeline parameter.\n"); - m->mothurOut("The chimera parameter allows you to enter a template to use for chimera detection. It is required, if not using pipeline parameter.\n"); - m->mothurOut("The classify parameter allows you to enter a template to use for classification. It is required, if not using pipeline parameter.\n"); - m->mothurOut("The taxonomy parameter allows you to enter a taxonomy file for the classify template to use for classification. It is required, if not using pipeline parameter.\n"); - m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); - m->mothurOut("The pipeline parameter allows you to enter your own pipeline file. This file should look like a mothur batchfile, but where you would be using a mothur generated file, you can use mothurmade instead.\n"); - m->mothurOut("Example: trim.seqs(processors=8, allfiles=T, maxambig=0, maxhomop=8, flip=T, bdiffs=1, pdiffs=2, qwindowaverage=35, qwindowsize=50, fasta=may1.v13.fasta, oligos=may1.v13.oligos, qfile=may1.v13.qual)\n"); - m->mothurOut("then, you could enter unique.seqs(fasta=mothurmade), and mothur would use the .trim.fasta file from the trim.seqs command. \n"); - m->mothurOut("then you could enter align.seqs(candidate=mothurmade, template=silva.v13.align, processors=8). , and mothur would use the .trim.unique.fasta file from the unique.seqs command. \n"); - m->mothurOut("If no pipeline file is given then mothur will use Pat's pipeline. \n\n"); - m->mothurOut("Here is a list of the commands used in Pat's pipeline.\n"); - m->mothurOut("All paralellized commands will use the processors you entered.\n"); - m->mothurOut("The sffinfo command takes your sff file and extracts the fasta and quality files.\n"); - m->mothurOut("The trim.seqs command uses your oligos file and the quality and fasta files generated by sffinfo.\n"); - m->mothurOut("The trim.seqs command sets the following parameters: allfiles=T, maxambig=0, maxhomop=8, flip=T, bdiffs=1, pdiffs=2, qwindowaverage=35, qwindowsize=50.\n"); - m->mothurOut("The unique.seqs command uses the trimmed fasta file and removes redundant sequences, don't worry the names file generated by unique.seqs will be used in the pipeline to make sure they are included.\n"); - m->mothurOut("The align.seqs command aligns the unique sequences using the aligners default options. \n"); - m->mothurOut("The screen.seqs command screens the sequences using optimize=end-minlength. \n"); - m->mothurOut("The pipeline uses chimera.slayer to detect chimeras using the default options. \n"); - m->mothurOut("The pipeline removes all sequences determined to be chimeric by chimera.slayer. \n"); - m->mothurOut("The filter.seqs command filters the sequences using vertical=T, trump=. \n"); - m->mothurOut("The unique.seqs command uses the filtered fasta file and name file to remove sequences that have become redundant after filtering.\n"); - m->mothurOut("The pre.cluster command clusters sequences that have no more than 2 differences.\n"); - m->mothurOut("The dist.seqs command is used to generate a column and phylip formatted distance matrix using cutoff=0.20 for column.\n"); - m->mothurOut("The pipeline uses cluster with method=average, hard=T. \n"); - m->mothurOut("The classify.seqs command is used to classify the sequences using the bayesian method with a cutoff of 80.\n"); - m->mothurOut("The phylotype command is used to cluster the sequences based on their classification.\n"); - m->mothurOut("The clearcut command is used to generate a tree using neighbor=T. \n"); - m->mothurOut("The summary.single and summary.shared commands are run on the otu files from cluster and phylotype commands. \n"); - m->mothurOut("The summary.shared command uses calc=sharednseqs-sharedsobs-sharedchao-sharedace-anderberg-jclass-jest-kulczynski-kulczynskicody-lennon-ochiai-sorclass-sorest-whittaker-braycurtis-jabund-morisitahorn-sorabund-thetan-thetayc. \n"); - m->mothurOut("The summary.single command uses calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson. \n"); - m->mothurOut("The classify.otu command is used to get the concensus taxonomy for otu files from cluster and phylotype commands. \n"); - m->mothurOut("The phylo.diversity command run on the tree generated by clearcut with rarefy=T, iters=100. \n"); - m->mothurOut("The unifrac commands are also run on the tree generated by clearcut with random=F, distance=T. \n"); - m->mothurOut("\n\n"); - } - catch(exception& e) { - m->errorOut(e, "PipelineCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -PipelineCommand::~PipelineCommand(){} - -//********************************************************************************************************************** - int PipelineCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } @@ -357,13 +342,11 @@ bool PipelineCommand::checkForValidAndRequiredParameters(string name, string opt if (name == "system") { return false; } - if (name == "system") { return false; } - //get shell of the command so we can check to make sure its valid without running it Command* command = cFactory->getCommand(name); //check to make sure all parameters are valid for command - vector validParameters = command->getValidParameters(); + vector validParameters = command->setParameters(); OptionParser parser(options); map parameters = parser.getParameters(); @@ -375,42 +358,42 @@ bool PipelineCommand::checkForValidAndRequiredParameters(string name, string opt for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, validParameters, it->second) != true) { return true; } // not valid - if (it->second == "mothurmade") { + if (it->second == "current") { itMade = mothurMadeFiles.find(it->first); if (itMade == mothurMadeFiles.end()) { - if ((name == "align.seqs") && (it->first == "candidate")) {} //do nothing about candidate - else { - m->mothurOut("You have the " + it->first + " listed as a mothurmade file for the " + name + " command, but it seems mothur will not make that file in your current pipeline, please correct."); m->mothurOutEndLine(); - return true; - } + m->mothurOut("You have the " + it->first + " listed as a current file for the " + name + " command, but it seems mothur will not make that file in your current pipeline, please correct."); m->mothurOutEndLine(); + return true; } } } //is the command missing any required - vector requiredParameters = command->getRequiredParameters(); - - //check for or - bool hasOr = false; - int numFound = 0; - if (requiredParameters.size() > 2) { - if (requiredParameters[(requiredParameters.size()-1)] == "or") { hasOr = true; } + vector commandParameters = command->getParameters(); + vector requiredParameters; + for (int i = 0; i < commandParameters.size(); i++) { + if (commandParameters[i].required) { + requiredParameters.push_back(commandParameters[i].name); + } } - + for (int i = 0; i < requiredParameters.size(); i++) { it = parameters.find(requiredParameters[i]); - if (it != parameters.end()) { numFound++; } - else { - if (!hasOr) { m->mothurOut(name + " requires the " + requiredParameters[i] + " parameter, please correct."); m->mothurOutEndLine(); } + if (it == parameters.end()) { + + string paraToLookFor = requiredParameters[i]; + + //does mothur have a current file for this? + itMade = mothurMadeFiles.find(requiredParameters[i]); + + if (itMade == mothurMadeFiles.end()) { + m->mothurOut(name + " requires the " + requiredParameters[i] + " parameter, please correct."); m->mothurOutEndLine(); + + } } } - - // if all are needed and not all are found - if ((!hasOr) && (numFound != requiredParameters.size())) { return true; } - //if one is needed and none are found - else if ((hasOr) && (numFound == 0)) { return true; } + //update MothurMade map > thisCommandsFile = command->getOutputFiles(); @@ -549,14 +532,12 @@ bool PipelineCommand::fillInMothurMade(string& options, mapfirst; string tempOption = it->second; - if (tempOption == "mothurmade") { - - if (it->first == "candidate") { paraType = "fasta"; } + if (tempOption == "current") { itMade = mothurMadeFiles.find(paraType); if (itMade == mothurMadeFiles.end()) { - m->mothurOut("Looking for a mothurmade " + paraType + " file, but it seems mothur has not made that file type in your current pipeline, please correct."); m->mothurOutEndLine(); + m->mothurOut("Looking for a current " + paraType + " file, but it seems mothur has not made that file type in your current pipeline, please correct."); m->mothurOutEndLine(); return true; }else{ vector temp = itMade->second; @@ -636,71 +617,71 @@ void PipelineCommand::createPatsPipeline(){ //trim.seqs command string fastaFile = m->getRootName(m->getSimpleName(sffFile)) + "fasta"; string qualFile = m->getRootName(m->getSimpleName(sffFile)) + "qual"; - thisCommand = "trim.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", allfiles=T, maxambig=0, maxhomop=8, flip=T, bdiffs=1, pdiffs=2, qwindowaverage=35, qwindowsize=50, oligos=" + oligosFile + ", qfile=" + qualFile + ")"; + thisCommand = "trim.seqs(processors=" + toString(processors) + ", fasta=current, allfiles=T, maxambig=0, maxhomop=8, flip=T, bdiffs=1, pdiffs=2, qwindowaverage=35, qwindowsize=50, oligos=" + oligosFile + ", qfile=current)"; commands.push_back(thisCommand); //unique.seqs string groupFile = m->getRootName(m->getSimpleName(fastaFile)) + "groups"; qualFile = m->getRootName(m->getSimpleName(fastaFile)) + "trim.qual"; fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "trim.fasta"; - thisCommand = "unique.seqs(fasta=" + fastaFile + ")"; + thisCommand = "unique.seqs(fasta=current)"; commands.push_back(thisCommand); //align.seqs string nameFile = m->getRootName(m->getSimpleName(fastaFile)) + "names"; fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "unique" + m->getExtension(fastaFile); - thisCommand = "align.seqs(processors=" + toString(processors) + ", candidate=" + fastaFile + ", template=" + alignFile + ")"; + thisCommand = "align.seqs(processors=" + toString(processors) + ", candidate=current, template=" + alignFile + ")"; commands.push_back(thisCommand); //screen.seqs fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "align"; - thisCommand = "screen.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", name=" + nameFile + ", group=" + groupFile + ", optimize=end-minlength)"; + thisCommand = "screen.seqs(processors=" + toString(processors) + ", fasta=current, name=current, group=current, optimize=end-minlength)"; commands.push_back(thisCommand); //chimera.slayer fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "good" + m->getExtension(fastaFile); nameFile = m->getRootName(m->getSimpleName(nameFile)) + "good" + m->getExtension(nameFile); groupFile = m->getRootName(m->getSimpleName(groupFile)) + "good" + m->getExtension(groupFile); - thisCommand = "chimera.slayer(processors=" + toString(processors) + ", fasta=" + fastaFile + ", template=" + chimeraFile + ")"; + thisCommand = "chimera.slayer(processors=" + toString(processors) + ", fasta=current, template=" + chimeraFile + ")"; commands.push_back(thisCommand); //remove.seqs string accnosFile = m->getRootName(m->getSimpleName(fastaFile)) + "slayer.accnos"; - thisCommand = "remove.seqs(fasta=" + fastaFile + ", name=" + nameFile + ", group=" + groupFile + ", accnos=" + accnosFile + ", dups=T)"; + thisCommand = "remove.seqs(fasta=current, name=current, group=current, accnos=current, dups=T)"; commands.push_back(thisCommand); //filter.seqs nameFile = m->getRootName(m->getSimpleName(nameFile)) + "pick" + m->getExtension(nameFile); groupFile = m->getRootName(m->getSimpleName(groupFile)) + "pick" + m->getExtension(groupFile); fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "pick" + m->getExtension(fastaFile); - thisCommand = "filter.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", vertical=T, trump=.)"; + thisCommand = "filter.seqs(processors=" + toString(processors) + ", fasta=current, vertical=T, trump=.)"; commands.push_back(thisCommand); //unique.seqs fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "filter.fasta"; - thisCommand = "unique.seqs(fasta=" + fastaFile + ", name=" + nameFile + ")"; + thisCommand = "unique.seqs(fasta=current, name=current)"; commands.push_back(thisCommand); //pre.cluster nameFile = m->getRootName(m->getSimpleName(fastaFile)) + "names"; fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "unique" + m->getExtension(fastaFile); - thisCommand = "pre.cluster(fasta=" + fastaFile + ", name=" + nameFile + ", diffs=2)"; + thisCommand = "pre.cluster(fasta=current, name=current, diffs=2)"; commands.push_back(thisCommand); //dist.seqs nameFile = m->getRootName(m->getSimpleName(fastaFile)) + "precluster.names"; fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "precluster" + m->getExtension(fastaFile); - thisCommand = "dist.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", cutoff=0.20)"; + thisCommand = "dist.seqs(processors=" + toString(processors) + ", fasta=current, cutoff=0.20)"; commands.push_back(thisCommand); //dist.seqs string columnFile = m->getRootName(m->getSimpleName(fastaFile)) + "dist"; - thisCommand = "dist.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", output=lt)"; + thisCommand = "dist.seqs(processors=" + toString(processors) + ", fasta=current, output=lt)"; commands.push_back(thisCommand); //read.dist string phylipFile = m->getRootName(m->getSimpleName(fastaFile)) + "phylip.dist"; - thisCommand = "read.dist(column=" + columnFile + ", name=" + nameFile + ")"; + thisCommand = "read.dist(column=current, name=current)"; commands.push_back(thisCommand); //cluster @@ -711,12 +692,12 @@ void PipelineCommand::createPatsPipeline(){ string rabundFile = m->getRootName(m->getSimpleName(columnFile)) + "an.rabund"; //degap.seqs - thisCommand = "degap.seqs(fasta=" + fastaFile + ")"; + thisCommand = "degap.seqs(fasta=current)"; commands.push_back(thisCommand); //classify.seqs fastaFile = m->getRootName(m->getSimpleName(fastaFile)) + "ng.fasta"; - thisCommand = "classify.seqs(processors=" + toString(processors) + ", fasta=" + fastaFile + ", name=" + nameFile + ", template=" + classifyFile + ", taxonomy=" + taxonomyFile + ", cutoff=80)"; + thisCommand = "classify.seqs(processors=" + toString(processors) + ", fasta=current, name=current, template=" + classifyFile + ", taxonomy=" + taxonomyFile + ", cutoff=80)"; commands.push_back(thisCommand); string RippedTaxName = m->getRootName(m->getSimpleName(taxonomyFile)); @@ -728,68 +709,68 @@ void PipelineCommand::createPatsPipeline(){ string taxSummaryFile = m->getRootName(m->getSimpleName(fastaFile)) + RippedTaxName + "tax.summary"; //phylotype - thisCommand = "phylotype(taxonomy=" + fastaTaxFile + ", name=" + nameFile + ")"; + thisCommand = "phylotype(taxonomy=current, name=current)"; commands.push_back(thisCommand); string phyloListFile = m->getRootName(m->getSimpleName(fastaTaxFile)) + "tx.list"; string phyloRabundFile = m->getRootName(m->getSimpleName(fastaTaxFile)) + "tx.rabund"; //clearcut - thisCommand = "clearcut(phylip=" + phylipFile + ", neighbor=T)"; + thisCommand = "clearcut(phylip=current, neighbor=T)"; commands.push_back(thisCommand); string treeFile = m->getRootName(m->getSimpleName(phylipFile)) + "tre"; //read.otu - thisCommand = "read.otu(list=" + listFile + ", group=" + groupFile + ", label=0.03)"; + thisCommand = "make.shared(list=" + listFile + ", group=" + groupFile + ", label=0.03)"; commands.push_back(thisCommand); string sharedFile = m->getRootName(m->getSimpleName(listFile)) + "shared"; //read.otu - thisCommand = "read.otu(list=" + phyloListFile + ", group=" + groupFile + ", label=1)"; + thisCommand = "make.shared(list=" + phyloListFile + ", group=" + groupFile + ", label=1)"; commands.push_back(thisCommand); string phyloSharedFile = m->getRootName(m->getSimpleName(phyloListFile)) + "shared"; //read.otu - thisCommand = "read.otu(shared=" + sharedFile + ")"; + thisCommand = "set.current(shared=" + sharedFile + ")"; commands.push_back(thisCommand); //summary.single - thisCommand = "summary.single(calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; + thisCommand = "summary.single(shared=current, calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; commands.push_back(thisCommand); //summary.shared - thisCommand = "summary.shared(calc=sharednseqs-sharedsobs-sharedchao-sharedace-anderberg-jclass-jest-kulczynski-kulczynskicody-lennon-ochiai-sorclass-sorest-whittaker-braycurtis-jabund-morisitahorn-sorabund-thetan-thetayc)"; + thisCommand = "summary.shared(shared=current, calc=sharednseqs-sharedsobs-sharedchao-sharedace-anderberg-jclass-jest-kulczynski-kulczynskicody-lennon-ochiai-sorclass-sorest-whittaker-braycurtis-jabund-morisitahorn-sorabund-thetan-thetayc)"; commands.push_back(thisCommand); //read.otu - thisCommand = "read.otu(rabund=" + rabundFile + ", label=0.03)"; - commands.push_back(thisCommand); + //thisCommand = "read.otu(rabund=" + rabundFile + ", label=0.03)"; + //commands.push_back(thisCommand); //summary.single - thisCommand = "summary.single(calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; + thisCommand = "summary.single(rabund=" + rabundFile + ", label=0.03, calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; commands.push_back(thisCommand); //read.otu - thisCommand = "read.otu(shared=" + phyloSharedFile + ")"; + thisCommand = "set.current(shared=" + phyloSharedFile + ")"; commands.push_back(thisCommand); //summary.single - thisCommand = "summary.single(calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; + thisCommand = "summary.single(shared=current, calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; commands.push_back(thisCommand); //summary.shared - thisCommand = "summary.shared(calc=sharednseqs-sharedsobs-sharedchao-sharedace-anderberg-jclass-jest-kulczynski-kulczynskicody-lennon-ochiai-sorclass-sorest-whittaker-braycurtis-jabund-morisitahorn-sorabund-thetan-thetayc)"; + thisCommand = "summary.shared(shared=current, calc=sharednseqs-sharedsobs-sharedchao-sharedace-anderberg-jclass-jest-kulczynski-kulczynskicody-lennon-ochiai-sorclass-sorest-whittaker-braycurtis-jabund-morisitahorn-sorabund-thetan-thetayc)"; commands.push_back(thisCommand); //read.otu - thisCommand = "read.otu(rabund=" + phyloRabundFile + ", label=1)"; - commands.push_back(thisCommand); + //thisCommand = "read.otu(rabund=" + phyloRabundFile + ", label=1)"; + //commands.push_back(thisCommand); //summary.single - thisCommand = "summary.single(calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; + thisCommand = "summary.single(rabund=" + phyloRabundFile + ", label=1, calc=nseqs-sobs-coverage-bergerparker-chao-ace-jack-bootstrap-boneh-efron-shen-solow-shannon-npshannon-invsimpson-qstat-simpsoneven-shannoneven-heip-smithwilson, size=5000)"; commands.push_back(thisCommand); //classify.otu @@ -801,19 +782,19 @@ void PipelineCommand::createPatsPipeline(){ commands.push_back(thisCommand); //read.tree - thisCommand = "read.tree(tree=" + treeFile + ", name=" + nameFile + ", group=" + groupFile + ")"; + thisCommand = "set.current(tree=" + treeFile + ", name=" + nameFile + ", group=" + groupFile + ")"; commands.push_back(thisCommand); //phylo.diversity - thisCommand = "phylo.diversity(iters=100,rarefy=T)"; + thisCommand = "phylo.diversity(tree=current, group=current, name=current, iters=100,rarefy=T)"; commands.push_back(thisCommand); //unifrac.weighted - thisCommand = "unifrac.weighted(random=false, distance=true, groups=all, processors=" + toString(processors) + ")"; + thisCommand = "unifrac.weighted(tree=current, group=current, name=current, random=false, distance=true, groups=all, processors=" + toString(processors) + ")"; commands.push_back(thisCommand); //unifrac.unweighted - thisCommand = "unifrac.unweighted(random=false, distance=true, processors=" + toString(processors) + ")"; + thisCommand = "unifrac.unweighted(tree=current, group=current, name=current, random=false, distance=true, processors=" + toString(processors) + ")"; commands.push_back(thisCommand); diff --git a/pipelinepdscommand.h b/pipelinepdscommand.h index 289a909..13695a6 100644 --- a/pipelinepdscommand.h +++ b/pipelinepdscommand.h @@ -20,20 +20,21 @@ class PipelineCommand : public Command { public: PipelineCommand(string); - PipelineCommand() { abort = true; calledHelp = true; } - ~PipelineCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } //empty - int execute(); - void help(); + PipelineCommand() { abort = true; calledHelp = true; setParameters(); } + ~PipelineCommand(){} + + vector setParameters(); + string getCommandName() { return "pipeline.pds"; } + string getCommandCategory() { return "Hidden"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: bool abort; CommandFactory* cFactory; vector outputNames; - map > outputTypes; vector commands; string outputDir, sffFile, alignFile, oligosFile, taxonomyFile, pipeFilename, classifyFile, chimeraFile; int processors; diff --git a/preclustercommand.cpp b/preclustercommand.cpp index 0fb9370..550a6b7 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -11,51 +11,57 @@ //********************************************************************************************************************** inline bool comparePriority(seqPNode first, seqPNode second) { return (first.numIdentical > second.numIdentical); } + //********************************************************************************************************************** -vector PreClusterCommand::getValidParameters(){ +vector PreClusterCommand::setParameters(){ try { - string Array[] = {"fasta", "name", "diffs", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pdiffs("diffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pdiffs); + 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, "PreClusterCommand", "getValidParameters"); + m->errorOut(e, "PreClusterCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -PreClusterCommand::PreClusterCommand(){ +string PreClusterCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["name"] = tempOutNames; + string helpString = ""; + helpString += "The pre.cluster command groups sequences that are within a given number of base mismatches.\n"; + helpString += "The pre.cluster command outputs a new fasta and name file.\n"; + helpString += "The pre.cluster command parameters are fasta, names and diffs. The fasta parameter is required. \n"; + helpString += "The names parameter allows you to give a list of seqs that are identical. This file is 2 columns, first column is name or representative sequence, second column is a list of its identical sequences separated by commas.\n"; + helpString += "The diffs parameter allows you to specify maximum number of mismatched bases allowed between sequences in a grouping. The default is 1.\n"; + helpString += "The pre.cluster command should be in the following format: \n"; + helpString += "pre.cluster(fasta=yourFastaFile, names=yourNamesFile, diffs=yourMaxDiffs) \n"; + helpString += "Example pre.cluster(fasta=amazon.fasta, diffs=2).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "PreClusterCommand", "PreClusterCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector PreClusterCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "PreClusterCommand", "getRequiredParameters"); + m->errorOut(e, "PreClusterCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector PreClusterCommand::getRequiredFiles(){ +PreClusterCommand::PreClusterCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["name"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "PreClusterCommand", "getRequiredFiles"); + m->errorOut(e, "PreClusterCommand", "PreClusterCommand"); exit(1); } } @@ -69,9 +75,7 @@ PreClusterCommand::PreClusterCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta", "name", "diffs", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -113,7 +117,11 @@ PreClusterCommand::PreClusterCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the pre.cluster command."); m->mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (fastafile == "not open") { abort = true; } //if the user changes the output directory command factory will send this info to us in the output parameter @@ -139,28 +147,6 @@ PreClusterCommand::PreClusterCommand(string option) { exit(1); } } - -//********************************************************************************************************************** -PreClusterCommand::~PreClusterCommand(){} -//********************************************************************************************************************** - -void PreClusterCommand::help(){ - try { - m->mothurOut("The pre.cluster command groups sequences that are within a given number of base mismatches.\n"); - m->mothurOut("The pre.cluster command outputs a new fasta and name file.\n"); - m->mothurOut("The pre.cluster command parameters are fasta, names and diffs. The fasta parameter is required. \n"); - m->mothurOut("The names parameter allows you to give a list of seqs that are identical. This file is 2 columns, first column is name or representative sequence, second column is a list of its identical sequences separated by commas.\n"); - m->mothurOut("The diffs parameter allows you to specify maximum number of mismatched bases allowed between sequences in a grouping. The default is 1.\n"); - m->mothurOut("The pre.cluster command should be in the following format: \n"); - m->mothurOut("pre.cluster(fasta=yourFastaFile, names=yourNamesFile, diffs=yourMaxDiffs) \n"); - m->mothurOut("Example pre.cluster(fasta=amazon.fasta, diffs=2).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "PreClusterCommand", "help"); - exit(1); - } -} //********************************************************************************************************************** int PreClusterCommand::execute(){ diff --git a/preclustercommand.h b/preclustercommand.h index 7bbb5a7..d8ee57d 100644 --- a/preclustercommand.h +++ b/preclustercommand.h @@ -32,13 +32,15 @@ class PreClusterCommand : public Command { public: PreClusterCommand(string); PreClusterCommand(); - ~PreClusterCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~PreClusterCommand(){} + + vector setParameters(); + string getCommandName() { return "pre.cluster"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: int diffs, length; diff --git a/quitcommand.cpp b/quitcommand.cpp index 462fe8f..85e8b52 100644 --- a/quitcommand.cpp +++ b/quitcommand.cpp @@ -10,40 +10,6 @@ #include "quitcommand.h" //********************************************************************************************************************** -vector QuitCommand::getValidParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "QuitCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector QuitCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "QuitCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector QuitCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "QuitCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** - QuitCommand::QuitCommand(string option) { abort = false; calledHelp = false; @@ -52,27 +18,10 @@ QuitCommand::QuitCommand(string option) { } //********************************************************************************************************************** - -void QuitCommand::help(){ - try { - m->mothurOut("The quit command will terminate mothur and should be in the following format: \n"); - m->mothurOut("quit() or quit\n\n"); - } - catch(exception& e) { - m->errorOut(e, "QuitCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - QuitCommand::~QuitCommand(){} - //********************************************************************************************************************** - int QuitCommand::execute(){ if (abort == true) { return 0; } return 1; } - //********************************************************************************************************************** diff --git a/quitcommand.h b/quitcommand.h index f901b17..e24bb77 100644 --- a/quitcommand.h +++ b/quitcommand.h @@ -22,17 +22,19 @@ public: QuitCommand(string); QuitCommand() {} ~QuitCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters() { return outputNames; } //dummy, doesn't really do anything + 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"; } + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: bool abort; vector outputNames; - map > outputTypes; }; #endif diff --git a/rarefact.cpp b/rarefact.cpp index 032cd93..d8a6b5c 100644 --- a/rarefact.cpp +++ b/rarefact.cpp @@ -183,7 +183,7 @@ try { } //if jumble is false all iters will be the same - if (globaldata->jumble == false) { nIters = 1; } + if (m->jumble == false) { nIters = 1; } //convert freq percentage to number int increment = 1; @@ -196,7 +196,7 @@ try { displays[i]->init(label); } - if (globaldata->jumble == true) { + if (m->jumble == true) { //randomize the groups random_shuffle(lookup.begin(), lookup.end()); } diff --git a/rarefact.h b/rarefact.h index 7d1fab4..5e42a78 100644 --- a/rarefact.h +++ b/rarefact.h @@ -5,7 +5,6 @@ #include "raredisplay.h" #include "ordervector.hpp" #include "mothur.h" -#include "globaldata.hpp" class Rarefact { @@ -14,14 +13,14 @@ public: Rarefact(OrderVector* o, vector disp, int p) : numSeqs(o->getNumSeqs()), order(o), displays(disp), label(o->getLabel()), processors(p) { m = MothurOut::getInstance(); } Rarefact(vector shared, vector disp) : - lookup(shared), displays(disp) { globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); } + lookup(shared), displays(disp) { m = MothurOut::getInstance(); } ~Rarefact(){}; int getCurve(float, int); int getSharedCurve(float, int); private: - GlobalData* globaldata; + OrderVector* order; vector displays; int numSeqs, numGroupComb, processors; diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index 4ab81ea..b6ad295 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -24,45 +24,60 @@ #include "jackknife.h" #include "coverage.h" + //********************************************************************************************************************** -vector RareFactCommand::getValidParameters(){ - try { - string Array[] = {"iters","freq","label","calc","abund","processors","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RareFactCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector RareFactCommand::getRequiredParameters(){ +vector RareFactCommand::setParameters(){ try { + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-npshannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap", "sobs", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter 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, "RareFactCommand", "getRequiredParameters"); + m->errorOut(e, "RareFactCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector RareFactCommand::getRequiredFiles(){ +string RareFactCommand::getHelpString(){ try { - string AlignArray[] = {"shared","list","rabund","sabund","or"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + ValidCalculators validCalculator; + string helpString = ""; + helpString += "The rarefaction.single command parameters are list, sabund, rabund, shared, label, iters, freq, calc, processors and abund. list, sabund, rabund or shared is required unless you have a valid current file. \n"; + helpString += "The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"; + helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n"; + helpString += "The rarefaction.single command should be in the following format: \n"; + helpString += "rarefaction.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n"; + helpString += "Example rarefaction.single(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson).\n"; + helpString += "The default values for iters is 1000, freq is 100, and calc is rarefaction which calculates the rarefaction curve for the observed richness.\n"; + validCalculator.printCalc("rarefaction"); + helpString += "The label parameter is used to analyze specific labels in your input.\n"; + helpString += "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "RareFactCommand", "getRequiredFiles"); + m->errorOut(e, "RareFactCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** RareFactCommand::RareFactCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["rarefaction"] = tempOutNames; outputTypes["r_chao"] = tempOutNames; @@ -88,27 +103,23 @@ RareFactCommand::RareFactCommand(){ //********************************************************************************************************************** RareFactCommand::RareFactCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Estimators.clear(); - + //allow user to run help - if(option == "help") { validCalculator = new ValidCalculators(); help(); delete validCalculator; abort = true; calledHelp = true; } + if(option == "help") { abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"iters","freq","label","calc","abund","processors","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } @@ -130,15 +141,92 @@ RareFactCommand::RareFactCommand(string option) { outputTypes["r_coverage"] = tempOutNames; outputTypes["r_nseqs"] = 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 = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + //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("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("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("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("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; } + } } - - //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund, rabund or shared file before you can use the rarefact.single command."); m->mothurOutEndLine(); abort = true; } + //check for required parameters + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { listfile = ""; abort = true; } + else if (listfile == "not found") { listfile = ""; } + else { format = "list"; inputfile = listfile; } + + sabundfile = validParameter.validFile(parameters, "sabund", true); + if (sabundfile == "not open") { sabundfile = ""; abort = true; } + else if (sabundfile == "not found") { sabundfile = ""; } + else { format = "sabund"; inputfile = sabundfile; } + + rabundfile = validParameter.validFile(parameters, "rabund", true); + if (rabundfile == "not open") { rabundfile = ""; abort = true; } + else if (rabundfile == "not found") { rabundfile = ""; } + else { format = "rabund"; inputfile = rabundfile; } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { format = "sharedfile"; inputfile = sharedfile; } + + if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + rabundfile = m->getRabundFile(); + if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } + else { + sabundfile = m->getSabundFile(); + if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list, sabund, rabund or shared file before you can use the collect.single command."); 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(inputfile); } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... label = validParameter.validFile(parameters, "label", false); @@ -147,12 +235,6 @@ RareFactCommand::RareFactCommand(string option) { if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } - - //if the user has not specified any labels use the ones from read.otu - if(label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } calc = validParameter.validFile(parameters, "calc", false); if (calc == "not found") { calc = "sobs"; } @@ -171,7 +253,8 @@ RareFactCommand::RareFactCommand(string option) { temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "1000"; } convert(temp, nIters); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); } @@ -183,60 +266,31 @@ RareFactCommand::RareFactCommand(string option) { } //********************************************************************************************************************** -void RareFactCommand::help(){ - try { - m->mothurOut("The rarefaction.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n"); - m->mothurOut("The rarefaction.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster.\n"); - m->mothurOut("The rarefaction.single command parameters are label, iters, freq, calc, processors and abund. No parameters are required. \n"); - m->mothurOut("The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"); - m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); - m->mothurOut("The rarefaction.single command should be in the following format: \n"); - m->mothurOut("rarefaction.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n"); - m->mothurOut("Example rarefaction.single(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson).\n"); - m->mothurOut("The default values for iters is 1000, freq is 100, and calc is rarefaction which calculates the rarefaction curve for the observed richness.\n"); - validCalculator->printCalc("rarefaction", cout); - m->mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "RareFactCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -RareFactCommand::~RareFactCommand(){} - -//********************************************************************************************************************** - int RareFactCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - string hadShared = ""; - if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } - else { hadShared = globaldata->getSharedFile(); inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } + if ((format != "sharedfile")) { inputFileNames.push_back(inputfile); } + else { inputFileNames = parseSharedFile(sharedfile); format = "rabund"; } - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } + if (m->control_pressed) { return 0; } for (int p = 0; p < inputFileNames.size(); p++) { string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])); - globaldata->inputFileName = inputFileNames[p]; - - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } + + if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } m->Groups.clear(); return 0; } if (inputFileNames.size() > 1) { m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); } int i; - validCalculator = new ValidCalculators(); - + ValidCalculators validCalculator; + for (i=0; iisValidCalculator("rarefaction", Estimators[i]) == true) { + if (validCalculator.isValidCalculator("rarefaction", Estimators[i]) == true) { if (Estimators[i] == "sobs") { rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction"))); outputNames.push_back(fileNameRoot+"rarefaction"); outputTypes["rarefaction"].push_back(fileNameRoot+"rarefaction"); @@ -290,25 +344,22 @@ int RareFactCommand::execute(){ //if the users entered no valid calculators don't execute command - if (rDisplays.size() == 0) { for(int i=0;iinputFileName); - read->read(&*globaldata); + if (rDisplays.size() == 0) { for(int i=0;igorder; + input = new InputData(inputFileNames[p], format); + order = input->getOrderVector(); string lastLabel = order->getLabel(); - input = globaldata->ginput; //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } for(int i=0;iginput = NULL; delete order; globaldata->gorder = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for(int i=0;icontrol_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } for(int i=0;iginput = NULL; delete order; globaldata->gorder = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for(int i=0;igetLabel()) == 1){ @@ -346,7 +397,7 @@ int RareFactCommand::execute(){ order = (input->getOrderVector()); } - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } for(int i=0;iginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for(int i=0;i::iterator it; @@ -361,7 +412,7 @@ int RareFactCommand::execute(){ } } - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } for(int i=0;iginput = NULL; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for(int i=0;igorder = NULL; - delete input; globaldata->ginput = NULL; - delete read; - delete validCalculator; - + delete input; } - if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } @@ -410,12 +456,7 @@ vector RareFactCommand::parseSharedFile(string filename) { map filehandles; map::iterator it3; - - //read first line - read = new ReadOTUFile(filename); - read->read(&*globaldata); - - input = globaldata->ginput; + input = new InputData(filename, "sharedfile"); vector lookup = input->getSharedRAbundVectors(); string sharedFileRoot = m->getRootName(filename); @@ -450,9 +491,9 @@ vector RareFactCommand::parseSharedFile(string filename) { for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - delete read; + delete input; - globaldata->ginput = NULL; + m->Groups.clear(); return filenames; } diff --git a/rarefactcommand.h b/rarefactcommand.h index 7da0b2f..67ab70c 100644 --- a/rarefactcommand.h +++ b/rarefactcommand.h @@ -14,48 +14,41 @@ #include "inputdata.h" #include "rarefact.h" #include "display.h" -#include "readotu.h" #include "validcalculator.h" - -class GlobalData; - class RareFactCommand : public Command { public: RareFactCommand(string); RareFactCommand(); - ~RareFactCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~RareFactCommand(){} + + vector setParameters(); + string getCommandName() { return "rarefaction.single"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; + vector rDisplays; - ReadOTUFile* read; OrderVector* order; InputData* input; - ValidCalculators* validCalculator; Rarefact* rCurve; int nIters, abund, processors; float freq; bool abort, allLines; set labels; //holds labels to be used - string label, calc; + string label, calc, sharedfile, listfile, rabundfile, sabundfile, format, inputfile; vector Estimators; vector inputFileNames, outputNames; vector groups; - map > outputTypes; string outputDir; vector parseSharedFile(string); - - }; #endif diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index ea460c0..746b09e 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -12,50 +12,63 @@ #include "sharednseqs.h" //********************************************************************************************************************** -vector RareFactSharedCommand::getValidParameters(){ +vector RareFactSharedCommand::setParameters(){ try { - string Array[] = {"iters","freq","label","calc","groups", "jumble","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pcalc("calc", "Multiple", "sharednseqs-sharedobserved", "sharedobserved", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter pjumble("jumble", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pjumble); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "RareFactSharedCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -RareFactSharedCommand::RareFactSharedCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["sharedrarefaction"] = tempOutNames; - outputTypes["sharedr_nseqs"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "RareFactSharedCommand", "RareFactSharedCommand"); + m->errorOut(e, "RareFactSharedCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector RareFactSharedCommand::getRequiredParameters(){ +string RareFactSharedCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + ValidCalculators validCalculator; + helpString += "The collect.shared command parameters are shared, label, freq, calc and groups. shared is required if there is no current sharedfile. \n"; + helpString += "The rarefaction.shared command parameters are shared, label, iters, groups, jumble and calc. shared is required if there is no current sharedfile. \n"; + helpString += "The rarefaction command should be in the following format: \n"; + helpString += "rarefaction.shared(label=yourLabel, iters=yourIters, calc=yourEstimators, jumble=yourJumble, groups=yourGroups).\n"; + helpString += "The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"; + helpString += "Example rarefaction.shared(label=unique-0.01-0.03, iters=10000, groups=B-C, jumble=T, calc=sharedobserved).\n"; + helpString += "The default values for iters is 1000, freq is 100, and calc is sharedobserved which calculates the shared rarefaction curve for the observed richness.\n"; + helpString += "The default value for groups is all the groups in your groupfile, and jumble is true.\n"; + helpString += validCalculator.printCalc("sharedrarefaction"); + helpString += "The label parameter is used to analyze specific labels in your input.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"; + helpString += "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "RareFactSharedCommand", "getRequiredParameters"); + m->errorOut(e, "RareFactSharedCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector RareFactSharedCommand::getRequiredFiles(){ +RareFactSharedCommand::RareFactSharedCommand(){ try { - string Array[] = {"shared"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["sharedrarefaction"] = tempOutNames; + outputTypes["sharedr_nseqs"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "RareFactSharedCommand", "getRequiredFiles"); + m->errorOut(e, "RareFactSharedCommand", "RareFactSharedCommand"); exit(1); } } @@ -63,29 +76,23 @@ vector RareFactSharedCommand::getRequiredFiles(){ RareFactSharedCommand::RareFactSharedCommand(string option) { try { - globaldata = GlobalData::getInstance(); - abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Estimators.clear(); - Groups.clear(); //allow user to run help - if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; calledHelp = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"iters","freq","label","calc","groups", "jumble","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; //check to make sure all parameters are valid for command - for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + for (it = parameters.begin(); it != parameters.end(); it++) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } @@ -94,18 +101,34 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { outputTypes["sharedrarefaction"] = tempOutNames; outputTypes["sharedr_nseqs"] = tempOutNames; - //make sure the user has already run the read.otu command - if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); m->mothurOutEndLine(); abort = true; } - else if (globaldata->getGroupFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); m->mothurOutEndLine(); 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("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; } + } } - //if the user changes the output directory command factory will send this info to us in the output parameter - outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ - outputDir = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + //get shared file + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current sharedfile and the shared 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(sharedfile); } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -116,11 +139,6 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if(label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } calc = validParameter.validFile(parameters, "calc", false); if (calc == "not found") { calc = "sharedobserved"; } @@ -134,7 +152,7 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { else { m->splitAtDash(groups, Groups); } - globaldata->Groups = Groups; + m->Groups = Groups; string temp; temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; } @@ -146,28 +164,7 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { temp = validParameter.validFile(parameters, "jumble", false); if (temp == "not found") { temp = "T"; } if (m->isTrue(temp)) { jumble = true; } else { jumble = false; } - globaldata->jumble = jumble; - - if (abort == false) { - - string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); -// format = globaldata->getFormat(); - - - validCalculator = new ValidCalculators(); - - for (int i=0; iisValidCalculator("sharedrarefaction", Estimators[i]) == true) { - if (Estimators[i] == "sharedobserved") { - rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", ""))); - outputNames.push_back(fileNameRoot+"shared.rarefaction"); outputTypes["sharedrarefaction"].push_back(fileNameRoot+"shared.rarefaction"); - }else if (Estimators[i] == "sharednseqs") { - rDisplays.push_back(new RareDisplay(new SharedNSeqs(), new SharedThreeColumnFile(fileNameRoot+"shared.r_nseqs", ""))); - outputNames.push_back(fileNameRoot+"shared.r_nseqs"); outputTypes["sharedr_nseqs"].push_back(fileNameRoot+"shared.r_nseqs"); - } - } - } - } + m->jumble = jumble; } @@ -177,59 +174,39 @@ RareFactSharedCommand::RareFactSharedCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void RareFactSharedCommand::help(){ - try { - m->mothurOut("The rarefaction.shared command can only be executed after a successful read.otu command.\n"); - m->mothurOut("The rarefaction.shared command parameters are label, iters, groups, jumble and calc. No parameters are required.\n"); - m->mothurOut("The rarefaction command should be in the following format: \n"); - m->mothurOut("rarefaction.shared(label=yourLabel, iters=yourIters, calc=yourEstimators, jumble=yourJumble, groups=yourGroups).\n"); - m->mothurOut("The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n"); - m->mothurOut("Example rarefaction.shared(label=unique-0.01-0.03, iters=10000, groups=B-C, jumble=T, calc=sharedobserved).\n"); - m->mothurOut("The default values for iters is 1000, freq is 100, and calc is sharedobserved which calculates the shared rarefaction curve for the observed richness.\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and jumble is true.\n"); - validCalculator->printCalc("sharedrarefaction", cout); - m->mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "RareFactSharedCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -RareFactSharedCommand::~RareFactSharedCommand(){ - if (abort == false) { - delete input; globaldata->ginput = NULL; - delete read; - delete validCalculator; - } -} - //********************************************************************************************************************** int RareFactSharedCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } + + string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(sharedfile)); + + ValidCalculators validCalculator; + + for (int i=0; iinputFileName); - read->read(&*globaldata); - input = globaldata->ginput; + input = new InputData(sharedfile, "sharedfile"); lookup = input->getSharedRAbundVectors(); string lastLabel = lookup[0]->getLabel(); if (m->control_pressed) { - globaldata->Groups.clear(); + m->Groups.clear(); + delete input; for(int i=0;icontrol_pressed) { - globaldata->Groups.clear(); + m->Groups.clear(); + delete input; for(int i=0;icontrol_pressed) { - globaldata->Groups.clear(); - for(int i=0;iGroups.clear(); + delete input; + for(int i=0;icontrol_pressed) { - globaldata->Groups.clear(); - for(int i=0;iGroups.clear(); + delete input; + for(int i=0;iGroups.clear(); + delete input; - //reset groups parameter - globaldata->Groups.clear(); - - if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } - return 0; - } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); diff --git a/rarefactsharedcommand.h b/rarefactsharedcommand.h index ee16221..8219e61 100644 --- a/rarefactsharedcommand.h +++ b/rarefactsharedcommand.h @@ -13,30 +13,28 @@ #include "inputdata.h" #include "rarefact.h" #include "display.h" -#include "readotu.h" #include "validcalculator.h" -class GlobalData; - class RareFactSharedCommand : public Command { public: RareFactSharedCommand(string); RareFactSharedCommand(); - ~RareFactSharedCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~RareFactSharedCommand() {} + + vector setParameters(); + string getCommandName() { return "rarefaction.shared"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; - ReadOTUFile* read; + vector lookup; InputData* input; - ValidCalculators* validCalculator; Rarefact* rCurve; vector rDisplays; int nIters; @@ -45,10 +43,8 @@ private: bool abort, allLines, jumble; set labels; //holds labels to be used - string label, calc, groups, outputDir; + string label, calc, groups, outputDir, sharedfile; vector Estimators, Groups, outputNames; - map > outputTypes; - }; diff --git a/readcluster.cpp b/readcluster.cpp index 205581c..025d718 100644 --- a/readcluster.cpp +++ b/readcluster.cpp @@ -12,7 +12,6 @@ /***********************************************************************/ ReadCluster::ReadCluster(string distfile, float c, string o, bool s){ - globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); distFile = distfile; cutoff = c; @@ -183,7 +182,6 @@ int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ for(int i=0;ipush_back(matrixNames[i]); } - globaldata->nameMap = nameMap; } diff --git a/readcluster.h b/readcluster.h index 9ca2a1b..e4d3e4c 100644 --- a/readcluster.h +++ b/readcluster.h @@ -29,7 +29,6 @@ public: ListVector* getListVector() { return list; } private: - GlobalData* globaldata; string distFile, outputDir; string OutPutFile, format; ListVector* list; diff --git a/readcolumn.cpp b/readcolumn.cpp index 2782bd0..f6f26d5 100644 --- a/readcolumn.cpp +++ b/readcolumn.cpp @@ -15,8 +15,16 @@ ReadColumnMatrix::ReadColumnMatrix(string df) : distFile(df){ successOpen = m->openInputFile(distFile, fileHandle); + sim = false; } +/***********************************************************************/ + +ReadColumnMatrix::ReadColumnMatrix(string df, bool s) : distFile(df){ + + successOpen = m->openInputFile(distFile, fileHandle); + sim = s; +} /***********************************************************************/ @@ -56,7 +64,7 @@ int ReadColumnMatrix::read(NameAssignment* nameMap){ //if (((itA->second == 8) && (itB->second == 1588)) || ((itA->second == 1588) && (itB->second == 8))) { cout << "found it" << endl; } if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(distance < cutoff && itA != itB){ if(itA->second > itB->second){ @@ -117,7 +125,7 @@ int ReadColumnMatrix::read(NameAssignment* nameMap){ } if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(distance < cutoff && itA->second > itB->second){ PCell value(itA->second, itB->second, distance); diff --git a/readcolumn.h b/readcolumn.h index 5e718af..415bef2 100644 --- a/readcolumn.h +++ b/readcolumn.h @@ -17,6 +17,7 @@ class ReadColumnMatrix : public ReadMatrix { public: ReadColumnMatrix(string); + ReadColumnMatrix(string, bool); ~ReadColumnMatrix(); int read(NameAssignment*); private: diff --git a/readdistcommand.cpp b/readdistcommand.cpp index 630f649..d3cbbb1 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -12,52 +12,16 @@ #include "readcolumn.h" #include "readmatrix.hpp" -//********************************************************************************************************************** -vector ReadDistCommand::getValidParameters(){ - try { - string Array[] = {"phylip", "column", "name", "cutoff", "precision", "group","outputdir","inputdir","sim"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ReadDistCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ReadDistCommand::getRequiredParameters(){ - try { - string Array[] = {"phylip","column","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ReadDistCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ReadDistCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ReadDistCommand", "getRequiredFiles"); - exit(1); - } -} //********************************************************************************************************************** ReadDistCommand::ReadDistCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command + /*//valid paramters for this command string Array[] = {"phylip", "column", "name", "cutoff", "precision", "group","outputdir","inputdir","sim"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); @@ -193,7 +157,7 @@ ReadDistCommand::ReadDistCommand(string option) { } } } - +*/ } } @@ -202,45 +166,13 @@ ReadDistCommand::ReadDistCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ReadDistCommand::help(){ - try { - m->mothurOut("The read.dist command parameter options are phylip or column, group, name, sim, cutoff and precision\n"); - m->mothurOut("The read.dist command can be used in two ways. The first is to read a phylip or column and run the cluster command\n"); - m->mothurOut("For this use the read.dist command should be in the following format: \n"); - m->mothurOut("read.dist(phylip=yourDistFile, name=yourNameFile, cutoff=yourCutoff, precision=yourPrecision) \n"); - m->mothurOut("The phylip or column parameter is required, but only one may be used. If you use a column file the name filename is required. \n"); - m->mothurOut("The sim parameter is used to indicate that your distance file contains similarity values instead of distance values. The default is false, if sim=true then mothur will convert the similarity values to distances. \n"); - m->mothurOut("If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.\n"); - m->mothurOut("The second way to use the read.dist command is to read a phylip or column and a group, so you can use the libshuff command.\n"); - m->mothurOut("For this use the read.dist command should be in the following format: \n"); - m->mothurOut("read.dist(phylip=yourPhylipfile, group=yourGroupFile). The cutoff and precision parameters are not valid with this use. \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. phylip), '=' and parameters (i.e.yourPhylipfile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ReadDistCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -ReadDistCommand::~ReadDistCommand(){ - if (abort == false) { - if (format != "matrix") { - delete read; - delete nameMap; - } - } -} - //********************************************************************************************************************** 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; @@ -314,6 +246,7 @@ int ReadDistCommand::execute(){ } m->mothurOut("It took " + toString(time(NULL) - start) + " secs to read "); m->mothurOutEndLine(); + */ return 0; } diff --git a/readdistcommand.h b/readdistcommand.h index 2f05ddb..8c248cd 100644 --- a/readdistcommand.h +++ b/readdistcommand.h @@ -21,23 +21,22 @@ namefile=yourNameFile, cutoff=yourCutoff, precision=yourPrecision). The phylipfi 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 GlobalData; - class ReadDistCommand : public Command { public: ReadDistCommand(string); ReadDistCommand() { abort = true; calledHelp = true; } - ~ReadDistCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~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."; } + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; double cutoff; int precision; ReadMatrix* read; @@ -47,7 +46,6 @@ private: string phylipfile, columnfile, namefile, groupfile, outputDir; NameAssignment* nameMap; vector outputNames; - map > outputTypes; bool abort, sim; diff --git a/readmatrix.hpp b/readmatrix.hpp index 31a4da4..49ae294 100644 --- a/readmatrix.hpp +++ b/readmatrix.hpp @@ -14,14 +14,13 @@ #include "listvector.hpp" #include "sparsematrix.hpp" #include "nameassignment.hpp" -#include "globaldata.hpp" class SparseMatrix; class ReadMatrix { public: - ReadMatrix(){ D = new SparseMatrix(); m = MothurOut::getInstance(); globaldata = GlobalData::getInstance(); } + ReadMatrix(){ D = new SparseMatrix(); m = MothurOut::getInstance(); } virtual ~ReadMatrix() {} virtual int read(NameAssignment*){ return 1; } @@ -35,7 +34,6 @@ public: protected: SparseMatrix* D; ListVector* list; - GlobalData* globaldata; float cutoff; MothurOut* m; bool sim; diff --git a/readotu.cpp b/readotu.cpp index 00448f8..5cb52bb 100644 --- a/readotu.cpp +++ b/readotu.cpp @@ -9,14 +9,14 @@ #include "readotu.h" -/***********************************************************************/ +/*********************************************************************** ReadOTUFile::ReadOTUFile(string pf): philFile(pf){ m = MothurOut::getInstance(); //m->openInputFile(philFile, fileHandle); } -/***********************************************************************/ +/*********************************************************************** //This function reads the list, rabund or sabund files to be used by collect and rarefact command. void ReadOTUFile::read(GlobalData* globaldata){ try { @@ -75,7 +75,7 @@ void ReadOTUFile::read(GlobalData* globaldata){ } } -/***********************************************************************/ +/*********************************************************************** ReadOTUFile::~ReadOTUFile(){ // delete input; diff --git a/readotu.h b/readotu.h index 6c8d67c..c2dcb99 100644 --- a/readotu.h +++ b/readotu.h @@ -9,7 +9,7 @@ * */ - +/* #include "rabundvector.hpp" #include "listvector.hpp" @@ -43,5 +43,5 @@ private: // InputData* getInput() { return input; } }; - +*/ #endif diff --git a/readotucommand.cpp b/readotucommand.cpp index 3d0b94d..19c936e 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -9,22 +9,12 @@ #include "readotucommand.h" -//********************************************************************************************************************** -vector ReadOtuCommand::getValidParameters(){ - try { - string Array[] = {"list","order","shared","relabund","label","group","sabund", "rabund","groups","ordergroup","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ReadOtuCommand", "getValidParameters"); - exit(1); - } -} + //********************************************************************************************************************** ReadOtuCommand::ReadOtuCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["rabund"] = tempOutNames; outputTypes["shared"] = tempOutNames; @@ -35,32 +25,8 @@ ReadOtuCommand::ReadOtuCommand(){ } } //********************************************************************************************************************** -vector ReadOtuCommand::getRequiredParameters(){ - try { - string Array[] = {"list","shared","relabund","sabund","rabund","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ChopSeqsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ReadOtuCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ReadOtuCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** ReadOtuCommand::ReadOtuCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; @@ -68,6 +34,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { if(option == "help") { help(); 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))); @@ -246,6 +213,7 @@ ReadOtuCommand::ReadOtuCommand(string option) { //gets whichever one of the above is set filename = globaldata->inputFileName; } + */ } } @@ -254,43 +222,15 @@ ReadOtuCommand::ReadOtuCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ReadOtuCommand::help(){ - try { - m->mothurOut("The read.otu command must be run before you execute a collect.single, rarefaction.single, summary.single, \n"); - m->mothurOut("collect.shared, rarefaction.shared, summary.shared heatmap.bin, heatmap.sim or venn command. Mothur will generate a .list, .rabund and .sabund upon completion of the cluster command \n"); - m->mothurOut("or you may use your own. The read.otu command parameter options are list, rabund, sabund, shared, relabund, group, order, ordergroup, label and groups.\n"); - m->mothurOut("The read.otu command can be used in two ways. The first is to read a list, rabund or sabund and run the collect.single, rarefaction.single or summary.single.\n"); - m->mothurOut("For this use the read.otu command should be in the following format: read.otu(list=yourListFile, order=yourOrderFile, label=yourLabels).\n"); - m->mothurOut("The list, rabund or sabund parameter is required, but you may only use one of them.\n"); - m->mothurOut("The label parameter is used to read specific labels in your input.\n"); - m->mothurOut("The second way to use the read.otu command is to read a list and a group, or a shared so you can use the collect.shared, rarefaction.shared or summary.shared commands.\n"); - m->mothurOut("In this case the read.otu command should be in the following format: read.otu(list=yourListFile, group=yourGroupFile) or read.otu(shared=yourSharedFile). \n"); - m->mothurOut("The list parameter and group paramaters or the shared paremeter is required. When using the command the second way with a list and group file read.otu command parses the .list file\n"); - m->mothurOut("and separates it into groups. It outputs a .shared file containing the OTU information for each group. The read.otu command also outputs a .rabund file for each group. \n"); - m->mothurOut("You can use the groups parameter to choose only specific groups to be used in the .shared and .rabund files. \n"); - m->mothurOut("You can use the ordergroup parameter to provide a file containing a list of group names in the order you would like them to appear in your shared file. \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "ReadOtuCommand", "help"); - exit(1); - } -} - - - -//********************************************************************************************************************** -ReadOtuCommand::~ReadOtuCommand(){} -//********************************************************************************************************************** +///********************************************************************************************************************** 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); @@ -324,7 +264,7 @@ int ReadOtuCommand::execute(){ delete shared; } - + */ return 0; } diff --git a/readotucommand.h b/readotucommand.h index eb0ca8f..d1dc5b7 100644 --- a/readotucommand.h +++ b/readotucommand.h @@ -15,22 +15,21 @@ #include "groupmap.h" #include "sharedcommand.h" -class GlobalData; - class ReadOtuCommand : public Command { public: ReadOtuCommand(string); ReadOtuCommand(); - ~ReadOtuCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~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."; } + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; InputData* input; Command* shared; GroupMap* groupMap; diff --git a/readphylip.cpp b/readphylip.cpp index 130decc..b13dc25 100644 --- a/readphylip.cpp +++ b/readphylip.cpp @@ -15,8 +15,17 @@ ReadPhylipMatrix::ReadPhylipMatrix(string distFile){ successOpen = m->openInputFile(distFile, fileHandle); + sim=false; } +/***********************************************************************/ + +ReadPhylipMatrix::ReadPhylipMatrix(string distFile, bool s){ + + successOpen = m->openInputFile(distFile, fileHandle); + sim=s; +} + /***********************************************************************/ @@ -85,7 +94,7 @@ int ReadPhylipMatrix::read(NameAssignment* nameMap){ if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(distance < cutoff){ PCell value(i, j, distance); @@ -105,7 +114,7 @@ int ReadPhylipMatrix::read(NameAssignment* nameMap){ if (m->control_pressed) { delete reading; fileHandle.close(); return 0; } if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(distance < cutoff){ PCell value(nameMap->get(matrixNames[i]), nameMap->get(matrixNames[j]), distance); @@ -137,7 +146,7 @@ int ReadPhylipMatrix::read(NameAssignment* nameMap){ if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(distance < cutoff && j < i){ PCell value(i, j, distance); @@ -157,7 +166,7 @@ int ReadPhylipMatrix::read(NameAssignment* nameMap){ if (m->control_pressed) { fileHandle.close(); delete reading; return 0; } if (distance == -1) { distance = 1000000; } - else if (globaldata->sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. + else if (sim) { distance = 1.0 - distance; } //user has entered a sim matrix that we need to convert. if(distance < cutoff && j < i){ PCell value(nameMap->get(matrixNames[i]), nameMap->get(matrixNames[j]), distance); diff --git a/readphylip.h b/readphylip.h index 3e5e749..244cc47 100644 --- a/readphylip.h +++ b/readphylip.h @@ -17,6 +17,7 @@ class ReadPhylipMatrix : public ReadMatrix { public: ReadPhylipMatrix(string); + ReadPhylipMatrix(string, bool); ~ReadPhylipMatrix(); int read(NameAssignment*); private: diff --git a/readtree.cpp b/readtree.cpp index 308115d..be7dc79 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -12,9 +12,7 @@ /***********************************************************************/ ReadTree::ReadTree() { try { - globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); - globaldata->gTree.clear(); } catch(exception& e) { m->errorOut(e, "ReadTree", "ReadTree"); @@ -22,6 +20,21 @@ ReadTree::ReadTree() { } } /***********************************************************************/ +int ReadTree::AssembleTrees() { + try { + //assemble users trees + for (int i = 0; i < Trees.size(); i++) { + if (m->control_pressed) { return 0; } + Trees[i]->assembleTree(); + } + return 0; + } + catch(exception& e) { + m->errorOut(e, "ReadTree", "AssembleTrees"); + exit(1); + } +} +/***********************************************************************/ int ReadTree::readSpecialChar(istream& f, char c, string name) { try { @@ -94,7 +107,7 @@ float ReadTree::readBranchLength(istream& f) { /***********************************************************************/ //This class reads a file in Newick form and stores it in a tree. -int ReadNewickTree::read() { +int ReadNewickTree::read(TreeMap* tmap) { try { holder = ""; int c, error; @@ -116,23 +129,23 @@ int ReadNewickTree::read() { } //make new tree - T = new Tree(); + T = new Tree(tmap); numNodes = T->getNumNodes(); numLeaves = T->getNumLeaves(); - error = readTreeString(); + error = readTreeString(tmap); //save trees for later commands - globaldata->gTree.push_back(T); + Trees.push_back(T); m->gobble(filehandle); } //if you are a nexus file }else if ((c = filehandle.peek()) == '#') { //get right number of seqs from nexus file. - Tree* temp = new Tree(); delete temp; + Tree* temp = new Tree(tmap); delete temp; - nexusTranslation(); //reads file through the translation and updates treemap + nexusTranslation(tmap); //reads file through the translation and updates treemap while((c = filehandle.peek()) != EOF) { // get past comments while ((c = filehandle.peek()) != EOF) { @@ -153,15 +166,15 @@ int ReadNewickTree::read() { filehandle.putback(c); //put back first ( of tree. //make new tree - T = new Tree(); + T = new Tree(tmap); numNodes = T->getNumNodes(); numLeaves = T->getNumLeaves(); //read tree info - error = readTreeString(); + error = readTreeString(tmap); //save trees for later commands - globaldata->gTree.push_back(T); + Trees.push_back(T); } } @@ -178,11 +191,11 @@ int ReadNewickTree::read() { } /**************************************************************************************************/ //This function read the file through the translation of the sequences names and updates treemap. -string ReadNewickTree::nexusTranslation() { +string ReadNewickTree::nexusTranslation(TreeMap* tmap) { try { holder = ""; - int numSeqs = globaldata->Treenames.size(); //must save this some when we clear old names we can still know how many sequences there were + int numSeqs = m->Treenames.size(); //must save this some when we clear old names we can still know how many sequences there were int comment = 0; // get past comments @@ -198,7 +211,7 @@ string ReadNewickTree::nexusTranslation() { } //update treemap - globaldata->gTreemap->namesOfSeqs.clear(); + tmap->namesOfSeqs.clear(); /*char c; string number, name; @@ -226,12 +239,12 @@ string ReadNewickTree::nexusTranslation() { name.erase(name.end()-1); //erase the comma //insert new one with new name - string group = globaldata->gTreemap->getGroup(name); - globaldata->gTreemap->treemap[toString(number)].groupname = group; - globaldata->gTreemap->treemap[toString(number)].vectorIndex = globaldata->gTreemap->getIndex(name); + string group = tmap->getGroup(name); + tmap->treemap[toString(number)].groupname = group; + tmap->treemap[toString(number)].vectorIndex = tmap->getIndex(name); //erase old one. so treemap[sarah].groupnumber is now treemap[1].groupnumber. if number is 1 and name is sarah. - globaldata->gTreemap->treemap.erase(name); - globaldata->gTreemap->namesOfSeqs.push_back(number); + tmap->treemap.erase(name); + tmap->namesOfSeqs.push_back(number); } return name; @@ -243,7 +256,7 @@ string ReadNewickTree::nexusTranslation() { } /**************************************************************************************************/ -int ReadNewickTree::readTreeString() { +int ReadNewickTree::readTreeString(TreeMap* tmap) { try { int n = 0; @@ -256,7 +269,7 @@ int ReadNewickTree::readTreeString() { if(ch == '('){ n = numLeaves; //number of leaves / sequences, we want node 1 to start where the leaves left off - lc = readNewickInt(filehandle, n, T); + lc = readNewickInt(filehandle, n, T, tmap); if (lc == -1) { m->mothurOut("error with lc"); m->mothurOutEndLine(); return -1; } //reports an error in reading if(filehandle.peek()==','){ @@ -268,7 +281,7 @@ int ReadNewickTree::readTreeString() { } if(rooted != 1){ - rc = readNewickInt(filehandle, n, T); + rc = readNewickInt(filehandle, n, T, tmap); if (rc == -1) { m->mothurOut("error with rc"); m->mothurOutEndLine(); return -1; } //reports an error in reading if(filehandle.peek() == ')'){ readSpecialChar(filehandle,')',"right parenthesis"); @@ -313,7 +326,7 @@ int ReadNewickTree::readTreeString() { } /**************************************************************************************************/ -int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { +int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T, TreeMap* tmap) { try { if (m->control_pressed) { return -1; } @@ -326,7 +339,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { //read all children vector childrenNodes; while(f.peek() != ')'){ - int child = readNewickInt(f, n, T); + int child = readNewickInt(f, n, T, tmap); if (child == -1) { return -1; } //reports an error in reading //cout << "child = " << child << endl; childrenNodes.push_back(child); @@ -397,7 +410,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { f.putback(d); //set group info - string group = globaldata->gTreemap->getGroup(name); + string group = tmap->getGroup(name); //find index in tree of name int n1 = T->getIndex(name); @@ -406,16 +419,16 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { if(group == "not found") { m->mothurOut("Name: " + name + " is not in your groupfile, and will be disregarded. \n"); //readOk = -1; return n1; - globaldata->gTreemap->namesOfSeqs.push_back(name); - globaldata->gTreemap->treemap[name].groupname = "xxx"; + tmap->namesOfSeqs.push_back(name); + tmap->treemap[name].groupname = "xxx"; map::iterator it; - it = globaldata->gTreemap->seqsPerGroup.find("xxx"); - if (it == globaldata->gTreemap->seqsPerGroup.end()) { //its a new group - globaldata->gTreemap->namesOfGroups.push_back("xxx"); - globaldata->gTreemap->seqsPerGroup["xxx"] = 1; + it = tmap->seqsPerGroup.find("xxx"); + if (it == tmap->seqsPerGroup.end()) { //its a new group + tmap->namesOfGroups.push_back("xxx"); + tmap->seqsPerGroup["xxx"] = 1; }else { - globaldata->gTreemap->seqsPerGroup["xxx"]++; + tmap->seqsPerGroup["xxx"]++; } group = "xxx"; diff --git a/readtree.h b/readtree.h index 7cfb4b4..b5b26ed 100644 --- a/readtree.h +++ b/readtree.h @@ -10,7 +10,6 @@ */ #include "mothur.h" -#include "globaldata.hpp" #include "tree.h" #define MAX_LINE 513 @@ -25,13 +24,17 @@ class ReadTree { ReadTree(); virtual ~ReadTree() {}; - virtual int read() = 0; + virtual int read(TreeMap*) = 0; int readSpecialChar(istream&, char, string); int readNodeChar(istream& f); float readBranchLength(istream& f); + + vector getTrees() { return Trees; } + int AssembleTrees(); protected: - GlobalData* globaldata; + vector Trees; + TreeMap* treeMap; int numNodes, numLeaves; MothurOut* m; @@ -45,13 +48,13 @@ class ReadNewickTree : public ReadTree { public: ReadNewickTree(string file) : treeFile(file) { m->openInputFile(file, filehandle); readOk = 0; } ~ReadNewickTree() {}; - int read(); + int read(TreeMap*); private: Tree* T; - int readNewickInt(istream&, int&, Tree*); - int readTreeString(); - string nexusTranslation(); + int readNewickInt(istream&, int&, Tree*, TreeMap*); + int readTreeString(TreeMap*); + string nexusTranslation(TreeMap*); ifstream filehandle; string treeFile; string holder; diff --git a/readtreecommand.cpp b/readtreecommand.cpp index 05a65b7..c476f5a 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -9,51 +9,17 @@ #include "readtreecommand.h" -//********************************************************************************************************************** -vector ReadTreeCommand::getValidParameters(){ - try { - string Array[] = {"tree","group","name","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ReadTreeCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ReadTreeCommand::getRequiredParameters(){ - try { - string Array[] = {"tree"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ReadTreeCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ReadTreeCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ReadTreeCommand", "getRequiredFiles"); - exit(1); - } -} + //********************************************************************************************************************** ReadTreeCommand::ReadTreeCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; //allow user to run help if(option == "help") { help(); 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))); @@ -107,7 +73,6 @@ ReadTreeCommand::ReadTreeCommand(string option) { 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; } - else { globaldata->setTreeFile(treefile); globaldata->setFormat("tree"); } groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } @@ -118,18 +83,14 @@ ReadTreeCommand::ReadTreeCommand(string option) { if (treefile != "") { Tree* tree = new Tree(treefile); delete tree; } //extracts names from tree to make faked out groupmap - globaldata->setGroupFile(groupfile); //read in group map info. treeMap = new TreeMap(); - for (int i = 0; i < globaldata->Treenames.size(); i++) { treeMap->addSeq(globaldata->Treenames[i], "Group1"); } - globaldata->gTreemap = treeMap; + for (int i = 0; i < m->Treenames.size(); i++) { treeMap->addSeq(m->Treenames[i], "Group1"); } }else { - globaldata->setGroupFile(groupfile); //read in group map info. treeMap = new TreeMap(groupfile); treeMap->readMap(); - globaldata->gTreemap = treeMap; } namefile = validParameter.validFile(parameters, "name", true); @@ -141,7 +102,7 @@ ReadTreeCommand::ReadTreeCommand(string option) { filename = treefile; read = new ReadNewickTree(filename); } - + */ } } catch(exception& e) { @@ -151,42 +112,19 @@ ReadTreeCommand::ReadTreeCommand(string option) { } //********************************************************************************************************************** -void ReadTreeCommand::help(){ - try { - m->mothurOut("The read.tree command must be run before you execute a unifrac.weighted, unifrac.unweighted. \n"); - m->mothurOut("It also must be run before using the parsimony command, unless you are using the randomtree parameter.\n"); - m->mothurOut("The read.tree command parameters are tree, group and name.\n"); - m->mothurOut("The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile).\n"); - m->mothurOut("The tree and group parameters are both required, if no group file is given then one group is assumed.\n"); - m->mothurOut("The name parameter allows you to enter a namefile.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "ReadTreeCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -ReadTreeCommand::~ReadTreeCommand(){ - if (abort == false) { delete read; } -} - -//********************************************************************************************************************** - int ReadTreeCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - + m->mothurOut(getHelpString()); m->mothurOutEndLine(); + /* int readOk; - readOk = read->read(); + readOk = read->read(treeMap); if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; } - vector T = globaldata->gTree; + vector T = read->gTree; //assemble users trees for (int i = 0; i < T.size(); i++) { @@ -241,7 +179,7 @@ int ReadTreeCommand::execute(){ globaldata->gTreemap = treeMap; } - + */ return 0; } catch(exception& e) { @@ -252,7 +190,8 @@ int ReadTreeCommand::execute(){ /*****************************************************************/ int ReadTreeCommand::readNamesFile() { try { - globaldata->names.clear(); + /* + m->names.clear(); numUniquesInName = 0; ifstream in; @@ -266,7 +205,7 @@ int ReadTreeCommand::readNamesFile() { numUniquesInName++; - itNames = globaldata->names.find(first); + itNames = m->names.find(first); if (itNames == globaldata->names.end()) { globaldata->names[first] = second; @@ -278,7 +217,7 @@ int ReadTreeCommand::readNamesFile() { }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) { diff --git a/readtreecommand.h b/readtreecommand.h index 464a825..25e0825 100644 --- a/readtreecommand.h +++ b/readtreecommand.h @@ -14,29 +14,28 @@ #include "readtree.h" #include "treemap.h" -class GlobalData; class ReadTreeCommand : public Command { public: ReadTreeCommand(string); ReadTreeCommand() { abort = true; calledHelp = true; } - ~ReadTreeCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~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."; } + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; ReadTree* read; TreeMap* treeMap; string filename, treefile, groupfile, namefile; bool abort; map nameMap; vector outputNames; - map > outputTypes; int readNamesFile(); int numUniquesInName; diff --git a/removegroupscommand.cpp b/removegroupscommand.cpp index b70b679..76dc630 100644 --- a/removegroupscommand.cpp +++ b/removegroupscommand.cpp @@ -13,21 +13,53 @@ #include "sharedutilities.h" //********************************************************************************************************************** -vector RemoveGroupsCommand::getValidParameters(){ +vector RemoveGroupsCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "accnos", "groups","list","taxonomy","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "RemoveGroupsCommand", "getValidParameters"); + m->errorOut(e, "RemoveGroupsCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string RemoveGroupsCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The remove.groups command removes sequences from a specfic group or set of groups from the following file types: fasta, name, group, list, taxonomy.\n"; + helpString += "It outputs a file containing the sequences NOT in the those specified groups.\n"; + helpString += "The remove.groups command parameters are accnos, fasta, name, group, list, taxonomy and groups. The group parameter is required, unless you have a current group file.\n"; + helpString += "You must also provide an accnos containing the list of groups to remove or set the groups parameter to the groups you wish to remove.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like removed. You can separate group names with dashes.\n"; + helpString += "The remove.groups command should be in the following format: remove.groups(accnos=yourAccnos, fasta=yourFasta, group=yourGroupFile).\n"; + helpString += "Example remove.groups(accnos=amazon.accnos, fasta=amazon.fasta, group=amazon.groups).\n"; + helpString += "or remove.groups(groups=pasture, fasta=amazon.fasta, amazon.groups).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "RemoveGroupsCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** RemoveGroupsCommand::RemoveGroupsCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["taxonomy"] = tempOutNames; @@ -41,29 +73,6 @@ RemoveGroupsCommand::RemoveGroupsCommand(){ } } //********************************************************************************************************************** -vector RemoveGroupsCommand::getRequiredParameters(){ - try { - string Array[] = {"group"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveGroupsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector RemoveGroupsCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveGroupsCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** RemoveGroupsCommand::RemoveGroupsCommand(string option) { try { abort = false; calledHelp = false; @@ -72,9 +81,7 @@ RemoveGroupsCommand::RemoveGroupsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name", "group", "accnos", "groups", "list","taxonomy","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -169,7 +176,12 @@ RemoveGroupsCommand::RemoveGroupsCommand(string option) { groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; m->mothurOut("You must provide a group file."); m->mothurOutEndLine(); abort = true; } + else if (groupfile == "not found") { + //if there is a current group file, use it + groupfile = m->getGroupFile(); + if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current groupfile and the group parameter is required."); m->mothurOutEndLine(); abort = true; } + } listfile = validParameter.validFile(parameters, "list", true); if (listfile == "not open") { abort = true; } @@ -198,26 +210,6 @@ RemoveGroupsCommand::RemoveGroupsCommand(string option) { } //********************************************************************************************************************** -void RemoveGroupsCommand::help(){ - try { - m->mothurOut("The remove.groups command removes sequences from a specfic group or set of groups from the following file types: fasta, name, group, list, taxonomy.\n"); - m->mothurOut("It outputs a file containing the sequences NOT in the those specified groups.\n"); - m->mothurOut("The remove.groups command parameters are accnos, fasta, name, group, list, taxonomy and groups. The group parameter is required.\n"); - m->mothurOut("You must also provide an accnos containing the list of groups to remove or set the groups parameter to the groups you wish to remove.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like removed. You can separate group names with dashes.\n"); - m->mothurOut("The remove.groups command should be in the following format: remove.groups(accnos=yourAccnos, fasta=yourFasta, group=yourGroupFile).\n"); - m->mothurOut("Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta, group=amazon.groups).\n"); - m->mothurOut("or remove.seqs(groups=pasture, fasta=amazon.fasta, amazon.groups).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "RemoveGroupsCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int RemoveGroupsCommand::execute(){ try { diff --git a/removegroupscommand.h b/removegroupscommand.h index 896697a..955d94d 100644 --- a/removegroupscommand.h +++ b/removegroupscommand.h @@ -21,19 +21,21 @@ public: RemoveGroupsCommand(string); RemoveGroupsCommand(); ~RemoveGroupsCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "remove.groups"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: set names; string accnosfile, fastafile, namefile, groupfile, listfile, taxfile, outputDir, groups; bool abort; vector outputNames, Groups; - map > outputTypes; GroupMap* groupMap; int readFasta(); diff --git a/removelineagecommand.cpp b/removelineagecommand.cpp index ebd0608..021b56c 100644 --- a/removelineagecommand.cpp +++ b/removelineagecommand.cpp @@ -12,21 +12,58 @@ #include "listvector.hpp" //********************************************************************************************************************** -vector RemoveLineageCommand::getValidParameters(){ +vector RemoveLineageCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "alignreport", "taxon", "dups", "list","taxonomy","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport); + CommandParameter ptaxon("taxon", "String", "", "", "", "", "",false,true); parameters.push_back(ptaxon); + CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "RemoveLineageCommand", "getValidParameters"); + m->errorOut(e, "RemoveLineageCommand", "setParameters"); exit(1); } } +//********************************************************************************************************************** +string RemoveLineageCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The remove.lineage command reads a taxonomy file and any of the following file types: fasta, name, group, list or alignreport file.\n"; + helpString += "It outputs a file containing only the sequences from the taxonomy file that are not from the taxon you requested to be removed.\n"; + helpString += "The remove.lineage command parameters are taxon, fasta, name, group, list, taxonomy, alignreport and dups. You must provide taxonomy unless you have a valid current taxonomy file.\n"; + helpString += "The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n"; + helpString += "The taxon parameter allows you to select the taxons you would like to remove, and is required.\n"; + helpString += "You may enter your taxons with confidence scores, doing so will remove only those sequences that belong to the taxonomy and whose cofidence scores fall below the scores you give.\n"; + helpString += "If they belong to the taxonomy and have confidences above those you provide the sequence will not be removed.\n"; + helpString += "The remove.lineage command should be in the following format: remove.lineage(taxonomy=yourTaxonomyFile, taxon=yourTaxons).\n"; + helpString += "Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon=Bacteria;Firmicutes;Bacilli;Lactobacillales;).\n"; + helpString += "Note: If you are running mothur in script mode you must wrap the taxon in ' characters so mothur will ignore the ; in the taxon.\n"; + helpString += "Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon='Bacteria;Firmicutes;Bacilli;Lactobacillales;').\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "RemoveLineageCommand", "getHelpString"); + exit(1); + } +} + + //********************************************************************************************************************** RemoveLineageCommand::RemoveLineageCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["taxonomy"] = tempOutNames; @@ -41,29 +78,6 @@ RemoveLineageCommand::RemoveLineageCommand(){ } } //********************************************************************************************************************** -vector RemoveLineageCommand::getRequiredParameters(){ - try { - string Array[] = {"taxonomy"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveLineageCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector RemoveLineageCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveLineageCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** RemoveLineageCommand::RemoveLineageCommand(string option) { try { abort = false; calledHelp = false; @@ -177,7 +191,11 @@ RemoveLineageCommand::RemoveLineageCommand(string option) { taxfile = validParameter.validFile(parameters, "taxonomy", true); if (taxfile == "not open") { abort = true; } - else if (taxfile == "not found") { taxfile = ""; m->mothurOut("The taxonomy parameter is required for the get.lineage command."); m->mothurOutEndLine(); abort = true; } + else if (taxfile == "not found") { + taxfile = m->getTaxonomyFile(); + if (taxfile != "") { m->mothurOut("Using " + taxfile + " as input file for the taxonomy parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current taxonomy file and the taxonomy parameter is required."); m->mothurOutEndLine(); abort = true; } + } string usedDups = "true"; string temp = validParameter.validFile(parameters, "dups", false); @@ -210,29 +228,6 @@ RemoveLineageCommand::RemoveLineageCommand(string option) { } //********************************************************************************************************************** -void RemoveLineageCommand::help(){ - try { - m->mothurOut("The remove.lineage command reads a taxonomy file and any of the following file types: fasta, name, group, list or alignreport file.\n"); - m->mothurOut("It outputs a file containing only the sequences from the taxonomy file that are not from the taxon you requested to be removed.\n"); - m->mothurOut("The remove.lineage command parameters are taxon, fasta, name, group, list, taxonomy, alignreport and dups. You must provide taxonomy and taxon.\n"); - m->mothurOut("The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n"); - m->mothurOut("The taxon parameter allows you to select the taxons you would like to remove.\n"); - m->mothurOut("You may enter your taxons with confidence scores, doing so will remove only those sequences that belong to the taxonomy and whose cofidence scores fall below the scores you give.\n"); - m->mothurOut("If they belong to the taxonomy and have confidences above those you provide the sequence will not be removed.\n"); - m->mothurOut("The remove.lineage command should be in the following format: remove.lineage(taxonomy=yourTaxonomyFile, taxon=yourTaxons).\n"); - m->mothurOut("Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon=Bacteria;Firmicutes;Bacilli;Lactobacillales;).\n"); - m->mothurOut("Note: If you are running mothur in script mode you must wrap the taxon in ' characters so mothur will ignore the ; in the taxon.\n"); - m->mothurOut("Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon='Bacteria;Firmicutes;Bacilli;Lactobacillales;').\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "RemoveLineageCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int RemoveLineageCommand::execute(){ try { diff --git a/removelineagecommand.h b/removelineagecommand.h index 02a4440..9fdca48 100644 --- a/removelineagecommand.h +++ b/removelineagecommand.h @@ -19,17 +19,18 @@ class RemoveLineageCommand : public Command { RemoveLineageCommand(string); RemoveLineageCommand(); ~RemoveLineageCommand(){}; - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + + vector setParameters(); + string getCommandName() { return "remove.lineage"; } + string getCommandCategory() { return "Phylotype Analysis"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: set names; vector outputNames; - map > outputTypes; string fastafile, namefile, groupfile, alignfile, listfile, taxfile, outputDir, taxons; bool abort, dups; diff --git a/removeotuscommand.cpp b/removeotuscommand.cpp index f1ef4ac..d1c12c8 100644 --- a/removeotuscommand.cpp +++ b/removeotuscommand.cpp @@ -11,55 +11,63 @@ #include "inputdata.h" #include "sharedutilities.h" - //********************************************************************************************************************** -vector RemoveOtusCommand::getValidParameters(){ +vector RemoveOtusCommand::setParameters(){ try { - string Array[] = { "group", "accnos","label", "groups","list","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "RemoveOtusCommand", "getValidParameters"); + m->errorOut(e, "RemoveOtusCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -RemoveOtusCommand::RemoveOtusCommand(){ +string RemoveOtusCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["group"] = tempOutNames; - outputTypes["list"] = tempOutNames; + string helpString = ""; + helpString += "The remove.otus command removes otus containing sequences from a specfic group or set of groups.\n"; + helpString += "It outputs a new list file containing the otus containing sequences NOT from in the those specified groups.\n"; + helpString += "The remove.otus command parameters are accnos, group, list, label and groups. The group and list parameters are required, unless you have valid current files.\n"; + helpString += "You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n"; + helpString += "The label parameter allows you to specify which distance you want to process.\n"; + helpString += "The remove.otus command should be in the following format: remove.otus(accnos=yourAccnos, list=yourListFile, group=yourGroupFile, label=yourLabel).\n"; + helpString += "Example remove.otus(accnos=amazon.accnos, list=amazon.fn.list, group=amazon.groups, label=0.03).\n"; + helpString += "or remove.otus(groups=pasture, list=amazon.fn.list, amazon.groups, label=0.03).\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "RemoveOtusCommand", "RemoveOtusCommand"); + m->errorOut(e, "RemoveOtusCommand", "getHelpString"); exit(1); } } -//********************************************************************************************************************** -vector RemoveOtusCommand::getRequiredParameters(){ - try { - string Array[] = {"group","label", "list"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveOtusCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector RemoveOtusCommand::getRequiredFiles(){ + +///********************************************************************************************************************** +RemoveOtusCommand::RemoveOtusCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["group"] = tempOutNames; + outputTypes["list"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "RemoveOtusCommand", "getRequiredFiles"); + m->errorOut(e, "RemoveOtusCommand", "RemoveOtusCommand"); exit(1); } } + //********************************************************************************************************************** RemoveOtusCommand::RemoveOtusCommand(string option) { try { @@ -69,9 +77,7 @@ RemoveOtusCommand::RemoveOtusCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = { "group", "accnos","label", "groups", "list","outputdir","inputdir" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -131,11 +137,19 @@ RemoveOtusCommand::RemoveOtusCommand(string option) { groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; m->mothurOut("You must provide a group file."); m->mothurOutEndLine(); abort = true; } + else if (groupfile == "not found") { + groupfile = m->getGroupFile(); + if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current group file and the group parameter is required."); m->mothurOutEndLine(); abort = true; } + } listfile = validParameter.validFile(parameters, "list", true); if (listfile == "not open") { abort = true; } - else if (listfile == "not found") { listfile = ""; m->mothurOut("You must provide a list file."); m->mothurOutEndLine(); abort = true; } + else if (listfile == "not found") { + listfile = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; } + } groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } @@ -144,7 +158,7 @@ RemoveOtusCommand::RemoveOtusCommand(string option) { } label = validParameter.validFile(parameters, "label", false); - if (label == "not found") { label = ""; m->mothurOut("You must provide a label to process."); m->mothurOutEndLine(); abort = true; } + if (label == "not found") { label = ""; m->mothurOut("You did not provide a label, I will use the first label in your inputfile."); m->mothurOutEndLine(); label=""; } if ((accnosfile == "") && (Groups.size() == 0)) { m->mothurOut("You must provide an accnos file or specify groups using the groups parameter."); m->mothurOutEndLine(); abort = true; } } @@ -157,27 +171,6 @@ RemoveOtusCommand::RemoveOtusCommand(string option) { } //********************************************************************************************************************** -void RemoveOtusCommand::help(){ - try { - m->mothurOut("The remove.otus command removes otus containing sequences from a specfic group or set of groups.\n"); - m->mothurOut("It outputs a new list file containing the otus containing sequences NOT from in the those specified groups.\n"); - m->mothurOut("The remove.otus command parameters are accnos, group, list, label and groups. The group, list and label parameters are required.\n"); - m->mothurOut("You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n"); - m->mothurOut("The label parameter allows you to specify which distance you want to process.\n"); - m->mothurOut("The remove.otus command should be in the following format: remove.otus(accnos=yourAccnos, list=yourListFile, group=yourGroupFile, label=yourLabel).\n"); - m->mothurOut("Example remove.otus(accnos=amazon.accnos, list=amazon.fn.list, group=amazon.groups, label=0.03).\n"); - m->mothurOut("or remove.otus(groups=pasture, list=amazon.fn.list, amazon.groups, label=0.03).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "RemoveOtusCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int RemoveOtusCommand::execute(){ try { @@ -250,6 +243,9 @@ int RemoveOtusCommand::readListGroup(){ ListVector* list = input->getListVector(); string lastLabel = list->getLabel(); + //using first label seen if none is provided + if (label == "") { label = lastLabel; } + //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set labels; labels.insert(label); set processedLabels; diff --git a/removeotuscommand.h b/removeotuscommand.h index 872b2c8..801eedc 100644 --- a/removeotuscommand.h +++ b/removeotuscommand.h @@ -21,18 +21,19 @@ public: RemoveOtusCommand(string); RemoveOtusCommand(); ~RemoveOtusCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "remove.otus"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: string accnosfile, groupfile, listfile, outputDir, groups, label; bool abort; vector outputNames, Groups; - map > outputTypes; GroupMap* groupMap; void readAccnos(); diff --git a/removerarecommand.cpp b/removerarecommand.cpp index bcb9af6..41355b9 100644 --- a/removerarecommand.cpp +++ b/removerarecommand.cpp @@ -14,14 +14,47 @@ #include "inputdata.h" //********************************************************************************************************************** -vector RemoveRareCommand::getValidParameters(){ +vector RemoveRareCommand::setParameters(){ try { - string Array[] = {"rabund","sabund", "group", "list", "shared","bygroup","nseqs","groups","label","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pshared); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pnseqs("nseqs", "Number", "", "0", "", "", "",false,true); parameters.push_back(pnseqs); + CommandParameter pbygroup("bygroup", "Boolean", "", "f", "", "", "",false,true); parameters.push_back(pbygroup); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "RemoveRareCommand", "getValidParameters"); + m->errorOut(e, "RemoveRareCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string RemoveRareCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The remove.rare command parameters are list, rabund, sabund, shared, group, label, groups, bygroup and nseqs.\n"; + helpString += "The remove.rare command reads one of the following file types: list, rabund, sabund or shared file. It outputs a new file after removing the rare otus.\n"; + helpString += "The groups parameter allows you to specify which of the groups you would like analyzed. Default=all. You may separate group names with dashes.\n"; + helpString += "The label parameter is used to analyze specific labels in your input. default=all. You may separate label names with dashes.\n"; + helpString += "The bygroup parameter is only valid with the shared file. default=f, meaning remove any OTU that has nseqs or fewer sequences across all groups.\n"; + helpString += "bygroups=T means remove any OTU that has nseqs or fewer sequences in each group (if groupA has 1 sequence and group B has 100 sequences in OTUZ and nseqs=1, then set the groupA count for OTUZ to 0 and keep groupB's count at 100.) \n"; + helpString += "The nseqs parameter allows you to set the cutoff for an otu to be deemed rare. It is required.\n"; + helpString += "The remove.rare command should be in the following format: remove.rare(shared=yourSharedFile, nseqs=yourRareCutoff).\n"; + helpString += "Example remove.rare(shared=amazon.fn.shared, nseqs=2).\n"; + helpString += "Note: No spaces between parameter labels (i.e. shared), '=' and parameters (i.e.yourSharedFile).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "RemoveRareCommand", "getHelpString"); exit(1); } } @@ -29,6 +62,7 @@ vector RemoveRareCommand::getValidParameters(){ RemoveRareCommand::RemoveRareCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["rabund"] = tempOutNames; outputTypes["sabund"] = tempOutNames; @@ -42,32 +76,8 @@ RemoveRareCommand::RemoveRareCommand(){ } } //********************************************************************************************************************** -vector RemoveRareCommand::getRequiredParameters(){ - try { - string Array[] = {"nseqs"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveRareCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector RemoveRareCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveRareCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** RemoveRareCommand::RemoveRareCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; @@ -75,9 +85,7 @@ RemoveRareCommand::RemoveRareCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"rabund","sabund", "group", "list", "shared", "bygroup", "nseqs","groups","label","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -169,7 +177,29 @@ RemoveRareCommand::RemoveRareCommand(string option) { if (sharedfile == "not open") { sharedfile = ""; abort = true; } else if (sharedfile == "not found") { sharedfile = ""; } - if ((sabundfile == "") && (rabundfile == "") && (sharedfile == "") && (listfile == "")) { m->mothurOut("You must provide at least one of the following: rabund, sabund, shared or list."); m->mothurOutEndLine(); abort = true; } + if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + listfile = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + rabundfile = m->getRabundFile(); + if (rabundfile != "") { m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } + else { + sabundfile = m->getSabundFile(); + if (sabundfile != "") { m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list, sabund, rabund or shared file."); m->mothurOutEndLine(); + abort = true; + } + } + } + } + } groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = "all"; } @@ -202,27 +232,6 @@ RemoveRareCommand::RemoveRareCommand(string option) { } //********************************************************************************************************************** -void RemoveRareCommand::help(){ - try { - m->mothurOut("The remove.rare command parameters are list, rabund, sabund, shared, group, label, groups, bygroup and nseqs.\n"); - m->mothurOut("The remove.rare command reads one of the following file types: list, rabund, sabund or shared file. It outputs a new file after removing the rare otus.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups you would like analyzed. Default=all. You may separate group names with dashes.\n"); - m->mothurOut("The label parameter is used to analyze specific labels in your input. default=all. You may separate label names with dashes.\n"); - m->mothurOut("The bygroup parameter is only valid with the shared file. default=f, meaning remove any OTU that has nseqs or fewer sequences across all groups.\n"); - m->mothurOut("bygroups=T means remove any OTU that has nseqs or fewer sequences in each group (if groupA has 1 sequence and group B has 100 sequences in OTUZ and nseqs=1, then set the groupA count for OTUZ to 0 and keep groupB's count at 100.) \n"); - m->mothurOut("The nseqs parameter allows you to set the cutoff for an otu to be deemed rare. It is required.\n"); - m->mothurOut("The remove.rare command should be in the following format: remove.rare(shared=yourSharedFile, nseqs=yourRareCutoff).\n"); - m->mothurOut("Example remove.rare(shared=amazon.fn.shared, nseqs=2).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. shared), '=' and parameters (i.e.yourSharedFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "RemoveRareCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int RemoveRareCommand::execute(){ try { @@ -609,7 +618,7 @@ int RemoveRareCommand::processRabund(){ //********************************************************************************************************************** int RemoveRareCommand::processShared(){ try { - globaldata->Groups = Groups; + m->Groups = Groups; string thisOutputDir = outputDir; if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); } diff --git a/removerarecommand.h b/removerarecommand.h index 388ec2d..fa22f7a 100644 --- a/removerarecommand.h +++ b/removerarecommand.h @@ -13,7 +13,7 @@ #include "command.hpp" #include "listvector.hpp" -#include "globaldata.hpp" + class RemoveRareCommand : public Command { @@ -22,21 +22,21 @@ public: RemoveRareCommand(string); RemoveRareCommand(); ~RemoveRareCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "remove.rare"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; string sabundfile, rabundfile, sharedfile, groupfile, listfile, outputDir, groups, label; int nseqs, allLines; bool abort, byGroup; vector outputNames, Groups; set labels; - map > outputTypes; int processSabund(); int processRabund(); diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index 02cb5d9..7e3b939 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -12,21 +12,54 @@ #include "listvector.hpp" //********************************************************************************************************************** -vector RemoveSeqsCommand::getValidParameters(){ +vector RemoveSeqsCommand::setParameters(){ try { - string Array[] = {"fasta","name", "group", "alignreport", "accnos", "qfile","list","taxonomy","outputdir","inputdir", "dups" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pqfile); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos); + CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "RemoveSeqsCommand", "getValidParameters"); + m->errorOut(e, "RemoveSeqsCommand", "setParameters"); exit(1); } } +//********************************************************************************************************************** +string RemoveSeqsCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The remove.seqs command reads an .accnos file and at least one of the following file types: fasta, name, group, list, taxonomy, quality or alignreport file.\n"; + helpString += "It outputs a file containing the sequences NOT in the .accnos file.\n"; + helpString += "The remove.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups. You must provide accnos and at least one of the file parameters.\n"; + helpString += "The dups parameter allows you to remove the entire line from a name file if you remove any name from the line. default=true. \n"; + helpString += "The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n"; + helpString += "Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "RemoveSeqsCommand", "getHelpString"); + exit(1); + } +} + + //********************************************************************************************************************** RemoveSeqsCommand::RemoveSeqsCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["taxonomy"] = tempOutNames; @@ -42,29 +75,6 @@ RemoveSeqsCommand::RemoveSeqsCommand(){ } } //********************************************************************************************************************** -vector RemoveSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"accnos"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveSeqsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector RemoveSeqsCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "RemoveSeqsCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** RemoveSeqsCommand::RemoveSeqsCommand(string option) { try { abort = false; calledHelp = false; @@ -73,9 +83,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name", "group", "alignreport", "accnos", "qfile", "list","taxonomy","outputdir","inputdir", "dups" }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -175,7 +183,14 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { //check for required parameters accnosfile = validParameter.validFile(parameters, "accnos", true); if (accnosfile == "not open") { abort = true; } - else if (accnosfile == "not found") { accnosfile = ""; m->mothurOut("You must provide an accnos file."); m->mothurOutEndLine(); abort = true; } + else if (accnosfile == "not found") { + accnosfile = m->getAccnosFile(); + if (accnosfile != "") { m->mothurOut("Using " + accnosfile + " as input file for the accnos parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You have no valid accnos file and accnos is required."); m->mothurOutEndLine(); + abort = true; + } + } fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } @@ -216,7 +231,6 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == "")) { m->mothurOut("You must provide at least one of the following: fasta, name, group, taxonomy, quality, alignreport or list."); m->mothurOutEndLine(); abort = true; } - if ((usedDups != "") && (namefile == "")) { m->mothurOut("You may only use dups with the name option."); m->mothurOutEndLine(); abort = true; } } } @@ -227,24 +241,6 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option) { } //********************************************************************************************************************** -void RemoveSeqsCommand::help(){ - try { - m->mothurOut("The remove.seqs command reads an .accnos file and at least one of the following file types: fasta, name, group, list, taxonomy, quality or alignreport file.\n"); - m->mothurOut("It outputs a file containing the sequences NOT in the .accnos file.\n"); - m->mothurOut("The remove.seqs command parameters are accnos, fasta, name, group, list, taxonomy, qfile, alignreport and dups. You must provide accnos and at least one of the file parameters.\n"); - m->mothurOut("The dups parameter allows you to remove the entire line from a name file if you remove any name from the line. default=true. \n"); - m->mothurOut("The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n"); - m->mothurOut("Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "RemoveSeqsCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - int RemoveSeqsCommand::execute(){ try { diff --git a/removeseqscommand.h b/removeseqscommand.h index de1e3d9..d99151e 100644 --- a/removeseqscommand.h +++ b/removeseqscommand.h @@ -19,19 +19,21 @@ class RemoveSeqsCommand : public Command { RemoveSeqsCommand(string); RemoveSeqsCommand(); ~RemoveSeqsCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + + vector setParameters(); + string getCommandName() { return "remove.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + + private: set names; string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, taxfile, qualfile, outputDir; bool abort, dups; vector outputNames; - map > outputTypes; int readFasta(); int readName(); diff --git a/reversecommand.cpp b/reversecommand.cpp index fffe8a2..0a2e938 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -12,56 +12,53 @@ #include "qualityscores.h" //********************************************************************************************************************** -vector ReverseSeqsCommand::getValidParameters(){ +vector ReverseSeqsCommand::setParameters(){ try { - string Array[] = {"fasta", "qfile", "outputdir", "inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "fastaQual", "none",false,false); parameters.push_back(pfasta); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "fastaQual", "none",false,false); parameters.push_back(pqfile); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ReverseSeqsCommand", "getValidParameters"); + m->errorOut(e, "ReverseSeqsCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ReverseSeqsCommand::ReverseSeqsCommand(){ +string ReverseSeqsCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["qfile"] = tempOutNames; + string helpString = ""; + helpString += "The reverse.seqs command reads a fastafile and outputs a fasta file containing the reverse compliment.\n"; + helpString += "The reverse.seqs command parameters fasta or qfile are required.\n"; + helpString += "The reverse.seqs command should be in the following format: \n"; + helpString += "reverse.seqs(fasta=yourFastaFile) \n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ReverseSeqsCommand", "ReverseSeqsCommand"); - exit(1); - } -} -//********************************************************************************************************************** - -vector ReverseSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta", "qfile"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ReverseSeqsCommand", "getRequiredParameters"); + m->errorOut(e, "ReverseSeqsCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** - -vector ReverseSeqsCommand::getRequiredFiles(){ +ReverseSeqsCommand::ReverseSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["qfile"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ReverseSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "ReverseSeqsCommand", "ReverseSeqsCommand"); exit(1); } -}//*************************************************************************************************************** +} +//*************************************************************************************************************** ReverseSeqsCommand::ReverseSeqsCommand(string option) { try { @@ -71,9 +68,7 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta", "qfile", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -103,6 +98,14 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option) { //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["fasta"] = inputDir + it->second; } } + + it = parameters.find("qfile"); + //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["qfile"] = inputDir + it->second; } + } } //check for required parameters @@ -114,16 +117,22 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option) { if (qualFileName == "not open") { abort = true; } else if (qualFileName == "not found") { qualFileName = ""; }//m->mothurOut("fasta is a required parameter for the reverse.seqs command."); m->mothurOutEndLine(); abort = true; } - if(fastaFileName == "not open" && qualFileName == "not open"){ - m->mothurOut("fasta or qfile is a required parameter for the reverse.seqs command."); - m->mothurOutEndLine(); - abort = true; + if((fastaFileName == "") && (qualFileName == "")){ + fastaFileName = m->getFastaFile(); + if (fastaFileName != "") { m->mothurOut("Using " + fastaFileName + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { + qualFileName = m->getQualFile(); + if (qualFileName != "") { m->mothurOut("Using " + qualFileName + " as input file for the qfile parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You have no current files for fasta or qfile, and fasta or qfile is a required parameter for the reverse.seqs command."); 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 = ""; - outputDir += m->hasPath(fastaFileName); //if user entered a file with a path then preserve it } } @@ -133,25 +142,6 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ReverseSeqsCommand::help(){ - try { - m->mothurOut("The reverse.seqs command reads a fastafile and outputs a fasta file containing the reverse compliment.\n"); - m->mothurOut("The reverse.seqs command parameters fasta or qfile are required.\n"); - m->mothurOut("The reverse.seqs command should be in the following format: \n"); - m->mothurOut("reverse.seqs(fasta=yourFastaFile) \n"); - } - catch(exception& e) { - m->errorOut(e, "ReverseSeqsCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -ReverseSeqsCommand::~ReverseSeqsCommand(){ /* do nothing */ } - //*************************************************************************************************************** @@ -167,7 +157,9 @@ int ReverseSeqsCommand::execute(){ m->openInputFile(fastaFileName, inFASTA); ofstream outFASTA; - fastaReverseFileName = outputDir + m->getRootName(m->getSimpleName(fastaFileName)) + "rc" + m->getExtension(fastaFileName); + 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); m->openOutputFile(fastaReverseFileName, outFASTA); while(!inFASTA.eof()){ @@ -193,7 +185,9 @@ int ReverseSeqsCommand::execute(){ m->openInputFile(qualFileName, inQual); ofstream outQual; - string qualReverseFileName = outputDir + m->getRootName(m->getSimpleName(qualFileName)) + "rc" + m->getExtension(qualFileName); + 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); while(!inQual.eof()){ diff --git a/reversecommand.h b/reversecommand.h index bd8d119..0d1da88 100644 --- a/reversecommand.h +++ b/reversecommand.h @@ -16,20 +16,21 @@ class ReverseSeqsCommand : public Command { public: ReverseSeqsCommand(string); ReverseSeqsCommand(); - ~ReverseSeqsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ReverseSeqsCommand() {} + + vector setParameters(); + string getCommandName() { return "reverse.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: bool abort; string fastaFileName, qualFileName, outputDir; vector outputNames; - map > outputTypes; }; diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index 8c334cb..7a6ea3a 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -11,15 +11,59 @@ #include "sequence.hpp" //********************************************************************************************************************** -vector ScreenSeqsCommand::getValidParameters(){ +vector ScreenSeqsCommand::setParameters(){ try { - string Array[] = {"fasta", "start", "end", "maxambig", "maxhomop","optimize","criteria", "minlength", "maxlength", - "name", "group", "alignreport","processors","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(palignreport); + CommandParameter pstart("start", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pstart); + CommandParameter pend("end", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pend); + CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxambig); + CommandParameter pmaxhomop("maxhomop", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxhomop); + CommandParameter pminlength("minlength", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pminlength); + CommandParameter pmaxlength("maxlength", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxlength); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pcriteria("criteria", "Number", "", "90", "", "", "",false,false); parameters.push_back(pcriteria); + CommandParameter poptimize("optimize", "Multiple", "none-start-end-maxambig-maxhomop-minlength-maxlength", "none", "", "", "",true,false); parameters.push_back(poptimize); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "getValidParameters"); + m->errorOut(e, "ScreenSeqsCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string ScreenSeqsCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The screen.seqs command reads a fastafile and creates .....\n"; + helpString += "The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, group, optimize, criteria and processors.\n"; + helpString += "The fasta parameter is required.\n"; + helpString += "The start parameter .... The default is -1.\n"; + helpString += "The end parameter .... The default is -1.\n"; + helpString += "The maxambig parameter allows you to set the maximum number of ambigious bases allowed. The default is -1.\n"; + helpString += "The maxhomop parameter allows you to set a maximum homopolymer length. \n"; + helpString += "The minlength parameter allows you to set and minimum sequence length. \n"; + helpString += "The maxlength parameter allows you to set and maximum sequence length. \n"; + helpString += "The processors parameter allows you to specify the number of processors to use while running the command. The default is 1.\n"; + helpString += "The optimize and criteria parameters allow you set the start, end, maxabig, maxhomop, minlength and maxlength parameters relative to your set of sequences .\n"; + helpString += "For example optimize=start-end, criteria=90, would set the start and end values to the position 90% of your sequences started and ended.\n"; + helpString += "The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile.\n"; + helpString += "The screen.seqs command should be in the following format: \n"; + helpString += "screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig, \n"; + helpString += "maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength) \n"; + helpString += "Example screen.seqs(fasta=abrecovery.fasta, name=abrecovery.names, group=abrecovery.groups, start=..., end=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "ScreenSeqsCommand", "getHelpString"); exit(1); } } @@ -27,6 +71,7 @@ vector ScreenSeqsCommand::getValidParameters(){ ScreenSeqsCommand::ScreenSeqsCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["name"] = tempOutNames; @@ -39,29 +84,6 @@ ScreenSeqsCommand::ScreenSeqsCommand(){ exit(1); } } -//********************************************************************************************************************** -vector ScreenSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ScreenSeqsCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "getRequiredFiles"); - exit(1); - } -} //*************************************************************************************************************** ScreenSeqsCommand::ScreenSeqsCommand(string option) { @@ -72,10 +94,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"fasta", "start", "end", "maxambig", "maxhomop","optimize","criteria", "minlength", "maxlength", - "name", "group", "alignreport","processors","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -136,7 +155,11 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the screen.seqs command."); m->mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (fastafile == "not open") { abort = true; } groupfile = validParameter.validFile(parameters, "group", true); @@ -178,17 +201,17 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { temp = validParameter.validFile(parameters, "maxlength", false); if (temp == "not found") { temp = "-1"; } convert(temp, maxLength); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } - convert(temp, processors); + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); temp = validParameter.validFile(parameters, "optimize", false); //optimizing trumps the optimized values original value - if (temp == "not found"){ temp = ""; } - else { m->splitAtDash(temp, optimize); } + if (temp == "not found"){ temp = "none"; } + m->splitAtDash(temp, optimize); //check for invalid optimize options set validOptimizers; - validOptimizers.insert("start"); validOptimizers.insert("end"); validOptimizers.insert("maxambig"); validOptimizers.insert("maxhomop"); validOptimizers.insert("minlength"); validOptimizers.insert("maxlength"); - + validOptimizers.insert("none"); validOptimizers.insert("start"); validOptimizers.insert("end"); validOptimizers.insert("maxambig"); validOptimizers.insert("maxhomop"); validOptimizers.insert("minlength"); validOptimizers.insert("maxlength"); for (int i = 0; i < optimize.size(); i++) { if (validOptimizers.count(optimize[i]) == 0) { m->mothurOut(optimize[i] + " is not a valid optimizer. Valid options are start, end, maxambig, maxhomop, minlength and maxlength."); m->mothurOutEndLine(); @@ -197,6 +220,8 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { } } + if (optimize.size() == 1) { if (optimize[0] == "none") { optimize.clear(); } } + temp = validParameter.validFile(parameters, "criteria", false); if (temp == "not found"){ temp = "90"; } convert(temp, criteria); } @@ -207,40 +232,6 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void ScreenSeqsCommand::help(){ - try { - m->mothurOut("The screen.seqs command reads a fastafile and creates .....\n"); - m->mothurOut("The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, group, optimize, criteria and processors.\n"); - m->mothurOut("The fasta parameter is required.\n"); - m->mothurOut("The start parameter .... The default is -1.\n"); - m->mothurOut("The end parameter .... The default is -1.\n"); - m->mothurOut("The maxambig parameter .... The default is -1.\n"); - m->mothurOut("The maxhomop parameter .... The default is -1.\n"); - m->mothurOut("The minlength parameter .... The default is -1.\n"); - m->mothurOut("The maxlength parameter .... The default is -1.\n"); - m->mothurOut("The processors parameter allows you to specify the number of processors to use while running the command. The default is 1.\n"); - m->mothurOut("The optimize and criteria parameters allow you set the start, end, maxabig, maxhomop, minlength and maxlength parameters relative to your set of sequences .\n"); - m->mothurOut("For example optimize=start-end, criteria=90, would set the start and end values to the position 90% of your sequences started and ended.\n"); - m->mothurOut("The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile.\n"); - m->mothurOut("The screen.seqs command should be in the following format: \n"); - m->mothurOut("screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig, \n"); - m->mothurOut("maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength) \n"); - m->mothurOut("Example screen.seqs(fasta=abrecovery.fasta, name=abrecovery.names, group=abrecovery.groups, start=..., end=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "ScreenSeqsCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -ScreenSeqsCommand::~ScreenSeqsCommand(){ /* do nothing */ } - //*************************************************************************************************************** int ScreenSeqsCommand::execute(){ diff --git a/screenseqscommand.h b/screenseqscommand.h index 45c9db5..b8ab242 100644 --- a/screenseqscommand.h +++ b/screenseqscommand.h @@ -17,13 +17,16 @@ class ScreenSeqsCommand : public Command { public: ScreenSeqsCommand(string); ScreenSeqsCommand(); - ~ScreenSeqsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ScreenSeqsCommand() {} + + vector setParameters(); + string getCommandName() { return "screen.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: @@ -52,7 +55,6 @@ private: int startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength, processors, criteria; vector outputNames; vector optimize; - map > outputTypes; map nameMap; int readNames(); diff --git a/secondarystructurecommand.cpp b/secondarystructurecommand.cpp index ece2de0..fec93e6 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -11,49 +11,49 @@ #include "sequence.hpp" //********************************************************************************************************************** -vector AlignCheckCommand::getValidParameters(){ +vector AlignCheckCommand::setParameters(){ try { - string Array[] = {"fasta", "name","map", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pmap("map", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pmap); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -AlignCheckCommand::AlignCheckCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["aligncheck"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "AlignCheckCommand"); + m->errorOut(e, "AlignCheckCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector AlignCheckCommand::getRequiredParameters(){ +string AlignCheckCommand::getHelpString(){ try { - string Array[] = {"fasta","map"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The align.check command reads a fasta file and map file.\n"; + helpString += "It outputs a file containing the secondary structure matches in the .align.check file.\n"; + helpString += "The align.check command parameters are fasta and map, both are required.\n"; + helpString += "The align.check command should be in the following format: align.check(fasta=yourFasta, map=yourMap).\n"; + helpString += "Example align.check(map=silva.ss.map, fasta=amazon.fasta).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "getRequiredParameters"); + m->errorOut(e, "AlignCheckCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector AlignCheckCommand::getRequiredFiles(){ +AlignCheckCommand::AlignCheckCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["aligncheck"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "getRequiredFiles"); + m->errorOut(e, "AlignCheckCommand", "AlignCheckCommand"); exit(1); } } @@ -68,9 +68,7 @@ AlignCheckCommand::AlignCheckCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name","map", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -124,7 +122,11 @@ AlignCheckCommand::AlignCheckCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; m->mothurOut("You must provide an fasta file."); m->mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { namefile = ""; abort = true; } @@ -140,27 +142,10 @@ AlignCheckCommand::AlignCheckCommand(string option) { } catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "RemoveSeqsCommand"); - exit(1); - } -} -//********************************************************************************************************************** - -void AlignCheckCommand::help(){ - try { - m->mothurOut("The align.check command reads a fasta file and map file.\n"); - m->mothurOut("It outputs a file containing the secondary structure matches in the .align.check file.\n"); - m->mothurOut("The align.check command parameters are fasta and map, both are required.\n"); - m->mothurOut("The align.check command should be in the following format: align.check(fasta=yourFasta, map=yourMap).\n"); - m->mothurOut("Example align.check(map=silva.ss.map, fasta=amazon.fasta).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "AlignCheckCommand", "help"); + m->errorOut(e, "AlignCheckCommand", "AlignCheckCommand"); exit(1); } } - //********************************************************************************************************************** int AlignCheckCommand::execute(){ @@ -209,7 +194,7 @@ int AlignCheckCommand::execute(){ //make sure this sequence is in the namefile, else error map::iterator it = nameMap.find(seq.getName()); - if (it == nameMap.end()) { cout << "[ERROR]: " << seq.getName() << " is not in your namefile, please correct." << endl; m->control_pressed = true; } + if (it == nameMap.end()) { m->mothurOut("[ERROR]: " + seq.getName() + " is not in your namefile, please correct."); m->mothurOutEndLine(); m->control_pressed = true; } else { num = it->second; } } diff --git a/secondarystructurecommand.h b/secondarystructurecommand.h index 0b654a4..2e04936 100644 --- a/secondarystructurecommand.h +++ b/secondarystructurecommand.h @@ -35,20 +35,21 @@ class AlignCheckCommand : public Command { AlignCheckCommand(string); AlignCheckCommand(); ~AlignCheckCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + + vector setParameters(); + string getCommandName() { return "align.check"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: vector structMap; string mapfile, fastafile, outputDir, namefile; bool abort; int seqLength, haderror; vector outputNames; - map > outputTypes; map nameMap; void readMap(); diff --git a/sensspeccommand.cpp b/sensspeccommand.cpp index 6a22fd6..7f5d9dc 100644 --- a/sensspeccommand.cpp +++ b/sensspeccommand.cpp @@ -10,49 +10,68 @@ #include "sensspeccommand.h" //********************************************************************************************************************** -vector SensSpecCommand::getValidParameters(){ +vector SensSpecCommand::setParameters(){ try { - string Array[] = {"list", "phylip", "column", "name", "hard", "label", "cutoff", "precision", "outputdir", "inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip); + //CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pcolumn); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pcutoff("cutoff", "Number", "", "-1.00", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); + CommandParameter phard("hard", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(phard); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "SensSpecCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -SensSpecCommand::SensSpecCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["sensspec"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "SensSpecCommand", "SensSpecCommand"); + m->errorOut(e, "SensSpecCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector SensSpecCommand::getRequiredParameters(){ +string SensSpecCommand::getHelpString(){ try { - string Array[] = {"list","phylip","column","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The get.oturep command parameters are phylip, column, list, fasta, name, group, large, weighted, cutoff, precision, groups, sorted and label. The fasta and list parameters are required, as well as phylip or column and name, unless you have valid current files.\n"; + helpString += "The label parameter allows you to select what distance levels you would like a output files created for, and is separated by dashes.\n"; + helpString += "The phylip or column parameter is required, but only one may be used. If you use a column file the name filename is required. \n"; + helpString += "If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.\n"; + helpString += "The get.oturep command should be in the following format: get.oturep(phylip=yourDistanceMatrix, fasta=yourFastaFile, list=yourListFile, name=yourNamesFile, group=yourGroupFile, label=yourLabels).\n"; + helpString += "Example get.oturep(phylip=amazon.dist, fasta=amazon.fasta, list=amazon.fn.list, group=amazon.groups).\n"; + helpString += "The default value for label is all labels in your inputfile.\n"; + helpString += "The sorted parameter allows you to indicate you want the output sorted. You can sort by sequence name, bin number, bin size or group. The default is no sorting, but your options are name, number, size, or group.\n"; + helpString += "The large parameter allows you to indicate that your distance matrix is too large to fit in RAM. The default value is false.\n"; + helpString += "The weighted parameter allows you to indicate that want to find the weighted representative. You must provide a namesfile to set weighted to true. The default value is false.\n"; + helpString += "The representative is found by selecting the sequence that has the smallest total distance to all other sequences in the OTU. If a tie occurs the smallest average distance is used.\n"; + helpString += "For weighted = false, mothur assumes the distance file contains only unique sequences, the list file may contain all sequences, but only the uniques are considered to become the representative. If your distance file contains all the sequences it would become weighted=true.\n"; + helpString += "For weighted = true, mothur assumes the distance file contains only unique sequences, the list file must contain all sequences, all sequences are considered to become the representative, but unique name will be used in the output for consistency.\n"; + helpString += "If your distance file contains all the sequence and you do not provide a name file, the weighted representative will be given, unless your listfile is unique. If you provide a namefile, then you can select weighted or unweighted.\n"; + helpString += "The group parameter allows you provide a group file.\n"; + helpString += "The groups parameter allows you to indicate that you want representative sequences for each group specified for each OTU, group name should be separated by dashes. ex. groups=A-B-C.\n"; + helpString += "The get.oturep command outputs a .fastarep and .rep.names file for each distance you specify, selecting one OTU representative for each bin.\n"; + helpString += "If you provide a groupfile, then it also appends the names of the groups present in that bin.\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "SensSpecCommand", "getRequiredParameters"); + m->errorOut(e, "SensSpecCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector SensSpecCommand::getRequiredFiles(){ +SensSpecCommand::SensSpecCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["sensspec"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "SensSpecCommand", "getRequiredFiles"); + m->errorOut(e, "SensSpecCommand", "SensSpecCommand"); exit(1); } } @@ -70,7 +89,7 @@ SensSpecCommand::SensSpecCommand(string option) { string temp; //valid paramters for this command - string AlignArray[] = {"list", "phylip", "column", "name", "hard", "label", "cutoff", "precision", "outputdir", "inputdir"}; + string AlignArray[] = {"list", "phylip", "column", "hard", "label", "cutoff", "precision", "outputdir", "inputdir"}; vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); @@ -118,29 +137,49 @@ SensSpecCommand::SensSpecCommand(string option) { if (path == "") { parameters["column"] = inputDir + it->second; } } - it = parameters.find("name"); + //it = parameters.find("name"); //user has given a template file - if(it != parameters.end()){ - path = m->hasPath(it->second); + //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; } - } + //if (path == "") { parameters["name"] = inputDir + it->second; } + //} } //check for required parameters listFile = validParameter.validFile(parameters, "list", true); - if (listFile == "not found") { m->mothurOut("list is a required parameter for the sens.spec command."); m->mothurOutEndLine(); abort = true; } + if (listFile == "not found") { + listFile = m->getListFile(); + if (listFile != "") { m->mothurOut("Using " + listFile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (listFile == "not open") { abort = true; } - distFile = validParameter.validFile(parameters, "column", true); - format = "column"; - if(distFile == "not found") { - distFile = validParameter.validFile(parameters, "phylip", true); - format = "phylip"; - } - if(distFile == "not found") { m->mothurOut("either column or phylip are required for the sens.spec command."); m->mothurOutEndLine(); abort = true; } - else if (distFile == "not open") { abort = true; } - + phylipfile = validParameter.validFile(parameters, "phylip", true); + if (phylipfile == "not found") { phylipfile = ""; } + else if (phylipfile == "not open") { abort = true; } + else { distFile = phylipfile; format = "phylip"; } + + columnfile = validParameter.validFile(parameters, "column", true); + if (columnfile == "not found") { columnfile = ""; } + else if (columnfile == "not open") { abort = true; } + else { distFile = columnfile; format = "column"; } + + if ((phylipfile == "") && (columnfile == "")) { //is there are current file available for either of these? + //give priority to column, then phylip + columnfile = m->getColumnFile(); + if (columnfile != "") { distFile = columnfile; format = "column"; m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); } + else { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { distFile = phylipfile; format = "phylip"; m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a phylip or column file."); m->mothurOutEndLine(); + abort = true; + } + } + }else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When executing a sens.spec command you must enter ONLY ONE of the following: phylip or column."); 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"){ @@ -179,30 +218,6 @@ SensSpecCommand::SensSpecCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void SensSpecCommand::help(){ - try { - m->mothurOut("The sens.spec command reads a fastaFile and creates .....\n"); - - - - m->mothurOut("Example sens.spec(...).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"); - m->mothurOut("For more details please check out the wiki http://www.mothur.org/wiki/Trim.seqs .\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "SensSpecCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -SensSpecCommand::~SensSpecCommand(){ /* do nothing */ } - //*************************************************************************************************************** int SensSpecCommand::execute(){ diff --git a/sensspeccommand.h b/sensspeccommand.h index 5e25afd..c690d57 100644 --- a/sensspeccommand.h +++ b/sensspeccommand.h @@ -19,13 +19,15 @@ class SensSpecCommand : public Command { public: SensSpecCommand(string); SensSpecCommand(); - ~SensSpecCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~SensSpecCommand(){} + + vector setParameters(); + string getCommandName() { return "sens.spec"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: void processPhylip(); @@ -33,11 +35,10 @@ private: void setUpOutput(); void outputStatistics(string, string); - string listFile, distFile, nameFile, sensSpecFileName; + string listFile, distFile, nameFile, sensSpecFileName, phylipfile, columnfile; string outputDir; string format; vector outputNames; - map > outputTypes; long int truePositives, falsePositives, trueNegatives, falseNegatives; bool abort; diff --git a/seqerrorcommand.cpp b/seqerrorcommand.cpp index 5a0cc02..f0ff086 100644 --- a/seqerrorcommand.cpp +++ b/seqerrorcommand.cpp @@ -13,14 +13,39 @@ #include "refchimeratest.h" //********************************************************************************************************************** -vector SeqErrorCommand::getValidParameters(){ +vector SeqErrorCommand::setParameters(){ try { - string Array[] = {"query", "reference", "name", "qfile", "report", "threshold", "ignorechimeras", "inputdir", "outputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pquery("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pquery); + CommandParameter preference("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(preference); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "QualReport",false,false); parameters.push_back(pqfile); + CommandParameter preport("report", "InputTypes", "", "", "none", "none", "QualReport",false,false); parameters.push_back(preport); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pignorechimeras("ignorechimeras", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pignorechimeras); + CommandParameter pthreshold("threshold", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pthreshold); + CommandParameter 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, "SeqErrorCommand", "getValidParameters"); + m->errorOut(e, "SeqErrorCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string SeqErrorCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The seq.error command reads a query alignment file and a reference alignment file and creates .....\n"; + helpString += "Example seq.error(...).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"; + helpString += "For more details please check out the wiki http://www.mothur.org/wiki/seq.error .\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "SeqErrorCommand", "getHelpString"); exit(1); } } @@ -44,29 +69,6 @@ SeqErrorCommand::SeqErrorCommand(){ exit(1); } } -//********************************************************************************************************************** -vector SeqErrorCommand::getRequiredParameters(){ - try { - string Array[] = {"query","reference"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SeqErrorCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SeqErrorCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SeqErrorCommand", "getRequiredFiles"); - exit(1); - } -} //*************************************************************************************************************** SeqErrorCommand::SeqErrorCommand(string option) { @@ -79,11 +81,7 @@ SeqErrorCommand::SeqErrorCommand(string option) { else { string temp; - - //valid paramters for this command - string AlignArray[] = {"query", "reference", "name", "qfile", "report", "threshold", "inputdir", "ignorechimeras", "outputdir"}; - - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -114,12 +112,12 @@ SeqErrorCommand::SeqErrorCommand(string option) { if (inputDir == "not found"){ inputDir = ""; } else { string path; - it = parameters.find("query"); + it = parameters.find("fasta"); //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["query"] = inputDir + it->second; } + if (path == "") { parameters["fasta"] = inputDir + it->second; } } it = parameters.find("reference"); @@ -156,8 +154,12 @@ SeqErrorCommand::SeqErrorCommand(string option) { } //check for required parameters - queryFileName = validParameter.validFile(parameters, "query", true); - if (queryFileName == "not found") { m->mothurOut("query is a required parameter for the seq.error command."); m->mothurOutEndLine(); abort = true; } + queryFileName = validParameter.validFile(parameters, "fasta", true); + if (queryFileName == "not found") { + queryFileName = m->getFastaFile(); + if (queryFileName != "") { m->mothurOut("Using " + queryFileName + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fasta file and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } else if (queryFileName == "not open") { abort = true; } referenceFileName = validParameter.validFile(parameters, "reference", true); @@ -168,12 +170,15 @@ SeqErrorCommand::SeqErrorCommand(string option) { //check for optional parameters namesFileName = validParameter.validFile(parameters, "name", true); if(namesFileName == "not found"){ namesFileName = ""; } + else if (namesFileName == "not open") { namesFileName = ""; abort = true; } qualFileName = validParameter.validFile(parameters, "qfile", true); if(qualFileName == "not found"){ qualFileName = ""; } + else if (qualFileName == "not open") { qualFileName = ""; abort = true; } reportFileName = validParameter.validFile(parameters, "report", true); if(reportFileName == "not found"){ reportFileName = ""; } + else if (reportFileName == "not open") { reportFileName = ""; abort = true; } if((reportFileName != "" && qualFileName == "") || (reportFileName == "" && qualFileName != "")){ m->mothurOut("if you use either a qual file or a report file, you have to have both."); @@ -204,26 +209,6 @@ SeqErrorCommand::SeqErrorCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void SeqErrorCommand::help(){ - try { - m->mothurOut("The seq.error command reads a query alignment file and a reference alignment file and creates .....\n"); - m->mothurOut("Example seq.error(...).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"); - m->mothurOut("For more details please check out the wiki http://www.mothur.org/wiki/seq.error .\n\n"); - } - catch(exception& e) { - m->errorOut(e, "SeqErrorCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -SeqErrorCommand::~SeqErrorCommand(){ /* void */ } - //*************************************************************************************************************** int SeqErrorCommand::execute(){ diff --git a/seqerrorcommand.h b/seqerrorcommand.h index 1194d42..19fcd47 100644 --- a/seqerrorcommand.h +++ b/seqerrorcommand.h @@ -43,13 +43,15 @@ class SeqErrorCommand : public Command { public: SeqErrorCommand(string); SeqErrorCommand(); - ~SeqErrorCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~SeqErrorCommand() {} + + vector setParameters(); + string getCommandName() { return "seq.error"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: bool abort; @@ -71,7 +73,6 @@ private: int maxLength; ofstream errorSummaryFile, errorSeqFile; vector outputNames; - map > outputTypes; vector referenceSeqs; vector > substitutionMatrix; diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index 8c13e7f..911e65f 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -11,49 +11,50 @@ #include "sequence.hpp" //********************************************************************************************************************** -vector SeqSummaryCommand::getValidParameters(){ +vector SeqSummaryCommand::setParameters(){ try { - string Array[] = {"fasta","name","processors","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter 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, "SeqSummaryCommand", "getValidParameters"); + m->errorOut(e, "SeqSummaryCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -SeqSummaryCommand::SeqSummaryCommand(){ +string SeqSummaryCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["summary"] = tempOutNames; + string helpString = ""; + helpString += "The summary.seqs command reads a fastafile and summarizes the sequences.\n"; + helpString += "The summary.seqs command parameters are fasta, name and processors, fasta is required, unless you have a valid current fasta file.\n"; + helpString += "The name parameter allows you to enter a name file associated with your fasta file. \n"; + helpString += "The summary.seqs command should be in the following format: \n"; + helpString += "summary.seqs(fasta=yourFastaFile, processors=2) \n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "SeqSummaryCommand", "SeqSummaryCommand"); - exit(1); - } -} -//********************************************************************************************************************** -vector SeqSummaryCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SeqSummaryCommand", "getRequiredParameters"); + m->errorOut(e, "SeqSummaryCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector SeqSummaryCommand::getRequiredFiles(){ +SeqSummaryCommand::SeqSummaryCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["summary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "SeqSummaryCommand", "getRequiredFiles"); + m->errorOut(e, "SeqSummaryCommand", "SeqSummaryCommand"); exit(1); } } @@ -67,9 +68,7 @@ SeqSummaryCommand::SeqSummaryCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta","name","processors","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -111,7 +110,11 @@ SeqSummaryCommand::SeqSummaryCommand(string option) { //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the summary.seqs command."); m->mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { namefile = ""; abort = true; } @@ -123,8 +126,9 @@ SeqSummaryCommand::SeqSummaryCommand(string option) { outputDir += m->hasPath(fastafile); //if user entered a file with a path then preserve it } - string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } - convert(temp, processors); + string temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); } @@ -134,27 +138,6 @@ SeqSummaryCommand::SeqSummaryCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void SeqSummaryCommand::help(){ - try { - m->mothurOut("The summary.seqs command reads a fastafile and summarizes the sequences.\n"); - m->mothurOut("The summary.seqs command parameters are fasta, name and processors, fasta is required.\n"); - m->mothurOut("The name parameter allows you to enter a name file associated with your fasta file. \n"); - m->mothurOut("The summary.seqs command should be in the following format: \n"); - m->mothurOut("summary.seqs(fasta=yourFastaFile, processors=2) \n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "SeqSummaryCommand", "help"); - exit(1); - } -} - -//*************************************************************************************************************** - -SeqSummaryCommand::~SeqSummaryCommand(){ /* do nothing */ } - //*************************************************************************************************************** int SeqSummaryCommand::execute(){ @@ -162,6 +145,9 @@ int SeqSummaryCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } + //set current fasta to fastafile + m->setFastaFile(fastafile); + string summaryFile = outputDir + m->getSimpleName(fastafile) + ".summary"; int numSeqs = 0; diff --git a/seqsummarycommand.h b/seqsummarycommand.h index 24c29a1..623c3c1 100644 --- a/seqsummarycommand.h +++ b/seqsummarycommand.h @@ -17,20 +17,20 @@ class SeqSummaryCommand : public Command { public: SeqSummaryCommand(string); SeqSummaryCommand(); - ~SeqSummaryCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~SeqSummaryCommand(){} + vector setParameters(); + string getCommandName() { return "summary.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: bool abort; string fastafile, outputDir, namefile; int processors; vector outputNames; - map > outputTypes; map nameMap; struct linePair { diff --git a/setcurrentcommand.cpp b/setcurrentcommand.cpp index a4f5c5c..16685b2 100644 --- a/setcurrentcommand.cpp +++ b/setcurrentcommand.cpp @@ -10,47 +10,67 @@ #include "setcurrentcommand.h" //********************************************************************************************************************** -vector SetCurrentCommand::getValidParameters(){ +vector SetCurrentCommand::setParameters(){ try { - string Array[] = {"outputdir","inputdir","clear", "phylip", "column", "list","rabund","sabund","name","group", - "design","order","tree","shared","ordergroup","relabund","fasta","qfile","sff","oligos","accnos","taxonomy"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pphylip); + CommandParameter pcolumn("column", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pcolumn); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plist); + CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(ptaxonomy); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pqfile); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); + CommandParameter prabund("rabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psabund); + CommandParameter pdesign("design", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pdesign); + CommandParameter porder("order", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(porder); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(ptree); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pshared); + CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pordergroup); + CommandParameter prelabund("relabund", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(prelabund); + CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psff); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos); + CommandParameter pclear("clear", "String", "", "", "", "", "",false,false); parameters.push_back(pclear); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "SetCurrentCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -SetCurrentCommand::SetCurrentCommand(){ - try { - abort = true; calledHelp = true; - } - catch(exception& e) { - m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand"); + m->errorOut(e, "SetCurrentCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector SetCurrentCommand::getRequiredParameters(){ +string SetCurrentCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The set.current command allows you to set the current files saved by mothur.\n"; + helpString += "The set.current command parameters are: clear, phylip, column, list, rabund, sabund, name, group, design, order, tree, shared, ordergroup, relabund, fasta, qfile, sff, oligos, accnos, taxonomy.\n"; + helpString += "The clear paramter is used to indicate which file types you would like to clear values for, multiple types can be separated by dashes.\n"; + helpString += "The set.current command should be in the following format: \n"; + helpString += "set.current(fasta=yourFastaFile) or set.current(fasta=amazon.fasta, clear=name-accnos)\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "SetCurrentCommand", "getRequiredParameters"); + m->errorOut(e, "SetCurrentCommand", "getHelpString"); exit(1); } } + + //********************************************************************************************************************** -vector SetCurrentCommand::getRequiredFiles(){ +SetCurrentCommand::SetCurrentCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); } catch(exception& e) { - m->errorOut(e, "SetCurrentCommand", "getRequiredFiles"); + m->errorOut(e, "SetCurrentCommand", "SetCurrentCommand"); exit(1); } } @@ -64,9 +84,7 @@ SetCurrentCommand::SetCurrentCommand(string option) { else { //valid paramters for this command - string Array[] = {"outputdir","inputdir","clear", "phylip", "column", "list","rabund","sabund","name","group", - "design","order","tree","shared","ordergroup","relabund","fasta","qfile","sff","oligos","accnos","taxonomy"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -354,25 +372,6 @@ SetCurrentCommand::SetCurrentCommand(string option) { } //********************************************************************************************************************** -void SetCurrentCommand::help(){ - try { - m->mothurOut("The set.current command allows you to set the current files saved by mothur.\n"); - m->mothurOut("The set.current command parameters are: clear, phylip, column, list, rabund, sabund, name, group, design, order, tree, shared, ordergroup, relabund, fasta, qfile, sff, oligos, accnos, taxonomy.\n"); - m->mothurOut("The clear paramter is used to indicate which file types you would like to clear values for, multiple types can be separated by dashes.\n"); - m->mothurOut("The set.current command should be in the following format: \n"); - m->mothurOut("set.current(fasta=yourFastaFile) or set.current(fasta=amazon.fasta, clear=name-accnos)\n"); - - } - catch(exception& e) { - m->errorOut(e, "SetCurrentCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** -SetCurrentCommand::~SetCurrentCommand(){} -//********************************************************************************************************************** - int SetCurrentCommand::execute(){ try { diff --git a/setcurrentcommand.h b/setcurrentcommand.h index 98033b7..5a40e4a 100644 --- a/setcurrentcommand.h +++ b/setcurrentcommand.h @@ -18,18 +18,19 @@ class SetCurrentCommand : public Command { public: SetCurrentCommand(string); SetCurrentCommand(); - ~SetCurrentCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~SetCurrentCommand() {} + + vector setParameters(); + string getCommandName() { return "set.current"; } + string getCommandCategory() { return "General"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: vector outputNames; - map > outputTypes; bool abort; string clearTypes; diff --git a/setdircommand.cpp b/setdircommand.cpp index a76db24..16e93b5 100644 --- a/setdircommand.cpp +++ b/setdircommand.cpp @@ -10,36 +10,44 @@ #include "setdircommand.h" //********************************************************************************************************************** -vector SetDirectoryCommand::getValidParameters(){ - try { - string Array[] = {"output","input","tempdefault","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SetDirectoryCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SetDirectoryCommand::getRequiredParameters(){ +vector SetDirectoryCommand::setParameters(){ try { + CommandParameter ptempdefault("tempdefault", "String", "", "", "", "", "",false,false); parameters.push_back(ptempdefault); + CommandParameter pinput("input", "String", "", "", "", "", "",false,false); parameters.push_back(pinput); + CommandParameter poutput("output", "String", "", "", "", "", "",false,false); parameters.push_back(poutput); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "SetDirectoryCommand", "getRequiredParameters"); + m->errorOut(e, "SetDirectoryCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector SetDirectoryCommand::getRequiredFiles(){ +string SetDirectoryCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The set.dir command can be used to direct the output files generated by mothur to a specific place, the directory must exist.\n"; + helpString += "The set.dir command can also be used to specify the directory where your input files are located, the directory must exist.\n"; + helpString += "The set.dir command can also be used to override or set the default location mothur will look for files if it is unable to find them, the directory must exist.\n"; + helpString += "The set.dir command parameters are input, output and tempdefault and one is required.\n"; + helpString += "To return the output to the same directory as the input files you may enter: output=clear.\n"; + helpString += "To return the input to the current working directory you may enter: input=clear.\n"; + helpString += "To set the output to the directory where mothur.exe is located you may enter: output=default.\n"; + helpString += "To set the input to the directory where mothur.exe is located you may enter: input=default.\n"; + helpString += "To return the tempdefault to the default you provided at compile time you may enter: tempdefault=clear.\n"; + helpString += "To set the tempdefault to the directory where mothur.exe is located you may enter: tempdefault=default.\n"; + helpString += "The set.dir command should be in the following format: set.dir(output=yourOutputDirectory, input=yourInputDirectory, tempdefault=yourTempDefault).\n"; + helpString += "Example set.outdir(output=/Users/lab/desktop/outputs, input=/Users/lab/desktop/inputs).\n"; + helpString += "Note: No spaces between parameter labels (i.e. output), '=' and parameters (i.e.yourOutputDirectory).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "SetDirectoryCommand", "getRequiredFiles"); + m->errorOut(e, "SetDirectoryCommand", "getHelpString"); exit(1); } } @@ -87,33 +95,6 @@ SetDirectoryCommand::SetDirectoryCommand(string option) { } //********************************************************************************************************************** -void SetDirectoryCommand::help(){ - try { - m->mothurOut("The set.dir command can be used to direct the output files generated by mothur to a specific place, the directory must exist.\n"); - m->mothurOut("The set.dir command can also be used to specify the directory where your input files are located, the directory must exist.\n"); - m->mothurOut("The set.dir command can also be used to override or set the default location mothur will look for files if it is unable to find them, the directory must exist.\n"); - m->mothurOut("The set.dir command parameters are input, output and tempdefault and one is required.\n"); - m->mothurOut("To return the output to the same directory as the input files you may enter: output=clear.\n"); - m->mothurOut("To return the input to the current working directory you may enter: input=clear.\n"); - m->mothurOut("To set the output to the directory where mothur.exe is located you may enter: output=default.\n"); - m->mothurOut("To set the input to the directory where mothur.exe is located you may enter: input=default.\n"); - m->mothurOut("To return the tempdefault to the default you provided at compile time you may enter: tempdefault=clear.\n"); - m->mothurOut("To set the tempdefault to the directory where mothur.exe is located you may enter: tempdefault=default.\n"); - m->mothurOut("The set.dir command should be in the following format: set.dir(output=yourOutputDirectory, input=yourInputDirectory, tempdefault=yourTempDefault).\n"); - m->mothurOut("Example set.outdir(output=/Users/lab/desktop/outputs, input=/Users/lab/desktop/inputs).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. output), '=' and parameters (i.e.yourOutputDirectory).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "SetDirectoryCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** - -SetDirectoryCommand::~SetDirectoryCommand(){} - -//********************************************************************************************************************** - int SetDirectoryCommand::execute(){ try { @@ -124,8 +105,7 @@ int SetDirectoryCommand::execute(){ //redirect output if ((output == "clear") || (output == "")) { output = ""; commandFactory->setOutputDirectory(output); } else if (output == "default") { - GlobalData* globaldata = GlobalData::getInstance(); - string exepath = globaldata->argv; + string exepath = m->argv; output = exepath.substr(0, (exepath.find_last_of('m'))); m->mothurOut("Changing output directory to " + output); m->mothurOutEndLine(); @@ -157,8 +137,7 @@ int SetDirectoryCommand::execute(){ //redirect input if ((input == "clear") || (input == "")) { input = ""; commandFactory->setInputDirectory(input); } else if (input == "default") { - GlobalData* globaldata = GlobalData::getInstance(); - string exepath = globaldata->argv; + string exepath = m->argv; input = exepath.substr(0, (exepath.find_last_of('m'))); m->mothurOut("Changing input directory to " + input); m->mothurOutEndLine(); @@ -200,8 +179,7 @@ int SetDirectoryCommand::execute(){ #endif }else if (tempdefault == "") { //do nothing }else if (tempdefault == "default") { - GlobalData* globaldata = GlobalData::getInstance(); - string exepath = globaldata->argv; + string exepath = m->argv; tempdefault = exepath.substr(0, (exepath.find_last_of('m'))); m->mothurOut("Changing default directory to " + tempdefault); m->mothurOutEndLine(); diff --git a/setdircommand.h b/setdircommand.h index 6263c5e..0d12e05 100644 --- a/setdircommand.h +++ b/setdircommand.h @@ -12,7 +12,6 @@ #include "command.hpp" #include "commandfactory.hpp" -#include "globaldata.hpp" /**********************************************************/ @@ -20,21 +19,23 @@ class SetDirectoryCommand : public Command { public: SetDirectoryCommand(string); - SetDirectoryCommand() { abort = true; calledHelp = true; } - ~SetDirectoryCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + SetDirectoryCommand() { abort = true; calledHelp = true; setParameters(); } + ~SetDirectoryCommand(){} + + vector setParameters(); + string getCommandName() { return "set.dir"; } + string getCommandCategory() { return "General"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: CommandFactory* commandFactory; string output, input, tempdefault; bool abort; vector outputNames; - map > outputTypes; + }; diff --git a/setlogfilecommand.cpp b/setlogfilecommand.cpp index f57dfaf..00e702c 100644 --- a/setlogfilecommand.cpp +++ b/setlogfilecommand.cpp @@ -9,38 +9,37 @@ #include "setlogfilecommand.h" + //********************************************************************************************************************** -vector SetLogFileCommand::getValidParameters(){ +vector SetLogFileCommand::setParameters(){ try { - string Array[] = {"name","append","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pappend("append", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pappend); + CommandParameter pname("name", "String", "", "", "", "", "",false,true); parameters.push_back(pname); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "SetLogFileCommand", "getValidParameters"); + m->errorOut(e, "SetLogFileCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector SetLogFileCommand::getRequiredParameters(){ +string SetLogFileCommand::getHelpString(){ try { - string Array[] = {"name"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The set.logfile command can be used to provide a specific name for your logfile and/or to append the log generated by mothur to an existing file.\n"; + helpString += "The set.logfile command parameters are name and append, name is required. Append is set to false by default.\n"; + helpString += "The set.logfile command should be in the following format: set.logfile(name=yourLogFileName, append=T).\n"; + helpString += "Example set.logfile(name=/Users/lab/desktop/output.txt, append=T).\n"; + helpString += "Note: No spaces between parameter labels (i.e. name), '=' and parameters (i.e.yourLogFileName).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "SetLogFileCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SetLogFileCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SetLogFileCommand", "getRequiredFiles"); + m->errorOut(e, "SetLogFileCommand", "getHelpString"); exit(1); } } @@ -79,24 +78,6 @@ SetLogFileCommand::SetLogFileCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void SetLogFileCommand::help(){ - try { - m->mothurOut("The set.logfile command can be used to provide a specific name for your logfile and/or to append the log generated by mothur to an existing file.\n"); - m->mothurOut("The set.logfile command parameters are name and append, name is required. Append is set to false by default.\n"); - m->mothurOut("The set.logfile command should be in the following format: set.logfile(name=yourLogFileName, append=T).\n"); - m->mothurOut("Example set.logfile(name=/Users/lab/desktop/output.txt, append=T).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. name), '=' and parameters (i.e.yourLogFileName).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "SetLogFileCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** - -SetLogFileCommand::~SetLogFileCommand(){} //********************************************************************************************************************** diff --git a/setlogfilecommand.h b/setlogfilecommand.h index e0555d0..0c0347b 100644 --- a/setlogfilecommand.h +++ b/setlogfilecommand.h @@ -20,20 +20,21 @@ class SetLogFileCommand : public Command { public: SetLogFileCommand(string); SetLogFileCommand() { abort = true; calledHelp = true; } - ~SetLogFileCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~SetLogFileCommand(){} + + vector setParameters(); + string getCommandName() { return "set.logfile"; } + string getCommandCategory() { return "General"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: CommandFactory* commandFactory; string name; bool abort, append; vector outputNames; - map > outputTypes; }; diff --git a/sffinfocommand.cpp b/sffinfocommand.cpp index f9f6db6..fda9604 100644 --- a/sffinfocommand.cpp +++ b/sffinfocommand.cpp @@ -11,21 +11,57 @@ #include "endiannessmacros.h" //********************************************************************************************************************** -vector SffInfoCommand::getValidParameters(){ - try { - string Array[] = {"sff","qfile","fasta","flow","trim","accnos","sfftxt","outputdir","inputdir", "outputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); +vector SffInfoCommand::setParameters(){ + try { + CommandParameter psff("sff", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(psff); + CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos); + CommandParameter psfftxt("sfftxt", "String", "", "", "", "", "",false,false); parameters.push_back(psfftxt); + CommandParameter pflow("flow", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pflow); + CommandParameter ptrim("trim", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(ptrim); + CommandParameter pfasta("fasta", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pfasta); + CommandParameter pqfile("name", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pqfile); + CommandParameter 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, "SffInfoCommand", "getValidParameters"); + m->errorOut(e, "SffInfoCommand", "setParameters"); exit(1); } } +//********************************************************************************************************************** +string SffInfoCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The sffinfo command reads a sff file and extracts the sequence data, or you can use it to parse a sfftxt file.\n"; + helpString += "The sffinfo command parameters are sff, fasta, qfile, accnos, flow, sfftxt, and trim. sff is required. \n"; + helpString += "The sff parameter allows you to enter the sff file you would like to extract data from. You may enter multiple files by separating them by -'s.\n"; + helpString += "The fasta parameter allows you to indicate if you would like a fasta formatted file generated. Default=True. \n"; + helpString += "The qfile parameter allows you to indicate if you would like a quality file generated. Default=True. \n"; + helpString += "The flow parameter allows you to indicate if you would like a flowgram file generated. Default=False. \n"; + helpString += "The sfftxt parameter allows you to indicate if you would like a sff.txt file generated. Default=False. \n"; + helpString += "If you want to parse an existing sfftxt file into flow, fasta and quality file, enter the file name using the sfftxt parameter. \n"; + helpString += "The trim parameter allows you to indicate if you would like a sequences and quality scores trimmed to the clipQualLeft and clipQualRight values. Default=True. \n"; + helpString += "The accnos parameter allows you to provide a accnos file containing the names of the sequences you would like extracted. You may enter multiple files by separating them by -'s. \n"; + helpString += "Example sffinfo(sff=mySffFile.sff, trim=F).\n"; + helpString += "Note: No spaces between parameter labels (i.e. sff), '=' and parameters (i.e.yourSffFileName).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "SffInfoCommand", "getHelpString"); + exit(1); + } +} + + //********************************************************************************************************************** SffInfoCommand::SffInfoCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["flow"] = tempOutNames; @@ -38,29 +74,6 @@ SffInfoCommand::SffInfoCommand(){ } } //********************************************************************************************************************** -vector SffInfoCommand::getRequiredParameters(){ - try { - string Array[] = {"sff", "sfftxt", "or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SffInfoCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SffInfoCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SffInfoCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** SffInfoCommand::SffInfoCommand(string option) { try { @@ -72,8 +85,7 @@ SffInfoCommand::SffInfoCommand(string option) { else { //valid paramters for this command - string Array[] = {"sff","qfile","fasta","flow","trim","accnos","sfftxt","outputdir","inputdir", "outputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -240,7 +252,12 @@ SffInfoCommand::SffInfoCommand(string option) { else if (sfftxtFilename == "not open") { sfftxtFilename = ""; } } - if ((sfftxtFilename == "") && (filenames.size() == 0)) { m->mothurOut("[ERROR]: you must provide a valid sff or sfftxt file."); m->mothurOutEndLine(); abort=true; } + if ((sfftxtFilename == "") && (filenames.size() == 0)) { + //if there is a current fasta file, use it + string filename = m->getSFFFile(); + if (filename != "") { filenames.push_back(filename); m->mothurOut("Using " + filename + " as input file for the sff parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("[ERROR]: you must provide a valid sff or sfftxt file."); m->mothurOutEndLine(); abort=true; } + } } } catch(exception& e) { @@ -248,32 +265,6 @@ SffInfoCommand::SffInfoCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void SffInfoCommand::help(){ - try { - m->mothurOut("The sffinfo command reads a sff file and extracts the sequence data, or you can use it to parse a sfftxt file..\n"); - m->mothurOut("The sffinfo command parameters are sff, fasta, qfile, accnos, flow, sfftxt, and trim. sff is required. \n"); - m->mothurOut("The sff parameter allows you to enter the sff file you would like to extract data from. You may enter multiple files by separating them by -'s.\n"); - m->mothurOut("The fasta parameter allows you to indicate if you would like a fasta formatted file generated. Default=True. \n"); - m->mothurOut("The qfile parameter allows you to indicate if you would like a quality file generated. Default=True. \n"); - m->mothurOut("The flow parameter allows you to indicate if you would like a flowgram file generated. Default=False. \n"); - m->mothurOut("The sfftxt parameter allows you to indicate if you would like a sff.txt file generated. Default=False. \n"); - m->mothurOut("If you want to parse an existing sfftxt file into flow, fasta and quality file, enter the file name using the sfftxt parameter. \n"); - m->mothurOut("The trim parameter allows you to indicate if you would like a sequences and quality scores trimmed to the clipQualLeft and clipQualRight values. Default=True. \n"); - m->mothurOut("The accnos parameter allows you to provide a accnos file containing the names of the sequences you would like extracted. You may enter multiple files by separating them by -'s. \n"); - m->mothurOut("Example sffinfo(sff=mySffFile.sff, trim=F).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. sff), '=' and parameters (i.e.yourSffFileName).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "SffInfoCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** - -SffInfoCommand::~SffInfoCommand(){} - //********************************************************************************************************************** int SffInfoCommand::execute(){ try { diff --git a/sffinfocommand.h b/sffinfocommand.h index 0fdf6fc..0e242af 100644 --- a/sffinfocommand.h +++ b/sffinfocommand.h @@ -64,13 +64,15 @@ class SffInfoCommand : public Command { public: SffInfoCommand(string); SffInfoCommand(); - ~SffInfoCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~SffInfoCommand(){} + + vector setParameters(); + string getCommandName() { return "sffinfo"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: string sffFilename, sfftxtFilename, outputDir, accnosName; @@ -78,7 +80,6 @@ private: bool abort, fasta, qual, trim, flow, sfftxt, hasAccnos; int mycount; set seqNames; - map > outputTypes; //extract sff file functions int extractSffInfo(string, string); diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 731f981..179424b 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -12,104 +12,205 @@ //sorts lowest to highest inline bool compareSharedRabunds(SharedRAbundVector* left, SharedRAbundVector* right){ return (left->getGroup() < right->getGroup()); -} -//********************************************************************************************************************** -vector SharedCommand::getValidParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SharedCommand", "getValidParameters"); - exit(1); - } } //********************************************************************************************************************** -SharedCommand::SharedCommand(){ - try { +vector SharedCommand::setParameters(){ + try { + CommandParameter plist("list", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(plist); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); + CommandParameter pordergroup("ordergroup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pordergroup); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - //initialize outputTypes - vector tempOutNames; - outputTypes["rabund"] = tempOutNames; - outputTypes["shared"] = tempOutNames; + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } + return myArray; } catch(exception& e) { - m->errorOut(e, "SharedCommand", "SharedCommand"); + m->errorOut(e, "SharedCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector SharedCommand::getRequiredParameters(){ +string SharedCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The make.shared command reads a list and group file and creates a shared file, as well as a rabund file for each group.\n"; + helpString += "The make.shared command parameters are list, group, ordergroup, groups and label. list and group are required unless a current file is available.\n"; + helpString += "The groups parameter allows you to indicate which groups you want to include, group names should be separated by dashes. ex. groups=A-B-C. Default is all groups in your groupfile.\n"; + helpString += "The label parameter allows you to indicate which labels you want to include, label names should be separated by dashes. Default is all labels in your list file.\n"; + helpString += "The ordergroup parameter allows you to indicate the order of the groups in the sharedfile, by default the groups are listed alphabetically.\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "SharedCommand", "getRequiredParameters"); + m->errorOut(e, "SharedCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector SharedCommand::getRequiredFiles(){ +SharedCommand::SharedCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + //initialize outputTypes + vector tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["shared"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "SharedCommand", "getRequiredFiles"); + m->errorOut(e, "SharedCommand", "SharedCommand"); exit(1); } } //********************************************************************************************************************** - -SharedCommand::SharedCommand(string o) : outputDir(o) { +SharedCommand::SharedCommand(string option) { try { - globaldata = GlobalData::getInstance(); - - //initialize outputTypes - vector tempOutNames; - outputTypes["rabund"] = tempOutNames; - outputTypes["shared"] = tempOutNames; - - //getting output filename - filename = globaldata->inputFileName; - if (outputDir == "") { outputDir += m->hasPath(filename); } - - filename = outputDir + m->getRootName(m->getSimpleName(filename)); - filename = filename + "shared"; - outputTypes["shared"].push_back(filename); + abort = false; calledHelp = false; + allLines = 1; - m->openOutputFile(filename, out); - pickedGroups = false; + //allow user to run help + if(option == "help") { help(); abort = true; calledHelp = true; } - groupMap = globaldata->gGroupmap; - - //if hte user has not specified any groups then use them all - if (globaldata->Groups.size() == 0) { - groups = groupMap->namesOfGroups; - }else{ //they have specified groups - groups = globaldata->Groups; - pickedGroups = true; - } - - //fill filehandles with neccessary ofstreams - int i; - ofstream* temp; - for (i=0; i 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; } + } + + //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("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("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; } + } + } + + + //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 = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current list file and the list parameter is required."); m->mothurOutEndLine(); abort = true; } + } + + ordergroupfile = validParameter.validFile(parameters, "ordergroup", true); + if (ordergroupfile == "not open") { abort = true; } + else if (ordergroupfile == "not found") { ordergroupfile = ""; } + + groupfile = validParameter.validFile(parameters, "group", true); + if (groupfile == "not open") { abort = true; } + else if (groupfile == "not found") { + groupfile = m->getGroupFile(); + if (groupfile != "") { + m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); + groupMap = new GroupMap(groupfile); + + int error = groupMap->readMap(); + if (error == 1) { abort = true; } + m->namesOfGroups = groupMap->namesOfGroups; + } + else { m->mothurOut("You have no current group file and the group parameter is required."); m->mothurOutEndLine(); abort = true; } + }else { + groupMap = new GroupMap(groupfile); + + int error = groupMap->readMap(); + if (error == 1) { abort = true; } + m->namesOfGroups = groupMap->namesOfGroups; + m->setGroupFile(groupfile); + } + + string groups = validParameter.validFile(parameters, "groups", false); + if (groups == "not found") { groups = ""; } + else { + m->splitAtDash(groups, Groups); + m->Groups = Groups; + } + + //check for optional parameter and set defaults + // ...at some point should added some additional type checking... + string label = validParameter.validFile(parameters, "label", false); + if (label == "not found") { label = ""; } + else { + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } + else { allLines = 1; } + } + + //getting output filename + filename = listfile; + if (outputDir == "") { outputDir += m->hasPath(filename); } + + filename = outputDir + m->getRootName(m->getSimpleName(filename)); + filename = filename + "shared"; + outputTypes["shared"].push_back(filename); + + m->openOutputFile(filename, out); + pickedGroups = false; + + //if hte user has not specified any groups then use them all + if (Groups.size() == 0) { + Groups = groupMap->namesOfGroups; m->Groups = Groups; + } + + //fill filehandles with neccessary ofstreams + int i; + ofstream* temp; + for (i=0; igetRootName(m->getSimpleName(listfile)); + + //clears file before we start to write to it below + for (int i=0; igetRootName(m->getSimpleName(globaldata->getListFile())); - - //clears file before we start to write to it below - for (int i=0; ierrorOut(e, "SharedCommand", "SharedCommand"); @@ -126,27 +227,22 @@ int SharedCommand::execute(){ //errorOff = ""; //if user provided an order file containing the order the shared file should be in read it - if (globaldata->getOrderGroupFile() != "") { readOrderFile(); } + if (ordergroupfile != "") { readOrderFile(); } - //read in listfile - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - delete read; - - input = globaldata->ginput; - SharedList = globaldata->gSharedList; + input = new InputData(listfile, "shared"); + SharedList = input->getSharedListVector(); string lastLabel = SharedList->getLabel(); vector lookup; if (m->control_pressed) { - delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL; + delete input; delete SharedList; delete groupMap; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); remove(filename.c_str()); - for (int i=0; iGroups.size() == 0) && (SharedList->getNumSeqs() != groupMap->getNumSeqs())) { //if the user has not specified any groups and their files don't match exit with error + if ((m->Groups.size() == 0) && (SharedList->getNumSeqs() != groupMap->getNumSeqs())) { //if the user has not specified any groups and their files don't match exit with error m->mothurOut("Your group file contains " + toString(groupMap->getNumSeqs()) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine(); out.close(); @@ -158,22 +254,22 @@ int SharedCommand::execute(){ for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - delete input; - globaldata->ginput = NULL; - delete SharedList; - globaldata->gSharedList = NULL; + + delete input; delete SharedList; delete groupMap; - return 1; + return 0; } //if user has specified groups make new groupfile for them - if (globaldata->Groups.size() != 0) { //make new group file + if (m->Groups.size() != 0) { //make new group file string groups = ""; - for (int i = 0; i < globaldata->Groups.size(); i++) { - groups += globaldata->Groups[i] + "."; - } + if (m->Groups.size() < 4) { + for (int i = 0; i < m->Groups.size(); i++) { + groups += m->Groups[i] + "."; + } + }else { groups = "merge"; } - string newGroupFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + groups + "groups"; + string newGroupFile = outputDir + m->getRootName(m->getSimpleName(listfile)) + groups + "groups"; ofstream outGroups; m->openOutputFile(newGroupFile, outGroups); @@ -181,7 +277,7 @@ int SharedCommand::execute(){ string groupName; for (int i = 0; i < names.size(); i++) { groupName = groupMap->getGroup(names[i]); - if (isValidGroup(groupName, globaldata->Groups)) { + if (isValidGroup(groupName, m->Groups)) { outGroups << names[i] << '\t' << groupName << endl; } } @@ -190,18 +286,18 @@ int SharedCommand::execute(){ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; - set userLabels = globaldata->labels; + set userLabels = labels; - while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) { + while((SharedList != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (m->control_pressed) { - delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL; + delete input; delete SharedList; delete groupMap; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); remove(filename.c_str()); - for (int i=0; iallLines == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){ + if(allLines == 1 || labels.count(SharedList->getLabel()) == 1){ lookup = SharedList->getSharedRAbundVector(); @@ -211,12 +307,12 @@ int SharedCommand::execute(){ } if (m->control_pressed) { - delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL; + delete input; delete SharedList; delete groupMap; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); remove(filename.c_str()); - for (int i=0; icontrol_pressed) { - delete input; delete SharedList; globaldata->ginput = NULL; globaldata->gSharedList = NULL; + delete input; delete SharedList; delete groupMap; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); remove(filename.c_str()); - for (int i=0; icontrol_pressed) { - delete input; globaldata->ginput = NULL; + delete input; delete groupMap; for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } out.close(); remove(filename.c_str()); - for (int i=0; igSharedList = NULL; - out.close(); for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - - //change format to shared to speed up commands - globaldata->setFormat("sharedfile"); - globaldata->setListFile(""); - globaldata->setGroupFile(""); - globaldata->setSharedFile(filename); - + delete input; delete groupMap; if (m->control_pressed) { - delete input; globaldata->ginput = NULL; remove(filename.c_str()); - for (int i=0; i thislookup) { if (order.size() == 0) { //user has not specified an order so do aplabetically sort(thislookup.begin(), thislookup.end(), compareSharedRabunds); - globaldata->Groups.clear(); + m->Groups.clear(); //initialize bin values for (int i = 0; i < thislookup.size(); i++) { out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t'; thislookup[i]->print(out); - globaldata->Groups.push_back(thislookup[i]->getGroup()); + m->Groups.push_back(thislookup[i]->getGroup()); RAbundVector rav = thislookup[i]->getRAbundVector(); m->openOutputFileAppend(fileroot + thislookup[i]->getGroup() + ".rabund", *(filehandles[thislookup[i]->getGroup()])); @@ -376,7 +463,7 @@ void SharedCommand::printSharedData(vector thislookup) { myMap[thislookup[i]->getGroup()] = thislookup[i]; } - globaldata->Groups.clear(); + m->Groups.clear(); //loop through ordered list and print the rabund for (int i = 0; i < order.size(); i++) { @@ -386,7 +473,7 @@ void SharedCommand::printSharedData(vector thislookup) { out << (myIt->second)->getLabel() << '\t' << (myIt->second)->getGroup() << '\t'; (myIt->second)->print(out); - globaldata->Groups.push_back((myIt->second)->getGroup()); + m->Groups.push_back((myIt->second)->getGroup()); RAbundVector rav = (myIt->second)->getRAbundVector(); m->openOutputFileAppend(fileroot + (myIt->second)->getGroup() + ".rabund", *(filehandles[(myIt->second)->getGroup()])); @@ -451,7 +538,7 @@ int SharedCommand::eliminateZeroOTUS(vector& thislookup) { int SharedCommand::createMisMatchFile() { try { ofstream outMisMatch; - string outputMisMatchName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); + string outputMisMatchName = outputDir + m->getRootName(m->getSimpleName(listfile)); //you have sequences in your list file that are not in your group file if (SharedList->getNumSeqs() > groupMap->getNumSeqs()) { @@ -570,7 +657,7 @@ int SharedCommand::readOrderFile() { order.clear(); ifstream in; - m->openInputFile(globaldata->getOrderGroupFile(), in); + m->openInputFile(ordergroupfile, in); string thisGroup; while(!in.eof()){ diff --git a/sharedcommand.h b/sharedcommand.h index 2c5ab23..f1e7c48 100644 --- a/sharedcommand.h +++ b/sharedcommand.h @@ -12,7 +12,6 @@ #include "command.hpp" #include "sharedlistvector.h" #include "inputdata.h" -#include "readotu.h" /* The shared() command: The shared command can only be executed after a successful read.shared command. @@ -21,20 +20,20 @@ There are no shared command parameters. The shared command should be in the following format: shared(). */ -class GlobalData; - class SharedCommand : public Command { public: SharedCommand(string); SharedCommand(); ~SharedCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help() {} + + vector setParameters(); + string getCommandName() { return "make.shared"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: void printSharedData(vector); @@ -42,17 +41,15 @@ private: int readOrderFile(); bool isValidGroup(string, vector); int eliminateZeroOTUS(vector&); - map > outputTypes; - GlobalData* globaldata; - ReadOTUFile* read; SharedListVector* SharedList; InputData* input; GroupMap* groupMap; - vector groups, outputNames, order; + vector Groups, outputNames, order; + set labels; ofstream out; - string filename, fileroot, outputDir; - bool firsttime, pickedGroups; + string filename, fileroot, outputDir, listfile, groupfile, ordergroupfile; + bool firsttime, pickedGroups, abort, allLines; map filehandles; map::iterator it3; diff --git a/sharedjackknife.cpp b/sharedjackknife.cpp index 26ad126..f80a8d4 100644 --- a/sharedjackknife.cpp +++ b/sharedjackknife.cpp @@ -88,8 +88,7 @@ EstOutput SharedJackknife::getValues(vector vectorShared){ SharedRAbundVector* shared1 = vectorShared[0]; SharedRAbundVector* shared2 = vectorShared[1]; if(numGroups == -1) { - globaldata = GlobalData::getInstance(); - numGroups = globaldata->Groups.size(); + numGroups = m->Groups.size(); } if(callCount == numGroups*(numGroups-1)/2) { diff --git a/sharedjackknife.h b/sharedjackknife.h index a248893..9f4ef72 100644 --- a/sharedjackknife.h +++ b/sharedjackknife.h @@ -11,7 +11,6 @@ */ #include "calculator.h" -#include "globaldata.hpp" /*This class implements the SharedJackknife estimator. It is a child of the calculator class.*/ @@ -26,7 +25,6 @@ public: EstOutput getValues(vector); private: - GlobalData* globaldata; int numGroups, callCount, count; bool currentCallDone; vector groups; diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 1493ee9..3852c0c 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -16,19 +16,17 @@ /***********************************************************************/ -SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; } +SharedListVector::SharedListVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0){ groupmap = NULL; } /***********************************************************************/ -SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){globaldata = GlobalData::getInstance(); groupmap = NULL; } +SharedListVector::SharedListVector(int n): DataVector(), data(n, "") , maxRank(0), numBins(0), numSeqs(0){ groupmap = NULL; } /***********************************************************************/ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { - globaldata = GlobalData::getInstance(); - //set up groupmap for later. - groupmap = new GroupMap(globaldata->getGroupFile()); + groupmap = new GroupMap(m->getGroupFile()); groupmap->readMap(); int hold; @@ -269,16 +267,16 @@ vector SharedListVector::getSharedRAbundVector() { map finder; //contains all groups in groupmap string group, names, name; - util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); + util->setGroups(m->Groups, groupmap->namesOfGroups); delete util; - for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) { + for (int i = 0; i < groupmap->namesOfGroups.size(); i++) { SharedRAbundVector* temp = new SharedRAbundVector(data.size()); - finder[globaldata->gGroupmap->namesOfGroups[i]] = temp; - finder[globaldata->gGroupmap->namesOfGroups[i]]->setLabel(label); - finder[globaldata->gGroupmap->namesOfGroups[i]]->setGroup(globaldata->gGroupmap->namesOfGroups[i]); - if (m->inUsersGroups(globaldata->gGroupmap->namesOfGroups[i], globaldata->Groups)) { //if this group is in user groups - lookup.push_back(finder[globaldata->gGroupmap->namesOfGroups[i]]); + finder[groupmap->namesOfGroups[i]] = temp; + finder[groupmap->namesOfGroups[i]]->setLabel(label); + finder[groupmap->namesOfGroups[i]]->setGroup(groupmap->namesOfGroups[i]); + if (m->inUsersGroups(groupmap->namesOfGroups[i], m->Groups)) { //if this group is in user groups + lookup.push_back(finder[groupmap->namesOfGroups[i]]); } } diff --git a/sharedlistvector.h b/sharedlistvector.h index 0586dff..56ea802 100644 --- a/sharedlistvector.h +++ b/sharedlistvector.h @@ -12,7 +12,6 @@ #include "datavector.hpp" #include "groupmap.h" -#include "globaldata.hpp" #include "sharedrabundvector.h" #include "sharedsabundvector.h" @@ -33,7 +32,7 @@ public: SharedListVector(); SharedListVector(int); SharedListVector(ifstream&); - SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){globaldata = GlobalData::getInstance(); groupmap = NULL; }; + SharedListVector(const SharedListVector& lv) : DataVector(lv.label), data(lv.data), maxRank(lv.maxRank), numBins(lv.numBins), numSeqs(lv.numSeqs){ groupmap = NULL; }; ~SharedListVector(){ if (groupmap != NULL) { delete groupmap; } }; int getNumBins() { return numBins; } @@ -58,7 +57,6 @@ public: private: vector data; //data[i] is a list of names of sequences in the ith OTU. - GlobalData* globaldata; GroupMap* groupmap; int maxRank; int numBins; diff --git a/sharedordervector.cpp b/sharedordervector.cpp index 15ee7fc..37cd283 100644 --- a/sharedordervector.cpp +++ b/sharedordervector.cpp @@ -28,10 +28,9 @@ SharedOrderVector::SharedOrderVector(string id, vector ov) : SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { //reads in a shared file try { - globaldata = GlobalData::getInstance(); maxRank = 0; numBins = 0; numSeqs = 0; - - if (globaldata->gGroupmap == NULL) { groupmap = new GroupMap(); } + + groupmap = new GroupMap(); int num, inputData, count; count = 0; numSeqs = 0; @@ -42,11 +41,11 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { //reads in a f >> label >> groupN >> num; holdLabel = label; - if (globaldata->gGroupmap == NULL) { - //save group in groupmap - groupmap->namesOfGroups.push_back(groupN); - groupmap->groupIndex[groupN] = 0; - } + + //save group in groupmap + groupmap->namesOfGroups.push_back(groupN); + groupmap->groupIndex[groupN] = 0; + for(int i=0;i> inputData; @@ -66,11 +65,11 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { //reads in a f >> groupN >> num; count++; - if (globaldata->gGroupmap == NULL) { - //save group in groupmap - groupmap->namesOfGroups.push_back(groupN); - groupmap->groupIndex[groupN] = count; - } + + //save group in groupmap + groupmap->namesOfGroups.push_back(groupN); + groupmap->groupIndex[groupN] = count; + for(int i=0;i> inputData; @@ -90,7 +89,7 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { //reads in a //put file pointer back since you are now at a new distance label for (int i = 0; i < nextLabel.length(); i++) { f.unget(); } - if (globaldata->gGroupmap == NULL) { globaldata->gGroupmap = groupmap; } + m->namesOfGroups = groupmap->namesOfGroups; updateStats(); @@ -286,8 +285,8 @@ vector SharedOrderVector::getSharedRAbundVector() { util = new SharedUtil(); vector lookup; - util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); - util->getSharedVectors(globaldata->Groups, lookup, this); + util->setGroups(m->Groups, m->namesOfGroups); + util->getSharedVectors(m->Groups, lookup, this); return lookup; } diff --git a/sharedordervector.h b/sharedordervector.h index 6aa8ba1..09d4959 100644 --- a/sharedordervector.h +++ b/sharedordervector.h @@ -42,11 +42,7 @@ struct individualFloat { #include "rabundvector.hpp" #include "sharedrabundvector.h" #include "sharedsabundvector.h" -#include "globaldata.hpp" #include "groupmap.h" -//#include "globaldata.hpp" - -class GlobalData; class SharedOrderVector : public DataVector { @@ -83,7 +79,6 @@ public: vector getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups private: - GlobalData* globaldata; GroupMap* groupmap; vector data; map< int, vector >::iterator it; diff --git a/sharedrabundfloatvector.cpp b/sharedrabundfloatvector.cpp index d65cc20..6c2dea1 100644 --- a/sharedrabundfloatvector.cpp +++ b/sharedrabundfloatvector.cpp @@ -12,14 +12,14 @@ /***********************************************************************/ -SharedRAbundFloatVector::SharedRAbundFloatVector() : DataVector(), maxRank(0.0), numBins(0), numSeqs(0.0) {globaldata = GlobalData::getInstance();} +SharedRAbundFloatVector::SharedRAbundFloatVector() : DataVector(), maxRank(0.0), numBins(0), numSeqs(0.0) {} /***********************************************************************/ SharedRAbundFloatVector::~SharedRAbundFloatVector() {} /***********************************************************************/ SharedRAbundFloatVector::SharedRAbundFloatVector(int n) : DataVector(), maxRank(0.0), numBins(n), numSeqs(0.0) { - globaldata = GlobalData::getInstance(); + individualFloat newGuy; //initialize data for (int i=0; i< n; i++) { @@ -32,9 +32,8 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(int n) : DataVector(), maxRank( //reads a shared file SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), maxRank(0.0), numBins(0), numSeqs(0.0) { try { - globaldata = GlobalData::getInstance(); - if (globaldata->gGroupmap == NULL) { groupmap = new GroupMap(); } + m->namesOfGroups.clear(); int num, count; float inputData; @@ -45,8 +44,8 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), ma for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } lookup.clear(); - if (globaldata->saveNextLabel == "") { f >> label; } - else { label = globaldata->saveNextLabel; } + if (m->saveNextLabel == "") { f >> label; } + else { label = m->saveNextLabel; } //read in first row since you know there is at least 1 group. f >> groupN >> num; @@ -59,11 +58,7 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), ma lookup[0]->setLabel(label); lookup[0]->setGroup(groupN); - if (globaldata->gGroupmap == NULL) { - //save group in groupmap - groupmap->namesOfGroups.push_back(groupN); - groupmap->groupIndex[groupN] = 0; - } + m->namesOfGroups.push_back(groupN); //fill vector. data = first sharedrabund in file for(int i=0;i> groupN >> num; count++; - if (globaldata->gGroupmap == NULL) { - //save group in groupmap - groupmap->namesOfGroups.push_back(groupN); - groupmap->groupIndex[groupN] = count; - } + m->namesOfGroups.push_back(groupN); //add new vector to lookup temp = new SharedRAbundFloatVector(); @@ -107,10 +98,8 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), ma if (f.eof() != true) { f >> nextLabel; } } - globaldata->saveNextLabel = nextLabel; + m->saveNextLabel = nextLabel; - if (globaldata->gGroupmap == NULL) { globaldata->gGroupmap = groupmap; } - } catch(exception& e) { m->errorOut(e, "SharedRAbundFloatVector", "SharedRAbundFloatVector"); @@ -287,12 +276,12 @@ vector SharedRAbundFloatVector::getSharedRAbundFloatVe SharedUtil* util; util = new SharedUtil(); - util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); + util->setGroups(m->Groups, m->namesOfGroups); bool remove = false; for (int i = 0; i < lookup.size(); i++) { //if this sharedrabund is not from a group the user wants then delete it. - if (util->isValidGroup(lookup[i]->getGroup(), globaldata->Groups) == false) { + if (util->isValidGroup(lookup[i]->getGroup(), m->Groups) == false) { delete lookup[i]; lookup[i] = NULL; lookup.erase(lookup.begin()+i); i--; diff --git a/sharedrabundfloatvector.h b/sharedrabundfloatvector.h index b0d8491..06fb604 100644 --- a/sharedrabundfloatvector.h +++ b/sharedrabundfloatvector.h @@ -15,7 +15,7 @@ #include "sharedordervector.h" #include "sharedsabundvector.h" #include "rabundvector.hpp" -#include "groupmap.h" +//#include "groupmap.h" /* This class is a child to datavector. It represents OTU information at a certain distance. It is similiar to an rabundvector except each member of data knows which group it belongs to. @@ -68,8 +68,8 @@ public: private: vector data; vector lookup; - GlobalData* globaldata; - GroupMap* groupmap; + //GlobalData* globaldata; + //GroupMap* groupmap; float maxRank; int numBins; float numSeqs; diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index a050ab3..1440ee1 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -14,8 +14,7 @@ /***********************************************************************/ - -SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {globaldata = GlobalData::getInstance();} +SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {} /***********************************************************************/ SharedRAbundVector::~SharedRAbundVector() { @@ -26,7 +25,6 @@ SharedRAbundVector::~SharedRAbundVector() { /***********************************************************************/ SharedRAbundVector::SharedRAbundVector(int n) : DataVector(), maxRank(0), numBins(n), numSeqs(0) { - globaldata = GlobalData::getInstance(); individual newGuy; //initialize data for (int i=0; i< n; i++) { @@ -61,9 +59,7 @@ SharedRAbundVector::SharedRAbundVector(string id, vector rav) : Data //reads a shared file SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numSeqs(0) { try { - globaldata = GlobalData::getInstance(); - - if (globaldata->gGroupmap == NULL) { groupmap = new GroupMap(); } + m->namesOfGroups.clear(); int num, inputData, count; count = 0; @@ -72,8 +68,8 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } lookup.clear(); - if (globaldata->saveNextLabel == "") { f >> label; } - else { label = globaldata->saveNextLabel; } + if (m->saveNextLabel == "") { f >> label; } + else { label = m->saveNextLabel; } //read in first row since you know there is at least 1 group. f >> groupN >> num; @@ -86,11 +82,7 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), lookup[0]->setLabel(label); lookup[0]->setGroup(groupN); - if (globaldata->gGroupmap == NULL) { - //save group in groupmap - groupmap->namesOfGroups.push_back(groupN); - groupmap->groupIndex[groupN] = 0; - } + m->namesOfGroups.push_back(groupN); //fill vector. data = first sharedrabund in file for(int i=0;i> groupN >> num; count++; - if (globaldata->gGroupmap == NULL) { - //save group in groupmap - - groupmap->namesOfGroups.push_back(groupN); - groupmap->groupIndex[groupN] = count; - } + m->namesOfGroups.push_back(groupN); //add new vector to lookup temp = new SharedRAbundVector(); @@ -136,9 +123,7 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), if (f.eof() != true) { f >> nextLabel; } } - globaldata->saveNextLabel = nextLabel; - - if (globaldata->gGroupmap == NULL) { globaldata->gGroupmap = groupmap; } + m->saveNextLabel = nextLabel; } catch(exception& e) { @@ -370,12 +355,12 @@ vector SharedRAbundVector::getSharedRAbundVectors(){ SharedUtil* util; util = new SharedUtil(); - util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups); + util->setGroups(m->Groups, m->namesOfGroups); bool remove = false; for (int i = 0; i < lookup.size(); i++) { //if this sharedrabund is not from a group the user wants then delete it. - if (util->isValidGroup(lookup[i]->getGroup(), globaldata->Groups) == false) { + if (util->isValidGroup(lookup[i]->getGroup(), m->Groups) == false) { remove = true; delete lookup[i]; lookup[i] = NULL; lookup.erase(lookup.begin()+i); diff --git a/sharedrabundvector.h b/sharedrabundvector.h index beece8e..887478f 100644 --- a/sharedrabundvector.h +++ b/sharedrabundvector.h @@ -15,7 +15,7 @@ #include "sharedsabundvector.h" #include "sharedrabundfloatvector.h" #include "rabundvector.hpp" -#include "groupmap.h" +//#include "groupmap.h" /* This class is a child to datavector. It represents OTU information at a certain distance. It is similiar to an rabundvector except each member of data knows which group it belongs to. @@ -23,7 +23,7 @@ An individual which knows the OTU from which it came, the group it is in and its abundance. */ -class GlobalData; +//class GlobalData; class SharedRAbundVector : public DataVector { @@ -75,8 +75,8 @@ public: private: vector data; vector lookup; - GlobalData* globaldata; - GroupMap* groupmap; + //GlobalData* globaldata; + //GroupMap* groupmap; int maxRank; int numBins; int numSeqs; diff --git a/sharedutilities.cpp b/sharedutilities.cpp index d2a43ea..15f16a6 100644 --- a/sharedutilities.cpp +++ b/sharedutilities.cpp @@ -305,7 +305,7 @@ bool SharedUtil::isValidGroup(string groupname, vector groups) { } } -/**************************************************************************************/ +/************************************************************************************** void SharedUtil::updateGroupIndex(vector& userGroups, map& index) { try { index.clear(); @@ -318,3 +318,6 @@ void SharedUtil::updateGroupIndex(vector& userGroups, map& exit(1); } } +/**************************************************************************************/ + + diff --git a/sharedutilities.h b/sharedutilities.h index df7e8d3..9892173 100644 --- a/sharedutilities.h +++ b/sharedutilities.h @@ -28,7 +28,7 @@ class SharedUtil { void setGroups(vector&, vector&, string); //globaldata->Groups, your tree or group map, mode void setGroups(vector&, vector&, string&, int&, string); //globaldata->Groups, your tree or group map, allgroups, numGroups, mode void getCombos(vector&, vector, int&); //groupcomb, globaldata->Groups, numcomb - void updateGroupIndex(vector&, map&); //globaldata->Groups, groupmap->groupIndex + //void updateGroupIndex(vector&, map&); //globaldata->Groups, groupmap->groupIndex bool isValidGroup(string, vector); private: diff --git a/shhhercommand.cpp b/shhhercommand.cpp index 024fbab..74669ed 100644 --- a/shhhercommand.cpp +++ b/shhhercommand.cpp @@ -26,64 +26,56 @@ #define MIN_WEIGHT 0.1 #define MIN_TAU 0.0001 #define MIN_ITER 10 - //********************************************************************************************************************** - -vector ShhherCommand::getValidParameters(){ +vector ShhherCommand::setParameters(){ try { - string Array[] = { - "file", "flow", "lookup", "cutoff", "sigma", "outputdir","inputdir", "processors", "maxiter", "mindelta", "order" - }; + CommandParameter pflow("flow", "InputTypes", "", "", "none", "fileflow", "none",false,false); parameters.push_back(pflow); + CommandParameter pfile("file", "InputTypes", "", "", "none", "fileflow", "none",false,false); parameters.push_back(pfile); + CommandParameter plookup("lookup", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(plookup); + CommandParameter pcutoff("cutoff", "Number", "", "0.01", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pmaxiter("maxiter", "Number", "", "1000", "", "", "",false,false); parameters.push_back(pmaxiter); + CommandParameter psigma("sigma", "Number", "", "60", "", "", "",false,false); parameters.push_back(psigma); + CommandParameter pmindelta("mindelta", "Number", "", "0.000001", "", "", "",false,false); parameters.push_back(pmindelta); + CommandParameter porder("order", "String", "", "", "", "", "",false,false); parameters.push_back(porder); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "ShhherCommand", "getValidParameters"); + m->errorOut(e, "ShhherCommand", "setParameters"); exit(1); } } - //********************************************************************************************************************** - -ShhherCommand::ShhherCommand(){ +string ShhherCommand::getHelpString(){ try { - abort = true; calledHelp = true; - - //initialize outputTypes - vector tempOutNames; - outputTypes["pn.dist"] = tempOutNames; - + string helpString = ""; + helpString += "The shhh.seqs command reads a file containing flowgrams and creates a file of corrected sequences.\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ShhherCommand", "ShhherCommand"); + m->errorOut(e, "ShhherCommand", "getHelpString"); exit(1); } } - //********************************************************************************************************************** -vector ShhherCommand::getRequiredParameters(){ +ShhherCommand::ShhherCommand(){ try { - string Array[] = {"flow"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ShhherCommand", "getRequiredParameters"); - exit(1); - } -} - -//********************************************************************************************************************** + abort = true; calledHelp = true; + setParameters(); + + //initialize outputTypes + vector tempOutNames; + outputTypes["pn.dist"] = tempOutNames; -vector ShhherCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; } catch(exception& e) { - m->errorOut(e, "ShhherCommand", "getRequiredFiles"); + m->errorOut(e, "ShhherCommand", "ShhherCommand"); exit(1); } } @@ -108,13 +100,7 @@ ShhherCommand::ShhherCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - - //valid paramters for this command - string AlignArray[] = { - "file", "flow", "lookup", "cutoff", "sigma", "outputdir","inputdir", "processors", "maxiter", "mindelta", "order" - }; - - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -196,8 +182,9 @@ ShhherCommand::ShhherCommand(string option) { else if(temp == "not open") { abort = true; } else { lookupFileName = temp; } - temp = validParameter.validFile(parameters, "processors", false);if (temp == "not found"){ temp = "1"; } - convert(temp, processors); + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found"){ temp = "0.01"; } convert(temp, cutoff); @@ -217,7 +204,6 @@ ShhherCommand::ShhherCommand(string option) { m->mothurOut("The value of the order option must be four bases long\n"); } - globaldata = GlobalData::getInstance(); } #ifdef USE_MPI @@ -230,23 +216,6 @@ ShhherCommand::ShhherCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -ShhherCommand::~ShhherCommand(){} - -//********************************************************************************************************************** - -void ShhherCommand::help(){ - try { - m->mothurOut("The shhher command reads a file containing flowgrams and creates a file of corrected sequences.\n"); - } - catch(exception& e) { - m->errorOut(e, "ShhherCommand", "help"); - exit(1); - } -} - //********************************************************************************************************************** #ifdef USE_MPI int ShhherCommand::execute(){ @@ -1154,11 +1123,6 @@ string ShhherCommand::createNamesFile(){ string ShhherCommand::cluster(string distFileName, string namesFileName){ try { - - globaldata->setNameFile(namesFileName); - globaldata->setColumnFile(distFileName); - globaldata->setFormat("column"); - ReadMatrix* read = new ReadColumnMatrix(distFileName); read->setCutoff(cutoff); diff --git a/shhhercommand.h b/shhhercommand.h index 51a5c3c..8d29d86 100644 --- a/shhhercommand.h +++ b/shhhercommand.h @@ -12,26 +12,25 @@ #include "mothur.h" #include "command.hpp" -#include "globaldata.hpp" + class ShhherCommand : public Command { public: ShhherCommand(string); ShhherCommand(); - ~ShhherCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~ShhherCommand() {} + + vector setParameters(); + string getCommandName() { return "shhh.seqs"; } + string getCommandCategory() { return "Hidden"; } + string getHelpString(); + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; int abort; - map > outputTypes; string outputDir, flowFileName, flowFilesFileName, lookupFileName, compositeFASTAFileName; diff --git a/splitabundcommand.cpp b/splitabundcommand.cpp index bdfbeae..810b839 100644 --- a/splitabundcommand.cpp +++ b/splitabundcommand.cpp @@ -10,21 +10,58 @@ #include "splitabundcommand.h" //********************************************************************************************************************** -vector SplitAbundCommand::getValidParameters(){ - try { - string Array[] = {"name","group","list","label","accnos","groups","fasta","cutoff","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); +vector SplitAbundCommand::setParameters(){ + try { + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pcutoff("cutoff", "Number", "", "0", "", "", "",false,true); parameters.push_back(pcutoff); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter paccnos("accnos", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(paccnos); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "SplitAbundCommand", "getValidParameters"); + m->errorOut(e, "SplitAbundCommand", "setParameters"); exit(1); } } +//********************************************************************************************************************** +string SplitAbundCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The split.abund command reads a fasta file and a list or a names file splits the sequences into rare and abundant groups. \n"; + helpString += "The split.abund command parameters are fasta, list, name, cutoff, group, label, groups, cutoff and accnos.\n"; + helpString += "The fasta and a list or name parameter are required, and you must provide a cutoff value.\n"; + helpString += "The cutoff parameter is used to qualify what is abundant and rare.\n"; + helpString += "The group parameter allows you to parse a group file into rare and abundant groups.\n"; + helpString += "The label parameter is used to read specific labels in your listfile you want to use.\n"; + helpString += "The accnos parameter allows you to output a .rare.accnos and .abund.accnos files to use with the get.seqs and remove.seqs commands.\n"; + helpString += "The groups parameter allows you to parse the files into rare and abundant files by group. \n"; + helpString += "For example if you set groups=A-B-C, you will get a .A.abund, .A.rare, .B.abund, .B.rare, .C.abund, .C.rare files. \n"; + helpString += "If you want .abund and .rare files for all groups, set groups=all. \n"; + helpString += "The split.abund command should be used in the following format: split.abund(fasta=yourFasta, list=yourListFile, group=yourGroupFile, label=yourLabels, cutoff=yourCutoff).\n"; + helpString += "Example: split.abund(fasta=abrecovery.fasta, list=abrecovery.fn.list, group=abrecovery.groups, label=0.03, cutoff=2).\n"; + helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "SplitAbundCommand", "getHelpString"); + exit(1); + } +} + //********************************************************************************************************************** SplitAbundCommand::SplitAbundCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["list"] = tempOutNames; outputTypes["name"] = tempOutNames; @@ -38,29 +75,6 @@ SplitAbundCommand::SplitAbundCommand(){ } } //********************************************************************************************************************** -vector SplitAbundCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta","list","name","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SplitAbundCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SplitAbundCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SplitAbundCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** SplitAbundCommand::SplitAbundCommand(string option) { try { abort = false; calledHelp = false; @@ -149,7 +163,11 @@ SplitAbundCommand::SplitAbundCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the split.abund command. "); m->mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { groupfile = ""; abort = true; } @@ -174,7 +192,15 @@ SplitAbundCommand::SplitAbundCommand(string option) { if ((groupfile == "") && (groups != "")) { m->mothurOut("You cannot select groups without a valid groupfile, I will disregard your groups selection. "); m->mothurOutEndLine(); groups = ""; Groups.clear(); } //do you have all files needed - if ((listfile == "") && (namefile == "")) { m->mothurOut("You must either a listfile or a namefile for the split.abund command. "); m->mothurOutEndLine(); abort = true; } + if ((listfile == "") && (namefile == "")) { + namefile = m->getNameFile(); + if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { + listfile = m->getListFile(); + if (listfile != "") { m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current list or namefile and the list or name parameter is required."); m->mothurOutEndLine(); abort = true; } + } + } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -202,29 +228,6 @@ SplitAbundCommand::SplitAbundCommand(string option) { } } //********************************************************************************************************************** -void SplitAbundCommand::help(){ - try { - m->mothurOut("The split.abund command reads a fasta file and a list or a names file splits the sequences into rare and abundant groups. \n"); - m->mothurOut("The split.abund command parameters are fasta, list, name, cutoff, group, label, groups, cutoff and accnos.\n"); - m->mothurOut("The fasta and a list or name parameter are required, and you must provide a cutoff value.\n"); - m->mothurOut("The cutoff parameter is used to qualify what is abundant and rare.\n"); - m->mothurOut("The group parameter allows you to parse a group file into rare and abundant groups.\n"); - m->mothurOut("The label parameter is used to read specific labels in your listfile you want to use.\n"); - m->mothurOut("The accnos parameter allows you to output a .rare.accnos and .abund.accnos files to use with the get.seqs and remove.seqs commands.\n"); - m->mothurOut("The groups parameter allows you to parse the files into rare and abundant files by group. \n"); - m->mothurOut("For example if you set groups=A-B-C, you will get a .A.abund, .A.rare, .B.abund, .B.rare, .C.abund, .C.rare files. \n"); - m->mothurOut("If you want .abund and .rare files for all groups, set groups=all. \n"); - m->mothurOut("The split.abund command should be used in the following format: split.abund(fasta=yourFasta, list=yourListFile, group=yourGroupFile, label=yourLabels, cutoff=yourCutoff).\n"); - m->mothurOut("Example: split.abund(fasta=abrecovery.fasta, list=abrecovery.fn.list, group=abrecovery.groups, label=0.03, cutoff=2).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "SplitAbundCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** SplitAbundCommand::~SplitAbundCommand(){ if (groupfile != "") { delete groupMap; } } diff --git a/splitabundcommand.h b/splitabundcommand.h index 2e409b2..c883a69 100644 --- a/splitabundcommand.h +++ b/splitabundcommand.h @@ -21,6 +21,7 @@ also allow an option where a user can give a group file with the list or names f #include "groupmap.h" #include "inputdata.h" #include "listvector.hpp" +#include "sequence.hpp" /***************************************************************************************/ @@ -30,13 +31,14 @@ public: SplitAbundCommand(string); SplitAbundCommand(); ~SplitAbundCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + + vector setParameters(); + string getCommandName() { return "split.abund"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: int splitList(ListVector*); @@ -50,7 +52,6 @@ private: int createNameMap(ListVector*); vector outputNames; - map > outputTypes; ListVector* list; GroupMap* groupMap; InputData* input; diff --git a/splitgroupscommand.cpp b/splitgroupscommand.cpp index 16d90a4..bdb6e7c 100644 --- a/splitgroupscommand.cpp +++ b/splitgroupscommand.cpp @@ -11,37 +11,41 @@ #include "sharedutilities.h" //********************************************************************************************************************** -vector SplitGroupCommand::getValidParameters(){ - try { - string Array[] = {"name","group","groups","fasta","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); +vector SplitGroupCommand::setParameters(){ + try { + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "SplitGroupCommand", "getValidParameters"); + m->errorOut(e, "SplitGroupCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector SplitGroupCommand::getRequiredParameters(){ +string SplitGroupCommand::getHelpString(){ try { - string Array[] = {"fasta","group"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + string helpString = ""; + helpString += "The split.group command reads a group file, and parses your fasta and names files by groups. \n"; + helpString += "The split.group command parameters are fasta, name, group and groups.\n"; + helpString += "The fasta and group parameters are required.\n"; + helpString += "The groups parameter allows you to select groups to create files for. \n"; + helpString += "For example if you set groups=A-B-C, you will get a .A.fasta, .A.names, .B.fasta, .B.names, .C.fasta, .C.names files. \n"; + helpString += "If you want .fasta and .names files for all groups, set groups=all. \n"; + helpString += "The split.group command should be used in the following format: split.group(fasta=yourFasta, group=yourGroupFile).\n"; + helpString += "Example: split.group(fasta=abrecovery.fasta, group=abrecovery.groups).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "SplitGroupCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SplitGroupCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SplitGroupCommand", "getRequiredFiles"); + m->errorOut(e, "SplitGroupCommand", "getHelpString"); exit(1); } } @@ -49,6 +53,7 @@ vector SplitGroupCommand::getRequiredFiles(){ SplitGroupCommand::SplitGroupCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["fasta"] = tempOutNames; outputTypes["name"] = tempOutNames; @@ -67,9 +72,7 @@ SplitGroupCommand::SplitGroupCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"name","group","groups","fasta","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -125,11 +128,19 @@ SplitGroupCommand::SplitGroupCommand(string option) { fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the split.group command. "); m->mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { + fastafile = m->getFastaFile(); + if (fastafile != "") { m->mothurOut("Using " + fastafile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + } groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { groupfile = ""; abort = true; } - else if (groupfile == "not found") { groupfile = ""; m->mothurOut("group is a required parameter for the split.group command. "); m->mothurOutEndLine(); abort = true; } + else if (groupfile == "not found") { + groupfile = m->getGroupFile(); + if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current groupfile and the group parameter is required."); m->mothurOutEndLine(); abort = true; } + } groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } @@ -146,27 +157,6 @@ SplitGroupCommand::SplitGroupCommand(string option) { } } //********************************************************************************************************************** -void SplitGroupCommand::help(){ - try { - m->mothurOut("The split.group command reads a group file, and parses your fasta and names files by groups. \n"); - m->mothurOut("The split.group command parameters are fasta, name, group and groups.\n"); - m->mothurOut("The fasta and group parameters are required.\n"); - m->mothurOut("The groups parameter allows you to select groups to create files for. \n"); - m->mothurOut("For example if you set groups=A-B-C, you will get a .A.fasta, .A.names, .B.fasta, .B.names, .C.fasta, .C.names files. \n"); - m->mothurOut("If you want .fasta and .names files for all groups, set groups=all. \n"); - m->mothurOut("The split.group command should be used in the following format: split.group(fasta=yourFasta, group=yourGroupFile).\n"); - m->mothurOut("Example: split.group(fasta=abrecovery.fasta, group=abrecovery.groups).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "SplitGroupCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** -SplitGroupCommand::~SplitGroupCommand(){ } -//********************************************************************************************************************** int SplitGroupCommand::execute(){ try { diff --git a/splitgroupscommand.h b/splitgroupscommand.h index c45c7ff..6705ba9 100644 --- a/splitgroupscommand.h +++ b/splitgroupscommand.h @@ -25,21 +25,21 @@ class SplitGroupCommand : public Command { public: SplitGroupCommand(string); SplitGroupCommand(); - ~SplitGroupCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + ~SplitGroupCommand() {} + + vector setParameters(); + string getCommandName() { return "split.group"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: int readNames(); int splitFasta(); vector outputNames; - map > outputTypes; map > nameMap; map >::iterator itNames; GroupMap* groupMap; diff --git a/subsamplecommand.cpp b/subsamplecommand.cpp index d24bcc5..5bc49d6 100644 --- a/subsamplecommand.cpp +++ b/subsamplecommand.cpp @@ -11,14 +11,53 @@ #include "sharedutilities.h" //********************************************************************************************************************** -vector SubSampleCommand::getValidParameters(){ - try { - string Array[] = {"fasta", "group", "list","shared","rabund","persample", "name","sabund","size","groups","label","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); +vector SubSampleCommand::setParameters(){ + try { + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(pfasta); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter plist("list", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(plist); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(pshared); + CommandParameter prabund("rabund", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(psabund); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter psize("size", "Number", "", "0", "", "", "",false,false); parameters.push_back(psize); + CommandParameter ppersample("persample", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ppersample); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "SubSampleCommand", "getValidParameters"); + m->errorOut(e, "SubSampleCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string SubSampleCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The sub.sample command is designed to be used as a way to normalize your data, or create a smaller set from your original set.\n"; + helpString += "The sub.sample command parameters are fasta, name, list, group, rabund, sabund, shared, groups, size, persample and label. You must provide a fasta, list, sabund, rabund or shared file as an input file.\n"; + helpString += "The namefile is only used with the fasta file, not with the listfile, because the list file should contain all sequences.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n"; + helpString += "The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"; + helpString += "The size parameter allows you indicate the size of your subsample.\n"; + helpString += "The persample parameter allows you indicate you want to select subsample of the same size from each of your groups, default=false. It is only used with the list and fasta files if a groupfile is given.\n"; + helpString += "persample=false will select a random set of sequences of the size you select, but the number of seqs from each group may differ.\n"; + helpString += "The size parameter is not set: with shared file size=number of seqs in smallest sample, with all other files if a groupfile is given and persample=true, then size=number of seqs in smallest sample, otherwise size=10% of number of seqs.\n"; + helpString += "The sub.sample command should be in the following format: sub.sample(list=yourListFile, group=yourGroupFile, groups=yourGroups, label=yourLabels).\n"; + helpString += "Example sub.sample(list=abrecovery.fn.list, group=abrecovery.groups, groups=B-C, size=20).\n"; + helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"; + helpString += "The sub.sample command outputs a .subsample file.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "SubSampleCommand", "getHelpString"); exit(1); } } @@ -26,6 +65,7 @@ vector SubSampleCommand::getValidParameters(){ SubSampleCommand::SubSampleCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["shared"] = tempOutNames; outputTypes["list"] = tempOutNames; @@ -41,43 +81,16 @@ SubSampleCommand::SubSampleCommand(){ } } //********************************************************************************************************************** -vector SubSampleCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta","list","shared","rabund", "sabund","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SubSampleCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SubSampleCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SubSampleCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** SubSampleCommand::SubSampleCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"fasta", "group", "list","shared","rabund","persample", "sabund","name","size","groups","label","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -209,7 +222,7 @@ SubSampleCommand::SubSampleCommand(string option) { else { pickedGroups = true; m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } string temp = validParameter.validFile(parameters, "size", false); if (temp == "not found"){ temp = "0"; } @@ -242,37 +255,6 @@ SubSampleCommand::SubSampleCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void SubSampleCommand::help(){ - try { - m->mothurOut("The sub.sample command is designed to be used as a way to normalize your data, or create a smaller set from your original set.\n"); - m->mothurOut("The sub.sample command parameters are fasta, name, list, group, rabund, sabund, shared, groups, size, persample and label. You must provide a fasta, list, sabund, rabund or shared file as an input file.\n"); - m->mothurOut("The namefile is only used with the fasta file, not with the listfile, because the list file should contain all sequences.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n"); - m->mothurOut("The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n"); - m->mothurOut("The size parameter allows you indicate the size of your subsample.\n"); - m->mothurOut("The persample parameter allows you indicate you want to select subsample of the same size from each of your groups, default=false. It is only used with the list and fasta files if a groupfile is given.\n"); - m->mothurOut("persample=false will select a random set of sequences of the size you select, but the number of seqs from each group may differ.\n"); - m->mothurOut("The size parameter is not set: with shared file size=number of seqs in smallest sample, with all other files if a groupfile is given and persample=true, then size=number of seqs in smallest sample, otherwise size=10% of number of seqs.\n"); - m->mothurOut("The sub.sample command should be in the following format: sub.sample(list=yourListFile, group=yourGroupFile, groups=yourGroups, label=yourLabels).\n"); - m->mothurOut("Example sub.sample(list=abrecovery.fn.list, group=abrecovery.groups, groups=B-C, size=20).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"); - m->mothurOut("The sub.sample command outputs a .subsample file.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "SubSampleCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -SubSampleCommand::~SubSampleCommand(){} - //********************************************************************************************************************** int SubSampleCommand::execute(){ diff --git a/subsamplecommand.h b/subsamplecommand.h index b00defd..6716903 100644 --- a/subsamplecommand.h +++ b/subsamplecommand.h @@ -11,11 +11,11 @@ */ #include "command.hpp" -#include "globaldata.hpp" #include "sharedrabundvector.h" #include "listvector.hpp" #include "rabundvector.hpp" #include "inputdata.h" +#include "sequence.hpp" class SubSampleCommand : public Command { @@ -23,23 +23,22 @@ class SubSampleCommand : public Command { public: SubSampleCommand(string); SubSampleCommand(); - ~SubSampleCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~SubSampleCommand() {} -private: - GlobalData* globaldata; + vector setParameters(); + string getCommandName() { return "sub.sample"; } + string getCommandCategory() { return "General"; } + string getHelpString(); + int execute(); + void help() { m->mothurOut(getHelpString()); } + +private: bool abort, pickedGroups, allLines, persample; string listfile, groupfile, sharedfile, rabundfile, sabundfile, fastafile, namefile; set labels; //holds labels to be used string groups, label, outputDir; vector Groups, outputNames; - map > outputTypes; int size; vector names; map > nameMap; diff --git a/summarycommand.cpp b/summarycommand.cpp index fbe7964..cc4b69f 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -35,49 +35,61 @@ #include "shen.h" //********************************************************************************************************************** -vector SummaryCommand::getValidParameters(){ +vector SummaryCommand::setParameters(){ try { - string Array[] = {"label","calc","abund","size","outputdir","groupmode","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); + CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund); + CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-np_shannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap-geometric-qstat-logseries-bergerparker-bstick-goodscoverage-efron-boneh-solow-shen", "sobs-chao-ace-jack-shannon-npshannon-simpson", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund); + CommandParameter psize("size", "Number", "", "0", "", "", "",false,false); parameters.push_back(psize); + CommandParameter pgroupmode("groupmode", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pgroupmode); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "SummaryCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -SummaryCommand::SummaryCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["summary"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "SummaryCommand", "SummaryCommand"); + m->errorOut(e, "SummaryCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector SummaryCommand::getRequiredParameters(){ +string SummaryCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + ValidCalculators validCalculator; + helpString += "The summary.single command parameters are list, sabund, rabund, shared, label, calc, abund and groupmode. list, sabund, rabund or shared is required unless you have a valid current file.\n"; + helpString += "The summary.single command should be in the following format: \n"; + helpString += "summary.single(label=yourLabel, calc=yourEstimators).\n"; + helpString += "Example summary.single(label=unique-.01-.03, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson).\n"; + helpString += validCalculator.printCalc("summary"); + helpString += "The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson\n"; + helpString += "If you are running summary.single with a shared file and would like your summary results collated in one file, set groupmode=t. (Default=true).\n"; + helpString += "The label parameter is used to analyze specific labels in your input.\n"; + helpString += "Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "SummaryCommand", "getRequiredParameters"); + m->errorOut(e, "SummaryCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector SummaryCommand::getRequiredFiles(){ +SummaryCommand::SummaryCommand(){ try { - string AlignArray[] = {"shared","list","rabund","sabund","or"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["summary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "SummaryCommand", "getRequiredFiles"); + m->errorOut(e, "SummaryCommand", "SummaryCommand"); exit(1); } } @@ -85,22 +97,18 @@ vector SummaryCommand::getRequiredFiles(){ SummaryCommand::SummaryCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Estimators.clear(); - + //allow user to run help - if(option == "help") { validCalculator = new ValidCalculators(); help(); delete validCalculator; abort = true; calledHelp = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"label","calc","abund","size","outputdir","groupmode","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; @@ -113,14 +121,91 @@ SummaryCommand::SummaryCommand(string option) { vector tempOutNames; outputTypes["summary"] = tempOutNames; - //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund, rabund or shared file before you can use the summary.single command."); m->mothurOutEndLine(); 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("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("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("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("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; } + } + } - //if the user changes the output directory command factory will send this info to us in the output parameter - outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ - outputDir = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + //check for required parameters + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { listfile = ""; abort = true; } + else if (listfile == "not found") { listfile = ""; } + else { format = "list"; inputfile = listfile; } + + sabundfile = validParameter.validFile(parameters, "sabund", true); + if (sabundfile == "not open") { sabundfile = ""; abort = true; } + else if (sabundfile == "not found") { sabundfile = ""; } + else { format = "sabund"; inputfile = sabundfile; } + + rabundfile = validParameter.validFile(parameters, "rabund", true); + if (rabundfile == "not open") { rabundfile = ""; abort = true; } + else if (rabundfile == "not found") { rabundfile = ""; } + else { format = "rabund"; inputfile = rabundfile; } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { format = "sharedfile"; inputfile = sharedfile; } + + if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + rabundfile = m->getRabundFile(); + if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); } + else { + sabundfile = m->getSabundFile(); + if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list, sabund, rabund or shared file before you can use the collect.single command."); 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(inputfile); } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -130,12 +215,6 @@ SummaryCommand::SummaryCommand(string option) { if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } else { allLines = 1; } } - - //if the user has not specified any labels use the ones from read.otu - if(label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } calc = validParameter.validFile(parameters, "calc", false); if (calc == "not found") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; } @@ -164,42 +243,15 @@ SummaryCommand::SummaryCommand(string option) { } //********************************************************************************************************************** -void SummaryCommand::help(){ - try { - m->mothurOut("The summary.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n"); - m->mothurOut("The summary.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster.\n"); - m->mothurOut("The summary.single command parameters are label, calc, abund and groupmode. No parameters are required.\n"); - m->mothurOut("The summary.single command should be in the following format: \n"); - m->mothurOut("summary.single(label=yourLabel, calc=yourEstimators).\n"); - m->mothurOut("Example summary.single(label=unique-.01-.03, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson).\n"); - validCalculator->printCalc("summary", cout); - m->mothurOut("The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson\n"); - m->mothurOut("If you are running summary.single with a shared file and would like your summary results collated in one file, set groupmode=t. (Default=true).\n"); - m->mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "SummaryCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -SummaryCommand::~SummaryCommand(){} - -//********************************************************************************************************************** - int SummaryCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } - string hadShared = ""; - if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } - else { hadShared = globaldata->getSharedFile(); inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } + if ((format != "sharedfile")) { inputFileNames.push_back(inputfile); } + else { inputFileNames = parseSharedFile(sharedfile); format = "rabund"; } - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } + if (m->control_pressed) { return 0; } int numLines = 0; int numCols = 0; @@ -210,7 +262,6 @@ int SummaryCommand::execute(){ numCols = 0; string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "summary"; - globaldata->inputFileName = inputFileNames[p]; outputNames.push_back(fileNameRoot); outputTypes["summary"].push_back(fileNameRoot); if (inputFileNames.size() > 1) { @@ -219,10 +270,10 @@ int SummaryCommand::execute(){ sumCalculators.clear(); - validCalculator = new ValidCalculators(); + ValidCalculators validCalculator; for (int i=0; iisValidCalculator("summary", Estimators[i]) == true) { + if (validCalculator.isValidCalculator("summary", Estimators[i]) == true) { if(Estimators[i] == "sobs"){ sumCalculators.push_back(new Sobs()); }else if(Estimators[i] == "chao"){ @@ -280,19 +331,16 @@ int SummaryCommand::execute(){ } //if the users entered no valid calculators don't execute command - if (sumCalculators.size() == 0) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } return 0; } + if (sumCalculators.size() == 0) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } ofstream outputFileHandle; m->openOutputFile(fileNameRoot, outputFileHandle); outputFileHandle << "label"; - - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - - sabund = globaldata->sabund; + + input = new InputData(inputFileNames[p], format); + sabund = input->getSAbundVector(); string lastLabel = sabund->getLabel(); - input = globaldata->ginput; - + for(int i=0;igetCols() == 1){ outputFileHandle << '\t' << sumCalculators[i]->getName(); @@ -309,11 +357,11 @@ int SummaryCommand::execute(){ set processedLabels; set userLabels = labels; - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;icontrol_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;igetLabel()) == 1){ @@ -325,7 +373,7 @@ int SummaryCommand::execute(){ for(int i=0;i data = sumCalculators[i]->getValues(sabund); - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;iprint(outputFileHandle); @@ -348,7 +396,7 @@ int SummaryCommand::execute(){ for(int i=0;i data = sumCalculators[i]->getValues(sabund); - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;iprint(outputFileHandle); @@ -366,7 +414,7 @@ int SummaryCommand::execute(){ sabund = input->getSAbundVector(); } - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;iginput = NULL; return 0; } + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i::iterator it; @@ -391,7 +439,7 @@ int SummaryCommand::execute(){ for(int i=0;i data = sumCalculators[i]->getValues(sabund); - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;isabund = NULL; delete input; globaldata->ginput = NULL; return 0; } + if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;iprint(outputFileHandle); @@ -403,22 +451,17 @@ int SummaryCommand::execute(){ outputFileHandle.close(); - if (m->control_pressed) { if (hadShared != "") { globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile"); } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;iginput = NULL; return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;iginput = NULL; - delete read; - delete validCalculator; - globaldata->sabund = NULL; + delete input; for(int i=0;isetSharedFile(hadShared); globaldata->setFormat("sharedfile"); } - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //create summary file containing all the groups data for each label - this function just combines the info from the files already created. - if ((hadShared != "") && (groupMode)) { outputNames.push_back(createGroupSummaryFile(numLines, numCols, outputNames)); } + if ((sharedfile != "") && (groupMode)) { outputNames.push_back(createGroupSummaryFile(numLines, numCols, outputNames)); } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } @@ -442,12 +485,7 @@ vector SummaryCommand::parseSharedFile(string filename) { map filehandles; map::iterator it3; - - //read first line - read = new ReadOTUFile(filename); - read->read(&*globaldata); - - input = globaldata->ginput; + input = new InputData(filename, "sharedfile"); vector lookup = input->getSharedRAbundVectors(); string sharedFileRoot = m->getRootName(filename); @@ -482,9 +520,8 @@ vector SummaryCommand::parseSharedFile(string filename) { for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) { delete it3->second; } - delete read; + delete input; - globaldata->ginput = NULL; return filenames; } @@ -498,7 +535,7 @@ string SummaryCommand::createGroupSummaryFile(int numLines, int numCols, vector< try { ofstream out; - string combineFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "groups.summary"; + string combineFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "groups.summary"; //open combined file m->openOutputFile(combineFileName, out); diff --git a/summarycommand.h b/summarycommand.h index d225109..5535237 100644 --- a/summarycommand.h +++ b/summarycommand.h @@ -13,39 +13,34 @@ #include "sabundvector.hpp" #include "inputdata.h" #include "calculator.h" -#include "readotu.h" #include "validcalculator.h" -class GlobalData; - class SummaryCommand : public Command { public: SummaryCommand(string); SummaryCommand(); - ~SummaryCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~SummaryCommand(){} + + vector setParameters(); + string getCommandName() { return "summary.single"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; - ReadOTUFile* read; vector sumCalculators; InputData* input; - ValidCalculators* validCalculator; SAbundVector* sabund; int abund, size; bool abort, allLines, groupMode; set labels; //holds labels to be used - string label, calc, outputDir; + string label, calc, outputDir, sharedfile, listfile, rabundfile, sabundfile, format, inputfile; vector Estimators; vector inputFileNames, outputNames; - map > outputTypes; vector groups; vector parseSharedFile(string); diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index b521444..6db7dab 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -51,49 +51,62 @@ #include "mempearson.h" //********************************************************************************************************************** -vector SummarySharedCommand::getValidParameters(){ +vector SummarySharedCommand::setParameters(){ try { - string Array[] = {"label","calc","groups","all","outputdir","distance","inputdir", "processors"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pdistance("distance", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pdistance); + CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-skulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter pall("all", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pall); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "SummarySharedCommand", "getValidParameters"); + m->errorOut(e, "SummarySharedCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -SummarySharedCommand::SummarySharedCommand(){ +string SummarySharedCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["summary"] = tempOutNames; + string helpString = ""; + ValidCalculators validCalculator; + helpString += "The summary.shared command parameters are shared, label, calc, distance, processors and all. shared is required if there is no current sharedfile.\n"; + helpString += "The summary.shared command should be in the following format: \n"; + helpString += "summary.shared(label=yourLabel, calc=yourEstimators, groups=yourGroups).\n"; + helpString += "Example summary.shared(label=unique-.01-.03, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan).\n"; + helpString += validCalculator.printCalc("sharedsummary"); + helpString += "The default value for calc is sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan\n"; + helpString += "The default value for groups is all the groups in your groupfile.\n"; + helpString += "The distance parameter allows you to indicate you would like a distance file created for each calculator for each label, default=f.\n"; + helpString += "The label parameter is used to analyze specific labels in your input.\n"; + helpString += "The all parameter is used to specify if you want the estimate of all your groups together. This estimate can only be made for sharedsobs and sharedchao calculators. The default is false.\n"; + helpString += "If you use sharedchao and run into memory issues, set all to false. \n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"; + helpString += "Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand"); + m->errorOut(e, "SummarySharedCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector SummarySharedCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SummarySharedCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SummarySharedCommand::getRequiredFiles(){ +SummarySharedCommand::SummarySharedCommand(){ try { - string Array[] = {"shared"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["summary"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "SummarySharedCommand", "getRequiredFiles"); + m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand"); exit(1); } } @@ -101,22 +114,18 @@ vector SummarySharedCommand::getRequiredFiles(){ SummarySharedCommand::SummarySharedCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Estimators.clear(); - + //allow user to run help - if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; calledHelp = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"label","calc","groups","all","outputdir","distance","inputdir", "processors"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; @@ -125,20 +134,38 @@ SummarySharedCommand::SummarySharedCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - //make sure the user has already run the read.otu command - if (globaldata->getSharedFile() == "") { - m->mothurOut("You must read a list and a group, or a shared before you can use the summary.shared command."); m->mothurOutEndLine(); abort = true; - } - //initialize outputTypes vector tempOutNames; outputTypes["summary"] = 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 = ""; - outputDir += m->hasPath(globaldata->getSharedFile()); //if user entered a file with a path then preserve it + //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("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; } + } + } + + //get shared file + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current sharedfile and the shared 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(sharedfile); } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -149,12 +176,7 @@ SummarySharedCommand::SummarySharedCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if(label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - + calc = validParameter.validFile(parameters, "calc", false); if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; } else { @@ -166,7 +188,7 @@ SummarySharedCommand::SummarySharedCommand(string option) { if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } string temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; } @@ -175,16 +197,17 @@ SummarySharedCommand::SummarySharedCommand(string option) { temp = validParameter.validFile(parameters, "distance", false); if (temp == "not found") { temp = "false"; } createPhylip = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if(temp == "not found"){ temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); if (abort == false) { - validCalculator = new ValidCalculators(); + ValidCalculators validCalculator; int i; for (i=0; iisValidCalculator("sharedsummary", Estimators[i]) == true) { + if (validCalculator.isValidCalculator("sharedsummary", Estimators[i]) == true) { if (Estimators[i] == "sharedsobs") { sumCalculators.push_back(new SharedSobsCS()); }else if (Estimators[i] == "sharedchao") { @@ -276,41 +299,6 @@ SummarySharedCommand::SummarySharedCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void SummarySharedCommand::help(){ - try { - m->mothurOut("The summary.shared command can only be executed after a successful read.otu command.\n"); - m->mothurOut("The summary.shared command parameters are label, calc, distance and all. No parameters are required.\n"); - m->mothurOut("The summary.shared command should be in the following format: \n"); - m->mothurOut("summary.shared(label=yourLabel, calc=yourEstimators, groups=yourGroups).\n"); - m->mothurOut("Example summary.shared(label=unique-.01-.03, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan).\n"); - validCalculator->printCalc("sharedsummary", cout); - m->mothurOut("The default value for calc is sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile.\n"); - m->mothurOut("The distance parameter allows you to indicate you would like a distance file created for each calculator for each label, default=f.\n"); - m->mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - m->mothurOut("The all parameter is used to specify if you want the estimate of all your groups together. This estimate can only be made for sharedsobs and sharedchao calculators. The default is false.\n"); - m->mothurOut("If you use sharedchao and run into memory issues, set all to false. \n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "SummarySharedCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -SummarySharedCommand::~SummarySharedCommand(){ - if (abort == false) { - delete read; - delete validCalculator; - } -} - //********************************************************************************************************************** int SummarySharedCommand::execute(){ @@ -319,7 +307,7 @@ int SummarySharedCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } ofstream outputFileHandle, outAll; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "shared.summary"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "shared.summary"; //if the users entered no valid calculators don't execute command if (sumCalculators.size() == 0) { return 0; } @@ -331,12 +319,8 @@ int SummarySharedCommand::execute(){ } } } - - //read first line - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - input = globaldata->ginput; + input = new InputData(sharedfile, "sharedfile"); lookup = input->getSharedRAbundVectors(); string lastLabel = lookup[0]->getLabel(); @@ -354,7 +338,7 @@ int SummarySharedCommand::execute(){ outputFileHandle.close(); //create file and put column headers for multiple groups file - string outAllFileName = ((m->getRootName(globaldata->inputFileName)) + "sharedmultiple.summary"); + string outAllFileName = ((m->getRootName(sharedfile)) + "sharedmultiple.summary"); if (mult == true) { m->openOutputFile(outAllFileName, outAll); outputNames.push_back(outAllFileName); @@ -387,10 +371,10 @@ int SummarySharedCommand::execute(){ if (m->control_pressed) { if (mult) { remove(outAllFileName.c_str()); } remove(outputFileName.c_str()); - delete input; globaldata->ginput = NULL; + delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for(int i=0;iGroups.clear(); + m->Groups.clear(); return 0; } /******************************************************/ @@ -398,7 +382,7 @@ int SummarySharedCommand::execute(){ /******************************************************/ //comparison breakup to be used by different processes later - numGroups = globaldata->Groups.size(); + numGroups = m->Groups.size(); lines.resize(processors); for (int i = 0; i < processors; i++) { lines[i].start = int (sqrt(float(i)/float(processors)) * numGroups); @@ -415,10 +399,10 @@ int SummarySharedCommand::execute(){ if (m->control_pressed) { if (mult) { remove(outAllFileName.c_str()); } remove(outputFileName.c_str()); - delete input; globaldata->ginput = NULL; + delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } for(int i=0;iGroups.clear(); + m->Groups.clear(); return 0; } @@ -458,9 +442,9 @@ int SummarySharedCommand::execute(){ if (m->control_pressed) { if (mult) { remove(outAllFileName.c_str()); } remove(outputFileName.c_str()); - delete input; globaldata->ginput = NULL; + delete input; for(int i=0;iGroups.clear(); + m->Groups.clear(); return 0; } @@ -489,10 +473,10 @@ int SummarySharedCommand::execute(){ //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); for(int i=0;iginput = NULL; + delete input; if (m->control_pressed) { remove(outAllFileName.c_str()); diff --git a/summarysharedcommand.h b/summarysharedcommand.h index 0771812..3d177e7 100644 --- a/summarysharedcommand.h +++ b/summarysharedcommand.h @@ -14,23 +14,23 @@ #include "sharedrabundvector.h" #include "inputdata.h" #include "calculator.h" -#include "readotu.h" #include "validcalculator.h" -class GlobalData; - class SummarySharedCommand : public Command { public: SummarySharedCommand(string); SummarySharedCommand(); - ~SummarySharedCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~SummarySharedCommand() {} + + vector setParameters(); + string getCommandName() { return "summary.shared"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: struct linePair { @@ -38,17 +38,13 @@ private: int end; }; vector lines; - GlobalData* globaldata; - ReadOTUFile* read; vector sumCalculators; InputData* input; - ValidCalculators* validCalculator; bool abort, allLines, mult, all, createPhylip; set labels; //holds labels to be used - string label, calc, groups; + string label, calc, groups, sharedfile; vector Estimators, Groups, outputNames; - map > outputTypes; vector lookup; string format, outputDir; int numGroups, processors; diff --git a/systemcommand.cpp b/systemcommand.cpp index abc07d0..6b0a6d0 100644 --- a/systemcommand.cpp +++ b/systemcommand.cpp @@ -9,41 +9,8 @@ #include "systemcommand.h" -//********************************************************************************************************************** -vector SystemCommand::getValidParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SystemCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SystemCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SystemCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector SystemCommand::getRequiredFiles(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "SystemCommand", "getRequiredFiles"); - exit(1); - } -} -//********************************************************************************************************************** +//********************************************************************************************************************** SystemCommand::SystemCommand(string option) { try { abort = false; calledHelp = false; @@ -74,12 +41,14 @@ SystemCommand::SystemCommand(string option) { } //********************************************************************************************************************** -void SystemCommand::help(){ +string SystemCommand::getHelpString(){ try { - m->mothurOut("The system command allows you to execute a system command from within mothur.\n"); - m->mothurOut("The system has no parameters.\n"); - m->mothurOut("The system command should be in the following format: system(yourCommand).\n"); - m->mothurOut("Example system(clear).\n"); + string helpString = ""; + helpString += "The system command allows you to execute a system command from within mothur.\n"; + helpString += "The system has no parameters.\n"; + helpString += "The system command should be in the following format: system(yourCommand).\n"; + helpString += "Example system(clear).\n"; + return helpString; } catch(exception& e) { m->errorOut(e, "SystemCommand", "help"); diff --git a/systemcommand.h b/systemcommand.h index 55b772b..892ac96 100644 --- a/systemcommand.h +++ b/systemcommand.h @@ -20,18 +20,20 @@ class SystemCommand : public Command { SystemCommand(string); SystemCommand() { abort = true; calledHelp = true; } ~SystemCommand(){} - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); - + + vector setParameters() { return outputNames; } //dummy does not do anything + string getCommandName() { return "system"; } + string getCommandCategory() { return "General"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } + private: string command; bool abort; vector outputNames; - map > outputTypes; + }; diff --git a/tree.cpp b/tree.cpp index 02f4004..53aa402 100644 --- a/tree.cpp +++ b/tree.cpp @@ -10,9 +10,8 @@ #include "tree.h" /*****************************************************************/ -Tree::Tree(int num) { +Tree::Tree(int num, TreeMap* t) : tmap(t) { try { - globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); numLeaves = num; @@ -26,12 +25,13 @@ Tree::Tree(int num) { } } /*****************************************************************/ -Tree::Tree(string g) { +Tree::Tree(string g) { //do not use tree generated by this its just to extract the treenames, its a chicken before the egg thing that needs to be revisited. try { - globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); - parseTreeFile(); globaldata->runParse = false; + tmap = NULL; + + parseTreeFile(); m->runParse = false; } catch(exception& e) { m->errorOut(e, "Tree", "Tree - just parse"); @@ -39,31 +39,30 @@ Tree::Tree(string g) { } } /*****************************************************************/ -Tree::Tree() { +Tree::Tree(TreeMap* t) : tmap(t) { try { - globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); - if (globaldata->runParse == true) { parseTreeFile(); globaldata->runParse = false; } + if (m->runParse == true) { parseTreeFile(); m->runParse = false; } //for(int i = 0; i < globaldata->Treenames.size(); i++) { cout << i << '\t' << globaldata->Treenames[i] << endl; } - numLeaves = globaldata->Treenames.size(); + numLeaves = m->Treenames.size(); numNodes = 2*numLeaves - 1; tree.resize(numNodes); //initialize groupNodeInfo - for (int i = 0; i < globaldata->gTreemap->namesOfGroups.size(); i++) { - groupNodeInfo[globaldata->gTreemap->namesOfGroups[i]].resize(0); + for (int i = 0; i < tmap->namesOfGroups.size(); i++) { + groupNodeInfo[tmap->namesOfGroups[i]].resize(0); } //initialize tree with correct number of nodes, name and group info. for (int i = 0; i < numNodes; i++) { //initialize leaf nodes if (i <= (numLeaves-1)) { - tree[i].setName(globaldata->Treenames[i]); + tree[i].setName(m->Treenames[i]); //save group info - string group = globaldata->gTreemap->getGroup(globaldata->Treenames[i]); + string group = tmap->getGroup(m->Treenames[i]); vector tempGroups; tempGroups.push_back(group); tree[i].setGroup(tempGroups); @@ -74,7 +73,7 @@ Tree::Tree() { tree[i].pGroups[group] = 1; //Treemap knows name, group and index to speed up search - globaldata->gTreemap->setIndex(globaldata->Treenames[i], i); + tmap->setIndex(m->Treenames[i], i); //intialize non leaf nodes }else if (i > (numLeaves-1)) { @@ -117,19 +116,19 @@ void Tree::addNamesToCounts() { string name = tree[i].getName(); - map::iterator itNames = globaldata->names.find(name); + map::iterator itNames = m->names.find(name); - if (itNames == globaldata->names.end()) { m->mothurOut(name + " is not in your name file, please correct."); m->mothurOutEndLine(); exit(1); } + if (itNames == m->names.end()) { m->mothurOut(name + " is not in your name file, please correct."); m->mothurOutEndLine(); exit(1); } else { vector dupNames; - m->splitAtComma(globaldata->names[name], dupNames); + m->splitAtComma(m->names[name], dupNames); map::iterator itCounts; int maxPars = 1; set groupsAddedForThisNode; for (int j = 0; j < dupNames.size(); j++) { - string group = globaldata->gTreemap->getGroup(dupNames[j]); + string group = tmap->getGroup(dupNames[j]); if (dupNames[j] != name) {//you already added yourself in the constructor @@ -196,7 +195,7 @@ int Tree::getIndex(string searchName) { try { //Treemap knows name, group and index to speed up search // getIndex function will return the vector index or -1 if seq is not found. - int index = globaldata->gTreemap->getIndex(searchName); + int index = tmap->getIndex(searchName); return index; } @@ -210,7 +209,7 @@ int Tree::getIndex(string searchName) { void Tree::setIndex(string searchName, int index) { try { //set index in treemap - globaldata->gTreemap->setIndex(searchName, index); + tmap->setIndex(searchName, index); } catch(exception& e) { m->errorOut(e, "Tree", "setIndex"); @@ -223,7 +222,7 @@ int Tree::assembleTree() { //float A = clock(); //if user has given a names file we want to include that info in the pgroups and pcount info. - if(globaldata->names.size() != 0) { addNamesToCounts(); } + if(m->names.size() != 0) { addNamesToCounts(); } //build the pGroups in non leaf nodes to be used in the parsimony calcs. for (int i = numLeaves; i < numNodes; i++) { @@ -274,7 +273,7 @@ void Tree::getSubTree(Tree* copy, vector Groups) { tree[i].setName(Groups[i]); //save group info - string group = globaldata->gTreemap->getGroup(Groups[i]); + string group = tmap->getGroup(Groups[i]); vector tempGroups; tempGroups.push_back(group); tree[i].setGroup(tempGroups); groupNodeInfo[group].push_back(i); @@ -284,7 +283,7 @@ void Tree::getSubTree(Tree* copy, vector Groups) { tree[i].pGroups[group] = 1; //Treemap knows name, group and index to speed up search - globaldata->gTreemap->setIndex(Groups[i], i); + tmap->setIndex(Groups[i], i); //intialize non leaf nodes }else if (i > (numLeaves-1)) { @@ -436,7 +435,7 @@ int Tree::populateNewTree(vector& oldtree, int node, int& index) { return (index++); }else { //you are a leaf - int indexInNewTree = globaldata->gTreemap->getIndex(oldtree[node].getName()); + int indexInNewTree = tmap->getIndex(oldtree[node].getName()); return indexInNewTree; } } @@ -633,8 +632,8 @@ void Tree::randomLabels(vector g) { try { //initialize groupNodeInfo - for (int i = 0; i < globaldata->gTreemap->namesOfGroups.size(); i++) { - groupNodeInfo[globaldata->gTreemap->namesOfGroups[i]].resize(0); + for (int i = 0; i < tmap->namesOfGroups.size(); i++) { + groupNodeInfo[tmap->namesOfGroups[i]].resize(0); } for(int i = 0; i < numLeaves; i++){ @@ -875,7 +874,7 @@ try { } } }else { //you are a leaf - string leafGroup = globaldata->gTreemap->getGroup(tree[node].getName()); + string leafGroup = tmap->getGroup(tree[node].getName()); if (mode == "branch") { out << leafGroup; @@ -938,7 +937,7 @@ void Tree::printBranch(int node, ostream& out, string mode, vector& theseN } } }else { //you are a leaf - string leafGroup = globaldata->gTreemap->getGroup(theseNodes[node].getName()); + string leafGroup = tmap->getGroup(theseNodes[node].getName()); if (mode == "branch") { out << leafGroup; @@ -987,7 +986,7 @@ void Tree::parseTreeFile() { //only takes names from the first tree and assumes that all trees use the same names. try { - string filename = globaldata->getTreeFile(); + string filename = m->getTreeFile(); ifstream filehandle; m->openInputFile(filename, filehandle); int c, comment; @@ -1053,9 +1052,9 @@ void Tree::parseTreeFile() { //c = , until done with translation then c = ; h = name.substr(name.length()-1, name.length()); name.erase(name.end()-1); //erase the comma - globaldata->Treenames.push_back(number); + m->Treenames.push_back(number); } - if(number == ";") { globaldata->Treenames.pop_back(); } //in case ';' from translation is on next line instead of next to last name + if(number == ";") { m->Treenames.pop_back(); } //in case ';' from translation is on next line instead of next to last name } } filehandle.close(); @@ -1102,7 +1101,7 @@ int Tree::readTreeString(ifstream& filehandle) { } //cout << "name = " << name << endl; - globaldata->Treenames.push_back(name); + m->Treenames.push_back(name); filehandle.putback(c); //k = c; //cout << " after putback" << k << endl; diff --git a/tree.h b/tree.h index 0b316c3..2d9d4f8 100644 --- a/tree.h +++ b/tree.h @@ -11,16 +11,14 @@ */ #include "treenode.h" -#include "globaldata.hpp" - -class GlobalData; +#include "treemap.h" /* This class represents the treefile. */ class Tree { public: - Tree(string); - Tree(int); - Tree(); //to generate a tree from a file + Tree(string); //do not use tree generated by this constructor its just to extract the treenames, its a chicken before the egg thing that needs to be revisited. + Tree(int, TreeMap*); + Tree(TreeMap*); //to generate a tree from a file ~Tree(); void getCopy(Tree*); //makes tree a copy of the one passed in. @@ -47,7 +45,7 @@ public: map< string, vector > groupNodeInfo; //maps group to indexes of leaf nodes with that group, different groups may contain same node because of names file. private: - GlobalData* globaldata; + TreeMap* tmap; int numNodes, numLeaves; ofstream out; string filename; diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index 07999f6..e5b7e74 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -51,51 +51,68 @@ #include "mempearson.h" //********************************************************************************************************************** -vector TreeGroupCommand::getValidParameters(){ +vector TreeGroupCommand::setParameters(){ try { - string Array[] = {"label","calc","groups", "phylip", "column", "name", "precision","cutoff","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pshared); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName",false,false); parameters.push_back(pcolumn); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter pcalc("calc", "Multiple", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-whittaker-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-hamming-structchi2-gower-memchi2-memchord-memeuclidean-mempearson", "jclass-thetayc", "", "", "",true,false); parameters.push_back(pcalc); + CommandParameter poutput("output", "Multiple", "lt-square", "lt", "", "", "",false,false); parameters.push_back(poutput); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "TreeGroupCommand", "getValidParameters"); + m->errorOut(e, "TreeGroupCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -TreeGroupCommand::TreeGroupCommand(){ +string TreeGroupCommand::getHelpString(){ try { - abort = true; calledHelp = true; - globaldata = GlobalData::getInstance(); - //initialize outputTypes - vector tempOutNames; - outputTypes["tree"] = tempOutNames; + string helpString = ""; + ValidCalculators validCalculator; + helpString += "The tree.shared command creates a .tre to represent the similiarity between groups or sequences.\n"; + helpString += "The tree.shared command parameters are shared, groups, calc, phylip, column, name, cutoff, precision and label.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n"; + helpString += "The group names are separated by dashes. The label allow you to select what distance levels you would like trees created for, and are also separated by dashes.\n"; + helpString += "The phylip or column parameter are required if you do not provide a sharedfile, and only one may be used. If you use a column file the name filename is required. \n"; + helpString += "If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.\n"; + helpString += "The tree.shared command should be in the following format: tree.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels).\n"; + helpString += "Example tree.shared(groups=A-B-C, calc=jabund-sorabund).\n"; + helpString += "The default value for groups is all the groups in your groupfile.\n"; + helpString += "The default value for calc is jclass-thetayc.\n"; + helpString += "The tree.shared command outputs a .tre file for each calculator you specify at each distance you choose.\n"; + helpString += validCalculator.printCalc("treegroup"); + helpString += "Or the tree.shared command can be in the following format: tree.shared(phylip=yourPhylipFile).\n"; + helpString += "Example tree.shared(phylip=abrecovery.dist).\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "TreeGroupCommand", "TreeGroupCommand"); + m->errorOut(e, "TreeGroupCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector TreeGroupCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "TreeGroupCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector TreeGroupCommand::getRequiredFiles(){ +TreeGroupCommand::TreeGroupCommand(){ try { - string Array[] = {"phylip","column","shared","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "TreeGroupCommand", "getRequiredFiles"); + m->errorOut(e, "TreeGroupCommand", "TreeGroupCommand"); exit(1); } } @@ -103,20 +120,14 @@ vector TreeGroupCommand::getRequiredFiles(){ TreeGroupCommand::TreeGroupCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Groups.clear(); - Estimators.clear(); //allow user to run help - if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; calledHelp = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"label","calc","groups", "phylip", "column", "name", "precision","cutoff","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser. getParameters(); @@ -163,32 +174,57 @@ TreeGroupCommand::TreeGroupCommand(string option) { } } - format = globaldata->getFormat(); - - //required parameters + //check for required parameters phylipfile = validParameter.validFile(parameters, "phylip", true); - if (phylipfile == "not open") { abort = true; } + if (phylipfile == "not open") { phylipfile = ""; abort = true; } else if (phylipfile == "not found") { phylipfile = ""; } - else { globaldata->newRead(); format = "phylip"; globaldata->setPhylipFile(phylipfile); } + else { inputfile = phylipfile; format = "phylip"; } columnfile = validParameter.validFile(parameters, "column", true); - if (columnfile == "not open") { abort = true; } + if (columnfile == "not open") { columnfile = ""; abort = true; } else if (columnfile == "not found") { columnfile = ""; } - else { globaldata->newRead(); format = "column"; globaldata->setColumnFile(columnfile); } + else { inputfile = columnfile; format = "column"; } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { inputfile = sharedfile; format = "sharedfile"; } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } - else { globaldata->setNameFile(namefile); } - //error checking on files - if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == ""))) { m->mothurOut("You must run the read.otu command or provide a distance file before running the tree.shared command."); m->mothurOutEndLine(); abort = true; } + if ((phylipfile == "") && (columnfile == "") && (sharedfile == "")) { + //is there are current file available for either of these? + //give priority to shared, then column, then phylip + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + columnfile = m->getColumnFile(); + if (columnfile != "") { inputfile = columnfile; format = "column"; m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); } + else { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { inputfile = phylipfile; format = "phylip"; m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a shared, phylip or column file."); m->mothurOutEndLine(); + abort = true; + } + } + } + } else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When running the tree.shared command with a distance file you may not use both the column and the phylip parameters."); m->mothurOutEndLine(); abort = true; } if (columnfile != "") { - if (namefile == "") { m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); abort = true; } + if (namefile == "") { + namefile = m->getNameFile(); + if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a namefile if you are going to use the column format."); 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); @@ -198,17 +234,11 @@ TreeGroupCommand::TreeGroupCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if(label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } calc = validParameter.validFile(parameters, "calc", false); @@ -229,101 +259,8 @@ TreeGroupCommand::TreeGroupCommand(string option) { //if the user changes the output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + outputDir += m->hasPath(inputfile); //if user entered a file with a path then preserve it } - - - if (abort == false) { - - validCalculator = new ValidCalculators(); - - if (format == "sharedfile") { - int i; - for (i=0; iisValidCalculator("treegroup", Estimators[i]) == true) { - if (Estimators[i] == "sharedsobs") { - treeCalculators.push_back(new SharedSobsCS()); - }else if (Estimators[i] == "sharedchao") { - treeCalculators.push_back(new SharedChao1()); - }else if (Estimators[i] == "sharedace") { - treeCalculators.push_back(new SharedAce()); - }else if (Estimators[i] == "jabund") { - treeCalculators.push_back(new JAbund()); - }else if (Estimators[i] == "sorabund") { - treeCalculators.push_back(new SorAbund()); - }else if (Estimators[i] == "jclass") { - treeCalculators.push_back(new Jclass()); - }else if (Estimators[i] == "sorclass") { - treeCalculators.push_back(new SorClass()); - }else if (Estimators[i] == "jest") { - treeCalculators.push_back(new Jest()); - }else if (Estimators[i] == "sorest") { - treeCalculators.push_back(new SorEst()); - }else if (Estimators[i] == "thetayc") { - treeCalculators.push_back(new ThetaYC()); - }else if (Estimators[i] == "thetan") { - treeCalculators.push_back(new ThetaN()); - }else if (Estimators[i] == "kstest") { - treeCalculators.push_back(new KSTest()); - }else if (Estimators[i] == "sharednseqs") { - treeCalculators.push_back(new SharedNSeqs()); - }else if (Estimators[i] == "ochiai") { - treeCalculators.push_back(new Ochiai()); - }else if (Estimators[i] == "anderberg") { - treeCalculators.push_back(new Anderberg()); - }else if (Estimators[i] == "kulczynski") { - treeCalculators.push_back(new Kulczynski()); - }else if (Estimators[i] == "kulczynskicody") { - treeCalculators.push_back(new KulczynskiCody()); - }else if (Estimators[i] == "lennon") { - treeCalculators.push_back(new Lennon()); - }else if (Estimators[i] == "morisitahorn") { - treeCalculators.push_back(new MorHorn()); - }else if (Estimators[i] == "braycurtis") { - treeCalculators.push_back(new BrayCurtis()); - }else if (Estimators[i] == "whittaker") { - treeCalculators.push_back(new Whittaker()); - }else if (Estimators[i] == "odum") { - treeCalculators.push_back(new Odum()); - }else if (Estimators[i] == "canberra") { - treeCalculators.push_back(new Canberra()); - }else if (Estimators[i] == "structeuclidean") { - treeCalculators.push_back(new StructEuclidean()); - }else if (Estimators[i] == "structchord") { - treeCalculators.push_back(new StructChord()); - }else if (Estimators[i] == "hellinger") { - treeCalculators.push_back(new Hellinger()); - }else if (Estimators[i] == "manhattan") { - treeCalculators.push_back(new Manhattan()); - }else if (Estimators[i] == "structpearson") { - treeCalculators.push_back(new StructPearson()); - }else if (Estimators[i] == "soergel") { - treeCalculators.push_back(new Soergel()); - }else if (Estimators[i] == "spearman") { - treeCalculators.push_back(new Spearman()); - }else if (Estimators[i] == "structkulczynski") { - treeCalculators.push_back(new StructKulczynski()); - }else if (Estimators[i] == "speciesprofile") { - treeCalculators.push_back(new SpeciesProfile()); - }else if (Estimators[i] == "hamming") { - treeCalculators.push_back(new Hamming()); - }else if (Estimators[i] == "structchi2") { - treeCalculators.push_back(new StructChi2()); - }else if (Estimators[i] == "gower") { - treeCalculators.push_back(new Gower()); - }else if (Estimators[i] == "memchi2") { - treeCalculators.push_back(new MemChi2()); - }else if (Estimators[i] == "memchord") { - treeCalculators.push_back(new MemChord()); - }else if (Estimators[i] == "memeuclidean") { - treeCalculators.push_back(new MemEuclidean()); - }else if (Estimators[i] == "mempearson") { - treeCalculators.push_back(new MemPearson()); - } - } - } - } - } } } @@ -332,45 +269,13 @@ TreeGroupCommand::TreeGroupCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void TreeGroupCommand::help(){ - try { - m->mothurOut("The tree.shared command creates a .tre to represent the similiarity between groups or sequences.\n"); - m->mothurOut("The tree.shared command can only be executed after a successful read.otu command or by providing a distance file.\n"); - m->mothurOut("The tree.shared command parameters are groups, calc, phylip, column, name, cutoff, precision and label.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n"); - m->mothurOut("The group names are separated by dashes. The label allow you to select what distance levels you would like trees created for, and are also separated by dashes.\n"); - m->mothurOut("The phylip or column parameter are required if you do not run the read.otu command first, and only one may be used. If you use a column file the name filename is required. \n"); - m->mothurOut("If you do not provide a cutoff value 10.00 is assumed. If you do not provide a precision value then 100 is assumed.\n"); - m->mothurOut("The tree.shared command should be in the following format: tree.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels).\n"); - m->mothurOut("Example tree.shared(groups=A-B-C, calc=jabund-sorabund).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile.\n"); - m->mothurOut("The default value for calc is jclass-thetayc.\n"); - m->mothurOut("The tree.shared command outputs a .tre file for each calculator you specify at each distance you choose.\n"); - validCalculator->printCalc("treegroup", cout); - m->mothurOut("Or the tree.shared command can be in the following format: tree.shared(phylip=yourPhylipFile).\n"); - m->mothurOut("Example tree.shared(phylip=abrecovery.dist).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "TreeGroupCommand", "help"); - exit(1); - } -} - - //********************************************************************************************************************** TreeGroupCommand::~TreeGroupCommand(){ - globaldata->Groups.clear(); if (abort == false) { - - if (format == "sharedfile") { delete read; delete input; globaldata->ginput = NULL; } + if (format == "sharedfile") { delete input; } else { delete readMatrix; delete matrix; delete list; } - delete tmap; globaldata->gTreemap = NULL; - delete validCalculator; + delete tmap; } } @@ -383,33 +288,114 @@ int TreeGroupCommand::execute(){ if (abort == true) { if (calledHelp) { return 0; } return 2; } if (format == "sharedfile") { + + ValidCalculators validCalculator; + + for (int i=0; imothurOut("You have given no valid calculators."); m->mothurOutEndLine(); return 0; } - if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; globaldata->gGroupmap = NULL; } - //you have groups - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - - input = globaldata->ginput; + input = new InputData(sharedfile, "sharedfile"); lookup = input->getSharedRAbundVectors(); lastLabel = lookup[0]->getLabel(); if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0; } //used in tree constructor - globaldata->runParse = false; + m->runParse = false; //create treemap class from groupmap for tree class to use tmap = new TreeMap(); - tmap->makeSim(globaldata->gGroupmap); - globaldata->gTreemap = tmap; + tmap->makeSim(m->namesOfGroups); //clear globaldatas old tree names if any - globaldata->Treenames.clear(); + m->Treenames.clear(); //fills globaldatas tree names - globaldata->Treenames = globaldata->Groups; + m->Treenames = m->Groups; if (m->control_pressed) { return 0; } @@ -419,7 +405,7 @@ int TreeGroupCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } }else{ //read in dist file - filename = globaldata->inputFileName; + filename = inputfile; if (format == "column") { readMatrix = new ReadColumnMatrix(filename); } else if (format == "phylip") { readMatrix = new ReadPhylipMatrix(filename); } @@ -444,18 +430,17 @@ int TreeGroupCommand::execute(){ if (m->control_pressed) { return 0; } tmap->makeSim(list); - globaldata->gTreemap = tmap; - globaldata->Groups = tmap->namesOfGroups; + m->Groups = tmap->namesOfGroups; //clear globaldatas old tree names if any - globaldata->Treenames.clear(); + m->Treenames.clear(); //fills globaldatas tree names - globaldata->Treenames = globaldata->Groups; + m->Treenames = m->Groups; //used in tree constructor - globaldata->runParse = false; + m->runParse = false; if (m->control_pressed) { return 0; } @@ -464,7 +449,7 @@ int TreeGroupCommand::execute(){ if (m->control_pressed) { return 0; } //create a new filename - outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "tre"; + outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "tre"; outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); createTree(); @@ -476,7 +461,7 @@ int TreeGroupCommand::execute(){ } //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); //set tree file as new current treefile string current = ""; @@ -502,7 +487,7 @@ int TreeGroupCommand::execute(){ int TreeGroupCommand::createTree(){ try { //create tree - t = new Tree(); + t = new Tree(tmap); //do merges and create tree structure by setting parents and children //there are numGroups - 1 merges to do @@ -742,7 +727,7 @@ int TreeGroupCommand::process(vector thisLookup) { for (int g = 0; g < numGroups; g++) { index[g] = g; } //create a new filename - outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre"; + outputFile = outputDir + m->getRootName(m->getSimpleName(inputfile)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre"; outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); for (int k = 0; k < thisLookup.size(); k++) { diff --git a/treegroupscommand.h b/treegroupscommand.h index c61c9fb..6bb35f2 100644 --- a/treegroupscommand.h +++ b/treegroupscommand.h @@ -13,7 +13,6 @@ #include "command.hpp" #include "inputdata.h" #include "groupmap.h" -#include "readotu.h" #include "validcalculator.h" #include "tree.h" #include "treemap.h" @@ -27,7 +26,6 @@ The user can select the lines or labels they wish to use as well as the groups they would like included. They can also use as many or as few calculators as they wish. */ -class GlobalData; typedef list::iterator MatData; @@ -37,12 +35,14 @@ public: TreeGroupCommand(string); TreeGroupCommand(); ~TreeGroupCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + + vector setParameters(); + string getCommandName() { return "tree.shared"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: int createTree(); @@ -50,8 +50,6 @@ private: int makeSimsShared(); int makeSimsDist(); - GlobalData* globaldata; - ReadOTUFile* read; ReadMatrix* readMatrix; SparseMatrix* matrix; NameAssignment* nameMap; @@ -62,14 +60,12 @@ private: vector< vector > simMatrix; map index; //maps row in simMatrix to vector index in the tree InputData* input; - ValidCalculators* validCalculator; vector lookup; string lastLabel; - string format, outputFile, groupNames, filename; + string format, outputFile, groupNames, filename, sharedfile, inputfile; int numGroups; ofstream out; float precision, cutoff; - map > outputTypes; bool abort, allLines; set labels; //holds labels to be used diff --git a/treemap.cpp b/treemap.cpp index 52a9003..7542385 100644 --- a/treemap.cpp +++ b/treemap.cpp @@ -170,13 +170,13 @@ void TreeMap::print(ostream& output){ } /************************************************************/ -void TreeMap::makeSim(GroupMap* groupmap) { +void TreeMap::makeSim(vector ThisnamesOfGroups) { try { //set names of groups - namesOfGroups = groupmap->namesOfGroups; + namesOfGroups = ThisnamesOfGroups; //set names of seqs to names of groups - namesOfSeqs = groupmap->namesOfGroups; + namesOfSeqs = ThisnamesOfGroups; // make map where key and value are both the group name since that what the tree.shared command wants for (int i = 0; i < namesOfGroups.size(); i++) { diff --git a/treemap.h b/treemap.h index d4b506e..9f10f37 100644 --- a/treemap.h +++ b/treemap.h @@ -42,7 +42,7 @@ public: map seqsPerGroup; //groupname, number of seqs in that group. map treemap; //sequence name and void print(ostream&); - void makeSim(GroupMap*); //takes groupmap info and fills treemap for use by tree.shared command. + void makeSim(vector); //takes groupmap info and fills treemap for use by tree.shared command. void makeSim(ListVector*); //takes listvector info and fills treemap for use by tree.shared command. private: diff --git a/trimflowscommand.cpp b/trimflowscommand.cpp index bf80ee8..e6c6fdf 100644 --- a/trimflowscommand.cpp +++ b/trimflowscommand.cpp @@ -11,48 +11,47 @@ #include "needlemanoverlap.hpp" //********************************************************************************************************************** - -vector TrimFlowsCommand::getValidParameters(){ +vector TrimFlowsCommand::setParameters(){ try { - string Array[] = {"flow", "maxflows", "minflows", - "fasta", "minlength", "maxlength", "maxhomop", "signal", "noise" - "oligos", "pdiffs", "bdiffs", "tdiffs", "order", - "allfiles", "processors", - "outputdir","inputdir" + CommandParameter pflow("flow", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pflow); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos); + CommandParameter pmaxhomop("maxhomop", "Number", "", "9", "", "", "",false,false); parameters.push_back(pmaxhomop); + CommandParameter pmaxflows("maxflows", "Number", "", "720", "", "", "",false,false); parameters.push_back(pmaxflows); + CommandParameter pminflows("minflows", "Number", "", "360", "", "", "",false,false); parameters.push_back(pminflows); + CommandParameter pminlength("minlength", "Number", "", "0", "", "", "",false,false); parameters.push_back(pminlength); + CommandParameter pmaxlength("maxlength", "Number", "", "0", "", "", "",false,false); parameters.push_back(pmaxlength); + CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppdiffs); + CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pbdiffs); + CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ptdiffs); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter psignal("signal", "Number", "", "0.50", "", "", "",false,false); parameters.push_back(psignal); + CommandParameter pnoise("noise", "Number", "", "0.70", "", "", "",false,false); parameters.push_back(pnoise); + CommandParameter pallfiles("allfiles", "Boolean", "", "t", "", "", "",false,false); parameters.push_back(pallfiles); + CommandParameter porder("order", "String", "", "", "", "", "",false,false); parameters.push_back(porder); + CommandParameter pfasta("fasta", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pfasta); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); - }; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "TrimFlowsCommand", "getValidParameters"); - exit(1); - } -} - -//********************************************************************************************************************** - -vector TrimFlowsCommand::getRequiredParameters(){ - try { - string Array[] = {"flow"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "TrimFlowsCommand", "getRequiredParameters"); + m->errorOut(e, "TrimFlowsCommand", "setParameters"); exit(1); } } - //********************************************************************************************************************** - -vector TrimFlowsCommand::getRequiredFiles(){ +string TrimFlowsCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The trim.flows command reads a flowgram file and creates .....\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"; + helpString += "For more details please check out the wiki http://www.mothur.org/wiki/Trim.flows.\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "TrimFlowsCommand", "getRequiredFiles"); + m->errorOut(e, "TrimFlowsCommand", "getHelpString"); exit(1); } } @@ -62,6 +61,7 @@ vector TrimFlowsCommand::getRequiredFiles(){ TrimFlowsCommand::TrimFlowsCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["flow"] = tempOutNames; outputTypes["fasta"] = tempOutNames; @@ -71,26 +71,6 @@ TrimFlowsCommand::TrimFlowsCommand(){ exit(1); } } - -//*************************************************************************************************************** - -TrimFlowsCommand::~TrimFlowsCommand(){ /* do nothing */ } - -//*************************************************************************************************************** - -void TrimFlowsCommand::help(){ - try { - m->mothurOut("The trim.flows command reads a flowgram file and creates .....\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"); - m->mothurOut("For more details please check out the wiki http://www.mothur.org/wiki/Trim.flows.\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "TrimFlowsCommand", "help"); - exit(1); - } -} - //********************************************************************************************************************** TrimFlowsCommand::TrimFlowsCommand(string option) { @@ -103,18 +83,8 @@ TrimFlowsCommand::TrimFlowsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"flow", "maxflows", "minflows", - "fasta", "minlength", "maxlength", "maxhomop", "signal", "noise", - "oligos", "pdiffs", "bdiffs", "tdiffs", "order", - "allfiles", "processors", - - // "group", - "outputdir","inputdir" - - }; - - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -224,8 +194,9 @@ TrimFlowsCommand::TrimFlowsCommand(string option) { temp = validParameter.validFile(parameters, "allfiles", false); if (temp == "not found"){ temp = "T"; } allFiles = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } - convert(temp, processors); + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); flowOrder = validParameter.validFile(parameters, "order", false); if (flowOrder == "not found"){ flowOrder = "TACG"; } diff --git a/trimflowscommand.h b/trimflowscommand.h index 7458dbe..0514a53 100644 --- a/trimflowscommand.h +++ b/trimflowscommand.h @@ -20,13 +20,15 @@ class TrimFlowsCommand : public Command { public: TrimFlowsCommand(string); TrimFlowsCommand(); - ~TrimFlowsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~TrimFlowsCommand() {} + + vector setParameters(); + string getCommandName() { return "trim.flows"; } + string getCommandCategory() { return "Hidden"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: bool abort; @@ -44,13 +46,9 @@ private: int createProcessesCreateTrim(string, string, string, string, vector >); int driverCreateTrim(string, string, string, string, vector >, linePair*); - - map > outputTypes; vector outputNames; set filesToRemove; - - void getOligos(vector >&); //a rewrite of what is in trimseqscommand.h int stripBarcode(Sequence&, int&); //largely redundant with trimseqscommand.h int stripForward(Sequence&, int&); //largely redundant with trimseqscommand.h diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index 6924ffc..9ff75df 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -11,65 +11,101 @@ #include "needlemanoverlap.hpp" //********************************************************************************************************************** - -vector TrimSeqsCommand::getValidParameters(){ +vector TrimSeqsCommand::setParameters(){ try { - string Array[] = {"fasta", "flip", "oligos", "maxambig", "maxhomop","minlength", "maxlength", "qfile", - "qthreshold", "qwindowaverage", "qstepsize", "qwindowsize", "qaverage", "rollaverage", - "keepfirst", "removelast", - "allfiles", "qtrim","tdiffs", "pdiffs", "bdiffs", "processors", "outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pfasta); + CommandParameter poligos("oligos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(poligos); + CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pqfile); + CommandParameter pflip("flip", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pflip); + CommandParameter pmaxambig("maxambig", "Number", "", "-1", "", "", "",false,false); parameters.push_back(pmaxambig); + CommandParameter pmaxhomop("maxhomop", "Number", "", "0", "", "", "",false,false); parameters.push_back(pmaxhomop); + CommandParameter pminlength("minlength", "Number", "", "0", "", "", "",false,false); parameters.push_back(pminlength); + CommandParameter pmaxlength("maxlength", "Number", "", "0", "", "", "",false,false); parameters.push_back(pmaxlength); + CommandParameter ppdiffs("pdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ppdiffs); + CommandParameter pbdiffs("bdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(pbdiffs); + CommandParameter ptdiffs("tdiffs", "Number", "", "0", "", "", "",false,false); parameters.push_back(ptdiffs); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter pallfiles("allfiles", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pallfiles); + CommandParameter pqtrim("qtrim", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pqtrim); + CommandParameter pqthreshold("qthreshold", "Number", "", "0", "", "", "",false,false); parameters.push_back(pqthreshold); + CommandParameter pqaverage("qaverage", "Number", "", "0", "", "", "",false,false); parameters.push_back(pqaverage); + CommandParameter prollaverage("rollaverage", "Number", "", "0", "", "", "",false,false); parameters.push_back(prollaverage); + CommandParameter pqwindowaverage("qwindowaverage", "Number", "", "0", "", "", "",false,false); parameters.push_back(pqwindowaverage); + CommandParameter pqstepsize("qstepsize", "Number", "", "1", "", "", "",false,false); parameters.push_back(pqstepsize); + CommandParameter pqwindowsize("qwindowsize", "Number", "", "50", "", "", "",false,false); parameters.push_back(pqwindowsize); + CommandParameter pkeepfirst("keepfirst", "Number", "", "0", "", "", "",false,false); parameters.push_back(pkeepfirst); + CommandParameter premovelast("removelast", "Number", "", "0", "", "", "",false,false); parameters.push_back(premovelast); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "TrimSeqsCommand", "getValidParameters"); + m->errorOut(e, "TrimSeqsCommand", "setParameters"); exit(1); } } - //********************************************************************************************************************** - -TrimSeqsCommand::TrimSeqsCommand(){ +string TrimSeqsCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["fasta"] = tempOutNames; - outputTypes["qfile"] = tempOutNames; - outputTypes["group"] = tempOutNames; + string helpString = ""; + helpString += "The trim.seqs command reads a fastaFile and creates 2 new fasta files, .trim.fasta and scrap.fasta, as well as group files if you provide and oligos file.\n"; + helpString += "The .trim.fasta contains sequences that meet your requirements, and the .scrap.fasta contains those which don't.\n"; + helpString += "The trim.seqs command parameters are fasta, flip, oligos, maxambig, maxhomop, minlength, maxlength, qfile, qthreshold, qaverage, diffs, qtrim, keepfirst, removelast and allfiles.\n"; + helpString += "The fasta parameter is required.\n"; + helpString += "The flip parameter will output the reverse compliment of your trimmed sequence. The default is false.\n"; + helpString += "The oligos parameter allows you to provide an oligos file.\n"; + helpString += "The maxambig parameter allows you to set the maximum number of ambigious bases allowed. The default is -1.\n"; + helpString += "The maxhomop parameter allows you to set a maximum homopolymer length. \n"; + helpString += "The minlength parameter allows you to set and minimum sequence length. \n"; + helpString += "The maxlength parameter allows you to set and maximum sequence length. \n"; + helpString += "The tdiffs parameter is used to specify the total number of differences allowed in the sequence. The default is pdiffs + bdiffs.\n"; + helpString += "The bdiffs parameter is used to specify the number of differences allowed in the barcode. The default is 0.\n"; + helpString += "The pdiffs parameter is used to specify the number of differences allowed in the primer. The default is 0.\n"; + helpString += "The qfile parameter allows you to provide a quality file.\n"; + helpString += "The qthreshold parameter allows you to set a minimum quality score allowed. \n"; + helpString += "The qaverage parameter allows you to set a minimum average quality score allowed. \n"; + helpString += "The qwindowsize parameter allows you to set a number of bases in a window. Default=50.\n"; + helpString += "The qwindowaverage parameter allows you to set a minimum average quality score allowed over a window. \n"; + helpString += "The rollaverage parameter allows you to set a minimum rolling average quality score allowed over a window. \n"; + helpString += "The qstepsize parameter allows you to set a number of bases to move the window over. Default=1.\n"; + helpString += "The allfiles parameter will create separate group and fasta file for each grouping. The default is F.\n"; + helpString += "The qtrim parameter will trim sequence from the point that they fall below the qthreshold and put it in the .trim file if set to true. The default is T.\n"; + helpString += "The keepfirst parameter trims the sequence to the first keepfirst number of bases after the barcode or primers are removed, before the sequence is checked to see if it meets the other requirements. \n"; + helpString += "The removelast removes the last removelast number of bases after the barcode or primers are removed, before the sequence is checked to see if it meets the other requirements.\n"; + helpString += "The trim.seqs command should be in the following format: \n"; + helpString += "trim.seqs(fasta=yourFastaFile, flip=yourFlip, oligos=yourOligos, maxambig=yourMaxambig, \n"; + helpString += "maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength) \n"; + helpString += "Example trim.seqs(fasta=abrecovery.fasta, flip=..., oligos=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n"; + helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"; + helpString += "For more details please check out the wiki http://www.mothur.org/wiki/Trim.seqs .\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "TrimSeqsCommand", "TrimSeqsCommand"); + m->errorOut(e, "TrimSeqsCommand", "getHelpString"); exit(1); } } -//********************************************************************************************************************** - -vector TrimSeqsCommand::getRequiredParameters(){ - try { - string Array[] = {"fasta"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "TrimSeqsCommand", "getRequiredParameters"); - exit(1); - } -} //********************************************************************************************************************** -vector TrimSeqsCommand::getRequiredFiles(){ +TrimSeqsCommand::TrimSeqsCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["fasta"] = tempOutNames; + outputTypes["qfile"] = tempOutNames; + outputTypes["group"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "TrimSeqsCommand", "getRequiredFiles"); + m->errorOut(e, "TrimSeqsCommand", "TrimSeqsCommand"); exit(1); } } - //*************************************************************************************************************** TrimSeqsCommand::TrimSeqsCommand(string option) { @@ -82,13 +118,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = { "fasta", "flip", "oligos", "maxambig", "maxhomop", "minlength", "maxlength", "qfile", - "qthreshold", "qwindowaverage", "qstepsize", "qwindowsize", "qaverage", "rollaverage", - "keepfirst", "removelast", - "allfiles", "qtrim","tdiffs", "pdiffs", "bdiffs", "processors", "outputdir","inputdir"}; - - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -141,8 +171,11 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { //check for required parameters fastaFile = validParameter.validFile(parameters, "fasta", true); - if (fastaFile == "not found") { m->mothurOut("fasta is a required parameter for the trim.seqs command."); m->mothurOutEndLine(); abort = true; } - else if (fastaFile == "not open") { abort = true; } + if (fastaFile == "not found") { + fastaFile = m->getFastaFile(); + if (fastaFile != "") { m->mothurOut("Using " + fastaFile + " as input file for the fasta parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; } + }else if (fastaFile == "not open") { 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"){ @@ -222,7 +255,8 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { temp = validParameter.validFile(parameters, "allfiles", false); if (temp == "not found") { temp = "F"; } allFiles = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found") { temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); @@ -246,54 +280,6 @@ TrimSeqsCommand::TrimSeqsCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void TrimSeqsCommand::help(){ - try { - m->mothurOut("The trim.seqs command reads a fastaFile and creates 2 new fasta files, .trim.fasta and scrap.fasta, as well as group files if you provide and oligos file.\n"); - m->mothurOut("The .trim.fasta contains sequences that meet your requirements, and the .scrap.fasta contains those which don't.\n"); - m->mothurOut("The trim.seqs command parameters are fasta, flip, oligos, maxambig, maxhomop, minlength, maxlength, qfile, qthreshold, qaverage, diffs, qtrim, keepfirst, removelast and allfiles.\n"); - m->mothurOut("The fasta parameter is required.\n"); - m->mothurOut("The flip parameter will output the reverse compliment of your trimmed sequence. The default is false.\n"); - m->mothurOut("The oligos parameter allows you to provide an oligos file.\n"); - m->mothurOut("The maxambig parameter allows you to set the maximum number of ambigious bases allowed. The default is -1.\n"); - m->mothurOut("The maxhomop parameter allows you to set a maximum homopolymer length. \n"); - m->mothurOut("The minlength parameter allows you to set and minimum sequence length. \n"); - m->mothurOut("The maxlength parameter allows you to set and maximum sequence length. \n"); - m->mothurOut("The tdiffs parameter is used to specify the total number of differences allowed in the sequence. The default is pdiffs + bdiffs.\n"); - m->mothurOut("The bdiffs parameter is used to specify the number of differences allowed in the barcode. The default is 0.\n"); - m->mothurOut("The pdiffs parameter is used to specify the number of differences allowed in the primer. The default is 0.\n"); - m->mothurOut("The qfile parameter allows you to provide a quality file.\n"); - m->mothurOut("The qthreshold parameter allows you to set a minimum quality score allowed. \n"); - m->mothurOut("The qaverage parameter allows you to set a minimum average quality score allowed. \n"); - m->mothurOut("The qwindowsize parameter allows you to set a number of bases in a window. Default=50.\n"); - m->mothurOut("The qwindowaverage parameter allows you to set a minimum average quality score allowed over a window. \n"); - m->mothurOut("The rollaverage parameter allows you to set a minimum rolling average quality score allowed over a window. \n"); - m->mothurOut("The qstepsize parameter allows you to set a number of bases to move the window over. Default=1.\n"); - m->mothurOut("The allfiles parameter will create separate group and fasta file for each grouping. The default is F.\n"); - m->mothurOut("The qtrim parameter will trim sequence from the point that they fall below the qthreshold and put it in the .trim file if set to true. The default is T.\n"); - m->mothurOut("The keepfirst parameter trims the sequence to the first keepfirst number of bases after the barcode or primers are removed, before the sequence is checked to see if it meets the other requirements. \n"); - m->mothurOut("The removelast removes the last removelast number of bases after the barcode or primers are removed, before the sequence is checked to see if it meets the other requirements.\n"); - m->mothurOut("The trim.seqs command should be in the following format: \n"); - m->mothurOut("trim.seqs(fasta=yourFastaFile, flip=yourFlip, oligos=yourOligos, maxambig=yourMaxambig, \n"); - m->mothurOut("maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength) \n"); - m->mothurOut("Example trim.seqs(fasta=abrecovery.fasta, flip=..., oligos=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"); - m->mothurOut("For more details please check out the wiki http://www.mothur.org/wiki/Trim.seqs .\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "TrimSeqsCommand", "help"); - exit(1); - } -} - - -//*************************************************************************************************************** - -TrimSeqsCommand::~TrimSeqsCommand(){ /* do nothing */ } - //*************************************************************************************************************** int TrimSeqsCommand::execute(){ diff --git a/trimseqscommand.h b/trimseqscommand.h index d40cfe3..2d0eabc 100644 --- a/trimseqscommand.h +++ b/trimseqscommand.h @@ -20,13 +20,15 @@ class TrimSeqsCommand : public Command { public: TrimSeqsCommand(string); TrimSeqsCommand(); - ~TrimSeqsCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~TrimSeqsCommand(){} + + vector setParameters(); + string getCommandName() { return "trim.seqs"; } + string getCommandCategory() { return "Sequence Processing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: @@ -51,7 +53,6 @@ private: bool cullAmbigs(Sequence&); bool compareDNASeq(string, string); int countDiffs(string, string); - map > outputTypes; bool abort; string fastaFile, oligoFile, qFileName, groupfile, outputDir; diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 5c0d583..a8c656c 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -10,22 +10,57 @@ #include "unifracunweightedcommand.h" //********************************************************************************************************************** -vector UnifracUnweightedCommand::getValidParameters(){ +vector UnifracUnweightedCommand::setParameters(){ try { - string Array[] = {"groups","iters","distance","random","root", "processors","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter prandom("random", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(prandom); + CommandParameter pdistance("distance", "Multiple", "column-lt-square", "column", "", "", "",false,false); parameters.push_back(pdistance); + CommandParameter proot("root", "Boolean", "F", "", "", "", "",false,false); parameters.push_back(proot); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "UnifracUnweightedCommand", "getValidParameters"); + m->errorOut(e, "UnifracUnweightedCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string UnifracUnweightedCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The unifrac.unweighted command parameters are tree, group, name, groups, iters, distance, processors, root and random. tree parameter is required unless you have valid current tree file.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 1 valid group.\n"; + helpString += "The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n"; + helpString += "The distance parameter allows you to create a distance file from the results. The default is false. You may set distance to lt, square or column.\n"; + helpString += "The random parameter allows you to shut off the comparison to random trees. The default is false, meaning compare don't your trees with randomly generated trees.\n"; + helpString += "The root parameter allows you to include the entire root in your calculations. The default is false, meaning stop at the root for this comparision instead of the root of the entire tree.\n"; + helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n"; + helpString += "The unifrac.unweighted command should be in the following format: unifrac.unweighted(groups=yourGroups, iters=yourIters).\n"; + helpString += "Example unifrac.unweighted(groups=A-B-C, iters=500).\n"; + helpString += "The default value for groups is all the groups in your groupfile, and iters is 1000.\n"; + helpString += "The unifrac.unweighted command output two files: .unweighted and .uwsummary their descriptions are in the manual.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "UnifracUnweightedCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** UnifracUnweightedCommand::UnifracUnweightedCommand(){ try { - globaldata = GlobalData::getInstance(); abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["unweighted"] = tempOutNames; outputTypes["uwsummary"] = tempOutNames; @@ -37,36 +72,11 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(){ exit(1); } } -//********************************************************************************************************************** -vector UnifracUnweightedCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "UnifracUnweightedCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector UnifracUnweightedCommand::getRequiredFiles(){ - try { - string Array[] = {"tree","group"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - - return myArray; - } - catch(exception& e) { - m->errorOut(e, "UnifracUnweightedCommand", "getRequiredFiles"); - exit(1); - } -} /***********************************************************/ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; - Groups.clear(); + //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } @@ -78,6 +88,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; @@ -93,22 +104,65 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { outputTypes["phylip"] = tempOutNames; outputTypes["column"] = tempOutNames; - if (globaldata->gTree.size() == 0) {//no trees were read - m->mothurOut("You must execute the read.tree command, before you may execute the unifrac.unweighted command."); 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 = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + //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; } + } } - + + m->runParse = true; + + //check for required parameters + treefile = validParameter.validFile(parameters, "tree", true); + if (treefile == "not open") { abort = true; } + else if (treefile == "not found") { //if there is a current design file, use it + treefile = m->getTreeFile(); + if (treefile != "") { m->mothurOut("Using " + treefile + " as input file for the tree parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current tree file and the tree parameter is required."); m->mothurOutEndLine(); abort = true; } + } + + //check for required parameters + groupfile = validParameter.validFile(parameters, "group", true); + if (groupfile == "not open") { abort = true; } + else if (groupfile == "not found") { groupfile = ""; } + + namefile = validParameter.validFile(parameters, "name", true); + if (namefile == "not open") { abort = true; } + else if (namefile == "not found") { namefile = ""; } + + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } itersString = validParameter.validFile(parameters, "iters", false); if (itersString == "not found") { itersString = "1000"; } @@ -127,7 +181,8 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { temp = validParameter.validFile(parameters, "root", false); if (temp == "not found") { temp = "F"; } includeRoot = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); convert(temp, processors); if (!random) { iters = 0; } //turn off random calcs @@ -136,26 +191,8 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { if ((phylip) && (Groups.size() == 0)) { groups = "all"; m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; - } - - if (abort == false) { - T = globaldata->gTree; - tmap = globaldata->gTreemap; - sumFile = outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".uwsummary"; - outputNames.push_back(sumFile); outputTypes["uwsummary"].push_back(sumFile); - m->openOutputFile(sumFile, outSum); - - util = new SharedUtil(); - util->setGroups(globaldata->Groups, tmap->namesOfGroups, allGroups, numGroups, "unweighted"); //sets the groups the user wants to analyze - util->getCombos(groupComb, globaldata->Groups, numComp); - - if (numGroups == 1) { numComp++; groupComb.push_back(allGroups); } - - unweighted = new Unweighted(tmap, includeRoot); - + m->Groups = Groups; } - } } @@ -165,37 +202,87 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { } } -//********************************************************************************************************************** - -void UnifracUnweightedCommand::help(){ - try { - m->mothurOut("The unifrac.unweighted command can only be executed after a successful read.tree command.\n"); - m->mothurOut("The unifrac.unweighted command parameters are groups, iters, distance, processors, root and random. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 1 valid group.\n"); - m->mothurOut("The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n"); - m->mothurOut("The distance parameter allows you to create a distance file from the results. The default is false. You may set distance to lt, square or column.\n"); - m->mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is false, meaning compare don't your trees with randomly generated trees.\n"); - m->mothurOut("The root parameter allows you to include the entire root in your calculations. The default is false, meaning stop at the root for this comparision instead of the root of the entire tree.\n"); - m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); - m->mothurOut("The unifrac.unweighted command should be in the following format: unifrac.unweighted(groups=yourGroups, iters=yourIters).\n"); - m->mothurOut("Example unifrac.unweighted(groups=A-B-C, iters=500).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and iters is 1000.\n"); - m->mothurOut("The unifrac.unweighted command output two files: .unweighted and .uwsummary their descriptions are in the manual.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "UnifracUnweightedCommand", "help"); - exit(1); - } -} - - /***********************************************************/ int UnifracUnweightedCommand::execute() { try { if (abort == true) { if (calledHelp) { return 0; } return 2; } + if (groupfile != "") { + //read in group map info. + tmap = new TreeMap(groupfile); + tmap->readMap(); + }else{ //fake out by putting everyone in one group + Tree* tree = new Tree(treefile); delete tree; //extracts names from tree to make faked out groupmap + tmap = new TreeMap(); + + for (int i = 0; i < m->Treenames.size(); i++) { tmap->addSeq(m->Treenames[i], "Group1"); } + } + + if (namefile != "") { readNamesFile(); } + + read = new ReadNewickTree(treefile); + int readOk = read->read(tmap); + + if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); delete tmap; delete read; return 0; } + + read->AssembleTrees(); + T = read->getTrees(); + delete read; + + //make sure all files match + //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 == m->Treenames.size()) { numNamesInTree = nameMap.size(); } + else { numNamesInTree = m->Treenames.size(); } + }else { numNamesInTree = m->Treenames.size(); } + + + //output any names that are in group file but not in tree + if (numNamesInTree < tmap->getNumSeqs()) { + for (int i = 0; i < tmap->namesOfSeqs.size(); i++) { + //is that name in the tree? + int count = 0; + for (int j = 0; j < m->Treenames.size(); j++) { + if (tmap->namesOfSeqs[i] == m->Treenames[j]) { break; } //found it + count++; + } + + if (m->control_pressed) { + delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + m->Groups.clear(); + return 0; + } + + //then you did not find it so report it + if (count == m->Treenames.size()) { + //if it is in your namefile then don't remove + map::iterator it = nameMap.find(tmap->namesOfSeqs[i]); + + if (it == nameMap.end()) { + m->mothurOut(tmap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine(); + tmap->removeSeq(tmap->namesOfSeqs[i]); + i--; //need this because removeSeq removes name from namesOfSeqs + } + } + } + } + + sumFile = outputDir + m->getSimpleName(treefile) + ".uwsummary"; + outputNames.push_back(sumFile); outputTypes["uwsummary"].push_back(sumFile); + m->openOutputFile(sumFile, outSum); + + util = new SharedUtil(); + util->setGroups(m->Groups, tmap->namesOfGroups, allGroups, numGroups, "unweighted"); //sets the groups the user wants to analyze + util->getCombos(groupComb, m->Groups, numComp); + delete util; + + if (numGroups == 1) { numComp++; groupComb.push_back(allGroups); } + + unweighted = new Unweighted(tmap, includeRoot); + int start = time(NULL); userData.resize(numComp,0); //data[0] = unweightedscore @@ -206,10 +293,12 @@ int UnifracUnweightedCommand::execute() { outSum << "Tree#" << '\t' << "Groups" << '\t' << "UWScore" <<'\t' << "UWSig" << endl; m->mothurOut("Tree#\tGroups\tUWScore\tUWSig"); m->mothurOutEndLine(); - + //get pscores for users trees for (int i = 0; i < T.size(); i++) { if (m->control_pressed) { + delete tmap; delete unweighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; @@ -218,9 +307,9 @@ int UnifracUnweightedCommand::execute() { counter = 0; if (random) { - output = new ColumnFile(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted", itersString); - outputNames.push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted"); - outputTypes["unweighted"].push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted"); + 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"); } @@ -232,7 +321,8 @@ int UnifracUnweightedCommand::execute() { userData = unweighted->getValues(T[i], processors, outputDir); //userData[0] = unweightedscore - if (m->control_pressed) { if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }return 0; } + if (m->control_pressed) { delete tmap; delete unweighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; }if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }return 0; } //output scores for each combination for(int k = 0; k < numComp; k++) { @@ -249,7 +339,8 @@ int UnifracUnweightedCommand::execute() { //we need a different getValues because when we swap the labels we only want to swap those in each pairwise comparison randomData = unweighted->getValues(T[i], "", "", processors, outputDir); - if (m->control_pressed) { if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { delete tmap; delete unweighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; }if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } for(int k = 0; k < numComp; k++) { //add trees unweighted score to map of scores @@ -286,7 +377,8 @@ int UnifracUnweightedCommand::execute() { } - if (m->control_pressed) { if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { delete tmap; delete unweighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; }if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //print output files printUWSummaryFile(i); @@ -302,6 +394,9 @@ int UnifracUnweightedCommand::execute() { outSum.close(); + m->Groups.clear(); + delete tmap; delete unweighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } @@ -400,10 +495,10 @@ void UnifracUnweightedCommand::createPhylipFile(int i) { try { string phylipFileName; if ((outputForm == "lt") || (outputForm == "square")) { - phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted.phylip.dist"; + phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted.phylip.dist"; outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName); }else { //column - phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted.column.dist"; + phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".unweighted.column.dist"; outputNames.push_back(phylipFileName); outputTypes["column"].push_back(phylipFileName); } @@ -412,18 +507,18 @@ void UnifracUnweightedCommand::createPhylipFile(int i) { if ((outputForm == "lt") || (outputForm == "square")) { //output numSeqs - out << globaldata->Groups.size() << endl; + out << m->Groups.size() << endl; } //make matrix with scores in it - vector< vector > dists; dists.resize(globaldata->Groups.size()); - for (int i = 0; i < globaldata->Groups.size(); i++) { - dists[i].resize(globaldata->Groups.size(), 0.0); + vector< vector > dists; dists.resize(m->Groups.size()); + for (int i = 0; i < m->Groups.size(); i++) { + dists[i].resize(m->Groups.size(), 0.0); } //flip it so you can print it int count = 0; - for (int r=0; rGroups.size(); r++) { + for (int r=0; rGroups.size(); r++) { for (int l = 0; l < r; l++) { dists[r][l] = utreeScores[count][0]; dists[l][r] = utreeScores[count][0]; @@ -432,9 +527,9 @@ void UnifracUnweightedCommand::createPhylipFile(int i) { } //output to file - for (int r=0; rGroups.size(); r++) { + for (int r=0; rGroups.size(); r++) { //output name - string name = globaldata->Groups[r]; + string name = m->Groups[r]; if (name.length() < 10) { //pad with spaces to make compatible while (name.length() < 10) { name += " "; } } @@ -449,12 +544,12 @@ void UnifracUnweightedCommand::createPhylipFile(int i) { out << name << '\t'; //output distances - for (int l = 0; l < globaldata->Groups.size(); l++) { out << dists[r][l] << '\t'; } + for (int l = 0; l < m->Groups.size(); l++) { out << dists[r][l] << '\t'; } out << endl; }else{ //output distances for (int l = 0; l < r; l++) { - string otherName = globaldata->Groups[l]; + string otherName = m->Groups[l]; if (otherName.length() < 10) { //pad with spaces to make compatible while (otherName.length() < 10) { otherName += " "; } } @@ -469,8 +564,48 @@ void UnifracUnweightedCommand::createPhylipFile(int i) { m->errorOut(e, "UnifracUnweightedCommand", "createPhylipFile"); exit(1); } +}/*****************************************************************/ +int UnifracUnweightedCommand::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 == m->names.end()) { + m->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)) { tmap->addSeq(dupNames[i], "Group1"); } + } + }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); m->names.clear(); namefile = ""; return 1; } + } + in.close(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "UnifracUnweightedCommand", "readNamesFile"); + exit(1); + } } /***********************************************************/ + diff --git a/unifracunweightedcommand.h b/unifracunweightedcommand.h index cd46b62..f462d51 100644 --- a/unifracunweightedcommand.h +++ b/unifracunweightedcommand.h @@ -15,25 +15,26 @@ #include "treemap.h" #include "sharedutilities.h" #include "fileoutput.h" - - -class GlobalData; +#include "readtree.h" class UnifracUnweightedCommand : public Command { public: UnifracUnweightedCommand(string); UnifracUnweightedCommand(); - ~UnifracUnweightedCommand() { globaldata->Groups.clear(); if (abort == false) { delete unweighted; delete util; } } - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } + ~UnifracUnweightedCommand() {} + + vector setParameters(); + string getCommandName() { return "unifrac.unweighted"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + int execute(); - void help(); + void help() { m->mothurOut(getHelpString()); } + private: - GlobalData* globaldata; + ReadTree* read; SharedUtil* util; FileOutput* output; vector T; //user trees @@ -41,7 +42,7 @@ class UnifracUnweightedCommand : public Command { Unweighted* unweighted; string sumFile, allGroups; vector groupComb; // AB. AC, BC... - int iters, numGroups, numComp, counter, processors; + int iters, numGroups, numComp, counter, processors, numUniquesInName; EstOutput userData; //unweighted score info for user tree EstOutput randomData; //unweighted score info for random trees vector< vector > utreeScores; //scores for users trees for each comb. @@ -51,16 +52,17 @@ class UnifracUnweightedCommand : public Command { vector< map > rCumul; //map -vector entry for each combination. bool abort, phylip, random, includeRoot; - string groups, itersString, outputDir, outputForm; + string groups, itersString, outputDir, outputForm, treefile, groupfile, namefile; vector Groups, outputNames; //holds groups to be used - map > outputTypes; ofstream outSum, out; ifstream inFile; + map nameMap; void printUWSummaryFile(int); void printUnweightedFile(); void createPhylipFile(int); + int readNamesFile(); }; diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index d521200..29cdf94 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -10,14 +10,49 @@ #include "unifracweightedcommand.h" //********************************************************************************************************************** -vector UnifracWeightedCommand::getValidParameters(){ +vector UnifracWeightedCommand::setParameters(){ try { - string Array[] = {"groups","iters","distance","random","processors","root","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); + CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); + CommandParameter prandom("random", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(prandom); + CommandParameter pdistance("distance", "Multiple", "column-lt-square", "column", "", "", "",false,false); parameters.push_back(pdistance); + CommandParameter proot("root", "Boolean", "F", "", "", "", "",false,false); parameters.push_back(proot); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "UnifracWeightedCommand", "getValidParameters"); + m->errorOut(e, "UnifracWeightedCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string UnifracWeightedCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The unifrac.weighted command parameters are tree, group, name, groups, iters, distance, processors, root and random. tree parameter is required unless you have valid current tree file.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"; + helpString += "The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n"; + helpString += "The distance parameter allows you to create a distance file from the results. The default is false.\n"; + helpString += "The random parameter allows you to shut off the comparison to random trees. The default is false, meaning don't compare your trees with randomly generated trees.\n"; + helpString += "The root parameter allows you to include the entire root in your calculations. The default is false, meaning stop at the root for this comparision instead of the root of the entire tree.\n"; + helpString += "The processors parameter allows you to specify the number of processors to use. The default is 1.\n"; + helpString += "The unifrac.weighted command should be in the following format: unifrac.weighted(groups=yourGroups, iters=yourIters).\n"; + helpString += "Example unifrac.weighted(groups=A-B-C, iters=500).\n"; + helpString += "The default value for groups is all the groups in your groupfile, and iters is 1000.\n"; + helpString += "The unifrac.weighted command output two files: .weighted and .wsummary their descriptions are in the manual.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "UnifracWeightedCommand", "getHelpString"); exit(1); } } @@ -25,6 +60,7 @@ vector UnifracWeightedCommand::getValidParameters(){ UnifracWeightedCommand::UnifracWeightedCommand(){ try { abort = true; calledHelp = true; + setParameters(); vector tempOutNames; outputTypes["weighted"] = tempOutNames; outputTypes["wsummary"] = tempOutNames; @@ -36,47 +72,21 @@ UnifracWeightedCommand::UnifracWeightedCommand(){ exit(1); } } -//********************************************************************************************************************** -vector UnifracWeightedCommand::getRequiredParameters(){ - try { - vector myArray; - return myArray; - } - catch(exception& e) { - m->errorOut(e, "UnifracWeightedCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector UnifracWeightedCommand::getRequiredFiles(){ - try { - string Array[] = {"tree","group"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "UnifracWeightedCommand", "getRequiredFiles"); - exit(1); - } -} /***********************************************************/ UnifracWeightedCommand::UnifracWeightedCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; - Groups.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string Array[] = {"groups","iters","distance","random","processors","root","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters=parser.getParameters(); + map::iterator it; ValidParameters validParameter; @@ -92,14 +102,58 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { outputTypes["phylip"] = tempOutNames; outputTypes["column"] = tempOutNames; - if (globaldata->gTree.size() == 0) {//no trees were read - m->mothurOut("You must execute the read.tree command, before you may execute the unifrac.weighted command."); 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 = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + //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; } + } } + + m->runParse = true; + + //check for required parameters + treefile = validParameter.validFile(parameters, "tree", true); + if (treefile == "not open") { abort = true; } + else if (treefile == "not found") { //if there is a current design file, use it + treefile = m->getTreeFile(); + if (treefile != "") { m->mothurOut("Using " + treefile + " as input file for the tree parameter."); m->mothurOutEndLine(); } + else { m->mothurOut("You have no current tree file and the tree parameter is required."); m->mothurOutEndLine(); abort = true; } + } + + //check for required parameters + groupfile = validParameter.validFile(parameters, "group", true); + if (groupfile == "not open") { abort = true; } + else if (groupfile == "not found") { groupfile = ""; } + + namefile = validParameter.validFile(parameters, "name", true); + if (namefile == "not open") { abort = true; } + else if (namefile == "not found") { namefile = ""; } + + outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } + //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -107,7 +161,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } itersString = validParameter.validFile(parameters, "iters", false); if (itersString == "not found") { itersString = "1000"; } @@ -126,27 +180,11 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { temp = validParameter.validFile(parameters, "root", false); if (temp == "not found") { temp = "F"; } includeRoot = m->isTrue(temp); - temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = "1"; } - convert(temp, processors); + temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); } + m->setProcessors(temp); + convert(temp, processors); if (!random) { iters = 0; } //turn off random calcs - - - if (abort == false) { - T = globaldata->gTree; - tmap = globaldata->gTreemap; - sumFile = outputDir + m->getSimpleName(globaldata->getTreeFile()) + ".wsummary"; - m->openOutputFile(sumFile, outSum); - outputNames.push_back(sumFile); outputTypes["wsummary"].push_back(sumFile); - - util = new SharedUtil(); - string s; //to make work with setgroups - util->setGroups(globaldata->Groups, tmap->namesOfGroups, s, numGroups, "weighted"); //sets the groups the user wants to analyze - util->getCombos(groupComb, globaldata->Groups, numComp); - - weighted = new Weighted(tmap, includeRoot); - - } } @@ -156,36 +194,86 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void UnifracWeightedCommand::help(){ - try { - m->mothurOut("The unifrac.weighted command can only be executed after a successful read.tree command.\n"); - m->mothurOut("The unifrac.weighted command parameters are groups, iters, distance, processors, root and random. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"); - m->mothurOut("The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n"); - m->mothurOut("The distance parameter allows you to create a distance file from the results. The default is false.\n"); - m->mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is false, meaning don't compare your trees with randomly generated trees.\n"); - m->mothurOut("The root parameter allows you to include the entire root in your calculations. The default is false, meaning stop at the root for this comparision instead of the root of the entire tree.\n"); - m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); - m->mothurOut("The unifrac.weighted command should be in the following format: unifrac.weighted(groups=yourGroups, iters=yourIters).\n"); - m->mothurOut("Example unifrac.weighted(groups=A-B-C, iters=500).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and iters is 1000.\n"); - m->mothurOut("The unifrac.weighted command output two files: .weighted and .wsummary their descriptions are in the manual.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "UnifracWeightedCommand", "help"); - exit(1); - } -} - /***********************************************************/ int UnifracWeightedCommand::execute() { try { if (abort == true) { if (calledHelp) { return 0; } return 2; } + if (groupfile != "") { + //read in group map info. + tmap = new TreeMap(groupfile); + tmap->readMap(); + }else{ //fake out by putting everyone in one group + Tree* tree = new Tree(treefile); delete tree; //extracts names from tree to make faked out groupmap + tmap = new TreeMap(); + + for (int i = 0; i < m->Treenames.size(); i++) { tmap->addSeq(m->Treenames[i], "Group1"); } + } + + if (namefile != "") { readNamesFile(); } + + read = new ReadNewickTree(treefile); + int readOk = read->read(tmap); + + if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); delete tmap; delete read; return 0; } + + read->AssembleTrees(); + T = read->getTrees(); + delete read; + + //make sure all files match + //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 == m->Treenames.size()) { numNamesInTree = nameMap.size(); } + else { numNamesInTree = m->Treenames.size(); } + }else { numNamesInTree = m->Treenames.size(); } + + + //output any names that are in group file but not in tree + if (numNamesInTree < tmap->getNumSeqs()) { + for (int i = 0; i < tmap->namesOfSeqs.size(); i++) { + //is that name in the tree? + int count = 0; + for (int j = 0; j < m->Treenames.size(); j++) { + if (tmap->namesOfSeqs[i] == m->Treenames[j]) { break; } //found it + count++; + } + + if (m->control_pressed) { + delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + m->Groups.clear(); + return 0; + } + + //then you did not find it so report it + if (count == m->Treenames.size()) { + //if it is in your namefile then don't remove + map::iterator it = nameMap.find(tmap->namesOfSeqs[i]); + + if (it == nameMap.end()) { + m->mothurOut(tmap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine(); + tmap->removeSeq(tmap->namesOfSeqs[i]); + i--; //need this because removeSeq removes name from namesOfSeqs + } + } + } + } + + sumFile = outputDir + m->getSimpleName(treefile) + ".wsummary"; + m->openOutputFile(sumFile, outSum); + outputNames.push_back(sumFile); outputTypes["wsummary"].push_back(sumFile); + + util = new SharedUtil(); + string s; //to make work with setgroups + util->setGroups(m->Groups, tmap->namesOfGroups, s, numGroups, "weighted"); //sets the groups the user wants to analyze + util->getCombos(groupComb, m->Groups, numComp); + delete util; + + weighted = new Weighted(tmap, includeRoot); + int start = time(NULL); //get weighted for users tree @@ -197,21 +285,23 @@ int UnifracWeightedCommand::execute() { //get weighted scores for users trees for (int i = 0; i < T.size(); i++) { - if (m->control_pressed) { outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { delete tmap; delete weighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } counter = 0; rScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC... uScores.resize(numComp); //data[0] = weightedscore AB, data[1] = weightedscore AC... if (random) { - output = new ColumnFile(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted", itersString); - outputNames.push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted"); - outputTypes["weighted"].push_back(outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted"); + 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"); } userData = weighted->getValues(T[i], processors, outputDir); //userData[0] = weightedscore - if (m->control_pressed) { if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { delete tmap; delete weighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; } if (random) { delete output; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //save users score for (int s=0; s > namesOfGroupCombos; for (int a=0; a groups; groups.push_back(globaldata->Groups[a]); groups.push_back(globaldata->Groups[l]); + vector groups; groups.push_back(m->Groups[a]); groups.push_back(m->Groups[l]); namesOfGroupCombos.push_back(groups); } } @@ -264,7 +354,8 @@ int UnifracWeightedCommand::execute() { driver(T[i], namesOfGroupCombos, 0, namesOfGroupCombos.size(), rScores); #endif - if (m->control_pressed) { delete output; outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { delete tmap; delete weighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; } delete output; outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } //report progress // m->mothurOut("Iter: " + toString(j+1)); m->mothurOutEndLine(); @@ -301,14 +392,17 @@ int UnifracWeightedCommand::execute() { } - if (m->control_pressed) { outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { delete tmap; delete weighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; } outSum.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } printWSummaryFile(); if (phylip) { createPhylipFile(); } //clear out users groups - globaldata->Groups.clear(); + m->Groups.clear(); + delete tmap; delete weighted; + for (int i = 0; i < T.size(); i++) { delete T[i]; } if (m->control_pressed) { @@ -412,7 +506,7 @@ int UnifracWeightedCommand::createProcesses(Tree* t, vector< vector > na /**************************************************************************************************/ int UnifracWeightedCommand::driver(Tree* t, vector< vector > namesOfGroupCombos, int start, int num, vector< vector >& scores) { try { - Tree* randT = new Tree(); + Tree* randT = new Tree(tmap); for (int h = start; h < (start+num); h++) { @@ -522,10 +616,10 @@ void UnifracWeightedCommand::createPhylipFile() { string phylipFileName; if ((outputForm == "lt") || (outputForm == "square")) { - phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted.phylip.dist"; + phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted.phylip.dist"; outputNames.push_back(phylipFileName); outputTypes["phylip"].push_back(phylipFileName); }else { //column - phylipFileName = outputDir + m->getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted.column.dist"; + phylipFileName = outputDir + m->getSimpleName(treefile) + toString(i+1) + ".weighted.column.dist"; outputNames.push_back(phylipFileName); outputTypes["column"].push_back(phylipFileName); } @@ -534,17 +628,17 @@ void UnifracWeightedCommand::createPhylipFile() { if ((outputForm == "lt") || (outputForm == "square")) { //output numSeqs - out << globaldata->Groups.size() << endl; + out << m->Groups.size() << endl; } //make matrix with scores in it - vector< vector > dists; dists.resize(globaldata->Groups.size()); - for (int i = 0; i < globaldata->Groups.size(); i++) { - dists[i].resize(globaldata->Groups.size(), 0.0); + vector< vector > dists; dists.resize(m->Groups.size()); + for (int i = 0; i < m->Groups.size(); i++) { + dists[i].resize(m->Groups.size(), 0.0); } //flip it so you can print it - for (int r=0; rGroups.size(); r++) { + for (int r=0; rGroups.size(); r++) { for (int l = 0; l < r; l++) { dists[r][l] = utreeScores[count]; dists[l][r] = utreeScores[count]; @@ -553,9 +647,9 @@ void UnifracWeightedCommand::createPhylipFile() { } //output to file - for (int r=0; rGroups.size(); r++) { + for (int r=0; rGroups.size(); r++) { //output name - string name = globaldata->Groups[r]; + string name = m->Groups[r]; if (name.length() < 10) { //pad with spaces to make compatible while (name.length() < 10) { name += " "; } } @@ -570,12 +664,12 @@ void UnifracWeightedCommand::createPhylipFile() { out << name << '\t'; //output distances - for (int l = 0; l < globaldata->Groups.size(); l++) { out << dists[r][l] << '\t'; } + for (int l = 0; l < m->Groups.size(); l++) { out << dists[r][l] << '\t'; } out << endl; }else{ //output distances for (int l = 0; l < r; l++) { - string otherName = globaldata->Groups[l]; + string otherName = m->Groups[l]; if (otherName.length() < 10) { //pad with spaces to make compatible while (otherName.length() < 10) { otherName += " "; } } @@ -650,7 +744,46 @@ void UnifracWeightedCommand::calculateFreqsCumuls() { exit(1); } } - +/*****************************************************************/ +int UnifracWeightedCommand::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 == m->names.end()) { + m->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)) { tmap->addSeq(dupNames[i], "Group1"); } + } + }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); m->names.clear(); namefile = ""; return 1; } + } + in.close(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "UnifracWeightedCommand", "readNamesFile"); + exit(1); + } +} /***********************************************************/ diff --git a/unifracweightedcommand.h b/unifracweightedcommand.h index 2eee7c4..612b64a 100644 --- a/unifracweightedcommand.h +++ b/unifracweightedcommand.h @@ -16,22 +16,22 @@ #include "progress.hpp" #include "sharedutilities.h" #include "fileoutput.h" - - -class GlobalData; +#include "readtree.h" class UnifracWeightedCommand : public Command { public: UnifracWeightedCommand(string); UnifracWeightedCommand(); - ~UnifracWeightedCommand() { if (abort == false) { delete weighted; delete util; } } - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~UnifracWeightedCommand() {} + + vector setParameters(); + string getCommandName() { return "unifrac.weighted"; } + string getCommandCategory() { return "Hypothesis Testing"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: struct linePair { @@ -41,7 +41,7 @@ class UnifracWeightedCommand : public Command { }; vector lines; - GlobalData* globaldata; + ReadTree* read; SharedUtil* util; FileOutput* output; vector T; //user trees @@ -61,13 +61,11 @@ class UnifracWeightedCommand : public Command { map validScores; //map contains scores from random bool abort, phylip, random, includeRoot; - string groups, itersString, outputForm; + string groups, itersString, outputForm, treefile, groupfile, namefile; vector Groups, outputNames; //holds groups to be used - map > outputTypes; - int processors; - - + int processors, numUniquesInName; ofstream outSum; + map nameMap; void printWSummaryFile(); void printWeightedFile(); @@ -77,6 +75,7 @@ class UnifracWeightedCommand : public Command { void calculateFreqsCumuls(); int createProcesses(Tree*, vector< vector >, vector< vector >&); int driver(Tree*, vector< vector >, int, int, vector< vector >&); + int readNamesFile(); }; diff --git a/unweighted.cpp b/unweighted.cpp index a75ddc5..90b6476 100644 --- a/unweighted.cpp +++ b/unweighted.cpp @@ -13,12 +13,11 @@ EstOutput Unweighted::getValues(Tree* t, int p, string o) { try { - globaldata = GlobalData::getInstance(); processors = p; outputDir = o; //if the users enters no groups then give them the score of all groups - int numGroups = globaldata->Groups.size(); + int numGroups = m->Groups.size(); //calculate number of comparsions int numComp = 0; @@ -26,7 +25,7 @@ EstOutput Unweighted::getValues(Tree* t, int p, string o) { for (int r=0; r groups; groups.push_back(globaldata->Groups[r]); groups.push_back(globaldata->Groups[l]); + vector groups; groups.push_back(m->Groups[r]); groups.push_back(m->Groups[l]); namesOfGroupCombos.push_back(groups); } } @@ -42,8 +41,8 @@ EstOutput Unweighted::getValues(Tree* t, int p, string o) { } namesOfGroupCombos.push_back(groups); }else { - for (int i = 0; i < globaldata->Groups.size(); i++) { - groups.push_back(globaldata->Groups[i]); + for (int i = 0; i < m->Groups.size(); i++) { + groups.push_back(m->Groups[i]); } namesOfGroupCombos.push_back(groups); } @@ -257,12 +256,11 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB, int p, string o) { try { - globaldata = GlobalData::getInstance(); processors = p; outputDir = o; //if the users enters no groups then give them the score of all groups - int numGroups = globaldata->Groups.size(); + int numGroups = m->Groups.size(); //calculate number of comparsions int numComp = 0; @@ -270,7 +268,7 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB, int p, st for (int r=0; r groups; groups.push_back(globaldata->Groups[r]); groups.push_back(globaldata->Groups[l]); + vector groups; groups.push_back(m->Groups[r]); groups.push_back(m->Groups[l]); namesOfGroupCombos.push_back(groups); } } @@ -286,8 +284,8 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB, int p, st } namesOfGroupCombos.push_back(groups); }else { - for (int i = 0; i < globaldata->Groups.size(); i++) { - groups.push_back(globaldata->Groups[i]); + for (int i = 0; i < m->Groups.size(); i++) { + groups.push_back(m->Groups[i]); } namesOfGroupCombos.push_back(groups); } @@ -414,7 +412,7 @@ EstOutput Unweighted::driver(Tree* t, vector< vector > namesOfGroupCombo int count = 0; - Tree* copyTree = new Tree; + Tree* copyTree = new Tree(tmap); for (int h = start; h < (start+num); h++) { diff --git a/unweighted.h b/unweighted.h index 0ccfab5..e751d2e 100644 --- a/unweighted.h +++ b/unweighted.h @@ -32,7 +32,6 @@ class Unweighted : public TreeCalculator { }; vector lines; - GlobalData* globaldata; EstOutput data; TreeMap* tmap; int processors; diff --git a/validcalculator.cpp b/validcalculator.cpp index f8c7cc3..2798b53 100644 --- a/validcalculator.cpp +++ b/validcalculator.cpp @@ -666,4 +666,79 @@ void ValidCalculators::printCalc(string parameter, ostream& out) { } } /********************************************************************/ +string ValidCalculators::printCalc(string parameter) { + try{ + string output = "The available estimators for calc are "; + //are you looking for a calculator for a single parameter + if (parameter == "single") { + for (it = single.begin(); it != single.end(); it++) { + output += it->first + ", "; + } + //are you looking for a calculator for a shared parameter + }else if (parameter == "shared") { + for (it = shared.begin(); it != shared.end(); it++) { + output += it->first + ", "; + } + //are you looking for a calculator for a rarefaction parameter + }else if (parameter == "rarefaction") { + for (it = rarefaction.begin(); it != rarefaction.end(); it++) { + output += it->first + ", "; + } + //are you looking for a calculator for a summary parameter + }else if (parameter == "summary") { + for (it = summary.begin(); it != summary.end(); it++) { + output += it->first + ", "; + } + //are you looking for a calculator for a sharedsummary parameter + }else if (parameter == "sharedsummary") { + for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) { + output += it->first + ", "; + } + }else if (parameter == "sharedrarefaction") { + for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) { + output += it->first + ", "; + } + }else if (parameter == "vennsingle") { + for (it = vennsingle.begin(); it != vennsingle.end(); it++) { + output += it->first + ", "; + } + }else if (parameter == "vennshared") { + for (it = vennshared.begin(); it != vennshared.end(); it++) { + output += it->first + ", "; + } + }else if (parameter == "treegroup") { + for (it = treegroup.begin(); it != treegroup.end(); it++) { + output += it->first + ", "; + } + }else if (parameter == "matrix") { + for (it = matrix.begin(); it != matrix.end(); it++) { + output += it->first + ", "; + } + }else if (parameter == "heat") { + for (it = heat.begin(); it != heat.end(); it++) { + output += it->first + ", "; + } + }else if (parameter == "boot") { + for (it = boot.begin(); it != boot.end(); it++) { + output += it->first + ", "; + } + }else if (parameter == "distance") { + for (it = distance.begin(); it != distance.end(); it++) { + output += it->first + ", "; + } + } + + //rip off comma + output = output.substr(0, output.length()-1); + output += "\n"; + + return output; + } + catch(exception& e) { + m->errorOut(e, "ValidCalculator", "printCalc"); + exit(1); + } +} +/********************************************************************/ + diff --git a/validcalculator.h b/validcalculator.h index bf8819f..6cdd4ae 100644 --- a/validcalculator.h +++ b/validcalculator.h @@ -24,6 +24,7 @@ class ValidCalculators { ~ValidCalculators(); bool isValidCalculator(string, string); void printCalc(string, ostream&); + string printCalc(string); private: map single; diff --git a/venn.cpp b/venn.cpp index cf77a92..cd14785 100644 --- a/venn.cpp +++ b/venn.cpp @@ -17,11 +17,9 @@ //********************************************************************************************************************** -Venn::Venn(string o, bool n) : outputDir(o), nseqs(n) { +Venn::Venn(string o, bool n, string f) : outputDir(o), nseqs(n), inputfile(f) { try { - globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); - } catch(exception& e) { m->errorOut(e, "Venn", "Venn"); @@ -35,7 +33,7 @@ vector Venn::getPic(SAbundVector* sabund, vector vCalcs) { vector outputNames; for(int i=0;igetRootName(m->getSimpleName(globaldata->inputFileName)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + "." + sabund->getLabel() + "." + vCalcs[i]->getName() + ".svg"; outputNames.push_back(filenamesvg); m->openOutputFile(filenamesvg, outsvg); @@ -93,7 +91,7 @@ vector Venn::getPic(vector lookup, vectorgetRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + ".svg"; outputNames.push_back(filenamesvg); m->openOutputFile(filenamesvg, outsvg); @@ -149,7 +147,7 @@ vector Venn::getPic(vector lookup, vectorgetRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + ".svg"; outputNames.push_back(filenamesvg); m->openOutputFile(filenamesvg, outsvg); @@ -250,7 +248,7 @@ vector Venn::getPic(vector lookup, vectorgetRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + ".svg"; outputNames.push_back(filenamesvg); m->openOutputFile(filenamesvg, outsvg); @@ -571,7 +569,7 @@ vector Venn::getPic(vector lookup, vectorgetName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { m->mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups. It will be disregarded. "); m->mothurOutEndLine(); } else{ - string filenamesvg = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg"; + string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + "." + vCalcs[i]->getName() + "." + lookup[0]->getGroup() + "-" + lookup[1]->getGroup() + "-" + lookup[2]->getGroup() + "-" + lookup[3]->getGroup() + ".svg"; outputNames.push_back(filenamesvg); m->openOutputFile(filenamesvg, outsvg); diff --git a/venn.h b/venn.h index 33935e6..c5c5f6f 100644 --- a/venn.h +++ b/venn.h @@ -12,7 +12,6 @@ #include "sabundvector.hpp" #include "sharedrabundvector.h" #include "datavector.hpp" -#include "globaldata.hpp" #include "calculator.h" @@ -20,16 +19,15 @@ class Venn { public: - Venn(string, bool); + Venn(string, bool, string); ~Venn(){}; vector getPic(SAbundVector*, vector); vector getPic(vector, vector); private: - GlobalData* globaldata; Calculator* singleCalc; - string groupComb, outputDir; + string groupComb, outputDir, inputfile; ofstream outsvg; MothurOut* m; bool nseqs; diff --git a/venncommand.cpp b/venncommand.cpp index 5cc0fea..c66d1e3 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -17,51 +17,64 @@ #include "sharedace.h" #include "nseqs.h" - //********************************************************************************************************************** -vector VennCommand::getValidParameters(){ +vector VennCommand::setParameters(){ try { - string Array[] = {"groups","label","calc","permute", "abund","nseqs","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist); + CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared); + CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); + CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel); + CommandParameter pcalc("calc", "String", "", "", "", "", "",false,false); parameters.push_back(pcalc); + CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund); + CommandParameter pnseqs("nseqs", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pnseqs); + CommandParameter ppermute("permute", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ppermute); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } return myArray; } catch(exception& e) { - m->errorOut(e, "VennCommand", "getValidParameters"); - exit(1); - } -} -//********************************************************************************************************************** -VennCommand::VennCommand(){ - try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["svg"] = tempOutNames; - } - catch(exception& e) { - m->errorOut(e, "VennCommand", "VennCommand"); + m->errorOut(e, "VennCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -vector VennCommand::getRequiredParameters(){ +string VennCommand::getHelpString(){ try { - vector myArray; - return myArray; + string helpString = ""; + helpString += "The venn command parameters are list, shared, groups, calc, abund, nseqs, permute and label. shared, relabund, list, rabund or sabund is required unless you have a valid current file.\n"; + helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your venn diagram, you may only use a maximum of 4 groups.\n"; + helpString += "The group names are separated by dashes. The label allows you to select what distance levels you would like a venn diagram created for, and are also separated by dashes.\n"; + helpString += "The venn command should be in the following format: venn(groups=yourGroups, calc=yourCalcs, label=yourLabels, abund=yourAbund).\n"; + helpString += "Example venn(groups=A-B-C, calc=sharedsobs-sharedchao, abund=20).\n"; + helpString += "The default value for groups is all the groups in your groupfile up to 4, and all labels in your inputfile will be used.\n"; + helpString += "The default value for calc is sobs if you have only read a list file or if you have selected only one group, and sharedsobs if you have multiple groups.\n"; + helpString += "The default available estimators for calc are sobs, chao and ace if you have only read a list file, and sharedsobs, sharedchao and sharedace if you have read a shared file.\n"; + helpString += "The nseqs parameter will output the number of sequences represented by the otus in the picture, default=F.\n"; + helpString += "If you have more than 4 groups, the permute parameter will find all possible combos of 4 of your groups and create pictures for them, default=F.\n"; + helpString += "The only estimators available four 4 groups are sharedsobs and sharedchao.\n"; + helpString += "The venn command outputs a .svg file for each calculator you specify at each distance you choose.\n"; + helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "VennCommand", "getRequiredParameters"); + m->errorOut(e, "VennCommand", "getHelpString"); exit(1); } } + //********************************************************************************************************************** -vector VennCommand::getRequiredFiles(){ +VennCommand::VennCommand(){ try { - string Array[] = {"list","shared","or"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["svg"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "VennCommand", "getRequiredFiles"); + m->errorOut(e, "VennCommand", "VennCommand"); exit(1); } } @@ -69,21 +82,18 @@ vector VennCommand::getRequiredFiles(){ VennCommand::VennCommand(string option) { try { - globaldata = GlobalData::getInstance(); abort = false; calledHelp = false; allLines = 1; - labels.clear(); //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } else { - //valid paramters for this command - string AlignArray[] = {"groups","label","calc","permute", "abund","nseqs","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); + map::iterator it; ValidParameters validParameter; @@ -92,16 +102,57 @@ VennCommand::VennCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - //make sure the user has already run the read.otu command - if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) { - m->mothurOut("You must read a list, or a list and a group, or a shared before you can use the venn command."); m->mothurOutEndLine(); 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("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("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; } + } } - //if the user changes the output directory command factory will send this info to us in the output parameter - outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ - outputDir = ""; - outputDir += m->hasPath(globaldata->inputFileName); //if user entered a file with a path then preserve it + //check for required parameters + listfile = validParameter.validFile(parameters, "list", true); + if (listfile == "not open") { listfile = ""; abort = true; } + else if (listfile == "not found") { listfile = ""; } + else { format = "list"; inputfile = listfile; } + + sharedfile = validParameter.validFile(parameters, "shared", true); + if (sharedfile == "not open") { sharedfile = ""; abort = true; } + else if (sharedfile == "not found") { sharedfile = ""; } + else { format = "sharedfile"; inputfile = sharedfile; } + + if ((sharedfile == "") && (listfile == "")) { + //is there are current file available for any of these? + //give priority to shared, then list, then rabund, then sabund + //if there is a current shared file, use it + sharedfile = m->getSharedFile(); + if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + listfile = m->getListFile(); + if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a list or shared file."); 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(inputfile); } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -112,20 +163,13 @@ VennCommand::VennCommand(string option) { else { allLines = 1; } } - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } - groups = validParameter.validFile(parameters, "groups", false); if (groups == "not found") { groups = ""; } else { m->splitAtDash(groups, Groups); - globaldata->Groups = Groups; + m->Groups = Groups; } - format = globaldata->getFormat(); calc = validParameter.validFile(parameters, "calc", false); if (calc == "not found") { if(format == "list") { calc = "sobs"; } @@ -149,47 +193,7 @@ VennCommand::VennCommand(string option) { temp = validParameter.validFile(parameters, "permute", false); if (temp == "not found"){ temp = "f"; } perm = m->isTrue(temp); - if (abort == false) { - validCalculator = new ValidCalculators(); - - int i; - - if (format == "list") { - for (i=0; iisValidCalculator("vennsingle", Estimators[i]) == true) { - if (Estimators[i] == "sobs") { - vennCalculators.push_back(new Sobs()); - }else if (Estimators[i] == "chao") { - vennCalculators.push_back(new Chao1()); - }else if (Estimators[i] == "ace") { - if(abund < 5) - abund = 10; - vennCalculators.push_back(new Ace(abund)); - } - } - } - }else { - for (i=0; iisValidCalculator("vennshared", Estimators[i]) == true) { - if (Estimators[i] == "sharedsobs") { - vennCalculators.push_back(new SharedSobsCS()); - }else if (Estimators[i] == "sharedchao") { - vennCalculators.push_back(new SharedChao1()); - }else if (Estimators[i] == "sharedace") { - vennCalculators.push_back(new SharedAce()); - } - } - } - } - - //if the users entered no valid calculators don't execute command - if (vennCalculators.size() == 0) { m->mothurOut("No valid calculators given, please correct."); m->mothurOutEndLine(); abort = true; } - else { venn = new Venn(outputDir, nseqs); } - } - } - - } catch(exception& e) { @@ -197,73 +201,59 @@ VennCommand::VennCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void VennCommand::help(){ - try { - m->mothurOut("The venn command can only be executed after a successful read.otu command.\n"); - m->mothurOut("The venn command parameters are groups, calc, abund, nseqs, permute and label. No parameters are required.\n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included in your venn diagram, you may only use a maximum of 4 groups.\n"); - m->mothurOut("The group names are separated by dashes. The label allows you to select what distance levels you would like a venn diagram created for, and are also separated by dashes.\n"); - m->mothurOut("The venn command should be in the following format: venn(groups=yourGroups, calc=yourCalcs, label=yourLabels, abund=yourAbund).\n"); - m->mothurOut("Example venn(groups=A-B-C, calc=sharedsobs-sharedchao, abund=20).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile up to 4, and all labels in your inputfile will be used.\n"); - m->mothurOut("The default value for calc is sobs if you have only read a list file or if you have selected only one group, and sharedsobs if you have multiple groups.\n"); - m->mothurOut("The default available estimators for calc are sobs, chao and ace if you have only read a list file, and sharedsobs, sharedchao and sharedace if you have read a list and group file or a shared file.\n"); - m->mothurOut("The nseqs parameter will output the number of sequences represented by the otus in the picture, default=F.\n"); - m->mothurOut("If you have more than 4 groups, the permute parameter will find all possible combos of 4 of your groups and create pictures for them, default=F.\n"); - m->mothurOut("The only estimators available four 4 groups are sharedsobs and sharedchao.\n"); - m->mothurOut("The venn command outputs a .svg file for each calculator you specify at each distance you choose.\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "VennCommand", "help"); - exit(1); - } -} - - -//********************************************************************************************************************** - -VennCommand::~VennCommand(){ - if (abort == false) { - delete input; globaldata->ginput = NULL; - delete read; - delete venn; - globaldata->sabund = NULL; - delete validCalculator; - } - -} - //********************************************************************************************************************** int VennCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } + + ValidCalculators validCalculator; + + if (format == "list") { + for (int i=0; imothurOut("No valid calculators given, please correct."); m->mothurOutEndLine(); return 0; } + + venn = new Venn(outputDir, nseqs, inputfile); + input = new InputData(inputfile, format); string lastLabel; if (format == "sharedfile") { - //you have groups - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - - input = globaldata->ginput; lookup = input->getSharedRAbundVectors(); lastLabel = lookup[0]->getLabel(); if ((lookup.size() > 4) && (perm)) { combosOfFour = findCombinations(lookup.size()); } }else if (format == "list") { - //you are using just a list file and have only one group - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - - sabund = globaldata->sabund; + sabund = input->getSAbundVector(); lastLabel = sabund->getLabel(); - input = globaldata->ginput; } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -278,7 +268,7 @@ int VennCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - globaldata->Groups.clear(); + m->Groups.clear(); delete venn; delete input; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } @@ -361,7 +351,7 @@ int VennCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } - globaldata->Groups.clear(); + m->Groups.clear(); delete venn; delete input; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } @@ -418,9 +408,10 @@ int VennCommand::execute(){ //reset groups parameter - globaldata->Groups.clear(); + m->Groups.clear(); if (m->control_pressed) { + m->Groups.clear(); delete venn; delete input; for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; @@ -433,7 +424,7 @@ int VennCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } - delete sabund; + delete sabund; delete venn; delete input; for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } @@ -476,6 +467,7 @@ int VennCommand::execute(){ if (m->control_pressed) { for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } + delete venn; delete input; return 0; } @@ -506,6 +498,7 @@ int VennCommand::execute(){ } if (m->control_pressed) { + delete venn; delete input; for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; @@ -513,6 +506,7 @@ int VennCommand::execute(){ } for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } + delete venn; delete input; m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); diff --git a/venncommand.h b/venncommand.h index 29beead..fe0e2a6 100644 --- a/venncommand.h +++ b/venncommand.h @@ -11,36 +11,30 @@ #include "command.hpp" #include "inputdata.h" -#include "readotu.h" #include "sharedlistvector.h" #include "venn.h" #include "validcalculator.h" - -class GlobalData; - - class VennCommand : public Command { public: VennCommand(string); VennCommand(); - ~VennCommand(); - vector getRequiredParameters(); - vector getValidParameters(); - vector getRequiredFiles(); - map > getOutputFiles() { return outputTypes; } - int execute(); - void help(); + ~VennCommand() {} + + vector setParameters(); + string getCommandName() { return "venn"; } + string getCommandCategory() { return "OTU-Based Approaches"; } + string getHelpString(); + + int execute(); + void help() { m->mothurOut(getHelpString()); } private: - GlobalData* globaldata; - ReadOTUFile* read; InputData* input; SharedListVector* SharedList; Venn* venn; vector vennCalculators; - ValidCalculators* validCalculator; vector lookup; set< set > combosOfFour; SAbundVector* sabund; @@ -48,9 +42,8 @@ private: bool abort, allLines, nseqs, perm; set labels; //holds labels to be used - string format, groups, calc, label, outputDir; + string format, groups, calc, label, outputDir, sharedfile, listfile, inputfile; vector Estimators, Groups, outputNames; - map > outputTypes; set< set > findCombinations(int); int getCombos(set, set< set >&); diff --git a/weighted.cpp b/weighted.cpp index cae2b92..d0defc3 100644 --- a/weighted.cpp +++ b/weighted.cpp @@ -13,15 +13,13 @@ EstOutput Weighted::getValues(Tree* t, int p, string o) { try { - globaldata = GlobalData::getInstance(); - data.clear(); //clear out old values int numGroups; vector D; processors = p; outputDir = o; - numGroups = globaldata->Groups.size(); + numGroups = m->Groups.size(); if (m->control_pressed) { return data; } @@ -31,7 +29,7 @@ EstOutput Weighted::getValues(Tree* t, int p, string o) { for (int l = 0; l < i; l++) { //initialize weighted scores //WScore[globaldata->Groups[i]+globaldata->Groups[l]] = 0.0; - vector groups; groups.push_back(globaldata->Groups[i]); groups.push_back(globaldata->Groups[l]); + vector groups; groups.push_back(m->Groups[i]); groups.push_back(m->Groups[l]); namesOfGroupCombos.push_back(groups); } } @@ -267,7 +265,6 @@ EstOutput Weighted::driver(Tree* t, vector< vector > namesOfGroupCombos, /**************************************************************************************************/ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { try { - globaldata = GlobalData::getInstance(); data.clear(); //clear out old values diff --git a/weighted.h b/weighted.h index d78edf4..c23a115 100644 --- a/weighted.h +++ b/weighted.h @@ -33,7 +33,6 @@ class Weighted : public TreeCalculator { }; vector lines; - GlobalData* globaldata; EstOutput data; TreeMap* tmap; map::iterator it; -- 2.39.2