]> git.donarmstrong.com Git - mothur.git/commitdiff
removed read.dist, read.otu, read.tree and globaldata. added current to defaults...
authorwestcott <westcott>
Wed, 6 Apr 2011 13:22:57 +0000 (13:22 +0000)
committerwestcott <westcott>
Wed, 6 Apr 2011 13:22:57 +0000 (13:22 +0000)
287 files changed:
Mothur.xcodeproj/project.pbxproj
aligncommand.cpp
aligncommand.h
amovacommand.cpp
amovacommand.h
anosimcommand.cpp
anosimcommand.h
binsequencecommand.cpp
binsequencecommand.h
blastalign.cpp
blastalign.hpp
blastdb.cpp
blastdb.hpp
bootstrapsharedcommand.cpp
bootstrapsharedcommand.h
catchallcommand.cpp
catchallcommand.h
chimerabellerophoncommand.cpp
chimerabellerophoncommand.h
chimeraccodecommand.cpp
chimeraccodecommand.h
chimeracheckcommand.cpp
chimeracheckcommand.h
chimerapintailcommand.cpp
chimerapintailcommand.h
chimeraseqscommand.cpp [deleted file]
chimeraseqscommand.h [deleted file]
chimeraslayercommand.cpp
chimeraslayercommand.h
chopseqscommand.cpp
chopseqscommand.h
classifyotucommand.cpp
classifyotucommand.h
classifyseqscommand.cpp
classifyseqscommand.h
clearcutcommand.cpp
clearcutcommand.h
clusterclassic.cpp
clusterclassic.h
clustercommand.cpp
clustercommand.h
clusterdoturcommand.cpp
clusterdoturcommand.h
clusterfragmentscommand.cpp
clusterfragmentscommand.h
clustersplitcommand.cpp
clustersplitcommand.h
collect.cpp
collect.h
collectcommand.cpp
collectcommand.h
collectsharedcommand.cpp
collectsharedcommand.h
command.hpp
commandfactory.cpp
commandoptionparser.cpp
consensuscommand.cpp
consensuscommand.h
consensusseqscommand.cpp
consensusseqscommand.h
corraxescommand.cpp
corraxescommand.h
datavector.hpp
decalc.cpp
deconvolutecommand.cpp
deconvolutecommand.h
degapseqscommand.cpp
degapseqscommand.h
deuniqueseqscommand.cpp
deuniqueseqscommand.h
distancecommand.cpp
distancecommand.h
engine.cpp
engine.hpp
filterseqscommand.cpp
filterseqscommand.h
fullmatrix.cpp
fullmatrix.h
getcurrentcommand.cpp
getcurrentcommand.h
getgroupcommand.cpp
getgroupcommand.h
getgroupscommand.cpp
getgroupscommand.h
getlabelcommand.cpp
getlabelcommand.h
getlineagecommand.cpp
getlineagecommand.h
getlistcountcommand.cpp
getlistcountcommand.h
getoturepcommand.cpp
getoturepcommand.h
getotuscommand.cpp
getotuscommand.h
getrabundcommand.cpp
getrabundcommand.h
getrelabundcommand.cpp
getrelabundcommand.h
getsabundcommand.cpp
getsabundcommand.h
getseqscommand.cpp
getseqscommand.h
getsharedotucommand.cpp
getsharedotucommand.h
globaldata.cpp
globaldata.hpp
groupmap.cpp
hclustercommand.cpp
hclustercommand.h
heatmap.cpp
heatmap.h
heatmapcommand.cpp
heatmapcommand.h
heatmapsim.cpp
heatmapsim.h
heatmapsimcommand.cpp
heatmapsimcommand.h
helpcommand.cpp
helpcommand.h
homovacommand.cpp
homovacommand.h
indicatorcommand.cpp
indicatorcommand.h
inputdata.cpp
inputdata.h
libshuffcommand.cpp
libshuffcommand.h
listseqscommand.cpp
listseqscommand.h
makefastqcommand.cpp
makefastqcommand.h
makegroupcommand.cpp
makegroupcommand.h
mantelcommand.cpp
mantelcommand.h
matrixoutputcommand.cpp
matrixoutputcommand.h
mergefilecommand.cpp
mergefilecommand.h
mergegroupscommand.cpp
mergegroupscommand.h
metastatscommand.cpp
metastatscommand.h
mgclustercommand.cpp
mgclustercommand.h
mothur.cpp
mothurout.cpp
mothurout.h
nmdscommand.cpp
nmdscommand.h
nocommands.cpp
nocommands.h
normalizesharedcommand.cpp
normalizesharedcommand.h
optionparser.cpp
otuhierarchycommand.cpp
otuhierarchycommand.h
pairwiseseqscommand.cpp
pairwiseseqscommand.h
parsefastaqcommand.cpp
parsefastaqcommand.h
parselistscommand.cpp
parselistscommand.h
parsimony.cpp
parsimony.h
parsimonycommand.cpp
parsimonycommand.h
pcacommand.cpp
pcacommand.h
pcoacommand.cpp
pcoacommand.h
phylodiversity.h
phylodiversitycommand.cpp
phylodiversitycommand.h
phylotypecommand.cpp
phylotypecommand.h
pipelinepdscommand.cpp
pipelinepdscommand.h
preclustercommand.cpp
preclustercommand.h
quitcommand.cpp
quitcommand.h
rarefact.cpp
rarefact.h
rarefactcommand.cpp
rarefactcommand.h
rarefactsharedcommand.cpp
rarefactsharedcommand.h
readcluster.cpp
readcluster.h
readcolumn.cpp
readcolumn.h
readdistcommand.cpp
readdistcommand.h
readmatrix.hpp
readotu.cpp
readotu.h
readotucommand.cpp
readotucommand.h
readphylip.cpp
readphylip.h
readtree.cpp
readtree.h
readtreecommand.cpp
readtreecommand.h
removegroupscommand.cpp
removegroupscommand.h
removelineagecommand.cpp
removelineagecommand.h
removeotuscommand.cpp
removeotuscommand.h
removerarecommand.cpp
removerarecommand.h
removeseqscommand.cpp
removeseqscommand.h
reversecommand.cpp
reversecommand.h
screenseqscommand.cpp
screenseqscommand.h
secondarystructurecommand.cpp
secondarystructurecommand.h
sensspeccommand.cpp
sensspeccommand.h
seqerrorcommand.cpp
seqerrorcommand.h
seqsummarycommand.cpp
seqsummarycommand.h
setcurrentcommand.cpp
setcurrentcommand.h
setdircommand.cpp
setdircommand.h
setlogfilecommand.cpp
setlogfilecommand.h
sffinfocommand.cpp
sffinfocommand.h
sharedcommand.cpp
sharedcommand.h
sharedjackknife.cpp
sharedjackknife.h
sharedlistvector.cpp
sharedlistvector.h
sharedordervector.cpp
sharedordervector.h
sharedrabundfloatvector.cpp
sharedrabundfloatvector.h
sharedrabundvector.cpp
sharedrabundvector.h
sharedutilities.cpp
sharedutilities.h
shhhercommand.cpp
shhhercommand.h
splitabundcommand.cpp
splitabundcommand.h
splitgroupscommand.cpp
splitgroupscommand.h
subsamplecommand.cpp
subsamplecommand.h
summarycommand.cpp
summarycommand.h
summarysharedcommand.cpp
summarysharedcommand.h
systemcommand.cpp
systemcommand.h
tree.cpp
tree.h
treegroupscommand.cpp
treegroupscommand.h
treemap.cpp
treemap.h
trimflowscommand.cpp
trimflowscommand.h
trimseqscommand.cpp
trimseqscommand.h
unifracunweightedcommand.cpp
unifracunweightedcommand.h
unifracweightedcommand.cpp
unifracweightedcommand.h
unweighted.cpp
unweighted.h
validcalculator.cpp
validcalculator.h
venn.cpp
venn.h
venncommand.cpp
venncommand.h
weighted.cpp
weighted.h

index 4bc5960998187c10304d8ea3d6874250d2120f1e..582beaf70ddc256d955b4677911069ab97971d16 100644 (file)
@@ -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 */; };
                A7A61F2B130062E000E05B6B /* amovacommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amovacommand.h; sourceTree = "<group>"; };
                A7A61F2C130062E000E05B6B /* amovacommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = amovacommand.cpp; sourceTree = "<group>"; };
                A7AACFBA132FE008003D6C4D /* currentfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = currentfile.h; sourceTree = "<group>"; };
+               A7DAAFA3133A254E003956EB /* commandparameter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = commandparameter.h; sourceTree = "<group>"; };
                A7E9B64F12D37EC300DA6239 /* ace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ace.cpp; sourceTree = "<group>"; };
                A7E9B65012D37EC300DA6239 /* ace.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ace.h; sourceTree = "<group>"; };
                A7E9B65112D37EC300DA6239 /* aligncommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = aligncommand.cpp; sourceTree = "<group>"; };
                A7E9B68312D37EC400DA6239 /* chimerapintailcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimerapintailcommand.h; sourceTree = "<group>"; };
                A7E9B68412D37EC400DA6239 /* chimerarealigner.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimerarealigner.cpp; sourceTree = "<group>"; };
                A7E9B68512D37EC400DA6239 /* chimerarealigner.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimerarealigner.h; sourceTree = "<group>"; };
-               A7E9B68612D37EC400DA6239 /* chimeraseqscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimeraseqscommand.cpp; sourceTree = "<group>"; };
-               A7E9B68712D37EC400DA6239 /* chimeraseqscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimeraseqscommand.h; sourceTree = "<group>"; };
                A7E9B68812D37EC400DA6239 /* chimeraslayer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimeraslayer.cpp; sourceTree = "<group>"; };
                A7E9B68912D37EC400DA6239 /* chimeraslayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = chimeraslayer.h; sourceTree = "<group>"; };
                A7E9B68A12D37EC400DA6239 /* chimeraslayercommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = chimeraslayercommand.cpp; sourceTree = "<group>"; };
                                A7E9B6B012D37EC400DA6239 /* commandfactory.hpp */,
                                A7E9B6B112D37EC400DA6239 /* commandoptionparser.cpp */,
                                A7E9B6B212D37EC400DA6239 /* commandoptionparser.hpp */,
+                               A7DAAFA3133A254E003956EB /* commandparameter.h */,
                                A7E9B6B412D37EC400DA6239 /* completelinkage.cpp */,
                                A7E9BA4212D3960D00DA6239 /* containers */,
                                A7AACFBA132FE008003D6C4D /* currentfile.h */,
                        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 = "<group>";
                                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 */,
                        );
                                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 */,
                                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 */,
                                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 */,
index a820542e42f4d7a7b9956b194f790555e634536a..5f64411f0d9d8df558fdf6d8b9282227899e1e57 100644 (file)
 #include "nast.hpp"
 #include "nastreport.hpp"
 
-
-//**********************************************************************************************************************
-vector<string> AlignCommand::getValidParameters(){     
-       try {
-               string AlignArray[] =  {"template","candidate","search","ksize","align","match","mismatch","gapopen","gapextend", "processors","flip","threshold","outputdir","inputdir"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "AlignCommand", "getValidParameters");
-               exit(1);
-       }
-}
 //**********************************************************************************************************************
-vector<string> AlignCommand::getRequiredParameters(){  
+vector<string> AlignCommand::setParameters(){  
        try {
-               string AlignArray[] =  {"template","candidate"};
-               vector<string> 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<string> 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<string> AlignCommand::getRequiredFiles(){       
+string AlignCommand::getHelpString(){  
        try {
-               vector<string> 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<string> AlignCommand::getRequiredFiles(){
 AlignCommand::AlignCommand(){  
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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<processors;i++) { 
+               for (int i=0;i<processIDS.size();i++) { 
                        int temp = processIDS[i];
                        wait(&temp);
                }
index 169b43512375aef99a22029b35425d87d6360afb..ef5a92e4b8aad04651ded1ed8caf58dc58c16b30 100644 (file)
@@ -22,12 +22,14 @@ public:
        AlignCommand(string);   
        AlignCommand();
        ~AlignCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       
+       vector<string> 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<int> processIDS;   //processid
        vector<linePair*> lines;
        bool MPIWroteAccnos;
-       map<string, vector<string> > outputTypes;
        
        AlignmentDB* templateDB;
        Alignment* alignment;
index 8ab08553c4969268be12230b68f0f80303da2989..8e3edd573b40706458c0b4c8a5803b6ed2265b14 100644 (file)
 #include "readphylipvector.h"
 #include "groupmap.h"
 
+
 //**********************************************************************************************************************
-vector<string> AmovaCommand::getValidParameters(){     
+vector<string> AmovaCommand::setParameters(){  
        try {
-               string Array[] =  {"outputdir","iters","phylip","design","alpha", "inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["amova"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "AmovaCommand", "AmovaCommand");
+               m->errorOut(e, "AmovaCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> AmovaCommand::getRequiredParameters(){  
+string AmovaCommand::getHelpString(){  
        try {
-               string Array[] =  {"design"};
-               vector<string> 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<string> AmovaCommand::getRequiredFiles(){       
+AmovaCommand::AmovaCommand(){  
        try {
-               string Array[] =  {};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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(){
index 51a420064fc0e560cebb291035b1d9245febce5c..f50df46f70a3c6cce602ba8eeb5a4987c6dd2c95 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       ~AmovaCommand() {}
+       
+       vector<string> 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<string, vector<int> >, double);
@@ -34,9 +34,7 @@ private:
        double calcSSTotal(map<string, vector<int> >&);
        map<string, vector<int> > getRandomizedGroups(map<string, vector<int> >);
 
-       
        bool abort;
-       map<string, vector<string> > outputTypes;
        vector<string> outputNames;
 
        string outputDir, inputDir, designFileName, phylipFileName;
index 79064a4bf6731cfcd1604f2a2c8d28f42e501b13..623b4333948a8996ab5122389a67bac2cb21bc6f 100644 (file)
 #include "readphylipvector.h"
 
 //**********************************************************************************************************************
-vector<string> AnosimCommand::getValidParameters(){    
+vector<string> AnosimCommand::setParameters(){ 
        try {
-               string Array[] =  {"outputdir","iters","phylip","design", "alpha","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> AnosimCommand::getRequiredParameters(){ 
-       try {
-               string Array[] =  {"design"};
-               vector<string> 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<string> AnosimCommand::getRequiredFiles(){      
+AnosimCommand::AnosimCommand(){        
        try {
-               string Array[] =  {};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index ab724007237d508e1b2dabf1bba521c5c38f7497..7bc5655702df0048aa8d6a476972d7456923d659 100644 (file)
@@ -20,18 +20,19 @@ class AnosimCommand : public Command {
 public:
        AnosimCommand(string);
        AnosimCommand();
-       ~AnosimCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       ~AnosimCommand(){}
+       
+       vector<string> 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<string, vector<string> > outputTypes;
        string outputDir, inputDir, designFileName, phylipFileName;
        
        vector<vector<double> > convertToRanks(vector<vector<double> >);
index 8b137c8935e099f6e806f60746244c0d244b9687..d1764acec4602f5d90783f7a0abf35195b63149d 100644 (file)
@@ -9,39 +9,43 @@
 
 #include "binsequencecommand.h"
 
+
 //**********************************************************************************************************************
-vector<string> BinSeqCommand::getValidParameters(){    
-       try {
-               string AlignArray[] =  {"fasta","label","name", "group","outputdir","inputdir"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "BinSeqCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> BinSeqCommand::getRequiredParameters(){ 
+vector<string> BinSeqCommand::setParameters(){ 
        try {
-               string AlignArray[] =  {"fasta"};
-               vector<string> 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<string> 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<string> BinSeqCommand::getRequiredFiles(){      
+string BinSeqCommand::getHelpString(){ 
        try {
-               string AlignArray[] =  {"list"};
-               vector<string> 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<string> BinSeqCommand::getRequiredFiles(){
 BinSeqCommand::BinSeqCommand(){        
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
@@ -88,20 +90,6 @@ BinSeqCommand::BinSeqCommand(string option) {
                        vector<string> 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<string> 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<string>::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
index df7ea7593dd266c71a3a1b7a49c03c70596a368f..fe83f20f59b0e6f4db7d765f9b1aa5dc17618252 100644 (file)
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       
+       vector<string> 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<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
        void readNamesFile();
        int process(ListVector*);
index 5e7fb61aa77e7c34ca7367393766b1a5455c9213..9af31dfa3e65e130d0bc347600aa28405f94b7f4 100644 (file)
 
 //**************************************************************************************************/
 
-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)
index 94bce82936a5e05404ee66e4eda6d5cad282f3b3..5b78da6b635770b53453cf9b6ec84493b17bf71a 100644 (file)
@@ -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;
 };
 
index bc92e1c5f083831a88ec2d10e7a0fe94c68bb6b7..776955588abb474ae8f1123f4cb93ad8bbb73883 100644 (file)
@@ -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
index 2e7423dcba612f332d7ef2f2657fac9aa16f1b79..9398ba0362b9f501bc6684b508c6befcfe20b4d5 100644 (file)
@@ -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
index afc3cf1533475b6bf78b8127ba34086193612371..7f7683bd4f3c779203d3e2944885ad65a4369bc9 100644 (file)
 #include "sharedmorisitahorn.h"
 #include "sharedbraycurtis.h"
 
+
 //**********************************************************************************************************************
-vector<string> BootSharedCommand::getValidParameters(){        
+vector<string> BootSharedCommand::setParameters(){     
        try {
-               string AlignArray[] =  {"label","calc","groups","iters","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> BootSharedCommand::getRequiredParameters(){     
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "BootSharedCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> BootSharedCommand::getRequiredFiles(){  
+BootSharedCommand::BootSharedCommand(){        
        try {
-               string AlignArray[] =  {"shared"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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; i<Estimators.size(); i++) {
                                        if (validCalculator->isValidCalculator("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<string> 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<string>::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<SharedRAbundVector*> 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;
        
        }
index 53f6a26fd471d395a19d414af75640dc9bb0d62c..50297b8f5e6f2170cf85487de23ca43c3138ccea 100644 (file)
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       
+       vector<string> 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<string> labels; //holds labels to be used
-       string outputFile, calc, groups, label, outputDir;
+       string outputFile, calc, groups, label, outputDir, sharedfile;
        int numGroups, iters;
        vector<string>  Estimators, Groups, outputNames; //holds estimators to be used
-       map< string, vector<string> > outputTypes;
-
 };
        
        
index ace1b00dc0b45e9500d6ba9aa8657fc44b854042..3effaf4eaafe09659252e6f93fa81f31dcc4e1db 100644 (file)
 #include "globaldata.hpp"
 
 //**********************************************************************************************************************
-vector<string> CatchAllCommand::getValidParameters(){  
+vector<string> CatchAllCommand::setParameters(){       
        try {
-               string AlignArray[] =  {"sabund","shared","label","inputdir","outputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["csv"] = tempOutNames;
-               outputTypes["summary"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "CatchAllCommand", "CatchAllCommand");
+               m->errorOut(e, "CatchAllCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> CatchAllCommand::getRequiredParameters(){       
+string CatchAllCommand::getHelpString(){       
        try {
-               string AlignArray[] =  {"sabund","shared","or"};
-               vector<string> 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<string> CatchAllCommand::getRequiredFiles(){    
+CatchAllCommand::CatchAllCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               //initialize outputTypes
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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<string> 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();
index 44bde029e382a382fcc0b407da5d789a1f302cb7..583191db8d547996bef24378fb2dfd50b7ac0a13 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map< string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
        
-private:
-
-       GlobalData* globaldata;
+       vector<string> 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<string> labels;
        vector<string> outputNames;
-       map< string, vector<string> > outputTypes;
        vector<string> groups;
        
        string process(SAbundVector*, string);
index 140a94993df3634fec862bd371f7658390b928e6..cc0aa43ceb4f6c6305ebef2e1850c2dfa23a1fc4 100644 (file)
 #include "bellerophon.h"
 
 //**********************************************************************************************************************
-vector<string> ChimeraBellerophonCommand::getValidParameters(){        
+vector<string> ChimeraBellerophonCommand::setParameters(){     
        try {
-               string AlignArray[] =  {"fasta","filter","correction","processors","window","increment","outputdir","inputdir"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ChimeraBellerophonCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ChimeraBellerophonCommand::getRequiredParameters(){     
-       try {
-               string AlignArray[] =  {"fasta"};
-               vector<string> 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<string> 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<string> ChimeraBellerophonCommand::getRequiredFiles(){  
+string ChimeraBellerophonCommand::getHelpString(){     
        try {
-               vector<string> 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<string> ChimeraBellerophonCommand::getRequiredFiles(){
 ChimeraBellerophonCommand::ChimeraBellerophonCommand(){        
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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{
                
index 6e1ae50794f23d92c75d0224011251e385ae8f43..867d3618888e37079ed7e61cc44e5a869924ab04 100644 (file)
@@ -21,13 +21,16 @@ class ChimeraBellerophonCommand : public Command {
 public:
        ChimeraBellerophonCommand(string);
        ChimeraBellerophonCommand();
-       ~ChimeraBellerophonCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map< string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ChimeraBellerophonCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        vector<string> fastaFileNames;
 };
 
index 457eaf314bf304fe3d7f9e5eec67509f07236a35..0b6117a98efba24d95da9df73aa15062141a8cad 100644 (file)
@@ -9,53 +9,69 @@
 
 #include "chimeraccodecommand.h"
 #include "ccode.h"
-
 //**********************************************************************************************************************
-vector<string> ChimeraCcodeCommand::getValidParameters(){      
+vector<string> ChimeraCcodeCommand::setParameters(){   
        try {
-               string AlignArray[] =  {"fasta", "filter", "processors", "window", "template", "mask", "numwanted", "outputdir","inputdir" };
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["chimera"] = tempOutNames;
-               outputTypes["mapinfo"] = tempOutNames;
-               outputTypes["accnos"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ChimeraCcodeCommand", "ChimeraCcodeCommand");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ChimeraCcodeCommand::getRequiredParameters(){   
-       try {
-               string AlignArray[] =  {"template","fasta"};
-               vector<string> 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<string> ChimeraCcodeCommand::getRequiredFiles(){        
+ChimeraCcodeCommand::ChimeraCcodeCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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{
                
index a9ed223b112cdb50876024c893257549e159481f..4f047e169183bc9d9294f1abb6f229015a162496 100644 (file)
@@ -21,13 +21,15 @@ class ChimeraCcodeCommand : public Command {
 public:
        ChimeraCcodeCommand(string);
        ChimeraCcodeCommand();
-       ~ChimeraCcodeCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ChimeraCcodeCommand(){}
+       
+       vector<string> 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<string> fastaFileNames;
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
-       
-       
 };
 
 /***********************************************************/
index c766b9a2dab6c2994df147423f61d14bf6f088a6..5a72afd054dd68eb4112bfa5f1cc6db52e992beb 100644 (file)
 #include "chimeracheckcommand.h"
 
 //**********************************************************************************************************************
-vector<string> ChimeraCheckCommand::getValidParameters(){      
+vector<string> ChimeraCheckCommand::setParameters(){   
        try {
-               string AlignArray[] =  {"fasta","processors","increment","template","ksize","svg", "name","outputdir","inputdir" };
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ChimeraCheckCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ChimeraCheckCommand::getRequiredParameters(){   
-       try {
-               string AlignArray[] =  {"template","fasta"};
-               vector<string> 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<string> 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<string> ChimeraCheckCommand::getRequiredFiles(){        
+string ChimeraCheckCommand::getHelpString(){   
        try {
-               vector<string> 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<string> ChimeraCheckCommand::getRequiredFiles(){
 ChimeraCheckCommand::ChimeraCheckCommand(){    
        try {
                abort = true; calledHelp = true;
+               setParameters();
                vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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(){
index 6e81812e469772b18a737930354f1bdf943a9ef9..221d35fe504bea29e6757b35aadd9449703543ab 100644 (file)
@@ -22,15 +22,17 @@ class ChimeraCheckCommand : public Command {
 public:
        ChimeraCheckCommand(string);
        ChimeraCheckCommand();
-       ~ChimeraCheckCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ChimeraCheckCommand(){}
+       
+       vector<string> 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<string> fastaFileNames;
        vector<string> nameFileNames;
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
-               
 };
 
 /***********************************************************/
index 038460fe1485dc531cec04f83b28793f0b55a550..2b6ed0348d11d11b7ab04d1ce92c9620de1427bd 100644 (file)
 #include "pintail.h"
 
 //**********************************************************************************************************************
-vector<string> ChimeraPintailCommand::getValidParameters(){    
+vector<string> ChimeraPintailCommand::setParameters(){ 
        try {
-               string AlignArray[] =  {"fasta","filter","processors","window" ,"increment","template","conservation","quantile","mask","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["chimera"] = tempOutNames;
-               outputTypes["accnos"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ChimeraPintailCommand", "ChimeraPintailCommand");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ChimeraPintailCommand::getRequiredParameters(){ 
-       try {
-               string AlignArray[] =  {"template","fasta"};
-               vector<string> 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<string> ChimeraPintailCommand::getRequiredFiles(){      
+ChimeraPintailCommand::ChimeraPintailCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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(){
index d2b2e03a3196d61cf7036ff879f1a18bec741ae6..abaef191e2c1ba137f83aad2fb3e7ea46bc0b7de 100644 (file)
@@ -23,14 +23,15 @@ public:
 
        ChimeraPintailCommand(string);
        ChimeraPintailCommand();
-       ~ChimeraPintailCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ChimeraPintailCommand(){}
        
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        vector<string> fastaFileNames;
-       
-       
 };
 
 /***********************************************************/
diff --git a/chimeraseqscommand.cpp b/chimeraseqscommand.cpp
deleted file mode 100644 (file)
index 9013e7d..0000000
+++ /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<string> ChimeraSeqsCommand::getValidParameters(){       
-       try {
-               vector<string> myArray; 
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ChimeraSeqsCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ChimeraSeqsCommand::getRequiredParameters(){    
-       try {
-               vector<string> myArray; 
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ChimeraSeqsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ChimeraSeqsCommand::getRequiredFiles(){ 
-       try {
-               vector<string> 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 (file)
index 7e51748..0000000
+++ /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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map< string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
-       
-               
-private:
-       vector<string> outputNames;
-       map< string, vector<string> > outputTypes;
-
-};
-
-/***********************************************************/
-
-#endif
-
index 9b4a87b6a45124d5e472952626207e82e1ebbb67..1556cb2272c3ad3301dbbc283c04fd4c5873023c 100644 (file)
 #include "deconvolutecommand.h"
 
 //**********************************************************************************************************************
-vector<string> ChimeraSlayerCommand::getValidParameters(){     
+vector<string> 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<string> 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<string> 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<string> 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<string> ChimeraSlayerCommand::getRequiredParameters(){  
+string ChimeraSlayerCommand::getHelpString(){  
        try {
-               string AlignArray[] =  {"template","fasta"};
-               vector<string> 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<string> ChimeraSlayerCommand::getRequiredFiles(){       
+ChimeraSlayerCommand::ChimeraSlayerCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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(){
index d201ccb5f1baa2c628f217c7c763523e832d70eb..02ebe722a522d763c309bab0ea2215f0ceac6f85 100644 (file)
@@ -21,15 +21,16 @@ class ChimeraSlayerCommand : public Command {
 public:
        ChimeraSlayerCommand(string);
        ChimeraSlayerCommand();
-       ~ChimeraSlayerCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ChimeraSlayerCommand() {}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        vector<string> fastaFileNames;
        vector<string> nameFileNames;
        
index a09ff65856ae39c1e8fbb1a662ed8bacd8860694..8775d95abab9a4577aaad0f29feec2d15bc39694 100644 (file)
 #include "sequence.hpp"
 
 //**********************************************************************************************************************
-vector<string> ChopSeqsCommand::getValidParameters(){  
+vector<string> ChopSeqsCommand::setParameters(){       
        try {
-               string AlignArray[] =  {"fasta","short","numbases","countgaps","keep","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> ChopSeqsCommand::getRequiredParameters(){       
-       try {
-               string Array[] =  {"fasta","numbases"};
-               vector<string> 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<string> ChopSeqsCommand::getRequiredFiles(){    
+ChopSeqsCommand::ChopSeqsCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index dbf4d23b71ebc1302672e66bc65472331117713f..92544ee30cb69df2f04b95a4e9f7c99c748e835e 100644 (file)
@@ -21,23 +21,22 @@ class ChopSeqsCommand : public Command {
                ChopSeqsCommand(string);
                ChopSeqsCommand();      
                ~ChopSeqsCommand(){};
-               vector<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();    
-               
+       
+               vector<string> 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<string> outputNames;
-               map<string, vector<string> > outputTypes;
                
                string getChopped(Sequence);
-               
-               
 };
 
 #endif
index 8d9f177941549b62742f76e0b38c5337ab5b3922..a70be07e955180d17208b47f50d92f82ba2fa438 100644 (file)
 #include "phylosummary.h"
 
 //**********************************************************************************************************************
-vector<string> ClassifyOtuCommand::getValidParameters(){       
+vector<string> ClassifyOtuCommand::setParameters(){    
        try {
-               string AlignArray[] =  {"list","label","name","taxonomy","basis","cutoff","probs","group","reftaxonomy","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["constaxonomy"] = tempOutNames;
-               outputTypes["taxsummary"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ClassifyOtuCommand", "ClassifyOtuCommand");
+               m->errorOut(e, "ClassifyOtuCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> ClassifyOtuCommand::getRequiredParameters(){    
+string ClassifyOtuCommand::getHelpString(){    
        try {
-               string Array[] =  {"list","taxonomy"};
-               vector<string> 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<string> ClassifyOtuCommand::getRequiredFiles(){ 
+ClassifyOtuCommand::ClassifyOtuCommand(){      
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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(){
index e81c246201f36b7904d26b702748e1ba653dff66..7f15c71c1847421abb88c3202d96e8ca7015837a 100644 (file)
@@ -20,13 +20,15 @@ class ClassifyOtuCommand : public Command {
 public:
        ClassifyOtuCommand(string);
        ClassifyOtuCommand();
-       ~ClassifyOtuCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ClassifyOtuCommand() {}
+       
+       vector<string> 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<string> outputNames;
        map<string, string> nameMap;
        map<string, string> taxMap;
-       map<string, vector<string> > outputTypes;
 
        int readNamesFile();
        int readTaxonomyFile();
index 6cfa3321c1cfd9b14cc3bf4b86d400c46feecb3c..6f8bc7ee1ae7436dc395291bf078336aaff1889f 100644 (file)
 
 
 //**********************************************************************************************************************
-vector<string> ClassifySeqsCommand::getValidParameters(){      
+vector<string> 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<string> 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<string> 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<string> 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<string> ClassifySeqsCommand::getRequiredParameters(){   
+string ClassifySeqsCommand::getHelpString(){   
        try {
-               string Array[] =  {"fasta","template","taxonomy"};
-               vector<string> 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<string> ClassifySeqsCommand::getRequiredFiles(){        
+ClassifySeqsCommand::ClassifySeqsCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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(){
index 16549135aacbe25e36d89f21c503f1baae2fe659..115360f7d5c3015130b0beef8a704f7669a382b5 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       
+       vector<string> 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<string> outputNames;
        map<string, vector<string> > nameMap;
        map<string,  vector<string> >::iterator itNames;
-       map<string, vector<string> > outputTypes;
        
        Classify* classify;
        
index 7fd8c134a0fdee4c6f93075f1d97e9f5ab98000a..afb215932958e273093726a3b71a398faabc4dc2 100644 (file)
@@ -15,51 +15,89 @@ extern "C" {
 #ifdef __cplusplus
 }
 #endif
+
 //**********************************************************************************************************************
-vector<string> ClearcutCommand::getValidParameters(){  
+vector<string> 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<string> 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<string> 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<string> tempOutNames;
-               outputTypes["tree"] = tempOutNames;
-               outputTypes["matrixout"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ClearcutCommand", "ClearcutCommand");
-               exit(1);
-       }
-}//**********************************************************************************************************************
-vector<string> ClearcutCommand::getRequiredParameters(){       
+string ClearcutCommand::getHelpString(){       
        try {
-               string Array[] =  {"fasta","phylip","or"};
-               vector<string> 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<string> ClearcutCommand::getRequiredFiles(){    
+ClearcutCommand::ClearcutCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
index ea6e279b88ca0f6d59312936b2c1652ff5b1a9b6..af456566b241a5592b710c01d7d0486090c80705 100644 (file)
@@ -26,20 +26,22 @@ class ClearcutCommand : public Command {
 public:
        ClearcutCommand(string);
        ClearcutCommand();
-       ~ClearcutCommand() {};
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       ~ClearcutCommand() {}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
+       
 };
 
 /****************************************************************************/
index 7f6e97ed68ebc0d44b1894fe462c5330fd73de3b..0048dc6053d0bab06130eeaa6ab5d10b576aeb48 100644 (file)
@@ -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; }
index 9a896f28df1a51d29978914e6922ce924b083e86..110c0408e5107e9acebd322c7a1070f364c13a7d 100644 (file)
@@ -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<string, int> seq2Bin;
        string method;
        
        MothurOut* m;
-       GlobalData* globaldata;
 };
 
 #endif
index 391b20a9de857755854401f96869c774508bd0af..9b0fcfd928cb5db6a6df12fb77a0583cc64cc4fb 100644 (file)
@@ -8,53 +8,62 @@
  */
 
 #include "clustercommand.h"
+#include "readphylip.h"
+#include "readcolumn.h"
+#include "readmatrix.hpp"
 
 //**********************************************************************************************************************
-vector<string> ClusterCommand::getValidParameters(){   
+vector<string> ClusterCommand::setParameters(){        
        try {
-               string AlignArray[] =  {"cutoff","precision","method","showabund","timing","hard","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> ClusterCommand::getRequiredParameters(){        
-       try {
-               vector<string> myArray; 
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ClusterCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ClusterCommand::getRequiredFiles(){     
+ClusterCommand::ClusterCommand(){      
        try {
-               string Array[] =  {"phylip","column","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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();
index 787f835a0f33d1d157aeab41568286c28a752520..368760ac9465c231674b84de2ffffa5b714382f2 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 };
 
 #endif
index 5bcfe03416f90700a02a4ff3d58ad312f788bb96..a9d3214b1d7ffb793d8a7813a55f26b7824795a0 100644 (file)
 #include "clusterclassic.h"
 
 //**********************************************************************************************************************
-vector<string> ClusterDoturCommand::getValidParameters(){      
+vector<string> ClusterDoturCommand::setParameters(){   
        try {
-               string AlignArray[] =  {"phylip","name","hard","cutoff","precision","method","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> ClusterDoturCommand::getRequiredParameters(){   
-       try {
-               string Array[] =  {"phylip"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ClusterDoturCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ClusterDoturCommand::getRequiredFiles(){        
+ClusterDoturCommand::ClusterDoturCommand(){    
        try {
-               vector<string> myArray; 
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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; }
index da2f4a7c000bb8b2ed0737c2b57dcc5d2569ccae..5358488c549ca911f9015a6e3f6caba81b9b4286 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~ClusterDoturCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 };
 
 #endif
index be78e76d75e15ace53867afb13bece32969c76ad..baea496ccb8b2b95aac764028493be1e51a302d1 100644 (file)
@@ -26,50 +26,57 @@ inline bool comparePriority(seqRNode first, seqRNode second) {
        return better; 
 }
 //**********************************************************************************************************************
-vector<string> ClusterFragmentsCommand::getValidParameters(){  
+vector<string> ClusterFragmentsCommand::setParameters(){       
        try {
-               string AlignArray[] =  {"fasta","name","diffs","percent","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> ClusterFragmentsCommand::getRequiredParameters(){       
-       try {
-               string Array[] =  {"fasta"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ClusterFragmentsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ClusterFragmentsCommand::getRequiredFiles(){    
+ClusterFragmentsCommand::ClusterFragmentsCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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 {
index 01f38e45ff55518238894a79503928759124679c..882ab332f1cf8f2dae29ce3436373ebeca4c5b4a 100644 (file)
@@ -32,13 +32,15 @@ class ClusterFragmentsCommand : public Command {
 public:
        ClusterFragmentsCommand(string);
        ClusterFragmentsCommand();
-       ~ClusterFragmentsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~ClusterFragmentsCommand() {}
+       
+       vector<string> 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<string, int> sizes;  //this map a seq name to the number of identical seqs in the names file
        map<string, int>::iterator itSize; 
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
        int readFASTA();
        void readNameFile();
index f9d38227f2d59709235bfe69f87385067317b1ab..6d908c61c94eb0917730479cf76a7f34cc102d15 100644 (file)
 
 
 //**********************************************************************************************************************
-vector<string> ClusterSplitCommand::getValidParameters(){      
+vector<string> ClusterSplitCommand::setParameters(){   
        try {
-               string AlignArray[] =  {"fasta","phylip","column","name","cutoff","precision","method","splitmethod","taxonomy","taxlevel","large","showabund","timing","hard","processors","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> ClusterSplitCommand::getValidParameters(){
 ClusterSplitCommand::ClusterSplitCommand(){    
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> tempOutNames;
                outputTypes["list"] = tempOutNames;
                outputTypes["rabund"] = tempOutNames;
@@ -44,33 +97,9 @@ ClusterSplitCommand::ClusterSplitCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> ClusterSplitCommand::getRequiredParameters(){   
-       try {
-               string Array[] =  {"fasta","phylip","column","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ClusterSplitCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ClusterSplitCommand::getRequiredFiles(){        
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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<string> ClusterSplitCommand::cluster(vector< map<string, string> > 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
index 9bce0995ee9cc9d7f212df0296335487502a3fd9..28c7d237dccb8ce31542c76f01378b0f8e053d71 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~ClusterSplitCommand() {}
        
+       vector<string> 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<int> processIDS;   //processid
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
-
+       
        string method, fileroot, tag, outputDir, phylipfile, columnfile, namefile, distfile, format, showabund, timing, splitmethod, taxFile, fastafile;
        double cutoff, splitcutoff;
        int precision, length, processors, taxLevelCutoff;
index ec5366b627d8e8f776ffd00c0bb63f98a748f4bc..8db4a28c5d33661741916e0d7560be470fd97ab2 100644 (file)
@@ -70,17 +70,15 @@ int Collect::getCurve(float percentFreq = 0.01){
 /***********************************************************************/
 int Collect::getSharedCurve(float percentFreq = 0.01){
 try {
-                               globaldata = GlobalData::getInstance();
                 vector<SharedRAbundVector*> lookup; 
                                vector<SharedRAbundVector*> 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++;
                }
index 79f88fb6dc4ea12a886107743fe7fd8a65a539d5..51712331401747192b62a9198ca6fa3cda8f4cef 100644 (file)
--- 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<Display*> displays;
        int numSeqs, numGroupComb, totalNumSeq;
index 4b59296fd645fa2947a31959f299d5628b8951cf..adaff9b1bc7b17d979b30106de2ee88c0d03631d 100644 (file)
 #include "shen.h"
 #include "coverage.h"
 
+
 //**********************************************************************************************************************
-vector<string> CollectCommand::getValidParameters(){   
-       try {
-               string AlignArray[] =  {"freq","label","calc","abund","size","outputdir","inputdir"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "CollectCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> CollectCommand::getRequiredParameters(){        
+vector<string> 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<string> 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<string> CollectCommand::getRequiredFiles(){     
+string CollectCommand::getHelpString(){        
        try {
-               string AlignArray[] =  {"shared","list","rabund","sabund","or"};
-               vector<string> 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<string> CollectCommand::getRequiredFiles(){
 CollectCommand::CollectCommand(){      
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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<string> processedLabels;
@@ -354,12 +407,10 @@ int CollectCommand::execute(){
                        if (m->control_pressed) {  
                                for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
                                for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
-                               delete input;  globaldata->ginput = 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;i<cDisplays.size();i++){    delete cDisplays[i];    }
                                        for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
-                                       delete input;  globaldata->ginput = 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;i<cDisplays.size();i++){    delete cDisplays[i];    }
                                        for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
-                                       delete input;  globaldata->ginput = 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;i<cDisplays.size();i++){    delete cDisplays[i];    }
                                        for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
-                                       delete input;  globaldata->ginput = 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;i<cDisplays.size();i++){    delete cDisplays[i];    }
                        cDisplays.clear();
-                       delete input;  globaldata->ginput = 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<string> CollectCommand::parseSharedFile(string filename) {
                
                map<string, ofstream*> filehandles;
                map<string, ofstream*>::iterator it3;
-               
-                               
-               //read first line
-               read = new ReadOTUFile(filename);       
-               read->read(&*globaldata); 
-                       
-               input = globaldata->ginput;
+                                       
+               input = new InputData(filename, "sharedfile");
                vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
                
                string sharedFileRoot = m->getRootName(filename);
@@ -542,9 +577,8 @@ vector<string> CollectCommand::parseSharedFile(string filename) {
                for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
                        delete it3->second;
                }
-               delete read;
+               
                delete input;
-               globaldata->ginput = NULL;
 
                return filenames;
        }
index 20c863b81dfd79fad597cd6e1e83571256873969..1884d04fb2719f088fa5b54475b4c70534f114e1 100644 (file)
 #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). 
        The label parameter is used to analyze specific labels in your input. */
 
 
-
-class GlobalData;
-
 class CollectCommand : public Command {
        
 public:
        CollectCommand(string); 
        CollectCommand();
-       ~CollectCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~CollectCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string label, calc, outputDir;
+       string label, calc, outputDir, sharedfile, listfile, rabundfile, sabundfile, format, inputfile;
        vector<string>  Estimators;
        vector<string> inputFileNames;
        vector<string> groups;
index 21695e328c90590572a9efebc7caf562c2525c75..0fe4d0f239fad770e83b68cee3f68eb9630aa368 100644 (file)
 #include "memeuclidean.h"
 #include "mempearson.h"
 
+
 //**********************************************************************************************************************
-vector<string> CollectSharedCommand::getValidParameters(){     
-       try {
-               string AlignArray[] =  {"freq","label","calc","groups","all","outputdir","inputdir"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "CollectSharedCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> CollectSharedCommand::getRequiredParameters(){  
+vector<string> 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<string> 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<string> CollectSharedCommand::getRequiredFiles(){       
+string CollectSharedCommand::getHelpString(){  
        try {
-               string AlignArray[] =  {"shared"};
-               vector<string> 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<string> CollectSharedCommand::getRequiredFiles(){
 CollectSharedCommand::CollectSharedCommand(){  
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters=parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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; i<Estimators.size(); i++) {
-                                       if (validCalculator->isValidCalculator("shared", Estimators[i]) == true) { 
+                               for (int i=0; i<Estimators.size(); i++) {
+                                       if (validCalculator.isValidCalculator("shared", Estimators[i]) == true) { 
                                                if (Estimators[i] == "sharedchao") { 
                                                        cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
                                                        outputNames.push_back(fileNameRoot+"shared.chao"); outputTypes["sharedchao"].push_back(fileNameRoot+"shared.chao");
@@ -396,43 +412,7 @@ CollectSharedCommand::CollectSharedCommand(string option)  {
        }
 }
 //**********************************************************************************************************************
-
-void CollectSharedCommand::help(){
-       try {
-               m->mothurOut("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;i<cDisplays.size();i++){    cDisplays[i]->setAll(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<string> 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;i<cDisplays.size();i++){    delete cDisplays[i];    }
-                                       delete order; 
-                                       globaldata->Groups.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;i<cDisplays.size();i++){    delete cDisplays[i];    }
-                                       globaldata->Groups.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;i<cDisplays.size();i++){    delete cDisplays[i];    }
                                delete order; 
-                               globaldata->Groups.clear();
+                               delete input;
+                               m->Groups.clear();
                                return 0;
                        }
 
@@ -552,7 +532,8 @@ int CollectSharedCommand::execute(){
                for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
                
                //reset groups parameter
-               globaldata->Groups.clear(); 
+               m->Groups.clear(); 
+               delete input;
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
index 327ce5d28832dbe7f25d69f6c0755f6e931c747d..d7f2f8f3d946208cee976595bf6d8113811e7094 100644 (file)
 
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       
+       vector<string> 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<Display*> cDisplays;
        float freq;
-       string format;
 
        bool abort, allLines, all;
        set<string> labels; //holds labels to be used
-       string label, calc, groups, outputDir;
+       string label, calc, groups, outputDir, sharedfile;
        vector<string>  Estimators, Groups, outputNames;
-       map<string, vector<string> > outputTypes;
-
-
 };
 
 #endif
index 93669ba7babe40f9b5889e953bf943d362cd7bbe..fd80ad1e9fc786fece31e00525476c453c6c2344 100644 (file)
 #include "optionparser.h"
 #include "validparameter.h"
 #include "mothurout.h"
+#include "commandparameter.h"
 
 
 class Command {
        
        public:
                Command() {  m = MothurOut::getInstance();   } 
-               virtual vector<string> getValidParameters() = 0;
-               virtual vector<string> getRequiredParameters() = 0; //adding "or" as the last element indicates one of the previous is needed
-               virtual vector<string> getRequiredFiles() = 0; //adding "or" as the last element indicates one of the previous is needed
-               virtual map<string, vector<string> > getOutputFiles() = 0; //file type to names
+               
+               //needed by gui
+               virtual string getCommandName() = 0;
+               virtual string getCommandCategory() = 0;
+               virtual string getHelpString() = 0;
+               
+               virtual map<string, vector<string> > getOutputFiles() { return outputTypes; }
+               virtual vector<string> setParameters() = 0; //to fill parameters
+               virtual vector<CommandParameter> getParameters() { return parameters; }
+       
                virtual int execute() = 0;
                virtual void help() = 0;
                virtual ~Command() { }
+       
        protected:
                MothurOut* m;
                bool calledHelp;
+                       
+               map<string, vector<string> > outputTypes;
+               vector<CommandParameter> parameters;
        
                map<string, vector<string> >::iterator itTypes;
 };
index e18e6ac1956e3f21f990d6c5b1c45be42dafebf9..a04ee160bb92870aa05865fc25e7504f8a689596 100644 (file)
@@ -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"
 #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;
index df216da738e7ba6dd92ec0817c6353b0b1723870..c5e000be7542716f46e24cbd20d2a81c0184e9a6 100644 (file)
@@ -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
index d64dc93c6b2c9e5812a24b02d19eaac8cc7ff742..75c6a3c6755badbcf1d4fba294a8811b24edbafc 100644 (file)
 #include "consensuscommand.h"
 
 //**********************************************************************************************************************
-vector<string> ConcensusCommand::getValidParameters(){ 
+vector<string> ConcensusCommand::setParameters(){      
        try {
-               vector<string> myArray; 
+               vector<string> 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<string> ConcensusCommand::getRequiredParameters(){      
+string ConcensusCommand::getHelpString(){      
        try {
-               vector<string> 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<string> ConcensusCommand::getRequiredFiles(){   
-       try {
-               string AlignArray[] =  {"tree","group"};
-               vector<string> 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<string> ConcensusCommand::getRequiredFiles(){
 ConcensusCommand::ConcensusCommand(){  
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> 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<string> 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) {
index d5072da082cd020d1836e39c06228fa4689eafbe..6bd5d3e0edffe82be92d116fcacfe1c0c94a3173 100644 (file)
 #include "tree.h"
 #include "treemap.h"
 #include "sharedutilities.h"
-       
-class GlobalData;
 
 class ConcensusCommand : public Command {
        
 public:
        ConcensusCommand(string);       
        ConcensusCommand();
-       ~ConcensusCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       ~ConcensusCommand() {}
+       
+       vector<string> setParameters();
+       string getCommandName()                 { return "concensus";   }
+       string getCommandCategory()             { return "Hidden";              }
+       string getHelpString(); 
+       
+       int execute(); 
+       void help() { m->mothurOut(getHelpString()); }  
+       
        
 private:
-       GlobalData* globaldata;
        SharedUtil* util;
        vector<Tree*> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
                                                                                
        int getSets();
        int getSubgroupRating(vector<string>);
index 482bac5dd40a62b58cb6b0eace303baab1fdeddb..bc47d8cca678ff9c8764651119ff255404a4ef65 100644 (file)
 #include "inputdata.h"
 
 //**********************************************************************************************************************
-vector<string> ConsensusSeqsCommand::getValidParameters(){     
+vector<string> ConsensusSeqsCommand::setParameters(){  
        try {
-               string Array[] =  {"fasta", "list", "name", "label","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> ConsensusSeqsCommand::getRequiredParameters(){  
+string ConsensusSeqsCommand::getHelpString(){  
        try {
-               string Array[] =  {"fasta", "list"};
-               vector<string> 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<string> ConsensusSeqsCommand::getRequiredFiles(){       
+ConsensusSeqsCommand::ConsensusSeqsCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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(){
index 555b62c63f263526917a388a6e03b62359cc1db3..07a4c0816020ee0c9678f81dbdafe108c0f0f92d 100644 (file)
@@ -18,13 +18,15 @@ class ConsensusSeqsCommand : public Command {
 public:
        ConsensusSeqsCommand(string);
        ConsensusSeqsCommand();
-       ~ConsensusSeqsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ConsensusSeqsCommand(){}
+       
+       vector<string> 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<string> labels;
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
        map<string, string> fastaMap;
        map<string, string> nameMap;
        map<string, string> nameFileMap;
index ae6ee3a92207f0ee9fe594b5208479452ed6b643..82cfa3683cbd0801da4a9805a567c84f67d3c427 100644 (file)
 #include "sharedutilities.h"
 
 //**********************************************************************************************************************
-vector<string> CorrAxesCommand::getValidParameters(){  
+vector<string> CorrAxesCommand::setParameters(){       
        try {
-               string Array[] =  {"axes","shared","relabund","numaxes","label","groups","method","metadata","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> CorrAxesCommand::getRequiredParameters(){       
+string CorrAxesCommand::getHelpString(){       
        try {
-               string Array[] =  {"axes"};
-               vector<string> 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<string> CorrAxesCommand::getRequiredParameters(){
 CorrAxesCommand::CorrAxesCommand(){    
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> tempOutNames;
                outputTypes["corr.axes"] = tempOutNames;
        }
@@ -46,31 +67,16 @@ CorrAxesCommand::CorrAxesCommand(){
                exit(1);
        }
 }
-
-//**********************************************************************************************************************
-vector<string> CorrAxesCommand::getRequiredFiles(){    
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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--; 
index bbe87abcbd1eeccb677a4e59c58ce64cb961944c..5f04c6a754393bda843abdf057e0f47763fd21cf 100644 (file)
@@ -19,25 +19,23 @@ class CorrAxesCommand : public Command {
 public:
        CorrAxesCommand(string);
        CorrAxesCommand();
-       ~CorrAxesCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
-       
-private:
+       ~CorrAxesCommand(){}
        
+       vector<string> 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<string> names;
        
        vector<string> outputNames, Groups;
-       map<string, vector<string> > outputTypes;
        vector<SharedRAbundFloatVector*> lookupFloat;
        vector<string> metadataLabels;
        
index 3ecd407bb35af63aa4a88f31722c469c219bc0a2..734ace57988f31c3f9bd911999fdc30940ecccd6 100644 (file)
@@ -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;         }
index 8d90a78a492e63ee97ede0b577e37fde39336fb4..9894adbda2aab2f4ddac2b786c69bffc8778335f 100644 (file)
@@ -952,7 +952,7 @@ map<int, int> DeCalculator::trimSeqs(Sequence* query, vector<Sequence*> topMatch
                map<int, int> 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++) {
index 62daa612d52a04fa72b85c1c621b89b539d14ab0..33e51ffdff96a570d2a91d85590b3a2111ddcf63 100644 (file)
 #include "deconvolutecommand.h"
 
 //**********************************************************************************************************************
-vector<string> DeconvoluteCommand::getValidParameters(){       
+vector<string> DeconvoluteCommand::setParameters(){    
        try {
-               string Array[] =  {"fasta", "name","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> DeconvoluteCommand::getRequiredParameters(){    
-       try {
-               string Array[] =  {"fasta"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "DeconvoluteCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> DeconvoluteCommand::getRequiredFiles(){ 
+DeconvoluteCommand::DeconvoluteCommand(){      
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
index 88b7a382d4c175a14c243d21e97a7580cba9c32d..8a1cb87cb87f62b9c5dc1a0c4073d13675fe105e 100644 (file)
@@ -22,17 +22,19 @@ public:
        DeconvoluteCommand(string);
        DeconvoluteCommand();
        ~DeconvoluteCommand() {}
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 
        bool abort;
 };
index 7fd2803a4ec6c5e578d7b180a9e08fda1af33385..81002c8385e78610794e2faa5f0241d67befbab7 100644 (file)
 #include "sequence.hpp"
 
 //**********************************************************************************************************************
-vector<string> DegapSeqsCommand::getValidParameters(){ 
+vector<string> DegapSeqsCommand::setParameters(){      
        try {
-               string Array[] =  {"fasta", "outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> DegapSeqsCommand::getRequiredParameters(){      
-       try {
-               string Array[] =  {"fasta"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "DegapSeqsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> DegapSeqsCommand::getRequiredFiles(){   
+DegapSeqsCommand::DegapSeqsCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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{
                
index 5501d49b6affcdfe7e24fb8b444f837800d08ff5..db93b02a299aae60666b1993469f7e00cdc31a58 100644 (file)
@@ -17,13 +17,15 @@ class DegapSeqsCommand : public Command {
 public:
        DegapSeqsCommand(string);
        DegapSeqsCommand();
-       ~DegapSeqsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~DegapSeqsCommand(){}
+       
+       vector<string> 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<string> outputNames;
        vector<string> fastaFileNames;
-       map<string, vector<string> > outputTypes;
+       
 };
 
 #endif
index 1d87204abd165396a20f99cbef0e3440eadbcd95..fb02764e93cc8ca2494773aebeccab857e58f378 100644 (file)
 #include "sequence.hpp"
 
 //**********************************************************************************************************************
-vector<string> DeUniqueSeqsCommand::getValidParameters(){      
+vector<string> DeUniqueSeqsCommand::setParameters(){   
        try {
-               string Array[] =  {"fasta", "name","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> DeUniqueSeqsCommand::getRequiredParameters(){   
-       try {
-               string Array[] =  {"fasta","name"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "DeUniqueSeqsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> DeUniqueSeqsCommand::getRequiredFiles(){        
+DeUniqueSeqsCommand::DeUniqueSeqsCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
index 13176a80a413a1bce9d84bb4cf496702a554c446..96ed29bd6aaa0f5a717d5164aa7a5a3e538dbaaf 100644 (file)
@@ -19,18 +19,20 @@ public:
        DeUniqueSeqsCommand(string);
        DeUniqueSeqsCommand();
        ~DeUniqueSeqsCommand() {}
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        bool abort;
        
        map<string, string> nameMap;
index 5ffe0da63cfbbafd80ab1813a66b3cdb9779725b..029b581f5d1f8590f16f075a79cde658055c518a 100644 (file)
 #include "onegapdist.h"
 #include "onegapignore.h"
 
-
 //**********************************************************************************************************************
-vector<string> DistanceCommand::getValidParameters(){  
+vector<string> DistanceCommand::setParameters(){       
        try {
-               string Array[] =  {"fasta","oldfasta","column", "output", "calc", "countends", "cutoff", "processors", "outputdir","inputdir","compress"};
-               vector<string> 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<string> 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<string> 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<string> DistanceCommand::getRequiredParameters(){       
-       try {
-               string Array[] =  {"fasta"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "DistanceCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> DistanceCommand::getRequiredFiles(){    
+DistanceCommand::DistanceCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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(){
index 595483d2b3e84aef55478a78bd84906771949e5d..23cc6a580a16756d5b30420cb825b5d43d21ae83 100644 (file)
@@ -22,13 +22,16 @@ class DistanceCommand : public Command {
 public:
        DistanceCommand(string);
        DistanceCommand();
-       ~DistanceCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~DistanceCommand() {}
+       
+       vector<string> 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<string>  Estimators, outputNames; //holds estimators to be used
-       map<string, vector<string> > outputTypes;
        
        //void m->appendFiles(string, string);
        void createProcesses(string);
index 54197174e1fa3da14861614734b1dc58314a466a..dbdcc36300f2fd5d3f5ea6135dbc8666f328bba0 100644 (file)
@@ -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) {
index d5846ba65fc287a6b7de3e7f5f6cfaa57a7f5951..5311da9e1e3aafb3c447b2e51ec411cb29c79d14 100644 (file)
 
 
 #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&);
 
index cb0b131f58e039f5eea76b784334715e1e7481e3..02bc192f370acbba19d14e7c6f45b9f2fd46f662 100644 (file)
 #include "filterseqscommand.h"
 #include "sequence.hpp"
 
+
 //**********************************************************************************************************************
-vector<string> FilterSeqsCommand::getValidParameters(){        
+vector<string> FilterSeqsCommand::setParameters(){     
        try {
-               string Array[] =  {"fasta", "trump", "soft", "hard", "vertical", "outputdir","inputdir", "processors"};
-               vector<string> 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<string> 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<string> 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<string> FilterSeqsCommand::getRequiredParameters(){     
-       try {
-               string Array[] =  {"fasta"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "FilterSeqsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> FilterSeqsCommand::getRequiredFiles(){  
+FilterSeqsCommand::FilterSeqsCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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() {     
index c670f37919e7da8ce3e3f3ee5d294cd4d23acd94..75e7895c6ef2d4a532dfae9d37ea4fc035243b75 100644 (file)
@@ -20,12 +20,14 @@ public:
        FilterSeqsCommand(string);\r
        FilterSeqsCommand();\r
        ~FilterSeqsCommand() {};\r
-       vector<string> getRequiredParameters();\r
-       vector<string> getValidParameters();\r
-       vector<string> getRequiredFiles();\r
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }\r
-       int execute();  \r
-       void help();\r
+       \r
+       vector<string> setParameters();\r
+       string getCommandName()                 { return "filter.seqs";                 }\r
+       string getCommandCategory()             { return "Sequence Processing"; }\r
+       string getHelpString(); \r
+       \r
+       int execute(); \r
+       void help() { m->mothurOut(getHelpString()); }  \r
        \r
 private:\r
        struct linePair {\r
@@ -42,7 +44,6 @@ private:
        int alignmentLength, processors;\r
        vector<int> bufferSizes;\r
        vector<string> outputNames;\r
-       map<string, vector<string> > outputTypes;\r
 \r
        char trump;\r
        bool abort;\r
index fe61307552b67bdc4567d00025e1a1401a9e70f3..4451d6645ea8691b941ebbc991f82cc4ce8b4706 100644 (file)
 
 /**************************************************************************/
 //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<numSeqs;i++){
                                        filehandle >> 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;
                                
index e2c0e31b5fa8e4ed81ced8ba88b61fc4620adbf3..9de7ead566d4d5446b5ea405b5e3c7eb24991cc0 100644 (file)
@@ -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;
 };
 
index bd7539a25a30a2c972dfa9157a1b25ceb3349c33..7bfae208ad9eb6b1a94ba92e2ae028c2f986f24a 100644 (file)
@@ -9,48 +9,46 @@
 
 #include "getcurrentcommand.h"
 
-
 //**********************************************************************************************************************
-vector<string> GetCurrentCommand::getValidParameters(){        
+vector<string> GetCurrentCommand::setParameters(){     
        try {
-               string Array[] =  {"outputdir","inputdir","clear"};
-               vector<string> 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<string> 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<string> GetCurrentCommand::getRequiredParameters(){     
+GetCurrentCommand::GetCurrentCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
        }
        catch(exception& e) {
-               m->errorOut(e, "GetCurrentCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> GetCurrentCommand::getRequiredFiles(){  
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index c36b6a599885aa81c127f1b0fff1626f7b8313c1..aa4f8f4f4e488fdb87474b0ceebd52ac25cd4f98 100644 (file)
@@ -17,18 +17,20 @@ class GetCurrentCommand : public Command {
        public:
                GetCurrentCommand(string);
                GetCurrentCommand();
-               ~GetCurrentCommand();
-               vector<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();
-               
+               ~GetCurrentCommand() {}
+       
+               vector<string> setParameters();
+               string getCommandName()                 { return "get.current"; }
+               string getCommandCategory()             { return "General";             }
+               string getHelpString(); 
+       
+               int execute(); 
+               void help() { m->mothurOut(getHelpString()); }  
+       
+       
        private:
                
                vector<string> outputNames;
-               map<string, vector<string> > outputTypes;
                bool abort;
        
                string clearTypes;
index ab3ccfa36f3f2d4e6a7e1f5af6a38434640f3105..ce3cf73d28e455fd3b111f3a10b7e74ba7f67186 100644 (file)
 #include "getgroupcommand.h"
 
 //**********************************************************************************************************************
-vector<string> GetgroupCommand::getValidParameters(){  
+vector<string> GetgroupCommand::setParameters(){       
        try {
-               string Array[] =  {"outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["bootgroup"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetgroupCommand", "GetgroupCommand");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> GetgroupCommand::getRequiredParameters(){       
-       try {
-               vector<string> 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<string> GetgroupCommand::getRequiredFiles(){    
+GetgroupCommand::GetgroupCommand(){    
        try {
-               string Array[] =  {"shared"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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;
index fb3e810666320ea2cd1c32d4b14b0c2cac08c995..79dd8057216ec17fcd706d5a6a480c461161a458 100644 (file)
  */
 
 #include "command.hpp"
-#include "globaldata.hpp"
 
 class GetgroupCommand : public Command {
 public:
        GetgroupCommand(string);
        GetgroupCommand();
-       ~GetgroupCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~GetgroupCommand() {}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        ofstream out;
        ifstream in;
        bool abort;
index 84b168a4c75164b339b7ed2b6f350d13021da5e4..aae74888accfc68b6226983b8025d1d05cca50ea 100644 (file)
 #include "sharedutilities.h"
 
 //**********************************************************************************************************************
-vector<string> GetGroupsCommand::getValidParameters(){ 
+vector<string> GetGroupsCommand::setParameters(){      
        try {
-               string Array[] =  {"fasta","name", "group", "accnos", "groups","list","taxonomy","outputdir","inputdir" };
-               vector<string> 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<string> 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<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["taxonomy"] = tempOutNames;
@@ -41,29 +72,6 @@ GetGroupsCommand::GetGroupsCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> GetGroupsCommand::getRequiredParameters(){      
-       try {
-               string Array[] =  {"group"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetGroupsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> GetGroupsCommand::getRequiredFiles(){   
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index 7c4c92fff02ae6f577ca92a736fb7b14711cb302..955de627ccb6f4952c6ed3a1444ee2b4d5397187 100644 (file)
@@ -21,19 +21,21 @@ public:
        GetGroupsCommand(string);       
        GetGroupsCommand();
        ~GetGroupsCommand(){}
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       
+       vector<string> setParameters();
+       string getCommandName()                 { return "get.groups";                          }
+       string getCommandCategory()             { return "OTU-Based Approaches";        }
+       string getHelpString(); 
+       
+       int execute(); 
+       void help() { m->mothurOut(getHelpString()); }  
+       
        
 private:
        set<string> names;
        string accnosfile, fastafile, namefile, groupfile, listfile, taxfile, outputDir, groups;
        bool abort;
        vector<string> outputNames, Groups;
-       map<string, vector<string> > outputTypes;
        GroupMap* groupMap;
        
        int readFasta();
index 3191d5dda80670b8490203032e35170cf7642044..236eef24acfdb4c0b82d2802abe63562db53ef4a 100644 (file)
@@ -9,38 +9,49 @@
 
 #include "getlabelcommand.h"
 
+
 //**********************************************************************************************************************
-vector<string> GetlabelCommand::getValidParameters(){  
+vector<string> GetlabelCommand::setParameters(){       
        try {
-               string Array[] =  {"outputdir","inputdir"};
-               vector<string> 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<string> 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<string> GetlabelCommand::getRequiredParameters(){       
+GetlabelCommand::GetlabelCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
        }
        catch(exception& e) {
-               m->errorOut(e, "GetlabelCommand", "getRequiredParameters");
+               m->errorOut(e, "GetlabelCommand", "CollectCommand");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> GetlabelCommand::getRequiredFiles(){    
+string GetlabelCommand::getHelpString(){       
        try {
-               string Array[] =  {"list","rabund","sabund", "or"};
-               vector<string> 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<string> 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<string> myArray = setParameters();
+                       
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       map<string,string>::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);
        }
 }
+//**********************************************************************************************************************
+
 
index 00945e1b362e6e19cf705cf77ee16a15e5a3ccf0..3aaa92d515948f9d927f3ff377629f3e376ff62e 100644 (file)
  */
 
 #include "command.hpp"
-#include "readmatrix.hpp"
+#include "ordervector.hpp"
+#include "inputdata.h"
 
-class GlobalData;
 
 class GetlabelCommand : public Command {
 public:
        GetlabelCommand(string);
-       GetlabelCommand(){}
-       ~GetlabelCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       GetlabelCommand();
+       ~GetlabelCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 };
 
 #endif
index 7950680c7e394ebbcf88f8108c4f7eb72029b3cd..5e35449dabd0d6c485780c3847f7971084c86f1c 100644 (file)
 #include "sequence.hpp"
 #include "listvector.hpp"
 
-
 //**********************************************************************************************************************
-vector<string> GetLineageCommand::getValidParameters(){        
+vector<string> GetLineageCommand::setParameters(){     
        try {
-               string Array[] =  {"fasta","name", "group", "alignreport", "taxon", "dups", "list","taxonomy","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["taxonomy"] = tempOutNames;
@@ -42,29 +77,6 @@ GetLineageCommand::GetLineageCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> GetLineageCommand::getRequiredParameters(){     
-       try {
-               string Array[] =  {"taxonomy","taxon"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetLineageCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> GetLineageCommand::getRequiredFiles(){  
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index 5b7c43ed65808f7038b3c46cb96f3b7a32b8849a..6375b9483fb335bafde123f3e99e4620c2614234 100644 (file)
@@ -18,20 +18,22 @@ class GetLineageCommand : public Command {
        
                GetLineageCommand(string);
                GetLineageCommand();
-               ~GetLineageCommand(){};
-               vector<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();    
-               
+               ~GetLineageCommand(){}
+       
+               vector<string> setParameters();
+               string getCommandName()                 { return "get.lineage";                         }
+               string getCommandCategory()             { return "Phylotype Analysis";          }
+               string getHelpString(); 
+       
+               int execute(); 
+               void help() { m->mothurOut(getHelpString()); }  
+       
+       
        private:
                set<string> names;
                vector<string> outputNames;
                string fastafile, namefile, groupfile, alignfile, listfile, taxfile, outputDir, taxons;
                bool abort, dups;
-               map<string, vector<string> > outputTypes;
                
                int readFasta();
                int readName();
index 78f26047e0debdf3e620b2e0179bfab12fe93354..404d35379730d3e3859a87654e795739f3f9b5cf 100644 (file)
 #include "getlistcountcommand.h"
 
 //**********************************************************************************************************************
-vector<string> GetListCountCommand::getValidParameters(){      
+vector<string> GetListCountCommand::setParameters(){   
        try {
-               string Array[] =  {"list","label","sort","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["otu"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetListCountCommand", "GetListCountCommand");
+               m->errorOut(e, "GetListCountCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> GetListCountCommand::getRequiredParameters(){   
+string GetListCountCommand::getHelpString(){   
        try {
-               string Array[] =  {"list"};
-               vector<string> 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<string> GetListCountCommand::getRequiredFiles(){        
+GetListCountCommand::GetListCountCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
@@ -86,8 +87,6 @@ GetListCountCommand::GetListCountCommand(string option)  {
                        //initialize outputTypes
                        vector<string> 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<string> processedLabels;
                set<string> 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();
index 60d28cc6a351011fdc34af98189025af5d26f487..40ff7d0636f38158eea14fd7523618ab2e107188 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       ~GetListCountCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
-       
+               
        void process(ListVector*);
 };
 /**********************************************************/
index 78c39f7c1c16e5bce1c4d0475ad06839ebe0758b..0ab12ab81e21e64e53b876ce8b1be4d43bbd9399 100644 (file)
@@ -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<string> tempOutNames;
-               outputTypes["fasta"] = tempOutNames;
-               outputTypes["name"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetOTURepCommand", "GetOTURepCommand");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> GetOTURepCommand::getValidParameters(){ 
+vector<string> GetOTURepCommand::setParameters(){      
        try {
-               string Array[] =  {"fasta","list","label","name", "group", "weighted","sorted", "phylip","column","large","cutoff","precision","groups","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> GetOTURepCommand::getRequiredParameters(){      
+string GetOTURepCommand::getHelpString(){      
        try {
-               string Array[] =  {"fasta","list"};
-               vector<string> 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<string> GetOTURepCommand::getRequiredFiles(){   
+GetOTURepCommand::GetOTURepCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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<SeqMap>(globaldata->gListVector->size()); 
+                       seqVec = vector<SeqMap>(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<string> 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; }
                
index 7a17c9de22a4c08b8d44a6e59ea3c6f07f18430a..d8f8f0905ba3c3e8c09dfb8ec83ec34f817db89e 100644 (file)
  /* 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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
-
+       ~GetOTURepCommand(){}
+       
+       vector<string> 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<SeqMap> seqVec;                  // contains maps with sequence index and distance
                                                                        // for all distances related to a certain sequence
        vector<int> rowPositions;
-       map<string, vector<string> > outputTypes;
 
        void readNamesFile();
        void readNamesFile(bool);
@@ -80,8 +78,6 @@ private:
        SeqMap getMap(int);
        string findRep(vector<string>);         // returns the name of the "representative" sequence of given bin or subset of a bin, for groups
        int processNames(string, string);
-                                                                                               
-
 };
 
 #endif
index 15d2bcb8e46454809cdc4441574a469abfc6d6b2..4a79d3aca506815faa0828288c2b23150bf59c1c 100644 (file)
 
 
 //**********************************************************************************************************************
-vector<string> GetOtusCommand::getValidParameters(){   
+vector<string> GetOtusCommand::setParameters(){        
        try {
-               string Array[] =  { "group", "accnos","label", "groups","list","outputdir","inputdir" };
-               vector<string> 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<string> 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<string> 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<string> GetOtusCommand::getRequiredParameters(){        
-       try {
-               string Array[] =  {"group","label", "list"};
-               vector<string> 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<string> GetOtusCommand::getRequiredFiles(){     
+GetOtusCommand::GetOtusCommand(){      
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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<string> labels; labels.insert(label);
                set<string> processedLabels;
index ec69acb4c0381c6b2b5190abf1a88ae214751647..34562fe7cf8f426048e5f1e71d568039bef1a117 100644 (file)
@@ -23,18 +23,20 @@ public:
        GetOtusCommand(string); 
        GetOtusCommand();
        ~GetOtusCommand(){}
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       
+       vector<string> 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<string> outputNames, Groups;
-       map<string, vector<string> > outputTypes;
        GroupMap* groupMap;
        
        void readAccnos();
index 3b03f3694967d6d480ba0dc00153454c7e8b074f..570d64e34166cafcf734181a370dd9fc854e64a3 100644 (file)
 #include "getrabundcommand.h"
 
 //**********************************************************************************************************************
-vector<string> GetRAbundCommand::getValidParameters(){ 
+vector<string> GetRAbundCommand::setParameters(){      
        try {
-               string Array[] =  {"label","sorted","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["rabund"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetRAbundCommand", "GetRAbundCommand");
+               m->errorOut(e, "GetRAbundCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> GetRAbundCommand::getRequiredParameters(){      
+string GetRAbundCommand::getHelpString(){      
        try {
-               vector<string> 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<string> GetRAbundCommand::getRequiredFiles(){   
+GetRAbundCommand::GetRAbundCommand(){  
        try {
-               string Array[] =  {"list"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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<string> processedLabels;
                set<string> 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");
index e853ac5f913a1d758e7a633510478ad30449feec..dd0cefc89457cb114596c988c35b6be59c650547 100644 (file)
 
 #include "command.hpp"
 #include "inputdata.h"
-#include "readotu.h"
 #include "listvector.hpp"
 
-class GlobalData;
 
 class GetRAbundCommand : public Command {
 public:
        GetRAbundCommand(string);
        GetRAbundCommand();
-       ~GetRAbundCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~GetRAbundCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 
        bool abort, allLines, sorted;
        set<string> labels; //holds labels to be used
index e79ccc9a3b3c9ec4812dc219af6dbe0428d5ece9..6397e358de806f08695d0707c6539352a282be44 100644 (file)
 #include "getrelabundcommand.h"
 
 //**********************************************************************************************************************
-vector<string> GetRelAbundCommand::getValidParameters(){       
+vector<string> GetRelAbundCommand::setParameters(){    
        try {
-               string Array[] =  {"groups","label","scale","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["relabund"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetRelAbundCommand", "GetRelAbundCommand");
+               m->errorOut(e, "GetRelAbundCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> GetRelAbundCommand::getRequiredParameters(){    
+string GetRelAbundCommand::getHelpString(){    
        try {
-               vector<string> 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<string> GetRelAbundCommand::getRequiredFiles(){ 
+GetRelAbundCommand::GetRelAbundCommand(){      
        try {
-               string Array[] =  {"shared"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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<string>::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;}
index 90d5f9a2ceb9c3164640d8482e88599324557495..ab1896f5b3c470d393453da29297814d697ca825 100644 (file)
  
 #include "command.hpp"
 #include "inputdata.h"
-#include "readotu.h"
 #include "sharedrabundvector.h"
 
-class GlobalData;
 
 class GetRelAbundCommand : public Command {
 
 public:
        GetRelAbundCommand(string);
        GetRelAbundCommand();
-       ~GetRelAbundCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~GetRelAbundCommand(){}
+       
+       vector<string> 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<SharedRAbundVector*> lookup;
        
        bool abort, allLines, pickedGroups;
        set<string> labels; //holds labels to be used
-       string groups, label, outputDir, scale;
+       string groups, label, outputDir, scale, sharedfile;
        vector<string> Groups, outputNames;
-       map<string, vector<string> > outputTypes;
        
        int getRelAbundance(vector<SharedRAbundVector*>&, ofstream&);
 
index 0533af3604bd6361dadae6294efeb11f6c6c8fd2..98bdcb2cba6cb726f9d793baca1c78f785a04c00 100644 (file)
 #include "getsabundcommand.h"
 
 //**********************************************************************************************************************
-vector<string> GetSAbundCommand::getValidParameters(){ 
+vector<string> GetSAbundCommand::setParameters(){      
        try {
-               string Array[] =  {"label","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["sabund"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetSAbundCommand", "GetSAbundCommand");
+               m->errorOut(e, "GetSAbundCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> GetSAbundCommand::getRequiredParameters(){      
+string GetSAbundCommand::getHelpString(){      
        try {
-               vector<string> 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<string> GetSAbundCommand::getRequiredFiles(){   
+GetSAbundCommand::GetSAbundCommand(){  
        try {
-               string Array[] =  {"list","rabund"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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<string> processedLabels;
                set<string> 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();
index b5363e1bce548af4af74408593d855cac4da973c..d17574f57a8b33e3a0625ae056d604859736e036 100644 (file)
 
 #include "command.hpp"
 #include "inputdata.h"
-#include "readotu.h"
 #include "sabundvector.hpp"
 
-class GlobalData;
-
 class GetSAbundCommand : public Command {
 public:
        GetSAbundCommand(string);
        GetSAbundCommand();
-       ~GetSAbundCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~GetSAbundCommand() {}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 
        bool abort, allLines;
        set<string> labels; //holds labels to be used
index ce820fea0da0bfecc47db0126c9c5c70425c74e6..5db28888b8dbe0ac643779b1cdcbe6ae01a37389 100644 (file)
 #include "listvector.hpp"
 
 //**********************************************************************************************************************
-vector<string> GetSeqsCommand::getValidParameters(){   
+vector<string> GetSeqsCommand::setParameters(){        
        try {
-               string Array[] =  {"fasta","name", "group", "qfile","alignreport", "accnos", "accnos2","dups", "list","taxonomy","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["taxonomy"] = tempOutNames;
@@ -43,29 +75,6 @@ GetSeqsCommand::GetSeqsCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> GetSeqsCommand::getRequiredParameters(){        
-       try {
-               string Array[] =  {"accnos"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetSeqsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> GetSeqsCommand::getRequiredFiles(){     
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index aef789aa7dd80a656a66c3061a2e8cadd1fe081b..07d13d6703426e1990fab1a1bc9afdb82124c801 100644 (file)
@@ -18,20 +18,22 @@ class GetSeqsCommand : public Command {
        
                GetSeqsCommand(string);
                GetSeqsCommand();
-               ~GetSeqsCommand(){};
-               vector<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();    
-               
+               ~GetSeqsCommand(){}
+       
+               vector<string> setParameters();
+               string getCommandName()                 { return "get.seqs";                            }
+               string getCommandCategory()             { return "Sequence Processing";         }
+               string getHelpString(); 
+       
+               int execute(); 
+               void help() { m->mothurOut(getHelpString()); }  
+       
+       
        private:
                set<string> names;
                vector<string> outputNames;
                string accnosfile, accnosfile2, fastafile, namefile, groupfile, alignfile, listfile, taxfile, qualfile, outputDir;
                bool abort, dups;
-               map<string, vector<string> > outputTypes;
                
                int readFasta();
                int readName();
index 4fe711e568728f0fa1af026bec4c21af822732cd..f12b1cd19a4a6a1f5c0c61074d4dc22e68aac6dd 100644 (file)
@@ -9,53 +9,66 @@
 
 #include "getsharedotucommand.h"
 
-
 //**********************************************************************************************************************
-vector<string> GetSharedOTUCommand::getValidParameters(){      
+vector<string> GetSharedOTUCommand::setParameters(){   
        try {
-               string Array[] =  {"label","unique","shared","fasta","list","group","output","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> GetSharedOTUCommand::getRequiredParameters(){   
-       try {
-               string Array[] =  {"list","group"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "GetSharedOTUCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> GetSharedOTUCommand::getRequiredFiles(){        
+GetSharedOTUCommand::GetSharedOTUCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               vector<string> 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<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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;        }
                
index 0e25721b6ca2bcd53967261e7fab18bb0dbead54..27a57b0242a92c95f694a941b4e2c05ed465c384 100644 (file)
@@ -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<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();    
+               ~GetSharedOTUCommand() {}
+       
+               vector<string> 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<string> 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<string> Groups;
                map<string, string> groupFinder;
                map<string, string>::iterator it;
                vector<Sequence> seqs;
                vector<string> outputNames;
-               map<string, vector<string> > outputTypes;
                
                int process(ListVector*);
                
index b18324b8766f9d498295a6e630caaec1b5cc9595..a0b80ecbbf77ef9e8b95b90b558656148651f9fc 100644 (file)
@@ -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 {
index b5e8c7cfc7cb246b9fbf9ca24097b1f3d190366c..59bbac5dc3c0bf0a4d99d6e671b083f9ed2dd954 100644 (file)
@@ -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<string>  Estimators, Groups; //holds estimators to be used
-       set<string> labels; //holds labels to be used
+       NameAssignment* nameMap;
+       string argv; //inputFileName,
+       bool runParse, jumble, sim; //allLines, 
+       vector<string>  Estimators;//, Groups; //holds estimators to be used
+       //set<string> labels; //holds labels to be used
        vector<string> Treenames;
        map<string, string> 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
index 9e9955671e41a6cfff3dc882e29ccbc4de9414ca..58e04c5db858791f28a99a5cb50795a570da0690 100644 (file)
@@ -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;
 }
 
index 128dee379080ddf32704367789c916d3bce14f41..582fc45f3f4744caf50705e6a10482509fbd4afe 100644 (file)
 #include "hclustercommand.h"
 
 //**********************************************************************************************************************
-vector<string> HClusterCommand::getValidParameters(){  
+vector<string> HClusterCommand::setParameters(){       
        try {
-               string Array[] =  {"cutoff","hard","precision","method","phylip","column","name","sorted","showabund","timing","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> HClusterCommand::getRequiredParameters(){       
-       try {
-               string Array[] =  {"phylip","column","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "HClusterCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> HClusterCommand::getRequiredFiles(){    
+HClusterCommand::HClusterCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> 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<seqDist> seqs; seqs.resize(1); // to start loop
                
                if (m->control_pressed) {  
@@ -374,18 +377,7 @@ int HClusterCommand::execute(){
                else if(rndPreviousDist<cutoff){
                        printData(toString(rndPreviousDist, length-1));
                }
-               
-               //delete globaldata's copy of the sparsematrix and listvector to free up memory
-               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");
-               
+                               
                sabundFile.close();
                rabundFile.close();
                listFile.close();
index fc0333174a87b111a0cda756dc24ff4669202cc9..5fbdb3d1ab3bfe15a141c1d710ea6d84186a07db 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~HClusterCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
        void printData(string label);
 };
index 7d6eeaa146b84db4233974a70c16dc482bc12ef9..36665ff7c6402652e2bfa2039ab0023294e1f248 100644 (file)
@@ -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<SharedRAbundVector*> 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<SharedRAbundFloatVector*> 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
index c291a4ded677b6394aa5da9819a0140cda75a8c6..2b491767d57e48c4a05728aa6a48cbfc6939b38f 100644 (file)
--- 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;
index 19a320afa409e9e7be546b69c85f8c3c99e05fa6..10c15d8b1dd9daed1ad21dd40b7e712b829a3ba5 100644 (file)
 #include "heatmapcommand.h"
 
 //**********************************************************************************************************************
-vector<string> HeatMapCommand::getValidParameters(){   
+vector<string> HeatMapCommand::setParameters(){        
        try {
-               string Array[] =  {"groups","label","sorted","scale","fontsize","numotu","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> HeatMapCommand::getRequiredParameters(){        
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "HeatMapCommand", "getRequiredParameters");
+               m->errorOut(e, "HeatMapCommand", "getHelpString");
                exit(1);
        }
 }
+
 //**********************************************************************************************************************
-vector<string> HeatMapCommand::getRequiredFiles(){     
+HeatMapCommand::HeatMapCommand(){      
        try {
-               string Array[] =  {"list","sabund","rabund","shared","relabund","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["svg"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "HeatMapCommand", "getRequiredFiles");
+               m->errorOut(e, "HeatMapCommand", "HeatMapCommand");
                exit(1);
        }
 }
@@ -60,26 +78,23 @@ vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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;
        }
index a85d510074c55a73adc25b07f16a8a81bdd4a30c..6fb5ff073fb5dea3b2a7237c114142ec0f3b184b 100644 (file)
 
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~HeatMapCommand(){}
+       
+       vector<string> 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<SharedRAbundVector*> lookup;
        vector<SharedRAbundFloatVector*> lookupFloat;
@@ -45,9 +43,8 @@ private:
 
        bool abort, allLines;
        set<string> 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<string> Groups, outputNames;
-       map<string, vector<string> > outputTypes;
        int numOTU, fontSize;
 
 
index efe4140fcdc42aa287af5dbc51a0152fc87371f5..9c5e780703a7d4f8d9117e38dddb693a40337bb0 100644 (file)
@@ -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<string> HeatMapSim::getPic(vector<SharedRAbundVector*> lookup, vector<Cal
                
                        if (m->control_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<double> > dists, vector<string> groups)
                
                vector<double> 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<double> > dists, vector<string> groups)
                
                //white backround
                outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString((dists.size() * 150) + 160) + "\" height=\"" + toString((dists.size() * 150) + 160)  + "\"/>"; 
-               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((dists.size() * 75) - 40) + "\" y=\"25\">Heatmap for " + globaldata->inputFileName + "</text>\n";
+               outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString((dists.size() * 75) - 40) + "\" y=\"25\">Heatmap for " + inputfile + "</text>\n";
                
                //column labels
                for (int h = 0; h < groups.size(); h++) {
index bb78e42df9e124c01969449ace2d59e5fe0dd7f9..a28995df7edf1cfc234fcd0c22416164b3c6c347 100644 (file)
@@ -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<string> getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
@@ -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;
                        
index 28b0221ba8458cb1a760fade14426ea6a7123568..5a84391813b768b33ed55f3dbc50d612f01111f2 100644 (file)
 #include "sharedmorisitahorn.h"
 #include "sharedbraycurtis.h"
 
+
 //**********************************************************************************************************************
-vector<string> HeatMapSimCommand::getValidParameters(){        
+vector<string> HeatMapSimCommand::setParameters(){     
        try {
-               string Array[] =  {"groups","label", "calc","phylip","column","name","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["svg"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> HeatMapSimCommand::getRequiredParameters(){     
-       try {
-               vector<string> 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<string> HeatMapSimCommand::getRequiredFiles(){  
+HeatMapSimCommand::HeatMapSimCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["svg"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "HeatMapSimCommand", "getRequiredFiles");
+               m->errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand");
                exit(1);
        }
 }
@@ -69,20 +86,14 @@ vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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<string> processedLabels;
                set<string> 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<string>::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;
        }
index cd12c176f44994e4ea1da4128737dabe2931b6ac..2a2c3676b31610b32dcb4b3996dc7134aa6078ed 100644 (file)
 
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~HeatMapSimCommand(){}
+       
+       vector<string> 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<SharedRAbundVector*> lookup;
        vector<Calculator*> heatCalculators;
        ValidCalculators* validCalculator;
        HeatMapSim* heatmap;
        OptionParser* parser;
-       map<string, string> parameters;
-       map<string, string>::iterator it;
        bool abort, allLines;
        set<string> 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<string> Estimators, Groups, outputNames;
-       map<string, vector<string> > outputTypes;
        
        int runCommandShared();
        int runCommandDist();
index 3c799b0903afdc58c20a244356b3ecd8f51cf972..47d04f9d528ab14053f468f2eacc7e150db736c0 100644 (file)
@@ -9,54 +9,12 @@
 
 #include "helpcommand.h"
 
-//**********************************************************************************************************************
-vector<string> HelpCommand::getValidParameters(){      
-       try {
-               
-               vector<string> myArray; 
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "HelpCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> HelpCommand::getRequiredParameters(){   
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "HelpCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> HelpCommand::getRequiredFiles(){        
-       try {
-               vector<string> 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);
        }
 }
-
 //**********************************************************************************************************************/
index d4e7b1fda16a88f8e88a30a46ba70e50fe1ce290..4794a67a8ca3dc8ed542534070910385d549bd15 100644 (file)
@@ -19,21 +19,20 @@ class HelpCommand : public Command {
 public:
        HelpCommand(string);
        HelpCommand() {}
-       ~HelpCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help() {};
+       ~HelpCommand(){}
        
-private:
-       CommandFactory* validCommands;
-       vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
+       vector<string> 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<string> outputNames;     
                
 };
  
index defccd3beeddb28da8d22a092a2ec43343e5add0..9f7483057220568d27752d5c6d2b68238d274629 100644 (file)
 #include "readphylipvector.h"
 
 //**********************************************************************************************************************
-
-vector<string> HomovaCommand::getValidParameters(){    
+vector<string> HomovaCommand::setParameters(){ 
        try {
-               string Array[] =  {"outputdir","iters","phylip","design","alpha", "inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["homova"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "HomovaCommand", "HomovaCommand");
+               m->errorOut(e, "HomovaCommand", "setParameters");
                exit(1);
        }
 }
-
 //**********************************************************************************************************************
-
-vector<string> HomovaCommand::getRequiredParameters(){ 
+string HomovaCommand::getHelpString(){ 
        try {
-               string Array[] =  {"design"};
-               vector<string> 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<string> HomovaCommand::getRequiredFiles(){      
+HomovaCommand::HomovaCommand(){        
        try {
-               string Array[] =  {};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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(){
index 11f3c07fcebb96ddfe7a473aac8ccb0f234e167d..ec7a793bc25082fe12bf1fc768a72e0209d6b96a 100644 (file)
@@ -21,13 +21,15 @@ class HomovaCommand : public Command {
 public:
        HomovaCommand(string);
        HomovaCommand();
-       ~HomovaCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       ~HomovaCommand(){}
+       
+       vector<string> 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<string, vector<int> >, double);
@@ -36,7 +38,6 @@ private:
        map<string, vector<int> > getRandomizedGroups(map<string, vector<int> >);
 
        bool abort;
-       map<string, vector<string> > outputTypes;
        vector<string> outputNames;
 
        string outputDir, inputDir, designFileName, phylipFileName;
index 654ec066f7610ae4def19f745c28512a71d3b196..8e80d5331ed6265f7da9640258cb399c4c11a15d 100644 (file)
 #include "indicatorcommand.h"
 #include "sharedutilities.h"
 
+
 //**********************************************************************************************************************
-vector<string> IndicatorCommand::getValidParameters(){ 
+vector<string> IndicatorCommand::setParameters(){      
        try {
-               string Array[] =  {"tree","shared","relabund","design","label","groups","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> IndicatorCommand::getRequiredParameters(){      
+string IndicatorCommand::getHelpString(){      
        try {
-               string Array[] =  {"tree"};
-               vector<string> 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<string> tempOutNames;
                outputTypes["tree"] = tempOutNames;
                outputTypes["summary"] = tempOutNames;
@@ -47,31 +67,16 @@ IndicatorCommand::IndicatorCommand(){
                exit(1);
        }
 }
-
-//**********************************************************************************************************************
-vector<string> IndicatorCommand::getRequiredFiles(){   
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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<string> 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<string> myGroups; myGroups.push_back(globaldata->Treenames[i]);
+                               vector<string> myGroups; myGroups.push_back(m->Treenames[i]);
                                vector<string> 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<Tree*> T = globaldata->gTree;
+               vector<Tree*> 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 = "";
index ae7499764dd7f32206ad36c01fdbd98fff3d8592..05db05c414de9e0917c68050aebc655afe3aa846 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       ~IndicatorCommand(){}
+       
+       vector<string> 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<string> outputNames, Groups;
-       map<string, vector<string> > outputTypes;
        vector<SharedRAbundVector*> lookup;
        vector<SharedRAbundFloatVector*> lookupFloat;
        
index 283fb7edc33856613612e10b0d293d0eea1f056d..ec23955513f42c218ed750be5471eb23ee08cd40 100644 (file)
 
 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<SharedRAbundVector*> InputData::getSharedRAbundVectors(){
                                }
                        }else if (format == "shared") {
                                SharedList = new SharedListVector(fileHandle);
+                               
                                if (SharedList != NULL) {
                                        return SharedList->getSharedRAbundVector();
                                }
@@ -455,7 +450,7 @@ vector<SharedRAbundVector*> InputData::getSharedRAbundVectors(string label){
                string  thisLabel;
                
                m->openInputFile(filename, in);
-               globaldata->saveNextLabel = "";
+               m->saveNextLabel = "";
        
                if(in){
                        if (format == "sharedfile")  {
@@ -481,6 +476,7 @@ vector<SharedRAbundVector*> 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<SharedRAbundFloatVector*> InputData::getSharedRAbundFloatVectors(string l
                string  thisLabel;
                
                m->openInputFile(filename, in);
-               globaldata->saveNextLabel = "";
+               m->saveNextLabel = "";
                
                if(in){
                        if (format == "relabund")  {
index ccf35512264023384e3426040dcddcad691f8a42..658b21d8cdfe649d8434e883655ecd18922f2554 100644 (file)
@@ -46,7 +46,6 @@ private:
        map<string,int> orderMap;
        string filename;
        MothurOut* m;
-       GlobalData* globaldata;
 };
 
 
index 129c9700c4f945813cbb639f028d71a57b88d7b1..dd3a65d5eba509888d26f6f1fd57124ab33333b3 100644 (file)
 #include "slibshuff.h"
 #include "dlibshuff.h"
 
+
+
 //**********************************************************************************************************************
-vector<string> LibShuffCommand::getValidParameters(){  
+vector<string> LibShuffCommand::setParameters(){       
        try {
-               string Array[] =  {"iters","groups","step","form","cutoff","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["coverage"] = tempOutNames;
-               outputTypes["libshuffsummary"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "LibShuffCommand", "LibShuffCommand");
+               m->errorOut(e, "LibShuffCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> LibShuffCommand::getRequiredParameters(){       
+string LibShuffCommand::getHelpString(){       
        try {
-               vector<string> 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<string> LibShuffCommand::getRequiredFiles(){    
+LibShuffCommand::LibShuffCommand(){    
        try {
-               string Array[] =  {"phylip","group"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<int> 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<int> 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;i<numGroups;i++){
                        pValueCounts[i].assign(numGroups, 0);
                }
        
-               if (m->control_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;i<numGroups-1;i++) {
                        for(int j=i+1;j<numGroups;j++) {
                                
-                               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->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;p<iters;p++) {      
                                        
-                                       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; }
                                        
                                        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;j<numGroups;j++){
                                indices[i][j] = index++;
                                
-                               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 k=0;k<savedMinValues[spoti][spotj].size();k++){
                                        
@@ -364,7 +432,7 @@ int LibShuffCommand::printSummaryFile() {
        try {
 
                ofstream outSum;
-               summaryFile = outputDir + m->getRootName(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;j<numGroups;j++){
                                if(m->control_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) {
index 3240860fc329bed3b9551359a6ff1b23a16b8019..97fcd1cce71290949fde06e96086ab0cc48db70b 100644 (file)
 #include "command.hpp"
 #include "fullmatrix.h"
 #include "libshuff.h"
+#include "groupmap.h"
 
 
-class GlobalData;
-
 class LibShuffCommand : public Command {
        
 public:
        LibShuffCommand(string);
        LibShuffCommand();      
        ~LibShuffCommand(){};
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       
+       vector<string> setParameters();
+       string getCommandName()                 { return "libshuff";                            }
+       string getCommandCategory()             { return "Hypothesis Testing";          }
+       string getHelpString(); 
+       
        int execute();
-       void help();    
-
+       void help() { m->mothurOut(getHelpString()); }  
+       
 private:
        vector<string> 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<vector<int> > pValueCounts;
        vector<vector<double> > savedDXYValues;
        vector<vector<vector<double> > > savedMinValues;
 
-       bool abort;
+       bool abort, sim;
        string outputFile, groups, userform, savegroups, outputDir;
        vector<string> Groups, outputNames; //holds groups to be used
-       map<string, vector<string> > outputTypes;
 };
 
 #endif
index a8a9d2b5a6cff6da2ab8e86e22af19782f5ce0bf..b977304c9ce54493e5f34dc20705ea1855b21bc4 100644 (file)
 #include "sequence.hpp"
 #include "listvector.hpp"
 
+
 //**********************************************************************************************************************
-vector<string> ListSeqsCommand::getValidParameters(){  
+vector<string> ListSeqsCommand::setParameters(){       
        try {
-               string Array[] =  {"fasta","name", "group", "alignreport","list","taxonomy","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> ListSeqsCommand::getRequiredParameters(){       
-       try {
-               string Array[] =  {"fasta","name", "group", "alignreport","list","taxonomy","or"};
-               vector<string> 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<string> ListSeqsCommand::getRequiredFiles(){    
+ListSeqsCommand::ListSeqsCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index 889b3733df47f346be5a3fd9dd327a0660913c61..bd7beae73360da9453911e7d5b755135a00f4d54 100644 (file)
@@ -19,16 +19,18 @@ class ListSeqsCommand : public Command {
                ListSeqsCommand(string);
                ListSeqsCommand();      
                ~ListSeqsCommand(){}
-               vector<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();    
-               
+       
+               vector<string> setParameters();
+               string getCommandName()                 { return "get.seqs";                            }
+               string getCommandCategory()             { return "Sequence Processing";         }
+               string getHelpString(); 
+       
+               int execute(); 
+               void help() { m->mothurOut(getHelpString()); }  
+       
+       
        private:
                vector<string> names, outputNames;
-               map<string, vector<string> > outputTypes;
                string fastafile, namefile, groupfile, alignfile, inputFileName, outputDir, listfile, taxfile;
                bool abort;
                
index 18ca8644a2f0bfffc1035706c7a6b46df8aba043..995dc6606d86963d64d1bee857233c9656836da6 100644 (file)
 #include "qualityscores.h"
 
 //**********************************************************************************************************************
-vector<string> MakeFastQCommand::getValidParameters(){ 
+vector<string> MakeFastQCommand::setParameters(){      
        try {
-               string Array[] =  {"fasta","qfile","outputdir","inputdir" };
-               vector<string> 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<string> 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<string> 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<string> MakeFastQCommand::getRequiredParameters(){      
-       try {
-               string Array[] =  {"fasta","qfile"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "MakeFastQCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> MakeFastQCommand::getRequiredFiles(){   
+MakeFastQCommand::MakeFastQCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index fd893ad590f2f8ed8590b4741a8a11e8ec0db484..946c990047fe8ad65f2fb332deb6e072534fc932 100644 (file)
@@ -20,19 +20,21 @@ public:
        MakeFastQCommand(string);       
        MakeFastQCommand();
        ~MakeFastQCommand(){}
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
        string convertQual(vector<int>);
        
index 8adfe09f7db893f6f8366f7cbecd18639b72f42c..6f640eb0732274bf6970c346dc9d6b9de553b1b4 100644 (file)
 #include "makegroupcommand.h"
 #include "sequence.hpp"
 
+
 //**********************************************************************************************************************
-vector<string> MakeGroupCommand::getValidParameters(){ 
+vector<string> MakeGroupCommand::setParameters(){      
        try {
-               string Array[] =  {"fasta", "output","groups","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["group"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "MakeGroupCommand", "MakeGroupCommand");
+               m->errorOut(e, "MakeGroupCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> MakeGroupCommand::getRequiredParameters(){      
+string MakeGroupCommand::getHelpString(){      
        try {
-               string Array[] =  {"fasta","groups"};
-               vector<string> 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<string> MakeGroupCommand::getRequiredFiles(){   
+MakeGroupCommand::MakeGroupCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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(){
index e836d20f50b7b04e6cedefbb4f01616f6380b538..1206938205b6fec35b5252e75f21d7d45af5522b 100644 (file)
@@ -17,20 +17,21 @@ class MakeGroupCommand : public Command {
 public:
        MakeGroupCommand(string);
        MakeGroupCommand();     
-       ~MakeGroupCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       ~MakeGroupCommand(){}
+       
+       vector<string> 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<string> fastaFileNames;
        vector<string> groupsNames, outputNames;
-       map<string, vector<string> > outputTypes;
        
        bool abort;
 };
index a1f7b3bafc35e3e7009462d3d944005bf055bd94..c41cde34e92374d4c21a57f51636d2729d464d13 100644 (file)
 #include "mantelcommand.h"
 #include "readphylipvector.h"
 
+
 //**********************************************************************************************************************
-vector<string> MantelCommand::getValidParameters(){    
+vector<string> MantelCommand::setParameters(){ 
        try {
-               string Array[] =  {"phylip1","phylip2","method","iters","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> MantelCommand::getRequiredParameters(){ 
+string MantelCommand::getHelpString(){ 
        try {
-               string Array[] =  {"phylip1", "phylip2"};
-               vector<string> 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<string> tempOutNames;
                outputTypes["mantel"] = tempOutNames;
        }
@@ -46,18 +62,6 @@ MantelCommand::MantelCommand(){
                exit(1);
        }
 }
-
-//**********************************************************************************************************************
-vector<string> MantelCommand::getRequiredFiles(){      
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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 {
                
index 0646b294c0a53bd327aca2a256a4eaa9ba45735b..224265bc3539a53e16b322847772b8fe2cdbc280 100644 (file)
@@ -17,13 +17,15 @@ class MantelCommand : public Command {
 public:
        MantelCommand(string);
        MantelCommand();
-       ~MantelCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       ~MantelCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 };
 
 
index ef2c23688e09e37167e8bd8421a0a493a4c4f943..effc368e0c7f932b719925a0afb349b5afee4bdf 100644 (file)
 #include "memchord.h"
 #include "memeuclidean.h"
 #include "mempearson.h"
+
 //**********************************************************************************************************************
-vector<string> MatrixOutputCommand::getValidParameters(){      
+vector<string> MatrixOutputCommand::setParameters(){   
        try {
-               string Array[] =  {"label","calc","groups","outputdir","inputdir", "output"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["phylip"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "MatrixOutputCommand", "MatrixOutputCommand");
+               m->errorOut(e, "MatrixOutputCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> MatrixOutputCommand::getRequiredParameters(){   
+string MatrixOutputCommand::getHelpString(){   
        try {
-               vector<string> 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<string> MatrixOutputCommand::getRequiredFiles(){        
+MatrixOutputCommand::MatrixOutputCommand(){    
        try {
-               string Array[] =  {"shared"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["phylip"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "MatrixOutputCommand", "getRequiredFiles");
+               m->errorOut(e, "MatrixOutputCommand", "MatrixOutputCommand");
                exit(1);
        }
 }
@@ -100,28 +109,23 @@ vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters  = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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<string> processedLabels;
                set<string> 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<string>::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<SharedRAbundVector*> 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);
                                        
index 2a7908167ac1ede1d402fa26c2f9c30978b31469..40706b96581ba3d72f76b5efc8783788f7d60102 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       
+       vector<string> 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<SharedRAbundVector*>);
        
-       GlobalData* globaldata;
-       ReadOTUFile* read;
        vector<Calculator*> matrixCalculators;
        vector< vector<float> > simMatrix;
        InputData* input;
        ValidCalculators* validCalculator;
        vector<SharedRAbundVector*> lookup;
-       string exportFileName, output;
+       string exportFileName, output, sharedfile;
        int numGroups;
        ofstream out;
 
@@ -55,9 +53,6 @@ private:
        set<string> labels; //holds labels to be used
        string outputFile, calc, groups, label, outputDir;
        vector<string>  Estimators, Groups, outputNames; //holds estimators to be used
-       map<string, vector<string> > outputTypes;
-       
-
 };
        
        
index 2b34a00b8c3961d581032dcf6b6929404428a3b4..cb241c6b301396e7c7d0482d98be861a926b8a64 100644 (file)
 #include "mergefilecommand.h"
 
 //**********************************************************************************************************************
-vector<string> MergeFileCommand::getValidParameters(){ 
+vector<string> MergeFileCommand::setParameters(){      
        try {
-               string Array[] =  {"input", "output","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> MergeFileCommand::getRequiredParameters(){      
-       try {
-               string Array[] =  {"input","output"};
-               vector<string> 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<string> MergeFileCommand::getRequiredFiles(){   
+MergeFileCommand::MergeFileCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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);
-       }
-}
-
 //**********************************************************************************************************************
index 56da3152309ec3c422cccb3aa0c6abce9f92be46..1ecc3cb6e24f72b99c5e4d9ddb0850e1cc16e082 100644 (file)
@@ -17,17 +17,18 @@ class MergeFileCommand : public Command {
 public:
        MergeFileCommand(string);
        MergeFileCommand();
-       ~MergeFileCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
-
+       ~MergeFileCommand(){}
+       
+       vector<string> setParameters();
+       string getCommandName()                 { return "merge.files"; }
+       string getCommandCategory()             { return "General";             }
+       string getHelpString(); 
+       
+       int execute(); 
+       void help() { m->mothurOut(getHelpString()); }  
+       
 private:
        vector<string> fileNames, outputNames;
-       map<string, vector<string> > outputTypes;
        string outputFileName;
        int numInputFiles;
        bool abort;
index 60b9c85481a2d455d53ab4b13a3bd46cfaf5a389..74bf0dea86c84c093d7d84b9c807b92be74892c6 100644 (file)
 #include "sharedutilities.h"
 
 //**********************************************************************************************************************
-vector<string> MergeGroupsCommand::getValidParameters(){       
+vector<string> MergeGroupsCommand::setParameters(){    
        try {
-               string Array[] =  {"shared","label","outputdir","design","groups","processors","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> MergeGroupsCommand::getRequiredParameters(){    
-       try {
-               string Array[] =  {"design", "shared"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "MergeGroupsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> MergeGroupsCommand::getRequiredFiles(){ 
+MergeGroupsCommand::MergeGroupsCommand(){      
        try {
-               string Array[] =  {};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["shared"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "MergeGroupsCommand", "getRequiredFiles");
+               m->errorOut(e, "MergeGroupsCommand", "MetaStatsCommand");
                exit(1);
        }
 }
@@ -62,18 +68,14 @@ vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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<string>::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;}
index 62839ec1a1dc80a3b77a7aad8666f35262f663b3..827f5a32762ce7f6d3c11fd0735e64f5e729e7fd 100644 (file)
 #include "inputdata.h"
 #include "sharedrabundvector.h"
 
-class GlobalData;
-
 class MergeGroupsCommand : public Command {
        
 public:
        MergeGroupsCommand(string);
        MergeGroupsCommand();
-       ~MergeGroupsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~MergeGroupsCommand() {}
+       
+       vector<string> 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<SharedRAbundVector*> lookup;
-       map<string, vector<string> > outputTypes;
        
        bool abort, allLines, pickedGroups;
        set<string> labels; //holds labels to be used
index e13e37c92c3103a3aabd1a4a6a7c68db443592ef..4bb50ab107bb4fdde1d97b790cd15f3cb42d8599 100644 (file)
 #include "sharedutilities.h"
 
 //**********************************************************************************************************************
-vector<string> MetaStatsCommand::getValidParameters(){ 
+vector<string> MetaStatsCommand::setParameters(){      
        try {
-               string Array[] =  {"groups","label","outputdir","iters","threshold","g","design","sets","processors","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["metastats"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "MetaStatsCommand", "MetaStatsCommand");
+               m->errorOut(e, "MetaStatsCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> MetaStatsCommand::getRequiredParameters(){      
+string MetaStatsCommand::getHelpString(){      
        try {
-               string Array[] =  {"design"};
-               vector<string> 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<string> MetaStatsCommand::getRequiredFiles(){   
+MetaStatsCommand::MetaStatsCommand(){  
        try {
-               string Array[] =  {"shared"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["metastats"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "MetaStatsCommand", "getRequiredFiles");
+               m->errorOut(e, "MetaStatsCommand", "MetaStatsCommand");
                exit(1);
        }
 }
@@ -63,18 +77,15 @@ vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
@@ -91,11 +102,6 @@ MetaStatsCommand::MetaStatsCommand(string option) {
                        vector<string> 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<string>::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<SharedRAbundVector*>& 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];
index 8c633b5417cbe07dc96827cf80c8e0b5522c0fad..1380444dc25e4b0ade5afc240acb2c942b6abd57 100644 (file)
  
 #include "command.hpp"
 #include "inputdata.h"
-#include "readotu.h"
 #include "sharedrabundvector.h"
 
-class GlobalData;
-
 class MetaStatsCommand : public Command {
 
 public:
        MetaStatsCommand(string);
        MetaStatsCommand();
-       ~MetaStatsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~MetaStatsCommand() {}
+       
+       vector<string> 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<linePair> lines;
        
-       GlobalData* globaldata;
        GroupMap* designMap;
-       ReadOTUFile* read;
        InputData* input;
        vector<SharedRAbundVector*> lookup;
-       map<string, vector<string> > outputTypes;
-       
+               
        bool abort, allLines, pickedGroups;
        set<string> labels; //holds labels to be used
-       string groups, label, outputDir, inputDir, designfile, sets;
+       string groups, label, outputDir, inputDir, designfile, sets, sharedfile;
        vector<string> Groups, outputNames, Sets;
        vector< vector<string> > namesOfGroupCombos;
        int iters, processors;
index 23f359eae8ab7fe84e9b86faf96d54d33ac8dcd3..b6c4164f0a49788145f47a3ea78f4f2244c168dc 100644 (file)
@@ -9,69 +9,82 @@
 
 #include "mgclustercommand.h"
 
-
 //**********************************************************************************************************************
-vector<string> MGClusterCommand::getValidParameters(){ 
+vector<string> MGClusterCommand::setParameters(){      
        try {
-               string Array[] =  {"blast", "method", "name", "hard", "cutoff", "precision", "length", "min", "penalty", "hcluster","merge","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> MGClusterCommand::getRequiredParameters(){      
-       try {
-               string Array[] =  {"blast"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "MGClusterCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> MGClusterCommand::getRequiredFiles(){   
+MGClusterCommand::MGClusterCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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; 
                }
index f16a8f0c5ebc75bf07039a54d910d266e418b94e..a51fec5b298991b976095c52b7944c2fbab84cb8 100644 (file)
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~MGClusterCommand(){}
+       
+       vector<string> 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<seqDist> overlapMatrix;
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
        string blastfile, method, namefile, overlapFile, distFile, outputDir;
        ofstream sabundFile, rabundFile, listFile;
index 9ed0dfc5d1645c5c2b65cabdb04063e300634d04..74e7e731cc391441280d202bb6913019e0fd0538 100644 (file)
@@ -14,7 +14,6 @@
 
 /**************************************************************************************************/
 
-GlobalData* GlobalData::_uniqueInstance = 0;
 CommandFactory* CommandFactory::_uniqueInstance = 0;
 MothurOut* MothurOut::_uniqueInstance = 0;
 
index 0c25f2a62ed8961cfc8c29080ae37cd2f2d6b77a..59e4fdcc080fe91e946dbc7d3b2a66d9e1dc02a0 100644 (file)
@@ -1730,7 +1730,6 @@ bool MothurOut::checkReleaseVersion(ifstream& file, string version) {
                exit(1);
        }
 }
-
 /**************************************************************************************************/
 
 
index 35805320227e168d6b2862fe889374fa939a0ca9..6654455063c37b56030a89c09c8d6ee71dcdf4be 100644 (file)
@@ -35,6 +35,11 @@ class MothurOut {
                void setReleaseDate(string r) { releaseDate = r; }
                string getVersion() { return version; }
                void setVersion(string r) { version = r; }
+               vector<string> Groups;
+               vector<string> Treenames;
+               map<string, string> names;
+               vector<string> 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;
index aa1cd660b9af25b9dfdb099741b06fb6769433c1..8fa0145ea7e97081000ee99337309861a0f8c7a9 100644 (file)
 #include "readphylipvector.h"
 
 //**********************************************************************************************************************
-vector<string> NMDSCommand::getValidParameters(){      
+vector<string> NMDSCommand::setParameters(){   
        try {
-               string Array[] =  {"phylip","axes","mindim","maxdim","iters","maxiters","epsilon","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["nmds"] = tempOutNames;
-               outputTypes["stress"] = tempOutNames;
-               outputTypes["iters"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "NMDSCommand", "NMDSCommand");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> NMDSCommand::getRequiredParameters(){   
-       try {
-               string Array[] =  {"phylip"};
-               vector<string> 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<string> NMDSCommand::getRequiredFiles(){        
+NMDSCommand::NMDSCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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 {
                
index 7979c67a3eb9d043c8e19ef2429a9e5ffdff57b0..861e8eaf95eb79a02c4e918a732f13c19f3ce845 100644 (file)
@@ -32,13 +32,15 @@ class NMDSCommand : public Command {
 public:
        NMDSCommand(string);    
        NMDSCommand();
-       ~NMDSCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~NMDSCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        LinearAlgebra linearCalc;
        
        vector< vector<double> > nmdsCalc(vector< vector<double> >&, vector< vector<double> >&, double&);
index eab873ba1eec6bc6a01b748f4ce6b441c9e1f4f1..9c223ee9e31c2eae2fb00da28a0a113bbf7ec01d 100644 (file)
@@ -9,49 +9,12 @@
 
 #include "nocommands.h"
 
-//**********************************************************************************************************************
-vector<string> NoCommand::getValidParameters(){        
-       try {
-               vector<string> myArray; 
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "NoCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> NoCommand::getRequiredParameters(){     
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "NoCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> NoCommand::getRequiredFiles(){  
-       try {
-               vector<string> 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";
index f11673f98ce4e7c5c01f8c2aa624e85911f01fc7..12bfc4dffc6082ab35cc405b5ab03b522391b02d 100644 (file)
@@ -19,17 +19,19 @@ class NoCommand : public Command {
 public:
        NoCommand(string);
        NoCommand() {}
-       ~NoCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help() {}
+       ~NoCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
                
 };
 
index 37cfb5daa98b4eeb850b44d60e5e9d80fa268de5..8a6b4adf524a40f8e38c350f6f322f7a9e1effe3 100644 (file)
 #include "normalizesharedcommand.h"
 
 //**********************************************************************************************************************
-vector<string> NormalizeSharedCommand::getValidParameters(){   
+vector<string> NormalizeSharedCommand::setParameters(){        
        try {
-               string Array[] =  {"groups","label","method","makerelabund","outputdir","inputdir","norm"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["shared"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> NormalizeSharedCommand::getRequiredParameters(){        
-       try {
-               vector<string> 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<string> NormalizeSharedCommand::getRequiredFiles(){     
+NormalizeSharedCommand::NormalizeSharedCommand(){      
        try {
-               string Array[] =  {"shared"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["shared"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "NormalizeSharedCommand", "getRequiredFiles");
+               m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand");
                exit(1);
        }
 }
@@ -60,26 +72,23 @@ vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string> 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<SharedRAbundVector*> 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<string> processedLabels;
                        set<string> 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<string>::iterator it;
@@ -289,6 +314,22 @@ int NormalizeSharedCommand::execute(){
                        set<string> processedLabels;
                        set<string> userLabels = labels;
                        
+                       //look for groups whose numseqs is below norm and remove them, warning the user
+                       if (norm != 0) { 
+                               m->Groups.clear();
+                               vector<SharedRAbundFloatVector*> 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<string>::iterator it;
@@ -370,7 +411,7 @@ int NormalizeSharedCommand::execute(){
                        
                }
                //reset groups parameter
-               globaldata->Groups.clear();  
+               m->Groups.clear();  
                delete input;
                out.close();
                
index bedff43da2532c99d2e672c27f0abc5a8ebbc9b8..26bc0e4ca542de7a7c56cf2299918ce0f2819e70 100644 (file)
 #include "inputdata.h"
 #include "sharedrabundvector.h"
 
-class GlobalData;
-
 class NormalizeSharedCommand : public Command {
 
 public:
        NormalizeSharedCommand(string);
        NormalizeSharedCommand();
-       ~NormalizeSharedCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~NormalizeSharedCommand() {}
+       
+       vector<string> 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<SharedRAbundVector*> lookup;
        vector<SharedRAbundFloatVector*> lookupFloat;
        
        bool abort, allLines, pickedGroups, makeRelabund;
        set<string> labels; //holds labels to be used
-       string groups, label, outputDir, method;
+       string groups, label, outputDir, method, sharedfile, relabundfile, format, inputfile;
        int norm;
        vector<string> Groups, outputNames;
-       map<string, vector<string> > outputTypes;
-       
+               
        int normalize(vector<SharedRAbundVector*>&, ofstream&);
        int normalize(vector<SharedRAbundFloatVector*>&, ofstream&);
        int eliminateZeroOTUS(vector<SharedRAbundVector*>&);
index 0506da6ff441c5a85e296c1fd6f3033110622335..71714f184e644105041910933a5bf877539deb24 100644 (file)
@@ -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<string, string> 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();
index b49af32a76c1cbb2d65ab2a5bf32555a171c5de7..17e29d9528c1122f73a2f81a32c1998dded037cf 100644 (file)
 #include "otuhierarchycommand.h"
 
 //**********************************************************************************************************************
-vector<string> OtuHierarchyCommand::getValidParameters(){      
+vector<string> OtuHierarchyCommand::setParameters(){   
        try {
-               string Array[] =  {"list","label","output","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["otuheirarchy"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "OtuHierarchyCommand", "OtuHierarchyCommand");
+               m->errorOut(e, "OtuHierarchyCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> OtuHierarchyCommand::getRequiredParameters(){   
+string OtuHierarchyCommand::getHelpString(){   
        try {
-               string Array[] =  {"list","label"};
-               vector<string> 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<string> OtuHierarchyCommand::getRequiredFiles(){        
+OtuHierarchyCommand::OtuHierarchyCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index dd5f3a7adc759733bf3972392485c79b94669977..b82ee7606cdafba5c3f392546cb82858eb8aad8b 100644 (file)
@@ -19,20 +19,22 @@ class OtuHierarchyCommand : public Command {
 public:
        OtuHierarchyCommand(string);
        OtuHierarchyCommand();
-       ~OtuHierarchyCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~OtuHierarchyCommand(){}
+       
+       vector<string> 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<string> labels; //holds labels to be used
        string label, listFile, outputDir, output;
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
        vector<ListVector> getListVectors();
                
index 5c890404dea8ed4c5e9c6dae0cef4f41a1ef5f70..0c9bcc5f8a5961de5054fbb0b2412f3df10c4506 100644 (file)
 
 
 //**********************************************************************************************************************
-vector<string> PairwiseSeqsCommand::getValidParameters(){      
+vector<string> PairwiseSeqsCommand::setParameters(){   
        try {
-               string AlignArray[] =  {"fasta","align","match","mismatch","gapopen","gapextend", "processors","calc","compress","cutoff","countends","output","outputdir","inputdir"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "PairwiseSeqsCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> PairwiseSeqsCommand::getRequiredParameters(){   
-       try {
-               string AlignArray[] =  {"fasta"};
-               vector<string> 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<string> 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<string> PairwiseSeqsCommand::getRequiredFiles(){        
+string PairwiseSeqsCommand::getHelpString(){   
        try {
-               vector<string> 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<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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(){
index cf73f3e82a2c0bd59bfff9fad48ee4628a2b1917..52ba63db10adf51e10e6440e5df7b92b78c4c894 100644 (file)
@@ -23,13 +23,15 @@ class PairwiseSeqsCommand : public Command {
 public:
        PairwiseSeqsCommand(string);    
        PairwiseSeqsCommand();
-       ~PairwiseSeqsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
+       ~PairwiseSeqsCommand() {}
+       
+       vector<string> 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<int> processIDS;   //end line, processid
        vector<distlinePair> lines;
-       map<string, vector<string> > outputTypes;
        
        Alignment* alignment;
        Dist* distCalculator;
index 87ec2d26651749f20153b7854ba7c3930eebd70c..75d6fa01be65bcccf8f176bfd29dcce843efc0e3 100644 (file)
 #include "sequence.hpp"
 
 //**********************************************************************************************************************
-vector<string> ParseFastaQCommand::getValidParameters(){       
+vector<string> ParseFastaQCommand::setParameters(){    
        try {
-               string Array[] =  {"fastq", "outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["fasta"] = tempOutNames;
-               outputTypes["qfile"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ParseFastaQCommand", "ParseFastaQCommand");
+               m->errorOut(e, "ParseFastaQCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> ParseFastaQCommand::getRequiredParameters(){    
+string ParseFastaQCommand::getHelpString(){    
        try {
-               string Array[] =  {"fastq"};
-               vector<string> 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<string> ParseFastaQCommand::getRequiredFiles(){ 
+ParseFastaQCommand::ParseFastaQCommand(){      
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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;   }
index c45405f42455de7bbdf93d7f2c391756d0700a05..fe77cf08f34e3760734fb7b70568c4db09d603a2 100644 (file)
@@ -18,18 +18,18 @@ class ParseFastaQCommand : public Command {
 public:
        ParseFastaQCommand(string);
        ParseFastaQCommand();
-       ~ParseFastaQCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       ~ParseFastaQCommand() {}
        
+       vector<string> setParameters();
+       string getCommandName()                 { return "parse.fastq";         }
+       string getCommandCategory()             { return "Sequence Processing"; }
+       string getHelpString(); 
+       
+       int execute(); 
+       void help() { m->mothurOut(getHelpString()); }          
 private:
 
        vector<string> outputNames;     
-       map<string, vector<string> > outputTypes;
        string outputDir, fastaQFile;
        bool abort;
        
index 2d26ef3672a364cd694e01d48922d9d53e56b0db..6e4082e0c139b76435aa073cd1f0c7013b85dca3 100644 (file)
 #include "parselistscommand.h"
 
 //**********************************************************************************************************************
-vector<string> ParseListCommand::getValidParameters(){ 
+vector<string> ParseListCommand::setParameters(){      
        try {
-               string Array[] =  {"list","group", "label", "outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> ParseListCommand::getRequiredParameters(){      
-       try {
-               string Array[] =  {"list","group"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ParseListCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ParseListCommand::getRequiredFiles(){   
+ParseListCommand::ParseListCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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 {
        
index 5ecc7ab13205d4f34d7c496a6b2cc3221615eafe..065c499ade25c46fb18ef3746fc5c08687c232d6 100644 (file)
@@ -21,13 +21,15 @@ class ParseListCommand : public Command {
 public:
        ParseListCommand(string);
        ParseListCommand();     
-       ~ParseListCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~ParseListCommand() {}
+       
+       vector<string> 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<string> labels;
        bool abort, allLines;
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
        map<string, ofstream*> filehandles;
        map<string, ofstream*>::iterator it3;
index 11abb9404c7e0ade1df9af56406681ceab65b5c8..54a3ffd93180376ff8a1efe67b121af3d36b9bc2 100644 (file)
 
 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<numGroups; r++) { 
                        for (int l = r+1; l < numGroups; l++) {
                                numComp++;
-                               vector<string> groups; groups.push_back(globaldata->Groups[r]); groups.push_back(globaldata->Groups[l]);
+                               vector<string> 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<string> > 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++) {
index fc905f2d3c432ab1ce4a05007e13ca0f14264fd0..b116aa2d1a55e0ba84571f1f4c9500c6be5d8fcc 100644 (file)
@@ -13,7 +13,6 @@
 
 #include "treecalculator.h"
 #include "treemap.h"
-#include "globaldata.hpp"
 
 /***********************************************************************/
 
@@ -33,7 +32,6 @@ class Parsimony : public TreeCalculator  {
                };
                vector<linePair> lines;
        
-               GlobalData* globaldata;
                EstOutput data;
                TreeMap* tmap;
                int processors;
index c0de504f32f379651d15fc95767821ec9abd56c7..a8c2d156be775455c729d9341386ecfb952323e4 100644 (file)
 #include "parsimonycommand.h"
 
 //**********************************************************************************************************************
-vector<string> ParsimonyCommand::getValidParameters(){ 
+vector<string> ParsimonyCommand::setParameters(){      
        try {
-               string Array[] =  {"random","groups","iters","processors","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["parsimony"] = tempOutNames;
-               outputTypes["psummary"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ParsimonyCommand", "ParsimonyCommand");
+               m->errorOut(e, "ParsimonyCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> ParsimonyCommand::getRequiredParameters(){      
+string ParsimonyCommand::getHelpString(){      
        try {
-               vector<string> 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<string> ParsimonyCommand::getRequiredFiles(){   
+ParsimonyCommand::ParsimonyCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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<string, string>::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<string, string>::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<string> 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);
+       }
+}
 /***********************************************************/
 
 
index 9e756b884fb087f95ca0d43c23027c8caaa33b3f..274cac4e94f46b51aca95695f9fc4d7a4ba9c981 100644 (file)
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
-
+       ~ParsimonyCommand(){}
+       
+       vector<string> 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<Tree*> T;           //user trees
@@ -43,8 +44,8 @@ private:
        TreeMap* savetmap;
        Parsimony* pars;
        vector<string> 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<int> numEachGroup; //vector containing the number of sequences in each group the users wants for random distrib.
        vector< vector<float> > userTreeScores; //scores for users trees for each comb.
        vector< vector<float> > 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<int, double> > uCumul;  //map <pscore, cumulative percentage of number of user trees with that score or lower .> -vector entry for each combination.
        
        ofstream outSum;
-       
-
        bool abort;
        string groups, itersString;
        vector<string> Groups, outputNames; //holds groups to be used
-       map<string, vector<string> > outputTypes;
-
+       map<string, string> nameMap;
+       
        void printParsimonyFile();  
        int printUSummaryFile();
        void getUserInput();
+       int readNamesFile();
        
 };
 
index 23c066b7beff9dd0d6c1da089221a07e510411ae..a91143bbd87c28deedc6edc03af4ffbea95f37de 100644 (file)
 #include "inputdata.h"
 
 //**********************************************************************************************************************
-vector<string> PCACommand::getValidParameters(){       
+vector<string> PCACommand::setParameters(){    
        try {
-               string Array[] =  {"label", "groups","metric","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> PCACommand::getRequiredParameters(){    
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "PCACommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> PCACommand::getRequiredFiles(){ 
+PCACommand::PCACommand(){      
        try {
-               string Array[] =  {"shared","relabund","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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<string> 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<SharedRAbundFloatVector*>& 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) {   
                        
index eedfcf35c58d508cb37ebc41416ca0a3bfc7b1c8..379cf6e654bb72b9e5a871ea93d1c230fe819809 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~PCACommand() {}
        
-private:
-       GlobalData* globaldata;
+       vector<string> 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<string> outputNames, Groups;
        set<string> labels;
-       map<string, vector<string> > outputTypes;
        LinearAlgebra linearCalc;
        
        //vector< vector<double> > createMatrix(vector<SharedRAbundFloatVector*>);
index 3cd844a36d5a5c253786b4eb29745388b042d2d4..6ebf6536e70042941fe4d4ec401f7035949da66c 100644 (file)
 #include "pcoacommand.h"
 #include "readphylipvector.h"
 
+
 //**********************************************************************************************************************
-vector<string> PCOACommand::getValidParameters(){      
+vector<string> PCOACommand::setParameters(){   
        try {
-               string Array[] =  {"phylip", "metric","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> PCOACommand::getRequiredParameters(){   
-       try {
-               string Array[] =  {"phylip"};
-               vector<string> 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<string> PCOACommand::getRequiredFiles(){        
+PCOACommand::PCOACommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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 {
        
index d923006bdb663bfd8a782a59738681f951eca79f..ea4d2b381e8c5b60a3d7006e51d128dda72081bb 100644 (file)
@@ -20,20 +20,21 @@ class PCOACommand : public Command {
 public:
        PCOACommand(string);    
        PCOACommand();
-       ~PCOACommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~PCOACommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        LinearAlgebra linearCalc;
        
        void get_comment(istream&, char, char);
index 5e0259541d691fc0b5b51cbf7f46feb6034f8cf8..a789efad2bff1549660dea79f05a1109c5953f20 100644 (file)
@@ -12,7 +12,6 @@
  */
 
 #include "treemap.h"
-#include "globaldata.hpp"
 #include "mothurout.h"
 
 
 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<int>, vector< vector< float> >&);
                
                
        private:
-               GlobalData* globaldata;
                MothurOut* m;
                TreeMap* tmap;
 };
index a987594815b00a2e2aa40e177a794a99014bbe33..0822582b2d16b4575f584fbefdd2fffefb39cf55 100644 (file)
 #include "phylodiversitycommand.h"
 
 //**********************************************************************************************************************
-vector<string> PhyloDiversityCommand::getValidParameters(){    
+vector<string> PhyloDiversityCommand::setParameters(){ 
        try {
-               string Array[] =  {"freq","rarefy","iters","groups","processors","summary","collect","scale","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> PhyloDiversityCommand::getRequiredParameters(){ 
+string PhyloDiversityCommand::getHelpString(){ 
        try {
-               vector<string> 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<string> PhyloDiversityCommand::getRequiredFiles(){      
+PhyloDiversityCommand::PhyloDiversityCommand(){        
        try {
-               string Array[] =  {"tree","group"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();;
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::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<Tree*> 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<string, string>::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<string> outputNames;
-                       
-               vector<Tree*> 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<int> 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<int>& procIters, Tree* t, map<
                vector<int> processIDS;
                map< string, vector<float> >::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<float> >& div, ma
                                //initialize counts
                                map<string, int> counts;
                                map< string, set<int> > 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<float> >& 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<float> >& 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<int>& num, map< string, vector<float>
        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<int>& num, map< string, vector<float>
                        
                        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<float> 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<string, string>::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<string> 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);
+       }
+}
+
 //**********************************************************************************************************************
 
 
index f5e205c4e40ce010239c0cc8beba6798e1a17aa4..df04b35d66f1c0dc36893074f6c840711395c49b 100644 (file)
 
 #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<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();  
-               void help();
+               ~PhyloDiversityCommand(){}
        
-       private:
-               GlobalData* globaldata;
-               
+               vector<string> 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<string> Groups, outputNames; //holds groups to be used, and outputFile names
-               map<string, vector<string> > outputTypes;
+               map<string, string> nameMap;
                
+               int readNamesFile();
                void printData(set<int>&, map< string, vector<float> >&, ofstream&, int);
                void printSumData(map< string, vector<float> >&, ofstream&, int);
                vector<float> calcBranchLength(Tree*, int, map< string, set<int> >&);
index c3aee4719859a4921ece77b25e7cf5dfe69d9aec..e7d12969a73a1a2d6576593fc36ec8eb5a9b1d2a 100644 (file)
 #include "sabundvector.hpp"
 
 //**********************************************************************************************************************
-vector<string> PhylotypeCommand::getValidParameters(){ 
+vector<string> PhylotypeCommand::setParameters(){      
        try {
-               string Array[] =  {"taxonomy","cutoff","label","name","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> PhylotypeCommand::getRequiredParameters(){      
+string PhylotypeCommand::getHelpString(){      
        try {
-               string Array[] =  {"taxonomy"};
-               vector<string> 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<string> PhylotypeCommand::getRequiredFiles(){   
+PhylotypeCommand::PhylotypeCommand(){  
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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 {
        
index e45e21b74a9ae58a6beef19a9a484344364c31de..36e679f28aab41ec31848084b117845a9ecab12c 100644 (file)
@@ -21,13 +21,15 @@ class PhylotypeCommand : public Command {
 public:
        PhylotypeCommand(string);       
        PhylotypeCommand();
-       ~PhylotypeCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute(); 
-       void help();    
+       ~PhylotypeCommand(){}
+       
+       vector<string> setParameters();
+       string getCommandName()                 { return "phylotype";                           }
+       string getCommandCategory()             { return "OTU-Based Approaches";        }
+       string getHelpString(); 
+       
+       int execute();
+       void help() { m->mothurOut(getHelpString()); }
        
 private:
        bool abort, allLines;
index 84282dcc39105c7f4d560b88fcacdcb4ed4342d6..19e7886bf700eaccf7196a1dd11badfc7365d50a 100644 (file)
 #include "commandoptionparser.hpp"
 
 //**********************************************************************************************************************
-vector<string> PipelineCommand::getValidParameters(){  
-       try {
-               string Array[] =  {"sff","oligos","align","chimera","classify","taxonomy","pipeline","processors","outputdir","inputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "PipelineCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> PipelineCommand::getRequiredParameters(){       
+vector<string> 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<string> 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<string> PipelineCommand::getRequiredFiles(){    
+string PipelineCommand::getHelpString(){       
        try {
-               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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<string> validParameters = command->getValidParameters();
+               vector<string> validParameters = command->setParameters();
                
                OptionParser parser(options);
                map<string, string> 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<string> 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<CommandParameter> commandParameters = command->getParameters();
+               vector<string> 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<string, vector<string> > thisCommandsFile = command->getOutputFiles();
@@ -549,14 +532,12 @@ bool PipelineCommand::fillInMothurMade(string& options, map<string, vector<strin
                        string paraType = it->first;
                        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<string> 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);
                
                
index 289a909c9d6eef64f4ad2fe61d136592c51120b6..13695a6ec9a178918ab74242d9a2f05a89b9ead7 100644 (file)
@@ -20,20 +20,21 @@ class PipelineCommand : public Command {
        
 public:
        PipelineCommand(string);
-       PipelineCommand() { abort = true; calledHelp = true; }
-       ~PipelineCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; } //empty
-       int execute();
-       void help();
+       PipelineCommand() { abort = true; calledHelp = true; setParameters(); }
+       ~PipelineCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        vector<string> commands;
        string outputDir, sffFile, alignFile, oligosFile, taxonomyFile, pipeFilename, classifyFile, chimeraFile;
        int processors;
index 0fb9370d191440562b9e6f6e7727ed00366b160b..550a6b74ebd99d81c47a169c99462f2a53b6b2b4 100644 (file)
 
 //**********************************************************************************************************************
 inline bool comparePriority(seqPNode first, seqPNode second) {  return (first.numIdentical > second.numIdentical); }
+
 //**********************************************************************************************************************
-vector<string> PreClusterCommand::getValidParameters(){        
+vector<string> PreClusterCommand::setParameters(){     
        try {
-               string Array[] =  {"fasta", "name", "diffs", "outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> PreClusterCommand::getRequiredParameters(){     
-       try {
-               string Array[] =  {"fasta"};
-               vector<string> 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<string> PreClusterCommand::getRequiredFiles(){  
+PreClusterCommand::PreClusterCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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(){
index 7bbb5a7f448351d1bf72616e3c40f7f10b41eda4..d8ee57de9424e623d0455e0327e6f636ce569135 100644 (file)
@@ -32,13 +32,15 @@ class PreClusterCommand : public Command {
 public:
        PreClusterCommand(string);
        PreClusterCommand();
-       ~PreClusterCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~PreClusterCommand(){}
+       
+       vector<string> setParameters();
+       string getCommandName()                 { return "pre.cluster";                         }
+       string getCommandCategory()             { return "Sequence Processing";         }
+       string getHelpString(); 
+       
+       int execute(); 
+       void help() { m->mothurOut(getHelpString()); }  
        
 private:
        int diffs, length;
index 462fe8fbf43e7f47a93ddefeb1058095cf636f86..85e8b526c455cfb5ee8c4ca50b64daec92dd6c24 100644 (file)
 #include "quitcommand.h"
 
 //**********************************************************************************************************************
-vector<string> QuitCommand::getValidParameters(){      
-       try {
-               vector<string> myArray; 
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "QuitCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> QuitCommand::getRequiredParameters(){   
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "QuitCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> QuitCommand::getRequiredFiles(){        
-       try {
-               vector<string> 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;
 }
-
 //**********************************************************************************************************************
index f901b17083b54f059e2cb9eef6d020318c9d5cda..e24bb775aa89ec31f7db5135ecb9952d570a2fb9 100644 (file)
@@ -22,17 +22,19 @@ public:
        QuitCommand(string);
        QuitCommand() {}
        ~QuitCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 };
 
 #endif
index 032cd93752db10521d18495aa141888e37720963..d8a6b5cc2be05f8022da2c9234a358bb6fa98e8c 100644 (file)
@@ -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());
                        }
index 7d1fab4b16b412b56f07225acac50936b0348e77..5e42a787bb77f44a7bb989c738c45b8449ed6e29 100644 (file)
@@ -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<Display*> disp, int p) :
                        numSeqs(o->getNumSeqs()), order(o), displays(disp), label(o->getLabel()), processors(p)  { m = MothurOut::getInstance(); }
        Rarefact(vector<SharedRAbundVector*> shared, vector<Display*> 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<Display*> displays;
        int numSeqs, numGroupComb, processors;
index 4ab81ea4ae3186265ce08286008fc48fcbac4881..b6ad295e819a0bef866270c79cea6c61ae7e567c 100644 (file)
 #include "jackknife.h"
 #include "coverage.h"
 
+
 //**********************************************************************************************************************
-vector<string> RareFactCommand::getValidParameters(){  
-       try {
-               string Array[] =  {"iters","freq","label","calc","abund","processors","outputdir","inputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "RareFactCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> RareFactCommand::getRequiredParameters(){       
+vector<string> 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<string> 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<string> RareFactCommand::getRequiredFiles(){    
+string RareFactCommand::getHelpString(){       
        try {
-               string AlignArray[] =  {"shared","list","rabund","sabund","or"};
-               vector<string> 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<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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; i<Estimators.size(); i++) {
-                               if (validCalculator->isValidCalculator("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;i<rDisplays.size();i++){       delete rDisplays[i];    } delete validCalculator; return 0; }
-                       
-                       read = new ReadOTUFile(globaldata->inputFileName);      
-                       read->read(&*globaldata); 
+                       if (rDisplays.size() == 0) { for(int i=0;i<rDisplays.size();i++){       delete rDisplays[i];    }  return 0; }
                        
-                       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<string> processedLabels;
                        set<string> userLabels = labels;
                        
-                       if (m->control_pressed) { if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  } for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    } delete validCalculator; delete read; delete input; globaldata->ginput = 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;i<rDisplays.size();i++){  delete rDisplays[i];    }  delete input;  delete order;  for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
                        
                        //as long as you are not at the end of the file or done wih the lines you want
                        while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                                
-                               if (m->control_pressed) { if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  } for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    } delete validCalculator; delete read; delete input; globaldata->ginput = 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;i<rDisplays.size();i++){  delete rDisplays[i];    }  delete input;  delete order;  for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
 
                                
                                if(allLines == 1 || labels.count(order->getLabel()) == 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;i<rDisplays.size();i++){    delete rDisplays[i];    } delete validCalculator; delete read; delete input; globaldata->ginput = 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<rDisplays.size();i++){  delete rDisplays[i];    }  delete input;   for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } return 0; }
 
                        //output error messages about any remaining user labels
                        set<string>::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;i<rDisplays.size();i++){    delete rDisplays[i];    } delete validCalculator; delete read; delete input; globaldata->ginput = 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<rDisplays.size();i++){  delete rDisplays[i];    }  delete input;   for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str()); } return 0; }
 
                        //run last label if you need to
                        if (needToRun == true)  {
@@ -379,14 +430,9 @@ int RareFactCommand::execute(){
                        
                        for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
                        rDisplays.clear();
-                       globaldata->gorder = 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<string> RareFactCommand::parseSharedFile(string filename) {
                map<string, ofstream*> filehandles;
                map<string, ofstream*>::iterator it3;
                
-                               
-               //read first line
-               read = new ReadOTUFile(filename);       
-               read->read(&*globaldata); 
-                       
-               input = globaldata->ginput;
+               input = new InputData(filename, "sharedfile");
                vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
                
                string sharedFileRoot = m->getRootName(filename);
@@ -450,9 +491,9 @@ vector<string> 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;
        }
index 7da0b2f9f5301d80302d97f7da23d1cd8fee12c1..67ab70ce2caede69c32fc8a61f6fe258d2133e80 100644 (file)
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       ~RareFactCommand(){}
+       
+       vector<string> 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<Display*> rDisplays;
-       ReadOTUFile* read;
        OrderVector* order;
        InputData* input;
-       ValidCalculators* validCalculator;
        Rarefact* rCurve;
        int nIters, abund, processors;
        float freq;
        
        bool abort, allLines;
        set<string> labels; //holds labels to be used
-       string label, calc;
+       string label, calc, sharedfile, listfile, rabundfile, sabundfile, format, inputfile;
        vector<string>  Estimators;
        vector<string> inputFileNames, outputNames;
        vector<string> groups;
-       map<string, vector<string> > outputTypes;
        string outputDir;
        
        vector<string> parseSharedFile(string);
-
-
 };
 
 #endif
index ea460c026e4c4ea77684893920b328288d3f9f63..746b09e8df8f4719f7ded9504e4f732b49fb559b 100644 (file)
 #include "sharednseqs.h"
 
 //**********************************************************************************************************************
-vector<string> RareFactSharedCommand::getValidParameters(){    
+vector<string> RareFactSharedCommand::setParameters(){ 
        try {
-               string Array[] =  {"iters","freq","label","calc","groups", "jumble","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["sharedrarefaction"] = tempOutNames;
-               outputTypes["sharedr_nseqs"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "RareFactSharedCommand", "RareFactSharedCommand");
+               m->errorOut(e, "RareFactSharedCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> RareFactSharedCommand::getRequiredParameters(){ 
+string RareFactSharedCommand::getHelpString(){ 
        try {
-               vector<string> 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<string> RareFactSharedCommand::getRequiredFiles(){      
+RareFactSharedCommand::RareFactSharedCommand(){        
        try {
-               string Array[] =  {"shared"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                        
                        //check to make sure all parameters are valid for command
-                       for (map<string,string>::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; i<Estimators.size(); i++) {
-                                       if (validCalculator->isValidCalculator("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; i<Estimators.size(); i++) {
+                       if (validCalculator.isValidCalculator("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");
+                               }
+                       }
+               }
                
                //if the users entered no valid calculators don't execute command
                if (rDisplays.size() == 0) { return 0; }
-
-               read = new ReadOTUFile(globaldata->inputFileName);      
-               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;i<rDisplays.size();i++){    delete rDisplays[i];    }
                        for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
@@ -250,7 +227,8 @@ int RareFactSharedCommand::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) { 
-                               globaldata->Groups.clear(); 
+                               m->Groups.clear(); 
+                               delete input;
                                for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }
                                for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
                                for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
@@ -294,10 +272,11 @@ int RareFactSharedCommand::execute(){
                }
                
                if (m->control_pressed) { 
-                               globaldata->Groups.clear(); 
-                               for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }
-                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
-                               return 0;
+                       m->Groups.clear(); 
+                       delete input;
+                       for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                       return 0;
                }
                
                //output error messages about any remaining user labels
@@ -314,10 +293,11 @@ int RareFactSharedCommand::execute(){
                }
                
                if (m->control_pressed) { 
-                               globaldata->Groups.clear(); 
-                               for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }
-                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
-                               return 0;
+                       m->Groups.clear(); 
+                       delete input; 
+                       for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                       return 0;
                }
                
                //run last label if you need to
@@ -333,14 +313,10 @@ int RareFactSharedCommand::execute(){
                }
                
                for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
+               m->Groups.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();
index ee16221903ce2ee738cd7b941ca90c5b57e05c04..8219e613b3c71d657deb31deb8a948f501dc6e52 100644 (file)
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       ~RareFactSharedCommand() {}
+       
+       vector<string> 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<SharedRAbundVector*> lookup;
        InputData* input;
-       ValidCalculators* validCalculator;
        Rarefact* rCurve;
        vector<Display*> rDisplays;
        int nIters;
@@ -45,10 +43,8 @@ private:
        
        bool abort, allLines, jumble;
        set<string> labels; //holds labels to be used
-       string label, calc, groups, outputDir;
+       string label, calc, groups, outputDir, sharedfile;
        vector<string>  Estimators, Groups, outputNames;
-       map<string, vector<string> > outputTypes;
-
 
 };
 
index 205581c72ab26bd767a0a4c47fdfcb3d73e124d5..025d718dea254f909ab57f98706216366aa3e710 100644 (file)
@@ -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;i<matrixNames.size();i++){
                                nameMap->push_back(matrixNames[i]);
                        }
-                       globaldata->nameMap = nameMap;
                }
                
        
index 9ca2a1b14010bf518e2bc366e4df9d77285361eb..e4d3e4c240882410737b0c785fc04f5fd49432b2 100644 (file)
@@ -29,7 +29,6 @@ public:
        ListVector* getListVector()             {       return list;    }
        
 private:
-       GlobalData* globaldata;
        string distFile, outputDir;
        string OutPutFile, format;
        ListVector* list;
index 2782bd08a84efd8a596364f14c56015e04407241..f6f26d512f1a11dffa1de864e971d29dd919884c 100644 (file)
 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);
index 5e718afda866d5c72f907d3d42693792d1972d62..415bef2fddf5a6272261cab2b0c364c64411fd8e 100644 (file)
@@ -17,6 +17,7 @@ class ReadColumnMatrix : public ReadMatrix {
        
 public:
        ReadColumnMatrix(string);
+       ReadColumnMatrix(string, bool);
        ~ReadColumnMatrix();
        int read(NameAssignment*);
 private:
index 630f6493fef9b542dfd8fea434f935987b6ac98f..d3cbbb1ff22335b346cb5c01ac90b8dd7c560149 100644 (file)
 #include "readcolumn.h"
 #include "readmatrix.hpp"
 
-//**********************************************************************************************************************
-vector<string> ReadDistCommand::getValidParameters(){  
-       try {
-               string Array[] =  {"phylip", "column", "name", "cutoff", "precision", "group","outputdir","inputdir","sim"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ReadDistCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ReadDistCommand::getRequiredParameters(){       
-       try {
-               string Array[] =  {"phylip","column","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ReadDistCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ReadDistCommand::getRequiredFiles(){    
-       try {
-               vector<string> 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<string> 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;
                
        }
index 2f05ddbd3169d4cd4f204245ca2a0dd88571cb8e..8c248cd0af21ff65cb6eab139f11e56f6bc74e83 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ReadDistCommand() {}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 
        bool abort, sim;
 
index 31a4da49c8decf24b75b059db4890d377fa54aef..49ae2946fda42c49c8475b040ac8f7e3f5617499 100644 (file)
 #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;
index 00448f8a24cced84a346dfedc434ffa838698371..5cb52bb8d8333e171d7e6de16b1e83057ff4d558 100644 (file)
@@ -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;
index 6c8d67cd5e9af9508bd91e4ab5e07e9ea5a061e1..c2dcb99fa0c8b6ac1337368a372c5655122bd5d8 100644 (file)
--- 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
index 3d0b94d84fb4ec54fe14e4b07a6adfde21f6f432..19c936e4ec4fd069849ac413721f7501f4fbc3ad 100644 (file)
@@ -9,22 +9,12 @@
 
 #include "readotucommand.h"
 
-//**********************************************************************************************************************
-vector<string> ReadOtuCommand::getValidParameters(){   
-       try {
-               string Array[] =  {"list","order","shared","relabund","label","group","sabund", "rabund","groups","ordergroup","outputdir","inputdir"};
-               vector<string> 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<string> tempOutNames;
                outputTypes["rabund"] = tempOutNames;
                outputTypes["shared"] = tempOutNames;
@@ -35,32 +25,8 @@ ReadOtuCommand::ReadOtuCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> ReadOtuCommand::getRequiredParameters(){        
-       try {
-               string Array[] =  {"list","shared","relabund","sabund","rabund","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ChopSeqsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ReadOtuCommand::getRequiredFiles(){     
-       try {
-               vector<string> 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<string> 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;
        }
index eb0ca8f7832e5f1877a172fa0449a3ae29e5416f..d1dc5b7fc73726b09d9dce49a71015c0f70d70da 100644 (file)
 #include "groupmap.h"
 #include "sharedcommand.h"
 
-class GlobalData;
-
 class ReadOtuCommand : public Command {
 public:
        ReadOtuCommand(string);
        ReadOtuCommand();
-       ~ReadOtuCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ReadOtuCommand() {}
+       
+       vector<string> 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;
index 130deccaf0adbb1af542034450d1362a20ae8b57..b13dc25c0eded92a950bfc41a782075624e47fdd 100644 (file)
 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);
index 3e5e7490c618b3d7dac55fb5bd8f8c1853d0ea93..244cc47e4085f2820f4fef01adddf0317075e88b 100644 (file)
@@ -17,6 +17,7 @@ class ReadPhylipMatrix : public ReadMatrix {
        
 public:
        ReadPhylipMatrix(string);
+       ReadPhylipMatrix(string, bool);
        ~ReadPhylipMatrix();
        int read(NameAssignment*);
 private:
index 308115d844bdf8aa24adf05de9841a60c1708fd8..be7dc79509abbc78aeeb0a66ab45ca57b0d1324a 100644 (file)
@@ -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<int> 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<string, int>::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";
index 7cfb4b426eef1ca38e562ae1c52b4ad240afc4e3..b5b26ed0b81ee7d3ad5a87a3515e54881b5daf78 100644 (file)
@@ -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<Tree*> getTrees() { return Trees; }
+               int AssembleTrees();
                
        protected:
-               GlobalData* globaldata;
+               vector<Tree*> 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;
index 05a65b736f93c376525b1cf64e2ed8275fc9c486..c476f5a89928cf131593178b40eb50d60130a7bd 100644 (file)
@@ -9,51 +9,17 @@
 
 #include "readtreecommand.h"
 
-//**********************************************************************************************************************
-vector<string> ReadTreeCommand::getValidParameters(){  
-       try {
-               string Array[] =  {"tree","group","name","outputdir","inputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ReadTreeCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ReadTreeCommand::getRequiredParameters(){       
-       try {
-               string Array[] =  {"tree"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ReadTreeCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ReadTreeCommand::getRequiredFiles(){    
-       try {
-               vector<string> 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<string> 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<Tree*> T = globaldata->gTree;
+               vector<Tree*> 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) {
index 464a825d002e7e1ac3cfe7f43af91142d2a6aeb9..25e08252dd29c0eab2f5c985805408b3c83e10e3 100644 (file)
 #include "readtree.h"
 #include "treemap.h"
 
-class GlobalData;
 
 class ReadTreeCommand : public Command {
 public:
        ReadTreeCommand(string);
        ReadTreeCommand() { abort = true; calledHelp = true; }
-       ~ReadTreeCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ReadTreeCommand() {}
+       
+       vector<string> 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<string, string> nameMap;
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
        int readNamesFile();
        int numUniquesInName;
index b70b679b6690b54f8b54ee7c147af71d139735f3..76dc630e2ae6e2cac50e563f2cdb67df521164e4 100644 (file)
 #include "sharedutilities.h"
 
 //**********************************************************************************************************************
-vector<string> RemoveGroupsCommand::getValidParameters(){      
+vector<string> RemoveGroupsCommand::setParameters(){   
        try {
-               string Array[] =  {"fasta","name", "group", "accnos", "groups","list","taxonomy","outputdir","inputdir" };
-               vector<string> 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<string> 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<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["taxonomy"] = tempOutNames;
@@ -41,29 +73,6 @@ RemoveGroupsCommand::RemoveGroupsCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> RemoveGroupsCommand::getRequiredParameters(){   
-       try {
-               string Array[] =  {"group"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "RemoveGroupsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> RemoveGroupsCommand::getRequiredFiles(){        
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index 896697aa4cfe7c9cfa7532db6e94b5f5590050ad..955d94d5090b5fc6caf4ba2a937261a173a3eb91 100644 (file)
@@ -21,19 +21,21 @@ public:
        RemoveGroupsCommand(string);    
        RemoveGroupsCommand();
        ~RemoveGroupsCommand(){}
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       
+       vector<string> setParameters();
+       string getCommandName()                 { return "remove.groups";                       }
+       string getCommandCategory()             { return "OTU-Based Approaches";        }
+       string getHelpString(); 
+       
+       int execute(); 
+       void help() { m->mothurOut(getHelpString()); }  
+       
        
 private:
        set<string> names;
        string accnosfile, fastafile, namefile, groupfile, listfile, taxfile, outputDir, groups;
        bool abort;
        vector<string> outputNames, Groups;
-       map<string, vector<string> > outputTypes;
        GroupMap* groupMap;
        
        int readFasta();
index ebd06084e23d481fe6eb1a18b8498807d688ca57..021b56cd02f36aaa88edac90a8773ed1090bc5a0 100644 (file)
 #include "listvector.hpp"
 
 //**********************************************************************************************************************
-vector<string> RemoveLineageCommand::getValidParameters(){     
+vector<string> RemoveLineageCommand::setParameters(){  
        try {
-               string Array[] =  {"fasta","name", "group", "alignreport", "taxon", "dups", "list","taxonomy","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["taxonomy"] = tempOutNames;
@@ -41,29 +78,6 @@ RemoveLineageCommand::RemoveLineageCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> RemoveLineageCommand::getRequiredParameters(){  
-       try {
-               string Array[] =  {"taxonomy"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "RemoveLineageCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> RemoveLineageCommand::getRequiredFiles(){       
-       try {
-               vector<string> 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 {
                
index 02a4440e79ec4a7e996b58a7b9209b30cc933dcd..9fdca48db66da3e0ddf5c603949c7380e61155b0 100644 (file)
@@ -19,17 +19,18 @@ class RemoveLineageCommand : public Command {
                RemoveLineageCommand(string);
                RemoveLineageCommand();
                ~RemoveLineageCommand(){};
-               vector<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();    
-               
+       
+               vector<string> setParameters();
+               string getCommandName()                 { return "remove.lineage";                      }
+               string getCommandCategory()             { return "Phylotype Analysis";          }
+               string getHelpString(); 
+       
+               int execute(); 
+               void help() { m->mothurOut(getHelpString()); }  
+       
        private:
                set<string> names;
                vector<string> outputNames;
-               map<string, vector<string> > outputTypes;
                string fastafile, namefile, groupfile, alignfile, listfile, taxfile, outputDir, taxons;
                bool abort, dups;
                
index f1ef4ac5a80c7e2782843349d1433680b38bda45..d1c12c888d8e34f377e4ea6ae661fad997021335 100644 (file)
 #include "inputdata.h"
 #include "sharedutilities.h"
 
-
 //**********************************************************************************************************************
-vector<string> RemoveOtusCommand::getValidParameters(){        
+vector<string> RemoveOtusCommand::setParameters(){     
        try {
-               string Array[] =  { "group", "accnos","label", "groups","list","outputdir","inputdir" };
-               vector<string> 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<string> 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<string> 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<string> RemoveOtusCommand::getRequiredParameters(){     
-       try {
-               string Array[] =  {"group","label", "list"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "RemoveOtusCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> RemoveOtusCommand::getRequiredFiles(){  
+
+///**********************************************************************************************************************
+RemoveOtusCommand::RemoveOtusCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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<string> labels; labels.insert(label);
                set<string> processedLabels;
index 872b2c8caf1e7b082a040b2da15960f39dcb27e0..801eedc6b598820dc101ad73d505e43b87f8f926 100644 (file)
@@ -21,18 +21,19 @@ public:
        RemoveOtusCommand(string);      
        RemoveOtusCommand();
        ~RemoveOtusCommand(){}
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       
+       vector<string> 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<string> outputNames, Groups;
-       map<string, vector<string> > outputTypes;
        GroupMap* groupMap;
        
        void readAccnos();
index bcb9af60d096a82b13c13efa35f4b74d54b0897b..41355b9560e910c03be93e527524e4363b86be11 100644 (file)
 #include "inputdata.h"
 
 //**********************************************************************************************************************
-vector<string> RemoveRareCommand::getValidParameters(){        
+vector<string> RemoveRareCommand::setParameters(){     
        try {
-               string Array[] =  {"rabund","sabund", "group", "list", "shared","bygroup","nseqs","groups","label","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> RemoveRareCommand::getValidParameters(){
 RemoveRareCommand::RemoveRareCommand(){        
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> tempOutNames;
                outputTypes["rabund"] = tempOutNames;
                outputTypes["sabund"] = tempOutNames;
@@ -42,32 +76,8 @@ RemoveRareCommand::RemoveRareCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> RemoveRareCommand::getRequiredParameters(){     
-       try {
-               string Array[] =  {"nseqs"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "RemoveRareCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> RemoveRareCommand::getRequiredFiles(){  
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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);  }
index 388ec2d762e763ef1623d573eb90fa4074dbb039..fa22f7a53e6c5149af4c1c1a51504cfb77e9b04e 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();    
+       
+       vector<string> 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<string> outputNames, Groups;
        set<string> labels;
-       map<string, vector<string> > outputTypes;
        
        int processSabund();
        int processRabund();
index 02cb5d94c2f286f3456f073ccd30db753f4743d3..7e3b93918da6420a6a61c2943a779e89d52ea527 100644 (file)
 #include "listvector.hpp"
 
 //**********************************************************************************************************************
-vector<string> RemoveSeqsCommand::getValidParameters(){        
+vector<string> RemoveSeqsCommand::setParameters(){     
        try {
-               string Array[] =  {"fasta","name", "group", "alignreport", "accnos", "qfile","list","taxonomy","outputdir","inputdir", "dups" };
-               vector<string> 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<string> 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<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["taxonomy"] = tempOutNames;
@@ -42,29 +75,6 @@ RemoveSeqsCommand::RemoveSeqsCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> RemoveSeqsCommand::getRequiredParameters(){     
-       try {
-               string Array[] =  {"accnos"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "RemoveSeqsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> RemoveSeqsCommand::getRequiredFiles(){  
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index de1e3d9d6aff8595a098cf8bf2fd6c1d5c79ec9f..d99151ec022dfdafcfa2327998466549cbcb3eda 100644 (file)
@@ -19,19 +19,21 @@ class RemoveSeqsCommand : public Command {
                RemoveSeqsCommand(string);      
                RemoveSeqsCommand();
                ~RemoveSeqsCommand(){}
-               vector<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();    
-               
+       
+               vector<string> setParameters();
+               string getCommandName()                 { return "remove.seqs";                         }
+               string getCommandCategory()             { return "Sequence Processing";         }
+               string getHelpString(); 
+       
+               int execute(); 
+               void help() { m->mothurOut(getHelpString()); }  
+       
+       
        private:
                set<string> names;
                string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, taxfile, qualfile, outputDir;
                bool abort, dups;
                vector<string> outputNames;
-               map<string, vector<string> > outputTypes;
                
                int readFasta();
                int readName();
index fffe8a2b9de510bead87e0c9762cf75f71af8ef3..0a2e9380ebd71a5deae50725d3b36c2d10b52c4e 100644 (file)
 #include "qualityscores.h"
 
 //**********************************************************************************************************************
-vector<string> ReverseSeqsCommand::getValidParameters(){       
+vector<string> ReverseSeqsCommand::setParameters(){    
        try {
-               string Array[] =  {"fasta", "qfile", "outputdir", "inputdir"};
-               vector<string> 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<string> 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<string> 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<string> ReverseSeqsCommand::getRequiredParameters(){    
-       try {
-               string Array[] =  {"fasta", "qfile"};
-               vector<string> 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<string> ReverseSeqsCommand::getRequiredFiles(){ 
+ReverseSeqsCommand::ReverseSeqsCommand(){      
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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()){
index bd8d1194ff095fa5fecff1b51570520b849dbf9a..0d1da8801adc5a2b5e5bfe9cf81ef58789de534c 100644 (file)
@@ -16,20 +16,21 @@ class ReverseSeqsCommand : public Command {
 public:
        ReverseSeqsCommand(string);
        ReverseSeqsCommand();
-       ~ReverseSeqsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ReverseSeqsCommand() {}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
 };
 
index 8c334cb217b00d709f7bfa35220dce6a8d6c5dad..7a6ea3a5f5cc8f0906c8e49c39d05d1d689f7e51 100644 (file)
 #include "sequence.hpp"
 
 //**********************************************************************************************************************
-vector<string> ScreenSeqsCommand::getValidParameters(){        
+vector<string> ScreenSeqsCommand::setParameters(){     
        try {
-               string Array[] =  {"fasta", "start", "end", "maxambig", "maxhomop","optimize","criteria", "minlength", "maxlength",
-                                                                       "name", "group", "alignreport","processors","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> ScreenSeqsCommand::getValidParameters(){
 ScreenSeqsCommand::ScreenSeqsCommand(){        
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["name"] = tempOutNames;
@@ -39,29 +84,6 @@ ScreenSeqsCommand::ScreenSeqsCommand(){
                exit(1);
        }
 }
-//**********************************************************************************************************************
-vector<string> ScreenSeqsCommand::getRequiredParameters(){     
-       try {
-               string Array[] =  {"fasta"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ScreenSeqsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> ScreenSeqsCommand::getRequiredFiles(){  
-       try {
-               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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<string> 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(){
index 45c9db5de13690840b5eede966c568aeda9a067e..b8ab242e187b2f1b0fccc8b087e7c17f2cc0c903 100644 (file)
@@ -17,13 +17,16 @@ class ScreenSeqsCommand : public Command {
 public:
        ScreenSeqsCommand(string);
        ScreenSeqsCommand();
-       ~ScreenSeqsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ScreenSeqsCommand() {}
+       
+       vector<string> 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<string> outputNames;
        vector<string> optimize;
-       map<string, vector<string> > outputTypes;
        map<string, int> nameMap;
        int readNames();
        
index ece2de0fee12364effae1b23065ef30903c22485..fec93e6e9f5f94414a392a1220b86153999b1f9d 100644 (file)
 #include "sequence.hpp"
 
 //**********************************************************************************************************************
-vector<string> AlignCheckCommand::getValidParameters(){        
+vector<string> AlignCheckCommand::setParameters(){     
        try {
-               string Array[] =  {"fasta", "name","map", "outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["aligncheck"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "AlignCheckCommand", "AlignCheckCommand");
+               m->errorOut(e, "AlignCheckCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> AlignCheckCommand::getRequiredParameters(){     
+string AlignCheckCommand::getHelpString(){     
        try {
-               string Array[] =  {"fasta","map"};
-               vector<string> 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<string> AlignCheckCommand::getRequiredFiles(){  
+AlignCheckCommand::AlignCheckCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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<string, int>::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; }
                                }
                                
index 0b654a4e02bdf42cdf5ebfc9ee419bdbd71eec2f..2e04936a8eea682d1f8511de11a16a601c9e9d1c 100644 (file)
@@ -35,20 +35,21 @@ class AlignCheckCommand : public Command {
                AlignCheckCommand(string);      
                AlignCheckCommand();
                ~AlignCheckCommand(){}
-               vector<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();    
-               
+       
+               vector<string> setParameters();
+               string getCommandName()                 { return "align.check";                         }
+               string getCommandCategory()             { return "Sequence Processing";         }
+               string getHelpString(); 
+       
+               int execute(); 
+               void help() { m->mothurOut(getHelpString()); }  
+       
        private:
                vector<int> structMap;
                string mapfile, fastafile, outputDir, namefile;
                bool abort;
                int seqLength, haderror;
                vector<string> outputNames;
-               map<string, vector<string> > outputTypes;
                map<string, int> nameMap;
                
                void readMap();
index 6a22fd686096e83308faf7a68e98e9391d722fe0..7f5d9dc05ff88882f90680a4f9281908102b573c 100644 (file)
 #include "sensspeccommand.h"
 
 //**********************************************************************************************************************
-vector<string> SensSpecCommand::getValidParameters(){  
+vector<string> SensSpecCommand::setParameters(){       
        try {
-               string Array[] =  {"list", "phylip", "column", "name", "hard", "label", "cutoff", "precision", "outputdir", "inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["sensspec"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SensSpecCommand", "SensSpecCommand");
+               m->errorOut(e, "SensSpecCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> SensSpecCommand::getRequiredParameters(){       
+string SensSpecCommand::getHelpString(){       
        try {
-               string Array[] =  {"list","phylip","column","or"};
-               vector<string> 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<string> SensSpecCommand::getRequiredFiles(){    
+SensSpecCommand::SensSpecCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> 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(){
index 5e25afd2098e2fed0385178eecfcfd60a65fb461..c690d5704652b3b68635614e4cf0b6e65050278e 100644 (file)
@@ -19,13 +19,15 @@ class SensSpecCommand : public Command {
 public:
        SensSpecCommand(string);
        SensSpecCommand();
-       ~SensSpecCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~SensSpecCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
 
        long int truePositives, falsePositives, trueNegatives, falseNegatives;
        bool abort;
index 5a0cc02fab59de9960e6626b4cbcc87e8ce82d1f..f0ff08691899d6f83c852aca4ee94bf0111fd1ee 100644 (file)
 #include "refchimeratest.h"
 
 //**********************************************************************************************************************
-vector<string> SeqErrorCommand::getValidParameters(){  
+vector<string> SeqErrorCommand::setParameters(){       
        try {
-               string Array[] =  {"query", "reference", "name", "qfile", "report", "threshold", "ignorechimeras", "inputdir", "outputdir"};
-               vector<string> 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<string> 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<string> SeqErrorCommand::getRequiredParameters(){       
-       try {
-               string Array[] =  {"query","reference"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SeqErrorCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> SeqErrorCommand::getRequiredFiles(){    
-       try {
-               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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(){
index 1194d42f2dfca3a8eedf3d379a7bd3aa3bd50661..19fcd4731d22edc39383003b62c796242b7a4363 100644 (file)
@@ -43,13 +43,15 @@ class SeqErrorCommand : public Command {
 public:
        SeqErrorCommand(string);
        SeqErrorCommand();
-       ~SeqErrorCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~SeqErrorCommand() {}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        
        vector<Sequence> referenceSeqs;
        vector<vector<int> > substitutionMatrix;
index 8c13e7fbbd76895b751ae982b8df9a093e1c1ca9..911e65fc9f8696834448ff9b3451b53e43f496b6 100644 (file)
 #include "sequence.hpp"
 
 //**********************************************************************************************************************
-vector<string> SeqSummaryCommand::getValidParameters(){        
+vector<string> SeqSummaryCommand::setParameters(){     
        try {
-               string Array[] =  {"fasta","name","processors","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> SeqSummaryCommand::getRequiredParameters(){     
-       try {
-               string Array[] =  {"fasta"};
-               vector<string> 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<string> SeqSummaryCommand::getRequiredFiles(){  
+SeqSummaryCommand::SeqSummaryCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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;
index 24c29a107b8189778c62b2eeb49258957a321be6..623c3c1e8f400f4262414a5cf546143d698840e7 100644 (file)
@@ -17,20 +17,20 @@ class SeqSummaryCommand : public Command {
 public:
        SeqSummaryCommand(string);
        SeqSummaryCommand();
-       ~SeqSummaryCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~SeqSummaryCommand(){}
        
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        map<string, int> nameMap;
        
        struct linePair {
index a4f5c5c1f7ac756c1803bb25dfd7a95133477580..16685b24c7c706d0c6cf5aa9d15da2e08e863112 100644 (file)
 #include "setcurrentcommand.h"
 
 //**********************************************************************************************************************
-vector<string> SetCurrentCommand::getValidParameters(){        
+vector<string> 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<string> 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<string> 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<string> SetCurrentCommand::getRequiredParameters(){     
+string SetCurrentCommand::getHelpString(){     
        try {
-               vector<string> 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<string> SetCurrentCommand::getRequiredFiles(){  
+SetCurrentCommand::SetCurrentCommand(){        
        try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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 {
                
index 98033b7b8d8bb4f1e68c5b62df4ddd97e239a35e..5a40e4a20f97377e86d973c2412cc17e12e3fcb0 100644 (file)
@@ -18,18 +18,19 @@ class SetCurrentCommand : public Command {
 public:
        SetCurrentCommand(string);
        SetCurrentCommand();
-       ~SetCurrentCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~SetCurrentCommand() {}
+       
+       vector<string> setParameters();
+       string getCommandName()                 { return "set.current"; }
+       string getCommandCategory()             { return "General";             }
+       string getHelpString(); 
+       
+       int execute(); 
+       void help() { m->mothurOut(getHelpString()); }  
        
 private:
        
        vector<string> outputNames;
-       map<string, vector<string> > outputTypes;
        bool abort;
        
        string clearTypes;
index a76db24282e2c00032ec747de2d1d5decf20e095..16e93b5e4f5e8feeb864693a3d4a96ac75b9ed61 100644 (file)
 #include "setdircommand.h"
 
 //**********************************************************************************************************************
-vector<string> SetDirectoryCommand::getValidParameters(){      
-       try {
-               string Array[] =  {"output","input","tempdefault","outputdir","inputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SetDirectoryCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> SetDirectoryCommand::getRequiredParameters(){   
+vector<string> 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<string> 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<string> SetDirectoryCommand::getRequiredFiles(){        
+string SetDirectoryCommand::getHelpString(){   
        try {
-               vector<string> 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();  
index 6263c5eb9a55c391a0a91adf657b82d2be97d6cf..0d12e05be43ce8ec055fa5a9bdc39dad62f9bca2 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       SetDirectoryCommand() { abort = true; calledHelp = true; setParameters(); }
+       ~SetDirectoryCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
+       
                
 };
 
index f57dfafeacd9caae5711f56c17c3102e083567f0..00e702c7b86d3d7bd16dfa5a162250f49402dae1 100644 (file)
@@ -9,38 +9,37 @@
 
 #include "setlogfilecommand.h"
 
+
 //**********************************************************************************************************************
-vector<string> SetLogFileCommand::getValidParameters(){        
+vector<string> SetLogFileCommand::setParameters(){     
        try {
-               string Array[] =  {"name","append","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> SetLogFileCommand::getRequiredParameters(){     
+string SetLogFileCommand::getHelpString(){     
        try {
-               string Array[] =  {"name"};
-               vector<string> 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<string> SetLogFileCommand::getRequiredFiles(){  
-       try {
-               vector<string> 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(){}
 
 //**********************************************************************************************************************
 
index e0555d00a185559841902dc232a4a603819df0dc..0c0347b61ac7620e925c59717ee03085917a2688 100644 (file)
@@ -20,20 +20,21 @@ class SetLogFileCommand : public Command {
 public:
        SetLogFileCommand(string);
        SetLogFileCommand() { abort = true; calledHelp = true; }
-       ~SetLogFileCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~SetLogFileCommand(){}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
                
 };
 
index f9f6db6cead382e12e85068ac66d56b4b7c7d148..fda9604fc9fd1128094076d315549accb77fab5e 100644 (file)
 #include "endiannessmacros.h"
 
 //**********************************************************************************************************************
-vector<string> SffInfoCommand::getValidParameters(){   
-       try {
-               string Array[] =  {"sff","qfile","fasta","flow","trim","accnos","sfftxt","outputdir","inputdir", "outputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+vector<string> 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<string> 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<string> tempOutNames;
                outputTypes["fasta"] = tempOutNames;
                outputTypes["flow"] = tempOutNames;
@@ -38,29 +74,6 @@ SffInfoCommand::SffInfoCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> SffInfoCommand::getRequiredParameters(){        
-       try {
-               string Array[] =  {"sff", "sfftxt", "or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SffInfoCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> SffInfoCommand::getRequiredFiles(){     
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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 {
index 0fdf6fce6647269d476945031255bb585e78ba83..0e242afa2f3eab6e53b1d8927c1658aecee97fc6 100644 (file)
@@ -64,13 +64,15 @@ class SffInfoCommand : public Command {
 public:
        SffInfoCommand(string);
        SffInfoCommand();
-       ~SffInfoCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~SffInfoCommand(){}
+       
+       vector<string> 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<string> seqNames;
-       map<string, vector<string> > outputTypes;
        
        //extract sff file functions
        int extractSffInfo(string, string);
index 731f981f7a7b9c14d7f0f9033671cc274b43595b..179424b3c9f395ce88774b00aa7f367581d8f775 100644 (file)
 //sorts lowest to highest
 inline bool compareSharedRabunds(SharedRAbundVector* left, SharedRAbundVector* right){
        return (left->getGroup() < right->getGroup());  
-} 
-//**********************************************************************************************************************
-vector<string> SharedCommand::getValidParameters(){    
-       try {
-               vector<string> myArray; 
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SharedCommand", "getValidParameters");
-               exit(1);
-       }
 }
 //**********************************************************************************************************************
-SharedCommand::SharedCommand(){        
-       try {           
+vector<string> 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<string> tempOutNames;
-               outputTypes["rabund"] = tempOutNames;
-               outputTypes["shared"] = tempOutNames;
+               vector<string> 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<string> SharedCommand::getRequiredParameters(){ 
+string SharedCommand::getHelpString(){ 
        try {
-               vector<string> 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<string> SharedCommand::getRequiredFiles(){      
+SharedCommand::SharedCommand(){        
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               //initialize outputTypes
+               vector<string> 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<string> 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<groups.size(); i++) {
-                       temp = new ofstream;
-                       filehandles[groups[i]] = temp;
+               else {
+                       
+                        //valid paramters for this command
+                        string Array[] =  {"list","label","group","groups","ordergroup","outputdir","inputdir"};
+                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                        
+                        OptionParser parser(option);
+                        map<string, string> parameters = parser.getParameters();
+                        
+                        ValidParameters validParameter;
+                        map<string, string>::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; i<Groups.size(); i++) {
+                               temp = new ofstream;
+                               filehandles[Groups[i]] = temp;
+                       }
+                       
+                       //set fileroot
+                       fileroot = outputDir + m->getRootName(m->getSimpleName(listfile));
+                       
+                       //clears file before we start to write to it below
+                       for (int i=0; i<Groups.size(); i++) {
+                               remove((fileroot + Groups[i] + ".rabund").c_str());
+                               outputNames.push_back((fileroot + Groups[i] + ".rabund"));
+                               outputTypes["rabund"].push_back((fileroot + Groups[i] + ".rabund"));
+                       }
+                       
                }
                
-               //set fileroot
-               fileroot = outputDir + m->getRootName(m->getSimpleName(globaldata->getListFile()));
-               
-               //clears file before we start to write to it below
-               for (int i=0; i<groups.size(); i++) {
-                       remove((fileroot + groups[i] + ".rabund").c_str());
-                       outputNames.push_back((fileroot + groups[i] + ".rabund"));
-                       outputTypes["rabund"].push_back((fileroot + groups[i] + ".rabund"));
-               }
-
        }
        catch(exception& e) {
                m->errorOut(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<SharedRAbundVector*> 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; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
-                       return 1
+                       for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                       return 0
                }
                                
-               if ((globaldata->Groups.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<string> processedLabels;
-               set<string> userLabels = globaldata->labels;    
+               set<string> 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; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
-                               return 1
+                               for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                               return 0
                        }
                
-                       if(globaldata->allLines == 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; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
-                                               return 1
+                                               for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                                               return 0
                                        }
                                        
                                        printSharedData(lookup); //prints info to the .shared file
@@ -240,12 +336,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; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
-                                               return 1
+                                               for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                                               return 0
                                        }
                                        
                                        printSharedData(lookup); //prints info to the .shared file
@@ -286,11 +382,11 @@ int SharedCommand::execute(){
                        }
                        
                        if (m->control_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; i<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
-                                       return 1
+                                       for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                                       return 0
                        }
                        
                        printSharedData(lookup); //prints info to the .shared file
@@ -298,27 +394,18 @@ int SharedCommand::execute(){
                        delete SharedList;
                }
                
-               globaldata->gSharedList = 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<groups.size(); i++) {  remove((fileroot + groups[i] + ".rabund").c_str());              }
-                               return 1
+                               for (int i=0; i<Groups.size(); i++) {  remove((fileroot + Groups[i] + ".rabund").c_str());              }
+                               return 0
                }
                
                //set rabund file as new current rabundfile
@@ -353,14 +440,14 @@ void SharedCommand::printSharedData(vector<SharedRAbundVector*> 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<SharedRAbundVector*> 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<SharedRAbundVector*> 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<SharedRAbundVector*>& 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()){
index 2c5ab237a2d39b006dee4eca4e9b9b2c65a57ebe..f1e7c48cd71ee7ff1984e43cb7bb5676a3ee42a5 100644 (file)
@@ -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.  
        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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help() {}
+       
+       vector<string> 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<SharedRAbundVector*>);
@@ -42,17 +41,15 @@ private:
        int readOrderFile();
        bool isValidGroup(string, vector<string>);
        int eliminateZeroOTUS(vector<SharedRAbundVector*>&);
-       map<string, vector<string> > outputTypes;
        
-       GlobalData* globaldata;
-       ReadOTUFile* read;
        SharedListVector* SharedList;
        InputData* input;
        GroupMap* groupMap;
-       vector<string> groups, outputNames, order;
+       vector<string> Groups, outputNames, order;
+       set<string> labels;
        ofstream out;
-       string filename, fileroot, outputDir;
-       bool firsttime, pickedGroups;
+       string filename, fileroot, outputDir, listfile, groupfile, ordergroupfile;
+       bool firsttime, pickedGroups, abort, allLines;
        map<string, ofstream*> filehandles;
        map<string, ofstream*>::iterator it3;
 
index 26ad1269cc55df28a47007364e8627b61dc7a7b8..f80a8d427ef027a725609e5814c0aaf713b87819 100644 (file)
@@ -88,8 +88,7 @@ EstOutput SharedJackknife::getValues(vector<SharedRAbundVector*> 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) {
index a2488932e6c1fb2ae68b304df44b5feb994220a9..9f4ef724cdf770da3d19a5ebd16dec36af43cc25 100644 (file)
@@ -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<SharedRAbundVector*>);
        
 private:
-       GlobalData* globaldata;
        int numGroups, callCount, count;
        bool currentCallDone;
        vector<SharedRAbundVector*> groups;
index 1493ee99622602d914af8ca61400b522e4701132..3852c0cb508cb77b79198df1b50da87053cff399 100644 (file)
 
 /***********************************************************************/
 
-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<SharedRAbundVector*> SharedListVector::getSharedRAbundVector() {
                map<string, SharedRAbundVector*> 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]]);
                        }
                }
        
index 0586dfff3ce56dbaae588639f14331c312b3fb84..56ea802a1b1bca511454f83ddcb9e8f29bd5ed27 100644 (file)
@@ -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<string> data;  //data[i] is a list of names of sequences in the ith OTU.
-       GlobalData* globaldata;
        GroupMap* groupmap;
        int maxRank;
        int numBins;
index 15ee7fc4e414988f86bca49ccd38070a2d96ef22..37cd28315a5c1928e965f7be8eef7ae0ef408692 100644 (file)
@@ -28,10 +28,9 @@ SharedOrderVector::SharedOrderVector(string id, vector<individual>  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<num;i++){
                        f >> 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<num;i++){
                                f >> 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<SharedRAbundVector*> SharedOrderVector::getSharedRAbundVector() {
                util = new SharedUtil();
                vector<SharedRAbundVector*> 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;
        }
index 6aa8ba1c1ed0dc6ef49f1aa5d8becac971852126..09d4959a0c741f8df9aa3bcb564d940d4825097d 100644 (file)
@@ -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<SharedRAbundVector*> getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups
        
 private:
-       GlobalData* globaldata;
        GroupMap* groupmap;
        vector<individual>  data; 
        map< int, vector<individual> >::iterator it;
index d65cc204cc97bd43941928bad593b515522625e6..6c2dea195fdea527678277633ad08f9fbe4fc795 100644 (file)
 
 /***********************************************************************/
 
-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<num;i++){
@@ -84,11 +79,7 @@ SharedRAbundFloatVector::SharedRAbundFloatVector(ifstream& f) : DataVector(), ma
                        f >> 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*> 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--; 
index b0d84916134478516504eba4d583a58d00ac5be0..06fb6044818709520d1d1ef9abd6a25368926424 100644 (file)
@@ -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<individualFloat>  data; 
        vector<SharedRAbundFloatVector*> lookup;
-       GlobalData* globaldata;
-       GroupMap* groupmap;
+       //GlobalData* globaldata;
+       //GroupMap* groupmap;
        float maxRank;
        int numBins;
        float numSeqs;
index a050ab3fe71998b5a8a6abf2b34b0e67f0083808..1440ee1135dfac48dfef52a7d47df39c56264eaa 100644 (file)
@@ -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<individual> 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<num;i++){
@@ -112,12 +104,7 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0),
                        f >> 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*> 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); 
index beece8e14a1082d7347a62fdc0e95ebcd24a9cc2..887478f2964b7d16407135d45905d977b1040ddf 100644 (file)
@@ -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<individual>  data; 
        vector<SharedRAbundVector*> lookup;
-       GlobalData* globaldata;
-       GroupMap* groupmap;
+       //GlobalData* globaldata;
+       //GroupMap* groupmap;
        int maxRank;
        int numBins;
        int numSeqs;
index d2a43eabb6ee5f832ddba748474ce2ba0b1f16a1..15f16a6f1942921ca41098dd502750d68c75ce3e 100644 (file)
@@ -305,7 +305,7 @@ bool SharedUtil::isValidGroup(string groupname, vector<string> groups) {
        }
 }
 
-/**************************************************************************************/
+/**************************************************************************************
 void SharedUtil::updateGroupIndex(vector<string>& userGroups, map<string, int>& index) {
        try {
                index.clear();
@@ -318,3 +318,6 @@ void SharedUtil::updateGroupIndex(vector<string>& userGroups, map<string, int>&
                exit(1);
        }
 }
+/**************************************************************************************/
+
+
index df7e8d3091d811285f15cb49402053ec09a4f535..9892173ff293590223ae285304402a55981bdac8 100644 (file)
@@ -28,7 +28,7 @@ class SharedUtil {
                void setGroups(vector<string>&, vector<string>&, string);  //globaldata->Groups, your tree or group map, mode
                void setGroups(vector<string>&, vector<string>&, string&, int&, string);  //globaldata->Groups, your tree or group map, allgroups, numGroups, mode
                void getCombos(vector<string>&, vector<string>, int&); //groupcomb, globaldata->Groups, numcomb
-               void updateGroupIndex(vector<string>&, map<string, int>&); //globaldata->Groups, groupmap->groupIndex
+               //void updateGroupIndex(vector<string>&, map<string, int>&); //globaldata->Groups, groupmap->groupIndex
                bool isValidGroup(string, vector<string>);
                
        private:
index 024fbab7221c328a02958d34084e4704da55b150..74669ed0d9dba0425c81e74852482a62e4f29b46 100644 (file)
 #define MIN_WEIGHT 0.1
 #define MIN_TAU 0.0001
 #define MIN_ITER 10
-
 //**********************************************************************************************************************
-
-vector<string> ShhherCommand::getValidParameters(){    
+vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               vector<string> 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<string> 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<string> ShhherCommand::getRequiredParameters(){ 
+ShhherCommand::ShhherCommand(){        
        try {
-               string Array[] =  {"flow"};
-               vector<string> 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<string> tempOutNames;
+               outputTypes["pn.dist"] = tempOutNames;
 
-vector<string> ShhherCommand::getRequiredFiles(){      
-       try {
-               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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);
                
index 51a5c3cc46fcad5ab70393bc0e153ffe6715b121..8d29d86e0ec606379e471a363dbe33af34336d8e 100644 (file)
 
 #include "mothur.h"
 #include "command.hpp"
-#include "globaldata.hpp"
+
 
 class ShhherCommand : public Command {
        
 public:
        ShhherCommand(string);
        ShhherCommand();
-       ~ShhherCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~ShhherCommand() {}
+       
+       vector<string> 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<string, vector<string> > outputTypes;
        
        string outputDir, flowFileName, flowFilesFileName, lookupFileName, compositeFASTAFileName;
 
index bdfbeae8f845fc235ac3d115367a13ac61ff883e..810b83915dadb9ed8863340dcfb27ac34e286dd8 100644 (file)
 #include "splitabundcommand.h"
 
 //**********************************************************************************************************************
-vector<string> SplitAbundCommand::getValidParameters(){        
-       try {
-               string Array[] =  {"name","group","list","label","accnos","groups","fasta","cutoff","outputdir","inputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+vector<string> 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<string> 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<string> tempOutNames;
                outputTypes["list"] = tempOutNames;
                outputTypes["name"] = tempOutNames;
@@ -38,29 +75,6 @@ SplitAbundCommand::SplitAbundCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> SplitAbundCommand::getRequiredParameters(){     
-       try {
-               string Array[] =  {"fasta","list","name","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SplitAbundCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> SplitAbundCommand::getRequiredFiles(){  
-       try {
-               vector<string> 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;  } 
 }
index 2e409b2aedd7606b6c689f48cb9e0e58f7a0bcfe..c883a690d9846febec2059b4d88ea1393ea2f52c 100644 (file)
@@ -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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
-
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        ListVector* list;
        GroupMap* groupMap;
        InputData* input;
index 16d90a48372f7c97d46f7fd4d0b640fde6b533fb..bdb6e7c0151b10cb96fc6d0aa59d66199dba2e6f 100644 (file)
 #include "sharedutilities.h"
 
 //**********************************************************************************************************************
-vector<string> SplitGroupCommand::getValidParameters(){        
-       try {
-               string Array[] =  {"name","group","groups","fasta","outputdir","inputdir"}; 
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+vector<string> 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<string> 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<string> SplitGroupCommand::getRequiredParameters(){     
+string SplitGroupCommand::getHelpString(){     
        try {
-               string Array[] =  {"fasta","group"};
-               vector<string> 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<string> SplitGroupCommand::getRequiredFiles(){  
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SplitGroupCommand", "getRequiredFiles");
+               m->errorOut(e, "SplitGroupCommand", "getHelpString");
                exit(1);
        }
 }
@@ -49,6 +53,7 @@ vector<string> SplitGroupCommand::getRequiredFiles(){
 SplitGroupCommand::SplitGroupCommand(){        
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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 {
        
index c45c7ff6b386111ba34897c3e13ff213e832b79f..6705ba98e3ab9ebd165429260828632eca43ede4 100644 (file)
@@ -25,21 +25,21 @@ class SplitGroupCommand : public Command {
 public:
        SplitGroupCommand(string);      
        SplitGroupCommand();
-       ~SplitGroupCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
-
+       ~SplitGroupCommand() {}
+       
+       vector<string> 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<string> outputNames;
-       map<string, vector<string> > outputTypes;
        map<string, vector<string> > nameMap;
        map<string, vector<string> >::iterator itNames;
        GroupMap* groupMap;
index d24bcc5ad616b324b444f929ec3be57716dd05de..5bc49d6503e8a3f24b35933129cb36a11cf08587 100644 (file)
 #include "sharedutilities.h"
 
 //**********************************************************************************************************************
-vector<string> SubSampleCommand::getValidParameters(){ 
-       try {
-               string Array[] =  {"fasta", "group", "list","shared","rabund","persample", "name","sabund","size","groups","label","outputdir","inputdir"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+vector<string> 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<string> 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<string> SubSampleCommand::getValidParameters(){
 SubSampleCommand::SubSampleCommand(){  
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> tempOutNames;
                outputTypes["shared"] = tempOutNames;
                outputTypes["list"] = tempOutNames;
@@ -41,43 +81,16 @@ SubSampleCommand::SubSampleCommand(){
        }
 }
 //**********************************************************************************************************************
-vector<string> SubSampleCommand::getRequiredParameters(){      
-       try {
-               string Array[] =  {"fasta","list","shared","rabund", "sabund","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SubSampleCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> SubSampleCommand::getRequiredFiles(){   
-       try {
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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(){
index b00defdd9d63e797675d8a7809e32fe1d92d6a63..6716903105f2fc25d018b77d977d6fa57875a148 100644 (file)
  */
  
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~SubSampleCommand() {}
        
-private:
-       GlobalData* globaldata;
+       vector<string> 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<string> labels; //holds labels to be used
        string groups, label, outputDir;
        vector<string> Groups, outputNames;
-       map<string, vector<string> > outputTypes;
        int size;
        vector<string> names;
        map<string, vector<string> > nameMap;
index fbe7964e67f7eb52600bbab1bde5dc28d3ef3a1f..cc4b69f27259fae22b74a17e0dd4826b476cce3f 100644 (file)
 #include "shen.h"
 
 //**********************************************************************************************************************
-vector<string> SummaryCommand::getValidParameters(){   
+vector<string> SummaryCommand::setParameters(){        
        try {
-               string Array[] =  {"label","calc","abund","size","outputdir","groupmode","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["summary"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SummaryCommand", "SummaryCommand");
+               m->errorOut(e, "SummaryCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> SummaryCommand::getRequiredParameters(){        
+string SummaryCommand::getHelpString(){        
        try {
-               vector<string> 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<string> SummaryCommand::getRequiredFiles(){     
+SummaryCommand::SummaryCommand(){      
        try {
-               string AlignArray[] =  {"shared","list","rabund","sabund","or"};
-               vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["summary"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "SummaryCommand", "getRequiredFiles");
+               m->errorOut(e, "SummaryCommand", "SummaryCommand");
                exit(1);
        }
 }
@@ -85,22 +97,18 @@ vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::iterator it;
                        
                        ValidParameters validParameter;
                        
@@ -113,14 +121,91 @@ SummaryCommand::SummaryCommand(string option)  {
                        vector<string> 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; i<Estimators.size(); i++) {
-                               if (validCalculator->isValidCalculator("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;i<sumCalculators.size();i++){
                                if(sumCalculators[i]->getCols() == 1){
                                        outputFileHandle << '\t' << sumCalculators[i]->getName();
@@ -309,11 +357,11 @@ int SummaryCommand::execute(){
                        set<string> processedLabels;
                        set<string> 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;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = 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;i<sumCalculators.size();i++){  delete sumCalculators[i]; }  delete sabund;  delete input;  return 0;  }
                        
                        while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                                
-                               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;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = 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;i<sumCalculators.size();i++){  delete sumCalculators[i]; }  delete sabund;  delete input;  return 0;  }
                                
                                if(allLines == 1 || labels.count(sabund->getLabel()) == 1){                     
                                        
@@ -325,7 +373,7 @@ int SummaryCommand::execute(){
                                        for(int i=0;i<sumCalculators.size();i++){
                                                vector<double> 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;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = 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;i<sumCalculators.size();i++){  delete sumCalculators[i]; }  delete sabund;  delete input;  return 0;  }
 
                                                outputFileHandle << '\t';
                                                sumCalculators[i]->print(outputFileHandle);
@@ -348,7 +396,7 @@ int SummaryCommand::execute(){
                                        for(int i=0;i<sumCalculators.size();i++){
                                                vector<double> 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;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = 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;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete sabund;  delete input;  return 0;  }
                                                
                                                outputFileHandle << '\t';
                                                sumCalculators[i]->print(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;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read;  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;i<sumCalculators.size();i++){  delete sumCalculators[i]; }   delete input;  return 0;  }
 
                        //output error messages about any remaining user labels
                        set<string>::iterator it;
@@ -391,7 +439,7 @@ int SummaryCommand::execute(){
                                for(int i=0;i<sumCalculators.size();i++){
                                        vector<double> 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;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = 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;i<sumCalculators.size();i++){  delete sumCalculators[i]; }  delete sabund;  delete input; return 0;  }
 
                                        outputFileHandle << '\t';
                                        sumCalculators[i]->print(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;i<sumCalculators.size();i++){  delete sumCalculators[i]; } delete validCalculator; delete read;  delete input; globaldata->ginput = NULL; return 0;  }
+                       if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) {       remove(outputNames[i].c_str());  } for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; }   delete input;  return 0;  }
 
                        
-                       delete input;  globaldata->ginput = NULL;
-                       delete read;
-                       delete validCalculator;
-                       globaldata->sabund = NULL;
+                       delete input;  
                        for(int i=0;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
                }
                
-               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;  }
                
                //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<string> SummaryCommand::parseSharedFile(string filename) {
                map<string, ofstream*> filehandles;
                map<string, ofstream*>::iterator it3;
                
-                               
-               //read first line
-               read = new ReadOTUFile(filename);       
-               read->read(&*globaldata); 
-                       
-               input = globaldata->ginput;
+               input = new InputData(filename, "sharedfile");
                vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
                
                string sharedFileRoot = m->getRootName(filename);
@@ -482,9 +520,8 @@ vector<string> 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);
index d225109359d4950ad88be6a1ff41dd49cf062251..5535237c98f97d32cacf3f967cb2501199a76473 100644 (file)
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~SummaryCommand(){}
+       
+       vector<string> 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<Calculator*> sumCalculators;     
        InputData* input;
-       ValidCalculators* validCalculator;
        SAbundVector* sabund;
        int abund, size;
 
        bool abort, allLines, groupMode;
        set<string> labels; //holds labels to be used
-       string label, calc, outputDir;
+       string label, calc, outputDir, sharedfile, listfile, rabundfile, sabundfile, format, inputfile;
        vector<string>  Estimators;
        vector<string> inputFileNames, outputNames;
-       map<string, vector<string> > outputTypes;
        vector<string> groups;
        
        vector<string> parseSharedFile(string);
index b5214448cd2a5e8f8af0b70bfc700ee05465d4af..6db7dab85b9b51ae798aaed4df4bc581adc5db6d 100644 (file)
 #include "mempearson.h"
 
 //**********************************************************************************************************************
-vector<string> SummarySharedCommand::getValidParameters(){     
+vector<string> SummarySharedCommand::setParameters(){  
        try {
-               string Array[] =  {"label","calc","groups","all","outputdir","distance","inputdir", "processors"};
-               vector<string> 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<string> 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<string> 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<string> SummarySharedCommand::getRequiredParameters(){  
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SummarySharedCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> SummarySharedCommand::getRequiredFiles(){       
+SummarySharedCommand::SummarySharedCommand(){  
        try {
-               string Array[] =  {"shared"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["summary"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "SummarySharedCommand", "getRequiredFiles");
+               m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand");
                exit(1);
        }
 }
@@ -101,22 +114,18 @@ vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
+                       map<string, string>::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<string> 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; i<Estimators.size(); i++) {
-                                       if (validCalculator->isValidCalculator("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;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
-                       globaldata->Groups.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;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
-                               globaldata->Groups.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;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
-                       globaldata->Groups.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;i<sumCalculators.size();i++){  delete sumCalculators[i]; }
-               delete input;  globaldata->ginput = NULL;
+               delete input;  
                
                if (m->control_pressed) {
                        remove(outAllFileName.c_str());  
index 077181220a836f6b118f68008996b411f81822fa..3d177e7a71967225011f6077a6597b4ac3b2486c 100644 (file)
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~SummarySharedCommand() {}
+       
+       vector<string> 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<linePair> lines;
-       GlobalData* globaldata;
-       ReadOTUFile* read;
        vector<Calculator*> sumCalculators;     
        InputData* input;
-       ValidCalculators* validCalculator;
        
        bool abort, allLines, mult, all, createPhylip;
        set<string> labels; //holds labels to be used
-       string label, calc, groups;
+       string label, calc, groups, sharedfile;
        vector<string>  Estimators, Groups, outputNames;
-       map<string, vector<string> > outputTypes;
        vector<SharedRAbundVector*> lookup;
        string format, outputDir;
        int numGroups, processors;
index abc07d0743a0a3e8f7172c27fe4094571abb3d5c..6b0a6d06474809f16fae1a0c17338ef1f7458dc7 100644 (file)
@@ -9,41 +9,8 @@
 
 #include "systemcommand.h"
 
-//**********************************************************************************************************************
-vector<string> SystemCommand::getValidParameters(){    
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SystemCommand", "getValidParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> SystemCommand::getRequiredParameters(){ 
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "SystemCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> SystemCommand::getRequiredFiles(){      
-       try {
-               vector<string> 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");
index 55b772b71ddaa62767746d7543f61ae09a5b5e39..892ac96268baeb2557c51cc67dd0fc571ea4dbfa 100644 (file)
@@ -20,18 +20,20 @@ class SystemCommand : public Command {
                SystemCommand(string);  
                SystemCommand() { abort = true; calledHelp = true; }
                ~SystemCommand(){}
-               vector<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();
-               void help();    
-               
+       
+               vector<string> 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<string> outputNames;
-               map<string, vector<string> > outputTypes;
+               
                
 };
 
index 02f400407cfaa5f8c9283fa4f96d8bbc2fb0c3d8..53aa4025bef940b9d3fcb830e6686760338ee8ef 100644 (file)
--- 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<string> 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<string, string>::iterator itNames = globaldata->names.find(name);
+                       map<string, string>::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<string> dupNames;
-                               m->splitAtComma(globaldata->names[name], dupNames);
+                               m->splitAtComma(m->names[name], dupNames);
                                
                                map<string, int>::iterator itCounts;
                                int maxPars = 1;
                                set<string> 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<string> Groups) {
                                tree[i].setName(Groups[i]);
                                
                                //save group info
-                               string group = globaldata->gTreemap->getGroup(Groups[i]);
+                               string group = tmap->getGroup(Groups[i]);
                                vector<string> tempGroups; tempGroups.push_back(group);
                                tree[i].setGroup(tempGroups);
                                groupNodeInfo[group].push_back(i); 
@@ -284,7 +283,7 @@ void Tree::getSubTree(Tree* copy, vector<string> 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<Node>& 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<string> 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<Node>& 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 0b316c3042f01cbb000a3aed975a778f8af5f9fc..2d9d4f815f90bd889c10b886853ca415840060f5 100644 (file)
--- a/tree.h
+++ b/tree.h
  */
 
 #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<int> > 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;
index 07999f6a1ff89499fd92b9429191704b51545f61..e5b7e74a7d71343af56fcb0dc6c54a18b61afd73 100644 (file)
 #include "mempearson.h"
 
 //**********************************************************************************************************************
-vector<string> TreeGroupCommand::getValidParameters(){ 
+vector<string> TreeGroupCommand::setParameters(){      
        try {
-               string Array[] =  {"label","calc","groups", "phylip", "column", "name", "precision","cutoff","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> 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<string> TreeGroupCommand::getRequiredParameters(){      
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "TreeGroupCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> TreeGroupCommand::getRequiredFiles(){   
+TreeGroupCommand::TreeGroupCommand(){  
        try {
-               string Array[] =  {"phylip","column","shared","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true;
+               setParameters();
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["tree"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "TreeGroupCommand", "getRequiredFiles");
+               m->errorOut(e, "TreeGroupCommand", "TreeGroupCommand");
                exit(1);
        }
 }
@@ -103,20 +120,14 @@ vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string, string> 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; i<Estimators.size(); i++) {
-                                               if (validCalculator->isValidCalculator("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; i<Estimators.size(); i++) {
+                               if (validCalculator.isValidCalculator("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());
+                                       }
+                               }
+                       }
+                       
                        //if the users entered no valid calculators don't execute command
                        if (treeCalculators.size() == 0) { m->mothurOut("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<SharedRAbundVector*> 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++) { 
index c61c9fbfa63bf84a2482955ca20aa914f89b9400..6bb35f26056ea14873b3b8d76773c207ab83243b 100644 (file)
@@ -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<PCell>::iterator MatData;
 
@@ -37,12 +35,14 @@ public:
        TreeGroupCommand(string);       
        TreeGroupCommand();
        ~TreeGroupCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();  
-       void help();
+       
+       vector<string> 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<float> > simMatrix;
        map<int, int> index;  //maps row in simMatrix to vector index in the tree       
        InputData* input;
-       ValidCalculators* validCalculator;
        vector<SharedRAbundVector*> lookup;
        string lastLabel;
-       string format, outputFile, groupNames, filename;
+       string format, outputFile, groupNames, filename, sharedfile, inputfile;
        int numGroups;
        ofstream out;
        float precision, cutoff;
-       map<string, vector<string> > outputTypes;
 
        bool abort, allLines;
        set<string> labels; //holds labels to be used
index 52a90031d380fedddd275bd5ebbb6a3f8600964c..75423855a7f583ae5ce62fc10118cf260589df6b 100644 (file)
@@ -170,13 +170,13 @@ void TreeMap::print(ostream& output){
 }
 
 /************************************************************/
-void TreeMap::makeSim(GroupMap* groupmap) {
+void TreeMap::makeSim(vector<string> 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++) {
index d4b506e6fb1d26675937f89f2cc1591e21a98c07..9f10f375660be529a2b2b53e6a87745d426bba19 100644 (file)
--- a/treemap.h
+++ b/treemap.h
@@ -42,7 +42,7 @@ public:
     map<string,int> seqsPerGroup;      //groupname, number of seqs in that group.
        map<string, GroupIndex> treemap; //sequence name and <groupname, vector index>
        void print(ostream&);
-       void makeSim(GroupMap*);  //takes groupmap info and fills treemap for use by tree.shared command.
+       void makeSim(vector<string>);  //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:
index bf80ee8cb3ea18ed3d363816eda22d0a501e141f..e6c6fdf8bd61099bca9b73fc5a106d4aaa692602 100644 (file)
 #include "needlemanoverlap.hpp"
 
 //**********************************************************************************************************************
-
-vector<string> TrimFlowsCommand::getValidParameters(){ 
+vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "TrimFlowsCommand", "getValidParameters");
-               exit(1);
-       }
-}
-
-//**********************************************************************************************************************
-
-vector<string> TrimFlowsCommand::getRequiredParameters(){      
-       try {
-               string Array[] =  {"flow"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               vector<string> 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<string> TrimFlowsCommand::getRequiredFiles(){   
+string TrimFlowsCommand::getHelpString(){      
        try {
-               vector<string> 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<string> TrimFlowsCommand::getRequiredFiles(){
 TrimFlowsCommand::TrimFlowsCommand(){  
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                                               
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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";              }
index 7458dbe60b90f52c900e3ffd8fb645ccce0d0e86..0514a53edc62362d3b95118d5d5e501fd2ef0b2e 100644 (file)
@@ -20,13 +20,15 @@ class TrimFlowsCommand : public Command {
 public:
        TrimFlowsCommand(string);
        TrimFlowsCommand();
-       ~TrimFlowsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~TrimFlowsCommand() {}
+       
+       vector<string> 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<vector<string> >); 
        int driverCreateTrim(string, string, string, string, vector<vector<string> >, linePair*);
 
-       
-       map<string, vector<string> > outputTypes;
        vector<string> outputNames;
        set<string> filesToRemove;
        
-       
-       
        void getOligos(vector<vector<string> >&);               //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
index 6924ffc5b8f1e8b3de357692167b5b0dbeb316e1..9ff75df7dc98571ec8585f50ff4cf3de0b4f5fed 100644 (file)
 #include "needlemanoverlap.hpp"
 
 //**********************************************************************************************************************
-
-vector<string> TrimSeqsCommand::getValidParameters(){  
+vector<string> 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<string> 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<string> 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<string> 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<string> TrimSeqsCommand::getRequiredParameters(){       
-       try {
-               string Array[] =  {"fasta"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "TrimSeqsCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
 
 //**********************************************************************************************************************
 
-vector<string> TrimSeqsCommand::getRequiredFiles(){    
+TrimSeqsCommand::TrimSeqsCommand(){    
        try {
-               vector<string> myArray;
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> 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(){
index d40cfe3c5604d66009ba22b568b0df71f3688faa..2d0eabc1aa5a1504d23d1fc146f525504f3213f9 100644 (file)
@@ -20,13 +20,15 @@ class TrimSeqsCommand : public Command {
 public:
        TrimSeqsCommand(string);
        TrimSeqsCommand();
-       ~TrimSeqsCommand();
-       vector<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~TrimSeqsCommand(){}
+       
+       vector<string> 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<string, vector<string> > outputTypes;
 
        bool abort;
        string fastaFile, oligoFile, qFileName, groupfile, outputDir;
index 5c0d5839c355e28c7a51e4a0433a840bd35a545f..a8c656cb5c5ffdc4a1e0fb3fd62e8eed0f1bb25f 100644 (file)
 #include "unifracunweightedcommand.h"
 
 //**********************************************************************************************************************
-vector<string> UnifracUnweightedCommand::getValidParameters(){ 
+vector<string> UnifracUnweightedCommand::setParameters(){      
        try {
-               string Array[] =  {"groups","iters","distance","random","root", "processors","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
                outputTypes["unweighted"] = tempOutNames;
                outputTypes["uwsummary"] = tempOutNames;
@@ -37,36 +72,11 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(){
                exit(1);
        }
 }
-//**********************************************************************************************************************
-vector<string> UnifracUnweightedCommand::getRequiredParameters(){      
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "UnifracUnweightedCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> UnifracUnweightedCommand::getRequiredFiles(){   
-       try {
-               string Array[] =  {"tree","group"};
-               vector<string> 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<string,string> parameters = parser.getParameters();
+                       map<string,string>::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<string, string>::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<float> > 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<float> > 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; r<globaldata->Groups.size(); r++) { 
+               for (int r=0; r<m->Groups.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; r<globaldata->Groups.size(); r++) { 
+               for (int r=0; r<m->Groups.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<string, string>::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<string> 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);
+       }
 }
 /***********************************************************/
 
 
 
+
index cd46b62b3462a4db2baa57865743d4bb37c198a7..f462d51f9b5b7022d61b0a521f2526475350b034 100644 (file)
 #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<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
+               ~UnifracUnweightedCommand() {}
+       
+               vector<string> 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<Tree*> T;           //user trees
@@ -41,7 +42,7 @@ class UnifracUnweightedCommand : public Command {
                Unweighted* unweighted;
                string sumFile, allGroups;
                vector<string> 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<float> > utreeScores; //scores for users trees for each comb.
@@ -51,16 +52,17 @@ class UnifracUnweightedCommand : public Command {
                vector< map<float, float> > rCumul;  //map <unweighted score, cumulative percentage of number of random trees with that score or higher.> -vector entry for each combination.
                
                bool abort, phylip, random, includeRoot;
-               string groups, itersString, outputDir, outputForm;
+               string groups, itersString, outputDir, outputForm, treefile, groupfile, namefile;
                vector<string> Groups, outputNames; //holds groups to be used
-               map<string, vector<string> > outputTypes;
 
                ofstream outSum, out;
                ifstream inFile;
+               map<string, string> nameMap;
                
                void printUWSummaryFile(int);
                void printUnweightedFile();
                void createPhylipFile(int);
+               int readNamesFile();
                 
                
 };
index d5212009b46003b4046c5f8e2895321edbcb907d..29cdf94091cebb65104e1b5691e5691e19a4e495 100644 (file)
 #include "unifracweightedcommand.h"
 
 //**********************************************************************************************************************
-vector<string> UnifracWeightedCommand::getValidParameters(){   
+vector<string> UnifracWeightedCommand::setParameters(){        
        try {
-               string Array[] =  {"groups","iters","distance","random","processors","root","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> UnifracWeightedCommand::getValidParameters(){
 UnifracWeightedCommand::UnifracWeightedCommand(){      
        try {
                abort = true; calledHelp = true; 
+               setParameters();
                vector<string> tempOutNames;
                outputTypes["weighted"] = tempOutNames;
                outputTypes["wsummary"] = tempOutNames;
@@ -36,47 +72,21 @@ UnifracWeightedCommand::UnifracWeightedCommand(){
                exit(1);
        }
 }
-//**********************************************************************************************************************
-vector<string> UnifracWeightedCommand::getRequiredParameters(){        
-       try {
-               vector<string> myArray;
-               return myArray;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "UnifracWeightedCommand", "getRequiredParameters");
-               exit(1);
-       }
-}
-//**********************************************************************************************************************
-vector<string> UnifracWeightedCommand::getRequiredFiles(){     
-       try {
-               string Array[] =  {"tree","group"};
-               vector<string> 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<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters=parser.getParameters();
+                       map<string,string>::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<string, string>::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<numComp; s++) {
@@ -228,7 +318,7 @@ int UnifracWeightedCommand::execute() {
                                vector< vector<string> > namesOfGroupCombos;
                                for (int a=0; a<numGroups; a++) { 
                                        for (int l = 0; l < a; l++) {   
-                                               vector<string> groups; groups.push_back(globaldata->Groups[a]); groups.push_back(globaldata->Groups[l]);
+                                               vector<string> 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<string> > na
 /**************************************************************************************************/
 int UnifracWeightedCommand::driver(Tree* t, vector< vector<string> > namesOfGroupCombos, int start, int num, vector< vector<double> >& 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<float> > 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<float> > 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; r<globaldata->Groups.size(); r++) { 
+                       for (int r=0; r<m->Groups.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; r<globaldata->Groups.size(); r++) { 
+                       for (int r=0; r<m->Groups.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<string, string>::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<string> 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);
+       }
+}
 /***********************************************************/
 
 
index 2eee7c44e674073420c217f1b4d49aa4dc769497..612b64abcfad0804c6981100dc6bdb12ebb5d219 100644 (file)
 #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<string> getRequiredParameters();
-               vector<string> getValidParameters();
-               vector<string> getRequiredFiles();
-               map<string, vector<string> > getOutputFiles() { return outputTypes; }
-               int execute();  
-               void help();
+               ~UnifracWeightedCommand() {}
+       
+               vector<string> 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<linePair> lines;
                
-               GlobalData* globaldata;
+               ReadTree* read;
                SharedUtil* util;
                FileOutput* output;
                vector<Tree*> T;           //user trees
@@ -61,13 +61,11 @@ class UnifracWeightedCommand : public Command {
                map<float, float>  validScores;  //map contains scores from random
                
                bool abort, phylip, random, includeRoot;
-               string groups, itersString, outputForm;
+               string groups, itersString, outputForm, treefile, groupfile, namefile;
                vector<string> Groups, outputNames; //holds groups to be used
-               map<string, vector<string> > outputTypes;
-               int processors;
-
-               
+               int processors, numUniquesInName;
                ofstream outSum;
+               map<string, string> nameMap;
                
                void printWSummaryFile();
                void printWeightedFile();  
@@ -77,6 +75,7 @@ class UnifracWeightedCommand : public Command {
                void calculateFreqsCumuls();
                int createProcesses(Tree*,  vector< vector<string> >,  vector< vector<double> >&);
                int driver(Tree*, vector< vector<string> >, int, int,  vector< vector<double> >&);
+               int readNamesFile();
                
 };
 
index a75ddc54058f878f63c579a4834754cb3890a374..90b6476543d67ee92d7c59624e2af8da2a7b2345 100644 (file)
 
 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<numGroups; r++) { 
                        for (int l = 0; l < r; l++) {
                                numComp++;
-                               vector<string> groups; groups.push_back(globaldata->Groups[r]); groups.push_back(globaldata->Groups[l]);
+                               vector<string> 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<string> > 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<numGroups; r++) { 
                        for (int l = 0; l < r; l++) {
                                numComp++;
-                               vector<string> groups; groups.push_back(globaldata->Groups[r]); groups.push_back(globaldata->Groups[l]);
+                               vector<string> 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<string> > namesOfGroupCombo
                
                int count = 0;
                
-               Tree* copyTree = new Tree;
+               Tree* copyTree = new Tree(tmap);
                
                for (int h = start; h < (start+num); h++) {
                
index 0ccfab55ad9500f46f33d74e1c1c19f95ec525ba..e751d2e79d19f17a2dd3a9af34ea11be95586ef4 100644 (file)
@@ -32,7 +32,6 @@ class Unweighted : public TreeCalculator  {
                };
                vector<linePair> lines;
                
-               GlobalData* globaldata;
                EstOutput data;
                TreeMap* tmap;
                int processors;
index f8c7cc3352e9281defb720c24d15ebda4337a44d..2798b53ba50c8f3ffd50a20fcaa7462d62a071a7 100644 (file)
@@ -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);
+       }
+}
+/********************************************************************/
+
 
index bf8819f4f317df5337c75975afd2e165ce376bcd..6cdd4ae3d9cc48176b1a525723b5b5c1cc78fdd2 100644 (file)
@@ -24,6 +24,7 @@ class ValidCalculators {
                ~ValidCalculators();
                bool isValidCalculator(string, string);
                void printCalc(string, ostream&);
+               string printCalc(string);
                
        private:
                map<string, string> single;
index cf77a921e3c58cb6c6db8fbd6c38d5a0a369bff6..cd14785b776723d10672f6c5de11505bfc5bdafe 100644 (file)
--- a/venn.cpp
+++ b/venn.cpp
 
 
 //**********************************************************************************************************************
-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<string> Venn::getPic(SAbundVector* sabund, vector<Calculator*> vCalcs) {
                vector<string> outputNames;
 
                for(int i=0;i<vCalcs.size();i++){
-                       string filenamesvg = outputDir + m->getRootName(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<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = outputDir + m->getRootName(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<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                        
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
-                               string filenamesvg = outputDir + m->getRootName(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<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                        //make a file for each calculator
                        for(int i=0;i<vCalcs.size();i++){
                        
-                               string filenamesvg = outputDir + m->getRootName(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<string> Venn::getPic(vector<SharedRAbundVector*> lookup, vector<Calculato
                                
                                if ((vCalcs[i]->getName() != "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 33935e6a2c9496fd984b8328cf33326dbeb23fa1..c5c5f6f80991a6751f2671a03d6e9c1459cd8c38 100644 (file)
--- 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"
 
 
 
 class Venn {
 public:
-       Venn(string, bool);
+       Venn(string, bool, string);
        ~Venn(){};
 
        vector<string> getPic(SAbundVector*, vector<Calculator*>);
        vector<string> getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
 
 private:
-       GlobalData* globaldata;
        Calculator* singleCalc;
-       string groupComb, outputDir;
+       string groupComb, outputDir, inputfile;
        ofstream outsvg;
        MothurOut* m;
        bool nseqs;
index 5cc0fea3affdfa6d021ff93bef964f478400f5bc..c66d1e368595ed5104984dd189cdb768185e70fb 100644 (file)
 #include "sharedace.h"
 #include "nseqs.h"
 
-
 //**********************************************************************************************************************
-vector<string> VennCommand::getValidParameters(){      
+vector<string> VennCommand::setParameters(){   
        try {
-               string Array[] =  {"groups","label","calc","permute", "abund","nseqs","outputdir","inputdir"};
-               vector<string> 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<string> 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<string> tempOutNames;
-               outputTypes["svg"] = tempOutNames;
-       }
-       catch(exception& e) {
-               m->errorOut(e, "VennCommand", "VennCommand");
+               m->errorOut(e, "VennCommand", "setParameters");
                exit(1);
        }
 }
 //**********************************************************************************************************************
-vector<string> VennCommand::getRequiredParameters(){   
+string VennCommand::getHelpString(){   
        try {
-               vector<string> 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<string> VennCommand::getRequiredFiles(){        
+VennCommand::VennCommand(){    
        try {
-               string Array[] =  {"list","shared","or"};
-               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
-               return myArray;
+               abort = true; calledHelp = true; 
+               setParameters();
+               vector<string> tempOutNames;
+               outputTypes["svg"] = tempOutNames;
        }
        catch(exception& e) {
-               m->errorOut(e, "VennCommand", "getRequiredFiles");
+               m->errorOut(e, "VennCommand", "VennCommand");
                exit(1);
        }
 }
@@ -69,21 +82,18 @@ vector<string> 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<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
+                       map<string,string>::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; i<Estimators.size(); i++) {
-                                               if (validCalculator->isValidCalculator("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; i<Estimators.size(); i++) {
-                                               if (validCalculator->isValidCalculator("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; i<Estimators.size(); i++) {
+                               if (validCalculator.isValidCalculator("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 (int i=0; i<Estimators.size(); i++) {
+                               if (validCalculator.isValidCalculator("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(); 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();
index 29beeadc32f422f8b053e1da86f483032e496e8d..fe0e2a6c1a9a063e9eb08527c64b23703153fed0 100644 (file)
  
 #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<string> getRequiredParameters();
-       vector<string> getValidParameters();
-       vector<string> getRequiredFiles();
-       map<string, vector<string> > getOutputFiles() { return outputTypes; }
-       int execute();
-       void help();
+       ~VennCommand() {}
+       
+       vector<string> 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<Calculator*> vennCalculators;    
-       ValidCalculators* validCalculator;
        vector<SharedRAbundVector*> lookup;
        set< set<int> > combosOfFour;
        SAbundVector* sabund;
@@ -48,9 +42,8 @@ private:
        
        bool abort, allLines, nseqs, perm;
        set<string> labels; //holds labels to be used
-       string format, groups, calc, label, outputDir;
+       string format, groups, calc, label, outputDir, sharedfile, listfile, inputfile;
        vector<string> Estimators, Groups, outputNames;
-       map<string, vector<string> > outputTypes;
        
        set< set<int> > findCombinations(int);
        int getCombos(set<int>, set< set<int> >&);
index cae2b92885632b697852babccd84d463b7a78564..d0defc3394b8aa3dc7010837c12ad4a8d0cfc472 100644 (file)
 
 EstOutput Weighted::getValues(Tree* t, int p, string o) {
     try {
-               globaldata = GlobalData::getInstance();
-               
                data.clear(); //clear out old values
                int numGroups;
                vector<double> 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<string> groups; groups.push_back(globaldata->Groups[i]); groups.push_back(globaldata->Groups[l]);
+                               vector<string> 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<string> > namesOfGroupCombos,
 /**************************************************************************************************/
 EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { 
  try {
-               globaldata = GlobalData::getInstance();
                
                data.clear(); //clear out old values
                
index d78edf4d49ffd17e24f8eb559747a43952ad522a..c23a11599b4b8d74fdfacd05a5a02ae727834455 100644 (file)
@@ -33,7 +33,6 @@ class Weighted : public TreeCalculator  {
                };
                vector<linePair> lines;
 
-               GlobalData* globaldata;
                EstOutput data;
                TreeMap* tmap;
                map<string, int>::iterator it;