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 */,
#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);
}
}
AlignCommand::AlignCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
outputTypes["alignreport"] = tempOutNames;
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();
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);
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"; }
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; }
+
}
}
}
}
//**********************************************************************************************************************
-
AlignCommand::~AlignCommand(){
if (abort == false) {
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(){
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);
}
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 {
vector<int> processIDS; //processid
vector<linePair*> lines;
bool MPIWroteAccnos;
- map<string, vector<string> > outputTypes;
AlignmentDB* templateDB;
Alignment* alignment;
#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;
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();
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);
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(){
*/
#include "command.hpp"
-
-//class GlobalData;
class GroupMap;
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);
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;
#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);
}
}
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();
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);
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 {
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> >);
#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);
}
}
BinSeqCommand::BinSeqCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
}
//**********************************************************************************************************************
BinSeqCommand::BinSeqCommand(string option) {
try {
- globaldata = GlobalData::getInstance();
abort = false; calledHelp = false;
allLines = 1;
labels.clear();
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();
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 = ""; }
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()){
//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...
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 = ""; }
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) {
}
//**********************************************************************************************************************
-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(){
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;
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());
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());
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;
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(); }
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
#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*);
//**************************************************************************************************/
-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)
*/
#include "mothur.h"
-#include "globaldata.hpp"
+
class BlastAlignment : public Alignment {
float mismatch;
float gapOpen;
float gapExtend;
- GlobalData* globaldata;
};
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();
BlastDB::BlastDB() : Database() {
try {
- globaldata = GlobalData::getInstance();
count = 0;
int randNumber = rand();
//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
*/
#include "mothur.h"
-#include "globaldata.hpp"
class BlastDB : public Database {
float gapExtend;
float match;
float misMatch;
- GlobalData* globaldata;
};
#endif
#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
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);
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) {
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();
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();
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());
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());
}
- 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;
}
}
- 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) {
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();
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;
}
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++) {
if (m->control_pressed) { return 1; }
//print newick file
- t->print(*out);
+ t->print(*out);*/
return 0;
/***********************************************************/
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);
}
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
}
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++) {
//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;
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;
}
#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 {
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;
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;
-
};
#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;
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();
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 {
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"){
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 {
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);
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++) {
}
string summaryfilename = combineSummmary(sumNames);
outputNames.push_back(summaryfilename); outputTypes["summary"].push_back(summaryfilename);
-
- globaldata->setSharedFile(sharedfile); globaldata->setFormat("sharedfile");
}
m->mothurOutEndLine();
#include "command.hpp"
#include "inputdata.h"
-#include "readotu.h"
#include "sabundvector.hpp"
/*
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);
#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);
}
}
ChimeraBellerophonCommand::ChimeraBellerophonCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["chimera"] = tempOutNames;
outputTypes["accnos"] = tempOutNames;
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();
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
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"; }
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{
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:
int processors, window, increment, numSeqs;
Chimera* chimera;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
vector<string> fastaFileNames;
};
#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);
}
}
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();
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
//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 = ""; }
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"; }
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{
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:
Chimera* chimera;
vector<string> fastaFileNames;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
-
-
};
/***********************************************************/
#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);
}
}
ChimeraCheckCommand::ChimeraCheckCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["chimera"] = tempOutNames;
}
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();
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
//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 = ""; }
}
}
- 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"; }
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(){
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 {
vector<string> fastaFileNames;
vector<string> nameFileNames;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
-
};
/***********************************************************/
#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);
}
}
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();
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");
//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
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"; }
//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; }
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(){
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 {
int processors, window, increment, numSeqs, templateSeqsLength;
Chimera* chimera;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
vector<string> fastaFileNames;
-
-
};
/***********************************************************/
+++ /dev/null
-/*
- * 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;
-}
-//**********************************************************************************************************************
-
-
+++ /dev/null
-#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
-
#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);
}
}
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();
//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
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"; }
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(){
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 {
Chimera* chimera;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
vector<string> fastaFileNames;
vector<string> nameFileNames;
#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);
}
}
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();
//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); }
}
//**********************************************************************************************************************
-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 {
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
#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{
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();
//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);
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(){
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:
vector<string> outputNames;
map<string, string> nameMap;
map<string, string> taxMap;
- map<string, vector<string> > outputTypes;
int readNamesFile();
int readTaxonomyFile();
//**********************************************************************************************************************
-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);
}
}
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();
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");
}
//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;
}
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);
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"; }
}
//**********************************************************************************************************************
-
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(){
#include "mothur.h"
#include "command.hpp"
-//#include "alignment.hpp"
#include "classify.h"
//KNN and Bayesian methods modeled from algorithms in
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 {
vector<string> outputNames;
map<string, vector<string> > nameMap;
map<string, vector<string> >::iterator itNames;
- map<string, vector<string> > outputTypes;
Classify* classify;
#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);
}
}
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();
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; }
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 {
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;
+
};
/****************************************************************************/
#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
cutoff = c;
aboveCutoff = cutoff + 10000.0;
m = MothurOut::getInstance();
- globaldata = GlobalData::getInstance();
}
catch(exception& e) {
m->errorOut(e, "ClusterClassic", "ClusterClassic");
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;
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; }
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; }
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; }
#include "mothur.h"
#include "mothurout.h"
#include "listvector.hpp"
-#include "globaldata.hpp"
#include "rabundvector.hpp"
+#include "nameassignment.hpp"
/*
* clusterclassic.h
class ClusterClassic {
public:
- ClusterClassic(float, string);
+ ClusterClassic(float, string, bool);
int readPhylipFile(string, NameAssignment*);
void update(double&);
double getSmallDist() { return smallDist; }
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
*/
#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);
}
}
//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;
}
//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
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);
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(){
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;
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;
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();
*/
#include "command.hpp"
-#include "globaldata.hpp"
#include "rabundvector.hpp"
#include "sabundvector.hpp"
#include "listvector.hpp"
#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).
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;
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;
void printData(string label);
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
};
#endif
#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);
}
}
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();
//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
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"; }
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(){
}
//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; }
#include "command.hpp"
#include "nameassignment.hpp"
-#include "globaldata.hpp"
#include "rabundvector.hpp"
#include "sabundvector.hpp"
#include "listvector.hpp"
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;
void printData(string label);
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
};
#endif
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);
}
}
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();
//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); }
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 {
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;
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();
//**********************************************************************************************************************
-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);
}
}
ClusterSplitCommand::ClusterSplitCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["list"] = tempOutNames;
outputTypes["rabund"] = tempOutNames;
}
}
//**********************************************************************************************************************
-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 = "";
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();
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 = ""; }
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
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") {
//**********************************************************************************************************************
-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 {
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
#include "listvector.hpp"
#include "cluster.hpp"
#include "sparsematrix.hpp"
-#include "globaldata.hpp"
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;
/***********************************************************************/
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();
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;
}
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
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++;
}
#include "rabundvector.hpp"
#include "sharedordervector.h"
#include "datavector.hpp"
-#include "globaldata.hpp"
#include "mothurout.h"
/***********************************************************************/
private:
SharedOrderVector* sharedorder;
- GlobalData* globaldata;
OrderVector* order;
vector<Display*> displays;
int numSeqs, numGroupComb, totalNumSeq;
#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);
}
}
CollectCommand::CollectCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["sobs"] = tempOutNames;
outputTypes["chao"] = tempOutNames;
//**********************************************************************************************************************
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;
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...
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 {
}
//**********************************************************************************************************************
-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();
}
//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;
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;
}
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;
}
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;
}
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;
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();
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);
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
delete it3->second;
}
- delete read;
+
delete input;
- globaldata->ginput = NULL;
return filenames;
}
#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;
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;
#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);
}
}
CollectSharedCommand::CollectSharedCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["sharedchao"] = tempOutNames;
outputTypes["sharedsobs"] = tempOutNames;
//**********************************************************************************************************************
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;
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..
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 {
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"; }
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");
}
}
//**********************************************************************************************************************
-
-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(){
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();
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;
}
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;
}
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;
}
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();
#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 {
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
#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;
};
*/
#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"
#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"
/*******************************************************/
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";
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";
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); }
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); }
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;
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); }
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); }
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;
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(); }
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(); }
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;
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
#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);
}
}
ConcensusCommand::ConcensusCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["tree"] = tempOutNames;
outputTypes["nodepairs"] = tempOutNames;
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) {
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();
if (itTypes != outputTypes.end()) {
if ((itTypes->second).size() != 0) { currentTree = (itTypes->second)[0]; m->setTreeFile(currentTree); }
}
-
+ */
return 0;
}
catch(exception& e) {
#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;
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>);
#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);
}
}
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();
//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; }
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(){
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:
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;
#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);
}
}
CorrAxesCommand::CorrAxesCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["corr.axes"] = tempOutNames;
}
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();
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; }
}
//**********************************************************************************************************************
-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 {
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--;
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;
class SharedSAbundVector;
class SharedRAbundVector;
class SharedRAbundFloatVector;
+class GroupMap;
class DataVector {
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; }
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++) {
#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);
}
}
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();
//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"){
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 {
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;
};
#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);
}
}
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();
//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);
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{
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:
string fastafile, outputDir;
vector<string> outputNames;
vector<string> fastaFileNames;
- map<string, vector<string> > outputTypes;
+
};
#endif
#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);
}
}
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();
//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"){
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; }
+ }
}
}
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 {
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;
#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);
}
}
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();
//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);
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);
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(){
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 {
bool abort;
vector<string> Estimators, outputNames; //holds estimators to be used
- map<string, vector<string> > outputTypes;
//void m->appendFiles(string, string);
void createProcesses(string);
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;
}
/***********************************************************************/
//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);
//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) {
//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));
//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) {
#include "mothur.h"
-#include "globaldata.hpp"
#include "commandoptionparser.hpp"
#include "command.hpp"
#include "commandfactory.hpp"
#include "mothurout.h"
-class GlobalData;
-
class Engine {
public:
Engine();
virtual bool getInput();
int openedBatch;
private:
- GlobalData* globaldata;
ifstream inputBatchFile;
string getNextCommand(ifstream&);
~InteractEngine();
virtual bool getInput();
private:
- GlobalData* globaldata;
+
};
virtual bool getInput();
int openedBatch;
private:
- GlobalData* globaldata;
string listOfCommands;
string getNextCommand(string&);
#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);
}
}
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();
//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);
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);
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() {
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
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
/**************************************************************************/
//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;
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;
}
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);
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;
#include "mothur.h"
#include "groupmap.h"
-#include "globaldata.hpp"
#include "progress.hpp"
class FullMatrix {
public:
- FullMatrix(){ m = MothurOut::getInstance(); }
- FullMatrix(ifstream&);
+ //FullMatrix(){ m = MothurOut::getInstance(); }
+ FullMatrix(ifstream&, GroupMap*, bool);
~FullMatrix(){};
int getNumSeqs();
int numSeqs;
int numGroups;
int numUserGroups;
- GlobalData* globaldata;
+ bool sim;
MothurOut* m;
};
#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);
}
}
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();
}
//**********************************************************************************************************************
-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 {
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;
#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
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; }
}
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) {
}
//**********************************************************************************************************************
-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;
*/
#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;
#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;
}
}
//**********************************************************************************************************************
-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;
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();
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; }
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; }
}
//**********************************************************************************************************************
-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 {
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();
#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);
}
}
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;
+ }
+ }
+ }
+ }
+ }
+
}
}
}
//**********************************************************************************************************************
-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;
}
exit(1);
}
}
+//**********************************************************************************************************************
+
*/
#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
#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;
}
}
//**********************************************************************************************************************
-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;
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();
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);
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; }
-
}
}
}
//**********************************************************************************************************************
-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 {
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();
#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();
//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);
//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...
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) {
}
//**********************************************************************************************************************
-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))) {
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());
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());
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();
#include "command.hpp"
#include "inputdata.h"
#include "listvector.hpp"
-#include "readotu.h"
-
-class GlobalData;
/**********************************************************/
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;
string label, listfile, outputDir, sort;
ofstream out;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
-
+
void process(ListVector*);
};
/**********************************************************/
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();
//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);
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...
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 = "";
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; }
//**********************************************************************************************************************
-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
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();
// 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;
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();
}
- //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);
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.
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); }
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());
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());
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;
}
}
remove(distFile.c_str());
}
- globaldata->gListVector = NULL;
- delete input; globaldata->ginput = NULL;
- delete read;
+ delete input;
if (!weighted) { nameFileMap.clear(); }
}
delete fasta;
- if (groupfile != "") {
- delete groupMap; globaldata->gGroupmap = NULL;
- }
+ if (groupfile != "") { delete groupMap; }
if (m->control_pressed) { return 0; }
/* 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"
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;
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);
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
//**********************************************************************************************************************
-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);
}
}
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();
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 = ""; }
}
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; }
}
}
//**********************************************************************************************************************
-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 {
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;
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();
#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);
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) {
}
//**********************************************************************************************************************
-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
//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();
m->mothurOutEndLine();
out.close();
-
- globaldata->gListVector = NULL;
-
+
//set rabund file as new current rabundfile
string current = "";
itTypes = outputTypes.find("rabund");
#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
#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...
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"; }
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(){
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();
//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){
//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;
}
//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;}
#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&);
#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 = ""; }
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); }
+
+
}
}
}
//**********************************************************************************************************************
-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
//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();
#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
#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;
}
}
//**********************************************************************************************************************
-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;
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();
//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 = ""; }
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; }
-
}
}
}
//**********************************************************************************************************************
-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 {
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();
#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);
}
}
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();
//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; }
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;
}
else {
userGroups = groups;
m->splitAtDash(groups, Groups);
- globaldata->Groups = Groups;
+ m->Groups = Groups;
unique = false;
}
}
//**********************************************************************************************************************
-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 {
if (m->control_pressed) { delete groupMap; return 0; }
- globaldata->gGroupmap = groupMap;
-
if (Groups.size() == 0) {
Groups = groupMap->namesOfGroups;
//reset groups parameter
- globaldata->Groups.clear();
+ m->Groups.clear();
if (lastlist != NULL) { delete lastlist; }
#include "listvector.hpp"
#include "sequence.hpp"
#include "groupmap.h"
-#include "globaldata.hpp"
//**********************************************************************************************************************
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*);
-
+/*
#include "globaldata.hpp"
#include "sharedlistvector.h"
#include "inputdata.h"
/*******************************************************/
-/******************************************************/
+/******************************************************
GlobalData* GlobalData::getInstance() {
if( _uniqueInstance == 0) {
_uniqueInstance = new GlobalData();
}
/*******************************************************/
-/******************************************************/
+/******************************************************
// These functions give you the option parameters of the commands
string GlobalData::getPhylipFile() { return phylipfile; }
string GlobalData::getColumnFile() { return columnfile; }
/*******************************************************/
-/******************************************************/
+/******************************************************
GlobalData::GlobalData() {
m = MothurOut::getInstance();
//option definitions should go here...
}
/*******************************************************/
-/******************************************************/
+/******************************************************
void GlobalData::clear() {
//option definitions should go here...
phylipfile = ""; //do we need this?
/*******************************************************/
-/******************************************************/
+/******************************************************
void GlobalData::newRead() {
try{
//remove old file names
//******************************************************/
-/******************************************************/
+/*****************************************************
GlobalData::~GlobalData() {
_uniqueInstance = 0;
try {
#ifndef GLOBALDATA_HPP
#define GLOBALDATA_HPP
-
+/*
#include "mothur.h"
#include "groupmap.h"
#include "treemap.h"
class GlobalData {
public:
static GlobalData* getInstance();
- ListVector* gListVector;
- SparseMatrix* gSparseMatrix;
+ /*ListVector* gListVector;
+ //SparseMatrix* gSparseMatrix;
InputData* ginput;
OrderVector* gorder;
ListVector* glist;
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();
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
~GlobalData();
-};
+};*/
#endif
m->gobble(fileHandle);
}
fileHandle.close();
+ m->namesOfGroups = namesOfGroups;
return error;
}
/************************************************************/
m->gobble(fileHandle);
}
fileHandle.close();
+ m->namesOfGroups = namesOfGroups;
return error;
}
#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);
}
}
//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
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 = ""; }
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
//**********************************************************************************************************************
-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;
list = read->getListVector();
delete read;
}else {
- list = new ListVector(globaldata->nameMap->getListVector());
+ list = new ListVector(nameMap->getListVector());
}
if (m->control_pressed) {
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) {
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();
*/
#include "command.hpp"
-#include "globaldata.hpp"
#include "hcluster.h"
#include "rabundvector.hpp"
#include "sabundvector.hpp"
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;
time_t start;
unsigned long loops;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
void printData(string label);
};
#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;
outputDir = dir;
numOTU = num;
fontSize = fsize;
+ inputfile = i;
}
catch(exception& e) {
m->errorOut(e, "HeatMap", "HeatMap");
}
- 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
}
}
- 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
}
}
- 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
#include "sharedrabundvector.h"
#include "sharedrabundfloatvector.h"
#include "datavector.hpp"
-#include "globaldata.hpp"
+
/***********************************************************************/
struct binCount {
class HeatMap {
public:
- HeatMap(string, string, int, int, string);
+ HeatMap(string, string, int, int, string, string);
~HeatMap(){};
string getPic(RAbundVector*);
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;
#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);
}
}
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; }
}
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);
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"; }
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(){
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
}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
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){
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
}
//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){
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
string outputFileName = heatmap->getPic(rabund);
outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
- delete rabund; globaldata->rabund = NULL;
+ delete rabund;
}
}else {
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){
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
}
//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;
}
#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;
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;
#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();
}
//**********************************************************************************************************************
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);
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
//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++) {
#include "sharedrabundvector.h"
#include "datavector.hpp"
-#include "globaldata.hpp"
#include "calculator.h"
/***********************************************************************/
class HeatMapSim {
public:
- HeatMapSim(string);
+ HeatMapSim(string, string);
~HeatMapSim(){};
vector<string> getPic(vector<SharedRAbundVector*>, vector<Calculator*>);
private:
void printLegend(int, float);
- GlobalData* globaldata;
- string format, groupComb, outputDir;
+ string format, groupComb, outputDir, inputfile;
ofstream outsvg;
MothurOut* m;
#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);
}
}
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();
//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; }
//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();
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(){
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;
//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();
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){
}
- 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;
}
}
- 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) {
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;
}
#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();
#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);
exit(1);
}
}
-
//**********************************************************************************************************************/
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;
};
#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) {
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();
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);
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(){
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);
map<string, vector<int> > getRandomizedGroups(map<string, vector<int> >);
bool abort;
- map<string, vector<string> > outputTypes;
vector<string> outputNames;
string outputDir, inputDir, designFileName, phylipFileName;
#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;
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();
if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
- globaldata->newRead();
+ m->runParse = true;
vector<string> tempOutNames;
outputTypes["tree"] = tempOutNames;
//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; }
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; }
}
//**********************************************************************************************************************
-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 {
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);
}
/***************************************************/
}
//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; }
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;
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();
/***************************************************/
// 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;
}
/***************************************************/
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 = "";
#include "command.hpp"
#include "readtree.h"
#include "treemap.h"
-#include "globaldata.hpp"
#include "sharedrabundvector.h"
#include "sharedrabundfloatvector.h"
#include "inputdata.h"
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;
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 = "";
}
/***********************************************************************/
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;
}
}else if (format == "shared") {
SharedList = new SharedListVector(fileHandle);
+
if (SharedList != NULL) {
return SharedList->getSharedRAbundVector();
}
string thisLabel;
m->openInputFile(filename, in);
- globaldata->saveNextLabel = "";
+ m->saveNextLabel = "";
if(in){
if (format == "sharedfile") {
while (in.eof() != true) {
SharedList = new SharedListVector(in);
+
if (SharedList != NULL) {
thisLabel = SharedList->getLabel();
//if you are at the last label
string thisLabel;
m->openInputFile(filename, in);
- globaldata->saveNextLabel = "";
+ m->saveNextLabel = "";
if(in){
if (format == "relabund") {
map<string,int> orderMap;
string filename;
MothurOut* m;
- GlobalData* globaldata;
};
#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; }
}
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
else {
savegroups = groups;
m->splitAtDash(groups, Groups);
- globaldata->Groups = Groups;
+ m->Groups = Groups;
}
string temp;
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"; }
}
}
//**********************************************************************************************************************
-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);
}
}
}
- 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;
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(); }
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);
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++){
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);
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;
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) {
#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
#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);
}
}
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();
}
//**********************************************************************************************************************
-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 {
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;
#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);
}
}
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();
//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); }
}
//**********************************************************************************************************************
-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 {
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>);
#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) {
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();
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
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(){
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;
};
#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;
}
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 {
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();
}
//**********************************************************************************************************************
-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 {
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:
int iters;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
};
#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);
}
}
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; }
}
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
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);
}
}
-//**********************************************************************************************************************
-
-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;
}
}
//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();
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();
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;
}
}
- 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) {
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 = "";
}
}
- 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);
#include "command.hpp"
#include "inputdata.h"
#include "groupmap.h"
-#include "readotu.h"
#include "validcalculator.h"
// aka. dist.shared()
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 {
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;
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;
-
-
};
#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);
}
}
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();
exit(1);
}
}
-
-//**********************************************************************************************************************
-
-MergeFileCommand::~MergeFileCommand() { /* do nothing */ }
-
//**********************************************************************************************************************
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);
- }
-}
-
//**********************************************************************************************************************
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;
#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);
}
}
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();
//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...
groups = validParameter.validFile(parameters, "groups", false);
if (groups == "not found") { groups = "all"; }
m->splitAtDash(groups, Groups);
- globaldata->Groups = Groups;
+ m->Groups = Groups;
}
}
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(){
//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){
//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;
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;}
#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
#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);
}
}
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();
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);
//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
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);
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);
}
}
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(){
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();
//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){
//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;
}
//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;}
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];
#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 {
};
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;
#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();
//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
}
}
//**********************************************************************************************************************
-
-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 {
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;
}
#include "readblast.h"
#include "sparsematrix.hpp"
#include "nameassignment.hpp"
-#include "globaldata.hpp"
#include "cluster.hpp"
#include "hcluster.h"
+#include "rabundvector.hpp"
+#include "sabundvector.hpp"
/**********************************************************************/
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;
ListVector oldList;
vector<seqDist> overlapMatrix;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
string blastfile, method, namefile, overlapFile, distFile, outputDir;
ofstream sabundFile, rabundFile, listFile;
/**************************************************************************************************/
-GlobalData* GlobalData::_uniqueInstance = 0;
CommandFactory* CommandFactory::_uniqueInstance = 0;
MothurOut* MothurOut::_uniqueInstance = 0;
exit(1);
}
}
-
/**************************************************************************************************/
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
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; }
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); }
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();
oligosfile = "";
accnosfile = "";
taxonomyfile = "";
+ processors = "1";
};
~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;
#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);
}
}
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();
//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; }
}
}
//**********************************************************************************************************************
-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 {
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:
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&);
#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";
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;
};
#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);
}
}
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; }
}
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
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"; }
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(); }
-
}
}
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(){
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;
//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){
//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;
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) {
//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){
//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;
}
//reset groups parameter
- globaldata->Groups.clear();
+ m->Groups.clear();
delete input;
out.close();
#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*>&);
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;
}
}
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();
#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);
}
}
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();
}
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"){
}
//**********************************************************************************************************************
-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 {
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();
//**********************************************************************************************************************
-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;
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();
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);
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);
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(){
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 {
int end;
};
-
vector<int> processIDS; //end line, processid
vector<distlinePair> lines;
- map<string, vector<string> > outputTypes;
Alignment* alignment;
Dist* distCalculator;
#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);
}
}
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();
}
//**********************************************************************************************************************
-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; }
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;
#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);
}
}
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();
//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();
}
}
//**********************************************************************************************************************
-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 {
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*);
set<string> labels;
bool abort, allLines;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
map<string, ofstream*> filehandles;
map<string, ofstream*>::iterator it3;
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;
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);
}
}
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);
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++) {
#include "treecalculator.h"
#include "treemap.h"
-#include "globaldata.hpp"
/***********************************************************************/
};
vector<linePair> lines;
- GlobalData* globaldata;
EstOutput data;
TreeMap* tmap;
int processors;
#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();
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; }
}
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);
}
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;
}
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;
}
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();
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;
}
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;
}
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;
}
}
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;
}
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();
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) {
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);
+ }
+}
/***********************************************************/
#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
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.
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();
};
#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);
}
}
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();
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 = "";
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;
}
}
}
//**********************************************************************************************************************
-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 {
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) {
#include "command.hpp"
#include "linearalgebra.h"
-#include "globaldata.hpp"
-
+#include "sharedrabundfloatvector.h"
/*****************************************************************/
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*>);
#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);
}
}
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();
//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"){
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);
}
}
}
//**********************************************************************************************************************
-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 {
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);
*/
#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;
};
#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;
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);
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; }
}
//**********************************************************************************************************************
-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); }
//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);
}
}
//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
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)
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();
//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++){
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];
}
}
}
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;
}
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);
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'; }
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);
+ }
+}
+
//**********************************************************************************************************************
#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> >&);
#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);
}
}
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();
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);
}
/**********************************************************************************************************************/
-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 {
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;
#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 {
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();
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();
}
//**********************************************************************************************************************
-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; }
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();
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();
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;
//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
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));
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
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);
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;
//**********************************************************************************************************************
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);
}
}
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();
//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
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(){
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;
#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;
}
//**********************************************************************************************************************
-
-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;
}
-
//**********************************************************************************************************************
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
}
//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;
displays[i]->init(label);
}
- if (globaldata->jumble == true) {
+ if (m->jumble == true) {
//randomize the groups
random_shuffle(lookup.begin(), lookup.end());
}
#include "raredisplay.h"
#include "ordervector.hpp"
#include "mothur.h"
-#include "globaldata.hpp"
class Rarefact {
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;
#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;
//**********************************************************************************************************************
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; }
}
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);
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"; }
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);
}
}
//**********************************************************************************************************************
-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");
//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){
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;
}
}
- 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) {
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; }
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);
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
delete it3->second;
}
- delete read;
+
delete input;
- globaldata->ginput = NULL;
+ m->Groups.clear();
return filenames;
}
#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
#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);
}
}
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; }
}
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...
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"; }
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"; }
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;
}
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]; }
//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]; }
}
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
}
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
}
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();
#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;
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;
-
};
/***********************************************************************/
ReadCluster::ReadCluster(string distfile, float c, string o, bool s){
- globaldata = GlobalData::getInstance();
m = MothurOut::getInstance();
distFile = distfile;
cutoff = c;
for(int i=0;i<matrixNames.size();i++){
nameMap->push_back(matrixNames[i]);
}
- globaldata->nameMap = nameMap;
}
ListVector* getListVector() { return list; }
private:
- GlobalData* globaldata;
string distFile, outputDir;
string OutPutFile, format;
ListVector* list;
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;
+}
/***********************************************************************/
//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){
}
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);
public:
ReadColumnMatrix(string);
+ ReadColumnMatrix(string, bool);
~ReadColumnMatrix();
int read(NameAssignment*);
private:
#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)));
}
}
}
-
+*/
}
}
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;
}
m->mothurOut("It took " + toString(time(NULL) - start) + " secs to read "); m->mothurOutEndLine();
+ */
return 0;
}
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;
string phylipfile, columnfile, namefile, groupfile, outputDir;
NameAssignment* nameMap;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
bool abort, sim;
#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; }
protected:
SparseMatrix* D;
ListVector* list;
- GlobalData* globaldata;
float cutoff;
MothurOut* m;
bool sim;
#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 {
}
}
-/***********************************************************************/
+/***********************************************************************
ReadOTUFile::~ReadOTUFile(){
// delete input;
*
*/
-
+/*
#include "rabundvector.hpp"
#include "listvector.hpp"
// InputData* getInput() { return input; }
};
-
+*/
#endif
#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;
}
}
//**********************************************************************************************************************
-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;
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)));
//gets whichever one of the above is set
filename = globaldata->inputFileName;
}
+ */
}
}
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);
delete shared;
}
-
+ */
return 0;
}
#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;
ReadPhylipMatrix::ReadPhylipMatrix(string distFile){
successOpen = m->openInputFile(distFile, fileHandle);
+ sim=false;
}
+/***********************************************************************/
+
+ReadPhylipMatrix::ReadPhylipMatrix(string distFile, bool s){
+
+ successOpen = m->openInputFile(distFile, fileHandle);
+ sim=s;
+}
+
/***********************************************************************/
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);
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);
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);
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);
public:
ReadPhylipMatrix(string);
+ ReadPhylipMatrix(string, bool);
~ReadPhylipMatrix();
int read(NameAssignment*);
private:
/***********************************************************************/
ReadTree::ReadTree() {
try {
- globaldata = GlobalData::getInstance();
m = MothurOut::getInstance();
- globaldata->gTree.clear();
}
catch(exception& e) {
m->errorOut(e, "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 {
/***********************************************************************/
//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;
}
//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) {
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);
}
}
}
/**************************************************************************************************/
//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
}
//update treemap
- globaldata->gTreemap->namesOfSeqs.clear();
+ tmap->namesOfSeqs.clear();
/*char c;
string number, name;
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;
}
/**************************************************************************************************/
-int ReadNewickTree::readTreeString() {
+int ReadNewickTree::readTreeString(TreeMap* tmap) {
try {
int n = 0;
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()==','){
}
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");
}
/**************************************************************************************************/
-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; }
//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);
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);
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";
*/
#include "mothur.h"
-#include "globaldata.hpp"
#include "tree.h"
#define MAX_LINE 513
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;
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;
#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)));
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; }
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);
filename = treefile;
read = new ReadNewickTree(filename);
}
-
+ */
}
}
catch(exception& e) {
}
//**********************************************************************************************************************
-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++) {
globaldata->gTreemap = treeMap;
}
-
+ */
return 0;
}
catch(exception& e) {
/*****************************************************************/
int ReadTreeCommand::readNamesFile() {
try {
- globaldata->names.clear();
+ /*
+ m->names.clear();
numUniquesInName = 0;
ifstream in;
numUniquesInName++;
- itNames = globaldata->names.find(first);
+ itNames = m->names.find(first);
if (itNames == globaldata->names.end()) {
globaldata->names[first] = second;
}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) {
#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;
#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;
}
}
//**********************************************************************************************************************
-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;
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();
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; }
}
//**********************************************************************************************************************
-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 {
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();
#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;
}
}
//**********************************************************************************************************************
-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;
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);
}
//**********************************************************************************************************************
-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 {
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;
#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 {
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();
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 = ""; }
}
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; }
}
}
//**********************************************************************************************************************
-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 {
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;
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();
#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);
}
}
RemoveRareCommand::RemoveRareCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["rabund"] = tempOutNames;
outputTypes["sabund"] = tempOutNames;
}
}
//**********************************************************************************************************************
-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;
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();
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"; }
}
//**********************************************************************************************************************
-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 {
//**********************************************************************************************************************
int RemoveRareCommand::processShared(){
try {
- globaldata->Groups = Groups;
+ m->Groups = Groups;
string thisOutputDir = outputDir;
if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
#include "command.hpp"
#include "listvector.hpp"
-#include "globaldata.hpp"
+
class RemoveRareCommand : public Command {
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();
#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;
}
}
//**********************************************************************************************************************
-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;
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();
//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; }
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; }
}
}
}
//**********************************************************************************************************************
-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 {
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();
#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 {
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();
//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
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
}
}
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 */ }
-
//***************************************************************************************************************
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()){
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()){
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;
};
#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);
}
}
ScreenSeqsCommand::ScreenSeqsCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
outputTypes["name"] = tempOutNames;
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) {
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();
//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);
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();
}
}
+ 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);
}
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(){
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:
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();
#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);
}
}
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();
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; }
}
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(){
//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; }
}
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();
#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);
}
}
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)));
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"){
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(){
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();
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;
#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);
}
}
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) {
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();
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");
}
//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);
//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.");
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(){
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;
int maxLength;
ofstream errorSummaryFile, errorSeqFile;
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
vector<Sequence> referenceSeqs;
vector<vector<int> > substitutionMatrix;
#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);
}
}
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();
//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; }
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);
}
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(){
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;
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 {
#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);
}
}
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();
}
//**********************************************************************************************************************
-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 {
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;
#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);
}
}
}
//**********************************************************************************************************************
-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 {
//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();
//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();
#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();
#include "command.hpp"
#include "commandfactory.hpp"
-#include "globaldata.hpp"
/**********************************************************/
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;
+
};
#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);
}
}
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(){}
//**********************************************************************************************************************
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;
};
#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;
}
}
//**********************************************************************************************************************
-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 {
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();
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) {
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 {
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;
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);
//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");
//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();
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);
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;
}
}
//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();
}
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
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
}
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
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
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()]));
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++) {
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()]));
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()) {
order.clear();
ifstream in;
- m->openInputFile(globaldata->getOrderGroupFile(), in);
+ m->openInputFile(ordergroupfile, in);
string thisGroup;
while(!in.eof()){
#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*>);
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;
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) {
*/
#include "calculator.h"
-#include "globaldata.hpp"
/*This class implements the SharedJackknife estimator.
It is a child of the calculator class.*/
EstOutput getValues(vector<SharedRAbundVector*>);
private:
- GlobalData* globaldata;
int numGroups, callCount, count;
bool currentCallDone;
vector<SharedRAbundVector*> groups;
/***********************************************************************/
-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;
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]]);
}
}
#include "datavector.hpp"
#include "groupmap.h"
-#include "globaldata.hpp"
#include "sharedrabundvector.h"
#include "sharedsabundvector.h"
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; }
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;
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;
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;
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;
//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();
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;
}
#include "rabundvector.hpp"
#include "sharedrabundvector.h"
#include "sharedsabundvector.h"
-#include "globaldata.hpp"
#include "groupmap.h"
-//#include "globaldata.hpp"
-
-class GlobalData;
class SharedOrderVector : public DataVector {
vector<SharedRAbundVector*> getSharedRAbundVector(); //returns sharedRabundVectors for all the users groups
private:
- GlobalData* globaldata;
GroupMap* groupmap;
vector<individual> data;
map< int, vector<individual> >::iterator it;
/***********************************************************************/
-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++) {
//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;
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;
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++){
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();
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");
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--;
#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.
private:
vector<individualFloat> data;
vector<SharedRAbundFloatVector*> lookup;
- GlobalData* globaldata;
- GroupMap* groupmap;
+ //GlobalData* globaldata;
+ //GroupMap* groupmap;
float maxRank;
int numBins;
float numSeqs;
/***********************************************************************/
-
-SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {globaldata = GlobalData::getInstance();}
+SharedRAbundVector::SharedRAbundVector() : DataVector(), maxRank(0), numBins(0), numSeqs(0) {}
/***********************************************************************/
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++) {
//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;
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;
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++){
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();
if (f.eof() != true) { f >> nextLabel; }
}
- globaldata->saveNextLabel = nextLabel;
-
- if (globaldata->gGroupmap == NULL) { globaldata->gGroupmap = groupmap; }
+ m->saveNextLabel = nextLabel;
}
catch(exception& e) {
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);
#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.
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 {
private:
vector<individual> data;
vector<SharedRAbundVector*> lookup;
- GlobalData* globaldata;
- GroupMap* groupmap;
+ //GlobalData* globaldata;
+ //GroupMap* groupmap;
int maxRank;
int numBins;
int numSeqs;
}
}
-/**************************************************************************************/
+/**************************************************************************************
void SharedUtil::updateGroupIndex(vector<string>& userGroups, map<string, int>& index) {
try {
index.clear();
exit(1);
}
}
+/**************************************************************************************/
+
+
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:
#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);
}
}
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();
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);
m->mothurOut("The value of the order option must be four bases long\n");
}
- globaldata = GlobalData::getInstance();
}
#ifdef USE_MPI
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(){
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);
#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;
#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;
}
}
//**********************************************************************************************************************
-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;
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; }
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...
}
}
//**********************************************************************************************************************
-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; }
}
#include "groupmap.h"
#include "inputdata.h"
#include "listvector.hpp"
+#include "sequence.hpp"
/***************************************************************************************/
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*);
int createNameMap(ListVector*);
vector<string> outputNames;
- map<string, vector<string> > outputTypes;
ListVector* list;
GroupMap* groupMap;
InputData* input;
#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);
}
}
SplitGroupCommand::SplitGroupCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["fasta"] = tempOutNames;
outputTypes["name"] = tempOutNames;
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();
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 = ""; }
}
}
//**********************************************************************************************************************
-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 {
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;
#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);
}
}
SubSampleCommand::SubSampleCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["shared"] = tempOutNames;
outputTypes["list"] = tempOutNames;
}
}
//**********************************************************************************************************************
-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();
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"; }
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(){
*/
#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 {
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;
#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);
}
}
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;
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...
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"; }
}
//**********************************************************************************************************************
-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;
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) {
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"){
}
//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();
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){
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);
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);
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;
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);
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; }
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);
for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
delete it3->second;
}
- delete read;
+
delete input;
- globaldata->ginput = NULL;
return filenames;
}
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);
#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);
#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);
}
}
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;
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...
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 {
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"; }
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") {
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(){
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; }
}
}
}
-
- //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();
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);
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;
}
/******************************************************/
/******************************************************/
//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);
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;
}
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;
}
//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());
#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 {
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;
#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;
}
//**********************************************************************************************************************
-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");
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;
+
};
#include "tree.h"
/*****************************************************************/
-Tree::Tree(int num) {
+Tree::Tree(int num, TreeMap* t) : tmap(t) {
try {
- globaldata = GlobalData::getInstance();
m = MothurOut::getInstance();
numLeaves = 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");
}
}
/*****************************************************************/
-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);
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)) {
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
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;
}
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");
//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++) {
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);
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)) {
return (index++);
}else { //you are a leaf
- int indexInNewTree = globaldata->gTreemap->getIndex(oldtree[node].getName());
+ int indexInNewTree = tmap->getIndex(oldtree[node].getName());
return indexInNewTree;
}
}
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++){
}
}
}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;
}
}
}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;
//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;
//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();
}
//cout << "name = " << name << endl;
- globaldata->Treenames.push_back(name);
+ m->Treenames.push_back(name);
filehandle.putback(c);
//k = c;
//cout << " after putback" << k << endl;
*/
#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.
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;
#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);
}
}
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();
}
}
- 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);
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);
//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());
- }
- }
- }
- }
- }
}
}
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;
}
}
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; }
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); }
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; }
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();
}
//reset groups parameter
- globaldata->Groups.clear();
+ m->Groups.clear();
//set tree file as new current treefile
string current = "";
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
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++) {
#include "command.hpp"
#include "inputdata.h"
#include "groupmap.h"
-#include "readotu.h"
#include "validcalculator.h"
#include "tree.h"
#include "treemap.h"
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;
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();
int makeSimsShared();
int makeSimsDist();
- GlobalData* globaldata;
- ReadOTUFile* read;
ReadMatrix* readMatrix;
SparseMatrix* matrix;
NameAssignment* nameMap;
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
}
/************************************************************/
-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++) {
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:
#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);
}
}
TrimFlowsCommand::TrimFlowsCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["flow"] = tempOutNames;
outputTypes["fasta"] = tempOutNames;
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) {
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();
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"; }
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;
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
#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) {
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();
//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"){
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);
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(){
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:
bool cullAmbigs(Sequence&);
bool compareDNASeq(string, string);
int countDiffs(string, string);
- map<string, vector<string> > outputTypes;
bool abort;
string fastaFile, oligoFile, qFileName, groupfile, outputDir;
#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;
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; }
OptionParser parser(option);
map<string,string> parameters = parser.getParameters();
+ map<string,string>::iterator it;
ValidParameters validParameter;
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"; }
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
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;
}
-
}
}
}
}
-//**********************************************************************************************************************
-
-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
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;
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");
}
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++) {
//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
}
- 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);
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; }
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);
}
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];
}
//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 += " "; }
}
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 += " "; }
}
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);
+ }
}
/***********************************************************/
+
#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
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.
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();
};
#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);
}
}
UnifracWeightedCommand::UnifracWeightedCommand(){
try {
abort = true; calledHelp = true;
+ setParameters();
vector<string> tempOutNames;
outputTypes["weighted"] = tempOutNames;
outputTypes["wsummary"] = tempOutNames;
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;
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...
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"; }
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);
-
- }
}
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
//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++) {
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);
}
}
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();
}
- 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) {
/**************************************************************************************************/
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++) {
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);
}
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];
}
//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 += " "; }
}
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 += " "; }
}
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);
+ }
+}
/***********************************************************/
#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 {
};
vector<linePair> lines;
- GlobalData* globaldata;
+ ReadTree* read;
SharedUtil* util;
FileOutput* output;
vector<Tree*> T; //user trees
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();
void calculateFreqsCumuls();
int createProcesses(Tree*, vector< vector<string> >, vector< vector<double> >&);
int driver(Tree*, vector< vector<string> >, int, int, vector< vector<double> >&);
+ int readNamesFile();
};
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;
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);
}
}
}
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);
}
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;
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);
}
}
}
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);
}
int count = 0;
- Tree* copyTree = new Tree;
+ Tree* copyTree = new Tree(tmap);
for (int h = start; h < (start+num); h++) {
};
vector<linePair> lines;
- GlobalData* globaldata;
EstOutput data;
TreeMap* tmap;
int processors;
}
}
/********************************************************************/
+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);
+ }
+}
+/********************************************************************/
+
~ValidCalculators();
bool isValidCalculator(string, string);
void printCalc(string, ostream&);
+ string printCalc(string);
private:
map<string, string> single;
//**********************************************************************************************************************
-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");
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);
//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);
//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);
//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);
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);
#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;
#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);
}
}
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;
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...
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"; }
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) {
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.
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;
}
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;
}
//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;
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;
}
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;
}
}
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;
}
for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; }
+ delete venn; delete input;
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
#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;
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> >&);
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; }
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);
}
}
/**************************************************************************************************/
EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) {
try {
- globaldata = GlobalData::getInstance();
data.clear(); //clear out old values
};
vector<linePair> lines;
- GlobalData* globaldata;
EstOutput data;
TreeMap* tmap;
map<string, int>::iterator it;