From 74844a60d80c6dd06e3fb02ee9b928424f9019b0 Mon Sep 17 00:00:00 2001 From: westcott Date: Fri, 26 Feb 2010 14:35:09 +0000 Subject: [PATCH] created mothurOut class to handle logfiles --- Mothur.xcodeproj/project.pbxproj | 6 + ace.cpp | 2 +- aligncommand.cpp | 124 +++-- alignment.cpp | 9 +- alignment.hpp | 1 + alignmentcell.hpp | 2 +- alignmentdb.cpp | 17 +- alignmentdb.h | 1 + averagelinkage.cpp | 2 +- bayesian.cpp | 20 +- bellerophon.cpp | 44 +- bergerparker.cpp | 2 +- binsequencecommand.cpp | 61 ++- binsequencecommand.h | 1 + blastalign.cpp | 4 +- blastdb.cpp | 12 +- boneh.cpp | 8 +- boneh.h | 4 +- bootstrap.cpp | 2 +- bootstrapsharedcommand.cpp | 70 ++- bootstrapsharedcommand.h | 2 +- bstick.cpp | 6 +- calculator.cpp | 906 +------------------------------ calculator.h | 6 +- ccode.cpp | 46 +- chao1.cpp | 2 +- chimera.cpp | 21 +- chimera.h | 9 +- chimeracheckrdp.cpp | 36 +- chimerarealigner.cpp | 8 +- chimerarealigner.h | 1 + chimeraseqscommand.cpp | 196 ++++--- chimeraslayer.cpp | 18 +- classify.cpp | 26 +- classify.h | 1 + classifyseqscommand.cpp | 106 ++-- classifyseqscommand.h | 2 +- cluster.cpp | 29 +- cluster.hpp | 2 + clustercommand.cpp | 47 +- clustercommand.h | 3 +- collect.cpp | 4 +- collect.h | 6 +- collectcommand.cpp | 72 ++- collectsharedcommand.cpp | 75 ++- collectsharedcommand.h | 2 +- command.hpp | 4 + commandfactory.cpp | 128 ++--- commandfactory.hpp | 2 + commandoptionparser.cpp | 8 +- commandoptionparser.hpp | 2 + completelinkage.cpp | 2 +- consensuscommand.cpp | 40 +- coverage.cpp | 2 +- database.cpp | 1 + database.hpp | 1 + datavector.hpp | 4 +- decalc.cpp | 54 +- decalc.h | 3 +- deconvolutecommand.cpp | 30 +- deconvolutecommand.h | 2 +- display.h | 4 +- dist.h | 3 +- distancecommand.cpp | 57 +- distancecommand.h | 2 +- distancedb.cpp | 14 +- efron.cpp | 6 +- efron.h | 4 +- engine.cpp | 65 +-- engine.hpp | 2 + fastamap.cpp | 6 +- fastamap.h | 4 +- fileoutput.cpp | 40 +- fileoutput.h | 4 +- filterseqscommand.cpp | 49 +- formatcolumn.cpp | 2 +- formatmatrix.h | 3 +- formatphylip.cpp | 2 +- fullmatrix.cpp | 19 +- fullmatrix.h | 3 +- geom.cpp | 2 +- getgroupcommand.cpp | 32 +- getlabelcommand.cpp | 22 +- getlistcountcommand.cpp | 44 +- getlistcountcommand.h | 1 + getoturepcommand.cpp | 83 +-- getoturepcommand.h | 1 + getrabundcommand.cpp | 46 +- getsabundcommand.cpp | 44 +- getseqscommand.cpp | 71 ++- getseqscommand.h | 3 +- getsharedotucommand.cpp | 78 +-- getsharedotucommand.h | 1 + globaldata.cpp | 5 +- globaldata.hpp | 2 +- goodscoverage.cpp | 2 +- gotohoverlap.cpp | 8 +- groupmap.cpp | 9 +- groupmap.h | 2 + hcluster.cpp | 39 +- hcluster.h | 1 + hclustercommand.cpp | 49 +- hclustercommand.h | 1 + heatmap.cpp | 19 +- heatmap.h | 5 +- heatmapcommand.cpp | 78 +-- heatmapcommand.h | 2 +- heatmapsim.cpp | 17 +- heatmapsim.h | 5 +- heatmapsimcommand.cpp | 87 +-- heatmapsimcommand.h | 2 +- helpcommand.cpp | 6 +- inputdata.cpp | 34 +- inputdata.h | 1 + jackknife.cpp | 6 +- kmerdb.cpp | 14 +- knn.cpp | 10 +- libshuff.cpp | 11 +- libshuff.h | 1 + libshuffcommand.cpp | 62 ++- libshuffcommand.h | 2 +- listseqscommand.cpp | 37 +- listvector.cpp | 20 +- logsd.cpp | 2 +- maligner.cpp | 66 +-- maligner.h | 1 + matrixoutputcommand.cpp | 64 ++- matrixoutputcommand.h | 2 +- mergefilecommand.cpp | 22 +- mgclustercommand.cpp | 57 +- mothur.cpp | 109 ++-- mothur.h | 201 ++----- nameassignment.cpp | 8 +- nameassignment.hpp | 1 + nast.cpp | 15 +- nast.hpp | 2 + needlemanoverlap.cpp | 10 +- nocommands.cpp | 4 +- npshannon.cpp | 2 +- optionparser.cpp | 4 +- optionparser.h | 2 + ordervector.cpp | 12 +- otuhierarchycommand.cpp | 48 +- parselistscommand.cpp | 47 +- parsimony.cpp | 2 +- parsimonycommand.cpp | 59 +- parsimonycommand.h | 2 +- pcacommand.cpp | 37 +- pcacommand.h | 1 + phylotree.cpp | 21 +- phylotree.h | 2 + phylotypecommand.cpp | 47 +- pintail.cpp | 32 +- preclustercommand.cpp | 52 +- preclustercommand.h | 2 +- progress.cpp | 33 +- progress.hpp | 4 +- qstat.cpp | 2 +- quitcommand.cpp | 8 +- rabundvector.cpp | 20 +- rarecalc.cpp | 2 +- rarecalc.h | 3 +- raredisplay.cpp | 10 +- rarefact.cpp | 6 +- rarefact.h | 5 +- rarefactcommand.cpp | 64 ++- rarefactsharedcommand.cpp | 53 +- rarefactsharedcommand.h | 4 +- readblast.cpp | 15 +- readblast.h | 1 + readcluster.cpp | 11 +- readcluster.h | 1 + readcolumn.cpp | 2 +- readdistcommand.cpp | 51 +- readmatrix.hpp | 3 +- readotu.cpp | 4 +- readotu.h | 1 + readotucommand.cpp | 41 +- readphylip.cpp | 10 +- readtree.cpp | 35 +- readtree.h | 1 + readtreecommand.cpp | 32 +- removeseqscommand.cpp | 71 +-- removeseqscommand.h | 1 + reversecommand.cpp | 24 +- sabundvector.cpp | 16 +- screenseqscommand.cpp | 64 ++- secondarystructurecommand.cpp | 39 +- seqsummarycommand.cpp | 46 +- sequence.cpp | 5 +- sequence.hpp | 3 +- sequencedb.cpp | 20 +- sequencedb.h | 1 + setdircommand.cpp | 34 +- shannon.cpp | 2 +- sharedace.cpp | 2 +- sharedanderbergs.cpp | 2 +- sharedbraycurtis.cpp | 2 +- sharedchao1.cpp | 24 +- sharedcommand.cpp | 32 +- sharedjabund.cpp | 2 +- sharedjackknife.cpp | 2 +- sharedjclass.cpp | 2 +- sharedjest.cpp | 2 +- sharedkstest.cpp | 2 +- sharedkulczynski.cpp | 2 +- sharedkulczynskicody.cpp | 2 +- sharedlennon.cpp | 2 +- sharedlistvector.cpp | 38 +- sharedmarczewski.cpp | 2 +- sharedmorisitahorn.cpp | 2 +- sharedochiai.cpp | 2 +- sharedordervector.cpp | 18 +- sharedrabundvector.cpp | 28 +- sharedsabundvector.cpp | 16 +- sharedsobs.cpp | 2 +- sharedsobscollectsummary.cpp | 2 +- sharedsorabund.cpp | 2 +- sharedsorclass.cpp | 2 +- sharedsorest.cpp | 2 +- sharedthetan.cpp | 2 +- sharedthetayc.cpp | 2 +- sharedutilities.cpp | 32 +- sharedutilities.h | 5 +- shen.cpp | 4 +- shen.h | 4 +- simpson.cpp | 2 +- singlelinkage.cpp | 4 +- slayer.cpp | 22 +- slayer.h | 1 + slibshuff.cpp | 4 +- solow.cpp | 4 +- solow.h | 4 +- sparsematrix.cpp | 18 +- sparsematrix.hpp | 2 + suffixdb.cpp | 4 +- suffixnodes.cpp | 18 +- suffixnodes.hpp | 2 + suffixtree.cpp | 4 +- suffixtree.hpp | 1 + summarycommand.cpp | 52 +- summarysharedcommand.cpp | 61 ++- summarysharedcommand.h | 2 +- systemcommand.cpp | 18 +- taxonomyequalizer.cpp | 15 +- taxonomyequalizer.h | 3 +- tree.cpp | 43 +- tree.h | 1 + treecalculator.h | 4 +- treegroupscommand.cpp | 79 +-- treegroupscommand.h | 2 +- treemap.cpp | 8 +- treemap.h | 3 +- treenode.cpp | 19 +- treenode.h | 2 + trimseqscommand.cpp | 91 ++-- unifracunweightedcommand.cpp | 63 ++- unifracunweightedcommand.h | 2 +- unifracweightedcommand.cpp | 64 ++- unifracweightedcommand.h | 4 +- unweighted.cpp | 4 +- uvest.cpp | 2 +- uvest.h | 5 +- validcalculator.cpp | 112 ++-- validcalculator.h | 3 + validparameter.cpp | 47 +- validparameter.h | 2 + venn.cpp | 28 +- venn.h | 5 +- venncommand.cpp | 97 ++-- weighted.cpp | 4 +- whittaker.cpp | 2 +- 272 files changed, 3017 insertions(+), 3408 deletions(-) diff --git a/Mothur.xcodeproj/project.pbxproj b/Mothur.xcodeproj/project.pbxproj index 5900f0a..f5a6700 100644 --- a/Mothur.xcodeproj/project.pbxproj +++ b/Mothur.xcodeproj/project.pbxproj @@ -164,6 +164,7 @@ A70B53AA0F4CD7AD0064797E /* getgroupcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70B53A40F4CD7AD0064797E /* getgroupcommand.cpp */; }; A70B53AB0F4CD7AD0064797E /* getlabelcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70B53A60F4CD7AD0064797E /* getlabelcommand.cpp */; }; A70DECD91063D8B40057C03C /* secondarystructurecommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70DECD81063D8B40057C03C /* secondarystructurecommand.cpp */; }; + A70F3FD01136E391004FDC52 /* mothurout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A70F3FCF1136E391004FDC52 /* mothurout.cpp */; }; A71CB8A311354B9F00848EF7 /* parselistscommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A71CB8A211354B9F00848EF7 /* parselistscommand.cpp */; }; A727E84A10D14568001A8432 /* readblast.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A727E84910D14568001A8432 /* readblast.cpp */; }; A7283FF81056CAE100D0CC69 /* chimeracheckrdp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7283FF71056CAE100D0CC69 /* chimeracheckrdp.cpp */; }; @@ -546,6 +547,8 @@ A70B53A70F4CD7AD0064797E /* getlabelcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getlabelcommand.h; sourceTree = SOURCE_ROOT; }; A70DECD71063D8B40057C03C /* secondarystructurecommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = secondarystructurecommand.h; sourceTree = SOURCE_ROOT; }; A70DECD81063D8B40057C03C /* secondarystructurecommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = secondarystructurecommand.cpp; sourceTree = SOURCE_ROOT; }; + A70F3FCE1136E391004FDC52 /* mothurout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mothurout.h; sourceTree = SOURCE_ROOT; }; + A70F3FCF1136E391004FDC52 /* mothurout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = mothurout.cpp; sourceTree = SOURCE_ROOT; }; A71CB8A111354B9F00848EF7 /* parselistscommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = parselistscommand.h; sourceTree = SOURCE_ROOT; }; A71CB8A211354B9F00848EF7 /* parselistscommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = parselistscommand.cpp; sourceTree = SOURCE_ROOT; }; A727E84810D14568001A8432 /* readblast.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = readblast.h; sourceTree = SOURCE_ROOT; }; @@ -685,6 +688,8 @@ 7E412FE90F8D3E2C00381DD0 /* libshuff.cpp */, 37E3ED800F4D9D0D00B5DF02 /* mothur.h */, 37D927EF0F21331F001D4494 /* mothur.cpp */, + A70F3FCE1136E391004FDC52 /* mothurout.h */, + A70F3FCF1136E391004FDC52 /* mothurout.cpp */, 373C691E0FC1C98600137ACD /* nast.hpp */, 373C691D0FC1C98600137ACD /* nast.cpp */, 373C692A0FC1C9EB00137ACD /* nastreport.hpp */, @@ -1349,6 +1354,7 @@ A794201111107897003AECCD /* distancedb.cpp in Sources */, A7E8A22F1125939F0011D39C /* chimerarealigner.cpp in Sources */, A71CB8A311354B9F00848EF7 /* parselistscommand.cpp in Sources */, + A70F3FD01136E391004FDC52 /* mothurout.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ace.cpp b/ace.cpp index 639a48f..1fde511 100644 --- a/ace.cpp +++ b/ace.cpp @@ -140,7 +140,7 @@ EstOutput Ace::getValues(SAbundVector* rank) { return data; } catch(exception& e) { - errorOut(e, "Ace", "getValues"); + m->errorOut(e, "Ace", "getValues"); exit(1); } } diff --git a/aligncommand.cpp b/aligncommand.cpp index 708a854..3b4b6c9 100644 --- a/aligncommand.cpp +++ b/aligncommand.cpp @@ -28,9 +28,9 @@ //********************************************************************************************************************** -AlignCommand::AlignCommand(string option){ +AlignCommand::AlignCommand(string option) { try { - // globaldata = GlobalData::getInstance(); + abort = false; //allow user to run help @@ -78,13 +78,13 @@ AlignCommand::AlignCommand(string option){ templateFileName = validParameter.validFile(parameters, "template", true); if (templateFileName == "not found") { - mothurOut("template is a required parameter for the align.seqs command."); - mothurOutEndLine(); + m->mothurOut("template 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); - if (candidateFileName == "not found") { mothurOut("candidate is a required parameter for the align.seqs command."); mothurOutEndLine(); abort = true; } + if (candidateFileName == "not found") { m->mothurOut("candidate is a required parameter for the align.seqs command."); m->mothurOutEndLine(); abort = true; } else { splitAtDash(candidateFileName, candidateFileNames); @@ -100,7 +100,7 @@ AlignCommand::AlignCommand(string option){ ifstream in; ableToOpen = openInputFile(candidateFileNames[i], in); if (ableToOpen == 1) { - mothurOut(candidateFileNames[i] + " will be disregarded."); mothurOutEndLine(); + m->mothurOut(candidateFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); //erase from file list candidateFileNames.erase(candidateFileNames.begin()+i); i--; @@ -109,7 +109,7 @@ AlignCommand::AlignCommand(string option){ } //make sure there is at least one valid file left - if (candidateFileNames.size() == 0) { mothurOut("no valid files."); mothurOutEndLine(); abort = true; } + if (candidateFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; } } //check for optional parameter and set defaults @@ -146,7 +146,7 @@ AlignCommand::AlignCommand(string option){ } catch(exception& e) { - errorOut(e, "AlignCommand", "AlignCommand"); + m->errorOut(e, "AlignCommand", "AlignCommand"); exit(1); } } @@ -166,27 +166,27 @@ AlignCommand::~AlignCommand(){ void AlignCommand::help(){ try { - mothurOut("The align.seqs command reads a file containing sequences and creates an alignment file and a report file.\n"); - mothurOut("The align.seqs command parameters are template, candidate, search, ksize, align, match, mismatch, gapopen and gapextend.\n"); - 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"); - 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"); - 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"); - mothurOut("The ksize parameter allows you to specify the kmer size for finding most similar template to candidate. The default is 8.\n"); - mothurOut("The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n"); - mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n"); - mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n"); - mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n"); - 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"); - 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"); - mothurOut("If the flip parameter is set to true the reverse complement of the sequence is aligned and the better alignment is reported.\n"); - 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"); - mothurOut("The align.seqs command should be in the following format: \n"); - mothurOut("align.seqs(template=yourTemplateFile, candidate=yourCandidateFile, align=yourAlignmentMethod, search=yourSearchmethod, ksize=yourKmerSize, match=yourMatchBonus, mismatch=yourMismatchpenalty, gapopen=yourGapopenPenalty, gapextend=yourGapExtendPenalty) \n"); - 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"); - mothurOut("Note: No spaces between parameter labels (i.e. candidate), '=' and parameters (i.e.yourFastaFile).\n\n"); + 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 and gapextend.\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) { - errorOut(e, "AlignCommand", "help"); + m->errorOut(e, "AlignCommand", "help"); exit(1); } } @@ -206,13 +206,14 @@ int AlignCommand::execute(){ else if(align == "blast") { alignment = new BlastAlignment(gapOpen, gapExtend, match, misMatch); } else if(align == "noalign") { alignment = new NoAlign(); } else { - mothurOut(align + " is not a valid alignment option. I will run the command using needleman."); - mothurOutEndLine(); + m->mothurOut(align + " is not a valid alignment option. I will run the command using needleman."); + m->mothurOutEndLine(); alignment = new NeedlemanOverlap(gapOpen, match, misMatch, longestBase); } + vector outputNames; for (int s = 0; s < candidateFileNames.size(); s++) { - mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); mothurOutEndLine(); + m->mothurOut("Aligning sequences from " + candidateFileNames[s] + " ..." ); m->mothurOutEndLine(); if (outputDir == "") { outputDir += hasPath(candidateFileNames[s]); } string alignFileName = outputDir + getRootName(getSimpleName(candidateFileNames[s])) + "align"; @@ -236,13 +237,13 @@ int AlignCommand::execute(){ driver(lines[0], alignFileName, reportFileName, accnosFileName, candidateFileNames[s]); //delete accnos file if its blank else report to user - if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); } + if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } else { - mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); + m->mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); if (!flip) { - mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); - }else{ mothurOut(" If the reverse compliment proved to be better it was reported."); } - mothurOutEndLine(); + m->mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); + }else{ m->mothurOut(" If the reverse compliment proved to be better it was reported."); } + m->mothurOutEndLine(); } } else{ @@ -303,11 +304,11 @@ int AlignCommand::execute(){ appendAlignFiles(nonBlankAccnosFiles[h], accnosFileName); remove(nonBlankAccnosFiles[h].c_str()); } - mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); + m->mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); if (!flip) { - mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); - }else{ mothurOut(" If the reverse compliment proved to be better it was reported."); } - mothurOutEndLine(); + m->mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); + }else{ m->mothurOut(" If the reverse compliment proved to be better it was reported."); } + m->mothurOutEndLine(); }else{ hasAccnos = false; } } #else @@ -323,29 +324,34 @@ int AlignCommand::execute(){ //delete accnos file if its blank else report to user if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } else { - mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); + m->mothurOut("Some of you sequences generated alignments that eliminated too many bases, a list is provided in " + accnosFileName + "."); if (!flip) { - mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); - }else{ mothurOut(" If the reverse compliment proved to be better it was reported."); } - mothurOutEndLine(); + m->mothurOut(" If you set the flip parameter to true mothur will try aligning the reverse compliment as well."); + }else{ m->mothurOut(" If the reverse compliment proved to be better it was reported."); } + m->mothurOutEndLine(); } #endif - mothurOut("Output File Names: " + alignFileName + ", " + reportFileName); - if (hasAccnos) { mothurOut(", " + accnosFileName + "."); } - else { mothurOut("."); } - mothurOutEndLine(); - - mothurOut("It took " + toString(time(NULL) - start) + " secs to align " + toString(numFastaSeqs) + " sequences."); - mothurOutEndLine(); - mothurOutEndLine(); + outputNames.push_back(alignFileName); + outputNames.push_back(reportFileName); + if (hasAccnos) { outputNames.push_back(accnosFileName); } + + m->mothurOut("It took " + toString(time(NULL) - start) + " secs to align " + toString(numFastaSeqs) + " sequences."); + m->mothurOutEndLine(); + m->mothurOutEndLine(); } + + 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; } catch(exception& e) { - errorOut(e, "AlignCommand", "execute"); + m->errorOut(e, "AlignCommand", "execute"); exit(1); } } @@ -444,10 +450,10 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName, delete candidateSeq; //report progress - if((i+1) % 100 == 0){ mothurOut(toString(i+1)); mothurOutEndLine(); } + if((i+1) % 100 == 0){ m->mothurOut(toString(i+1)); m->mothurOutEndLine(); } } //report progress - if((line->numSeqs) % 100 != 0){ mothurOut(toString(line->numSeqs)); mothurOutEndLine(); } + if((line->numSeqs) % 100 != 0){ m->mothurOut(toString(line->numSeqs)); m->mothurOutEndLine(); } alignmentFile.close(); inFASTA.close(); @@ -456,7 +462,7 @@ int AlignCommand::driver(linePair* line, string alignFName, string reportFName, return 1; } catch(exception& e) { - errorOut(e, "AlignCommand", "driver"); + m->errorOut(e, "AlignCommand", "driver"); exit(1); } } @@ -479,7 +485,7 @@ void AlignCommand::createProcesses(string alignFileName, string reportFileName, }else if (pid == 0){ driver(lines[process], alignFileName + toString(getpid()) + ".temp", reportFileName + toString(getpid()) + ".temp", accnosFName + toString(getpid()) + ".temp", filename); exit(0); - }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); } + }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } } //force parent to wait until all the processes are done @@ -490,7 +496,7 @@ void AlignCommand::createProcesses(string alignFileName, string reportFileName, #endif } catch(exception& e) { - errorOut(e, "AlignCommand", "createProcesses"); + m->errorOut(e, "AlignCommand", "createProcesses"); exit(1); } } @@ -514,7 +520,7 @@ void AlignCommand::appendAlignFiles(string temp, string filename) { output.close(); } catch(exception& e) { - errorOut(e, "AlignCommand", "appendAlignFiles"); + m->errorOut(e, "AlignCommand", "appendAlignFiles"); exit(1); } } @@ -539,7 +545,7 @@ void AlignCommand::appendReportFiles(string temp, string filename) { output.close(); } catch(exception& e) { - errorOut(e, "AlignCommand", "appendReportFiles"); + m->errorOut(e, "AlignCommand", "appendReportFiles"); exit(1); } } diff --git a/alignment.cpp b/alignment.cpp index 2734c38..d543dbd 100644 --- a/alignment.cpp +++ b/alignment.cpp @@ -21,13 +21,14 @@ Alignment::Alignment() { /* do nothing */ } Alignment::Alignment(int A) : nCols(A), nRows(A) { try { + m = MothurOut::getInstance(); alignment.resize(nRows); // For the Gotoh and Needleman-Wunsch we initialize the dynamic programming for(int i=0;ierrorOut(e, "Alignment", "Alignment"); exit(1); } } @@ -43,7 +44,7 @@ void Alignment::resize(int A) { } } catch(exception& e) { - errorOut(e, "Alignment", "resize"); + m->errorOut(e, "Alignment", "resize"); exit(1); } } @@ -107,7 +108,7 @@ void Alignment::traceBack(){ // This traceback routine is used by the dynamic seqBend = seqB.length() - seqBend - 1; } catch(exception& e) { - errorOut(e, "Alignment", "traceBack"); + m->errorOut(e, "Alignment", "traceBack"); exit(1); } } @@ -120,7 +121,7 @@ Alignment::~Alignment(){ } } catch(exception& e) { - errorOut(e, "Alignment", "~Alignment"); + m->errorOut(e, "Alignment", "~Alignment"); exit(1); } } diff --git a/alignment.hpp b/alignment.hpp index 6dd7f0a..7a943fd 100644 --- a/alignment.hpp +++ b/alignment.hpp @@ -49,6 +49,7 @@ protected: int pairwiseLength; int nRows, nCols, lA, lB; vector > alignment; + MothurOut* m; }; /**************************************************************************************************/ diff --git a/alignmentcell.hpp b/alignmentcell.hpp index c309048..569198f 100644 --- a/alignmentcell.hpp +++ b/alignmentcell.hpp @@ -12,7 +12,7 @@ * used to calcualte the alignment. Initially everything is set to zero and all pointers are set to 'x' * */ - +#include "mothurout.h" //******************************************************************************************************************** class AlignmentCell { diff --git a/alignmentdb.cpp b/alignmentdb.cpp index 5c758ec..59405ef 100644 --- a/alignmentdb.cpp +++ b/alignmentdb.cpp @@ -16,13 +16,14 @@ /**************************************************************************************************/ AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch){ // This assumes that the template database is in fasta format, may try { // need to alter this in the future? + m = MothurOut::getInstance(); longest = 0; ifstream fastaFile; openInputFile(fastaFileName, fastaFile); - mothurOutEndLine(); - mothurOut("Reading in the " + fastaFileName + " template sequences...\t"); cout.flush(); + m->mothurOutEndLine(); + m->mothurOut("Reading in the " + fastaFileName + " template sequences...\t"); cout.flush(); while (!fastaFile.eof()) { Sequence temp(fastaFile); gobble(fastaFile); @@ -39,8 +40,8 @@ AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, floa fastaFile.close(); //all of this is elsewhere already! - mothurOut("DONE."); - mothurOutEndLine(); cout.flush(); + m->mothurOut("DONE."); + m->mothurOutEndLine(); cout.flush(); //in case you delete the seqs and then ask for them emptySequence = Sequence(); @@ -61,8 +62,8 @@ AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, floa else if(method == "suffix") { search = new SuffixDB(numSeqs); } else if(method == "blast") { search = new BlastDB(gapOpen, gapExtend, match, misMatch); } else { - mothurOut(method + " is not a valid search option. I will run the command using kmer, ksize=8."); - mothurOutEndLine(); + m->mothurOut(method + " is not a valid search option. I will run the command using kmer, ksize=8."); + m->mothurOutEndLine(); search = new KmerDB(fastaFileName, 8); } @@ -82,7 +83,7 @@ AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, floa search->setNumSeqs(numSeqs); } catch(exception& e) { - errorOut(e, "AlignmentDB", "AlignmentDB"); + m->errorOut(e, "AlignmentDB", "AlignmentDB"); exit(1); } } @@ -99,7 +100,7 @@ Sequence AlignmentDB::findClosestSequence(Sequence* seq) { } catch(exception& e) { - errorOut(e, "AlignmentDB", "findClosestSequence"); + m->errorOut(e, "AlignmentDB", "findClosestSequence"); exit(1); } } diff --git a/alignmentdb.h b/alignmentdb.h index fe4e526..d665f78 100644 --- a/alignmentdb.h +++ b/alignmentdb.h @@ -34,6 +34,7 @@ private: Database* search; vector templateSequences; Sequence emptySequence; + MothurOut* m; }; /**************************************************************************************************/ diff --git a/averagelinkage.cpp b/averagelinkage.cpp index 2acbacc..b98c8e2 100644 --- a/averagelinkage.cpp +++ b/averagelinkage.cpp @@ -43,7 +43,7 @@ bool AverageLinkage::updateDistance(MatData& colCell, MatData& rowCell) { return(true); } catch(exception& e) { - errorOut(e, "AverageLinkage", "updateDistance"); + m->errorOut(e, "AverageLinkage", "updateDistance"); exit(1); } } diff --git a/bayesian.cpp b/bayesian.cpp index a83f1ed..42fb023 100644 --- a/bayesian.cpp +++ b/bayesian.cpp @@ -43,10 +43,10 @@ Classify(tfile, tempFile, method, ksize, 0.0, 0.0, 0.0, 0.0), kmerSize(ksize), c int start = time(NULL); if(probFileTest && probFileTest2){ - mothurOut("Reading template probabilities... "); cout.flush(); + m->mothurOut("Reading template probabilities... "); cout.flush(); readProbFile(probFileTest, probFileTest2); }else{ - mothurOut("Calculating template probabilities... "); cout.flush(); + m->mothurOut("Calculating template probabilities... "); cout.flush(); ofstream out; openOutputFile(probFileName, out); @@ -88,11 +88,11 @@ Classify(tfile, tempFile, method, ksize, 0.0, 0.0, 0.0, 0.0), kmerSize(ksize), c } - mothurOut("DONE."); mothurOutEndLine(); - mothurOut("It took " + toString(time(NULL) - start) + " seconds get probabilities. "); mothurOutEndLine(); + m->mothurOut("DONE."); m->mothurOutEndLine(); + m->mothurOut("It took " + toString(time(NULL) - start) + " seconds get probabilities. "); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "Bayesian", "Bayesian"); + m->errorOut(e, "Bayesian", "Bayesian"); exit(1); } } @@ -122,7 +122,7 @@ string Bayesian::getTaxonomy(Sequence* seq) { return tax; } catch(exception& e) { - errorOut(e, "Bayesian", "getTaxonomy"); + m->errorOut(e, "Bayesian", "getTaxonomy"); exit(1); } } @@ -196,7 +196,7 @@ string Bayesian::bootstrapResults(vector kmers, int tax, int numToSelect) { } catch(exception& e) { - errorOut(e, "Bayesian", "bootstrapResults"); + m->errorOut(e, "Bayesian", "bootstrapResults"); exit(1); } } @@ -225,7 +225,7 @@ int Bayesian::getMostProbableTaxonomy(vector queryKmer) { return indexofGenus; } catch(exception& e) { - errorOut(e, "Bayesian", "getMostProbableTaxonomy"); + m->errorOut(e, "Bayesian", "getMostProbableTaxonomy"); exit(1); } } @@ -252,7 +252,7 @@ map Bayesian::parseTaxMap(string newTax) { } catch(exception& e) { - errorOut(e, "Bayesian", "parseTax"); + m->errorOut(e, "Bayesian", "parseTax"); exit(1); } } @@ -291,7 +291,7 @@ void Bayesian::readProbFile(ifstream& in, ifstream& inNum) { in.close(); } catch(exception& e) { - errorOut(e, "Bayesian", "readProbFile"); + m->errorOut(e, "Bayesian", "readProbFile"); exit(1); } } diff --git a/bellerophon.cpp b/bellerophon.cpp index 17859dc..02b2829 100644 --- a/bellerophon.cpp +++ b/bellerophon.cpp @@ -21,7 +21,7 @@ Bellerophon::Bellerophon(string name, string o) { outputDir = o; } catch(exception& e) { - errorOut(e, "Bellerophon", "Bellerophon"); + m->errorOut(e, "Bellerophon", "Bellerophon"); exit(1); } } @@ -39,33 +39,33 @@ void Bellerophon::print(ostream& out, ostream& outAcc) { if (pref[i].score[0] > 1.0) { above1++; outAcc << pref[i].name << endl; - mothurOut(pref[i].name + " is a suspected chimera at breakpoint " + toString(pref[i].midpoint)); mothurOutEndLine(); - mothurOut("It's score is " + toString(pref[i].score[0]) + " with suspected left parent " + pref[i].leftParent[0] + " and right parent " + pref[i].rightParent[0]); mothurOutEndLine(); + m->mothurOut(pref[i].name + " is a suspected chimera at breakpoint " + toString(pref[i].midpoint)); m->mothurOutEndLine(); + m->mothurOut("It's score is " + toString(pref[i].score[0]) + " with suspected left parent " + pref[i].leftParent[0] + " and right parent " + pref[i].rightParent[0]); m->mothurOutEndLine(); } } //output results to screen - mothurOutEndLine(); - mothurOut("Sequence with preference score above 1.0: " + toString(above1)); mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Sequence with preference score above 1.0: " + toString(above1)); m->mothurOutEndLine(); int spot; spot = pref.size()-1; - mothurOut("Minimum:\t" + toString(pref[spot].score[0])); mothurOutEndLine(); + m->mothurOut("Minimum:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine(); spot = pref.size() * 0.975; - mothurOut("2.5%-tile:\t" + toString(pref[spot].score[0])); mothurOutEndLine(); + m->mothurOut("2.5%-tile:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine(); spot = pref.size() * 0.75; - mothurOut("25%-tile:\t" + toString(pref[spot].score[0])); mothurOutEndLine(); + m->mothurOut("25%-tile:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine(); spot = pref.size() * 0.50; - mothurOut("Median: \t" + toString(pref[spot].score[0])); mothurOutEndLine(); + m->mothurOut("Median: \t" + toString(pref[spot].score[0])); m->mothurOutEndLine(); spot = pref.size() * 0.25; - mothurOut("75%-tile:\t" + toString(pref[spot].score[0])); mothurOutEndLine(); + m->mothurOut("75%-tile:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine(); spot = pref.size() * 0.025; - mothurOut("97.5%-tile:\t" + toString(pref[spot].score[0])); mothurOutEndLine(); + m->mothurOut("97.5%-tile:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine(); spot = 0; - mothurOut("Maximum:\t" + toString(pref[spot].score[0])); mothurOutEndLine(); + m->mothurOut("Maximum:\t" + toString(pref[spot].score[0])); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "Bellerophon", "print"); + m->errorOut(e, "Bellerophon", "print"); exit(1); } } @@ -96,28 +96,28 @@ int Bellerophon::getChimeras() { } distCalculator = new eachGapDist(); - +cout << "fastafile = " << fastafile << endl; //read in sequences seqs = readSeqs(fastafile); - - if (unaligned) { mothurOut("Your sequences need to be aligned when you use the bellerophon method."); mothurOutEndLine(); return 1; } + cout << "here:"<< endl; + if (unaligned) { m->mothurOut("Your sequences need to be aligned when you use the bellerophon method."); m->mothurOutEndLine(); return 1; } int numSeqs = seqs.size(); - if (numSeqs == 0) { mothurOut("Error in reading you sequences."); mothurOutEndLine(); exit(1); } + if (numSeqs == 0) { m->mothurOut("Error in reading you sequences."); m->mothurOutEndLine(); exit(1); } //set default window to 25% of sequence length string seq0 = seqs[0]->getAligned(); if (window == 0) { window = seq0.length() / 4; } else if (window > (seq0.length() / 2)) { - mothurOut("Your sequence length is = " + toString(seq0.length()) + ". You have selected a window size greater than the length of half your aligned sequence. I will run it with a window size of " + toString((seq0.length() / 2))); mothurOutEndLine(); + m->mothurOut("Your sequence length is = " + toString(seq0.length()) + ". You have selected a window size greater than the length of half your aligned sequence. I will run it with a window size of " + toString((seq0.length() / 2))); m->mothurOutEndLine(); window = (seq0.length() / 2); } if (increment > (seqs[0]->getAlignLength() - (2*window))) { if (increment != 10) { - mothurOut("You have selected a increment that is too large. I will use the default."); mothurOutEndLine(); + m->mothurOut("You have selected a increment that is too large. I will use the default."); m->mothurOutEndLine(); increment = 10; if (increment > (seqs[0]->getAlignLength() - (2*window))) { increment = 0; } @@ -234,7 +234,7 @@ int Bellerophon::getChimeras() { } catch(exception& e) { - errorOut(e, "Bellerophon", "getChimeras"); + m->errorOut(e, "Bellerophon", "getChimeras"); exit(1); } } @@ -259,7 +259,7 @@ int Bellerophon::createSparseMatrix(int startSeq, int endSeq, SparseMatrix* spar return 1; } catch(exception& e) { - errorOut(e, "Bellerophon", "createSparseMatrix"); + m->errorOut(e, "Bellerophon", "createSparseMatrix"); exit(1); } } @@ -382,7 +382,7 @@ void Bellerophon::generatePreferences(vector left, vector right, } catch(exception& e) { - errorOut(e, "Bellerophon", "generatePreferences"); + m->errorOut(e, "Bellerophon", "generatePreferences"); exit(1); } } diff --git a/bergerparker.cpp b/bergerparker.cpp index a1e4b06..d00403c 100644 --- a/bergerparker.cpp +++ b/bergerparker.cpp @@ -23,7 +23,7 @@ EstOutput BergerParker::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "BergerParker", "getValues"); + m->errorOut(e, "BergerParker", "getValues"); exit(1); } } diff --git a/binsequencecommand.cpp b/binsequencecommand.cpp index 6618eb6..274a890 100644 --- a/binsequencecommand.cpp +++ b/binsequencecommand.cpp @@ -10,7 +10,7 @@ #include "binsequencecommand.h" //********************************************************************************************************************** -BinSeqCommand::BinSeqCommand(string option){ +BinSeqCommand::BinSeqCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -45,8 +45,8 @@ BinSeqCommand::BinSeqCommand(string option){ //make sure the user has already run the read.otu command if (globaldata->getListFile() == "") { - mothurOut("You must read a listfile before running the bin.seqs command."); - mothurOutEndLine(); + m->mothurOut("You must read a listfile before running the bin.seqs command."); + m->mothurOutEndLine(); abort = true; } @@ -83,7 +83,7 @@ BinSeqCommand::BinSeqCommand(string option){ //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { mothurOut("fasta is a required parameter for the bin.seqs command."); mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the bin.seqs command."); m->mothurOutEndLine(); abort = true; } else if (fastafile == "not open") { abort = true; } //check for optional parameter and set defaults @@ -124,7 +124,7 @@ BinSeqCommand::BinSeqCommand(string option){ } } catch(exception& e) { - errorOut(e, "BinSeqCommand", "BinSeqCommand"); + m->errorOut(e, "BinSeqCommand", "BinSeqCommand"); exit(1); } } @@ -132,18 +132,18 @@ BinSeqCommand::BinSeqCommand(string option){ void BinSeqCommand::help(){ try { - mothurOut("The bin.seqs command can only be executed after a successful read.otu command of a listfile.\n"); - mothurOut("The bin.seqs command parameters are fasta, name, label and group. The fasta parameter is required.\n"); - 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"); - mothurOut("The bin.seqs command should be in the following format: bin.seqs(fasta=yourFastaFile, name=yourNamesFile, group=yourGroupFile, label=yourLabels).\n"); - mothurOut("Example bin.seqs(fasta=amazon.fasta, group=amazon.groups, name=amazon.names).\n"); - mothurOut("The default value for label is all lines in your inputfile.\n"); - mothurOut("The bin.seqs command outputs a .fasta file for each distance you specify appending the OTU number to each name.\n"); - mothurOut("If you provide a groupfile, then it also appends the sequences group to the name.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); + 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) { - errorOut(e, "BinSeqCommand", "help"); + m->errorOut(e, "BinSeqCommand", "help"); exit(1); } } @@ -232,12 +232,12 @@ int BinSeqCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -252,10 +252,16 @@ int BinSeqCommand::execute(){ delete list; } + 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; } catch(exception& e) { - errorOut(e, "BinSeqCommand", "execute"); + m->errorOut(e, "BinSeqCommand", "execute"); exit(1); } } @@ -289,7 +295,7 @@ void BinSeqCommand::readNamesFile() { } catch(exception& e) { - errorOut(e, "BinSeqCommand", "readNamesFile"); + m->errorOut(e, "BinSeqCommand", "readNamesFile"); exit(1); } } @@ -301,8 +307,11 @@ int BinSeqCommand::process(ListVector* list) { string outputFileName = outputDir + getRootName(getSimpleName(globaldata->getListFile())) + list->getLabel() + ".fasta"; openOutputFile(outputFileName, out); + + //save to output list of output file names + outputNames.push_back(outputFileName); - mothurOut(list->getLabel()); mothurOutEndLine(); + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); //for each bin in the list vector for (int i = 0; i < list->size(); i++) { @@ -323,7 +332,7 @@ int BinSeqCommand::process(ListVector* list) { }else {//if you do have groups string group = groupMap->getGroup(name); if (group == "not found") { - mothurOut(name + " is missing from your group file. Please correct. "); mothurOutEndLine(); + m->mothurOut(name + " is missing from your group file. Please correct. "); m->mothurOutEndLine(); remove(outputFileName.c_str()); return 1; }else{ @@ -333,7 +342,7 @@ int BinSeqCommand::process(ListVector* list) { } } }else { - mothurOut(name + " is missing from your fasta or name file. Please correct. "); mothurOutEndLine(); + m->mothurOut(name + " is missing from your fasta or name file. Please correct. "); m->mothurOutEndLine(); remove(outputFileName.c_str()); return 1; } @@ -351,7 +360,7 @@ int BinSeqCommand::process(ListVector* list) { }else {//if you do have groups string group = groupMap->getGroup(binnames); if (group == "not found") { - mothurOut(binnames + " is missing from your group file. Please correct. "); mothurOutEndLine(); + m->mothurOut(binnames + " is missing from your group file. Please correct. "); m->mothurOutEndLine(); remove(outputFileName.c_str()); return 1; }else{ @@ -361,7 +370,7 @@ int BinSeqCommand::process(ListVector* list) { } } }else { - mothurOut(binnames + " is missing from your fasta or name file. Please correct. "); mothurOutEndLine(); + m->mothurOut(binnames + " is missing from your fasta or name file. Please correct. "); m->mothurOutEndLine(); remove(outputFileName.c_str()); return 1; } @@ -372,7 +381,7 @@ int BinSeqCommand::process(ListVector* list) { } catch(exception& e) { - errorOut(e, "BinSeqCommand", "process"); + m->errorOut(e, "BinSeqCommand", "process"); exit(1); } } diff --git a/binsequencecommand.h b/binsequencecommand.h index 2804235..6ea7305 100644 --- a/binsequencecommand.h +++ b/binsequencecommand.h @@ -41,6 +41,7 @@ private: string filename, fastafile, namesfile, groupfile, label, outputDir; ofstream out; ifstream in, inNames; + vector outputNames; void readNamesFile(); int process(ListVector*); diff --git a/blastalign.cpp b/blastalign.cpp index 624210f..04c7716 100644 --- a/blastalign.cpp +++ b/blastalign.cpp @@ -102,9 +102,9 @@ void BlastAlignment::setPairwiseSeqs(){ // This method call assigns the blast ge pairwiseLength = 0; // string dummy; -// while(dummy != "query:"){ mothurOut(dummy, ""); mothurOutEndLine(); blastFile >> dummy; } +// while(dummy != "query:"){ m->mothurOut(dummy, ""); m->mothurOutEndLine(); blastFile >> dummy; } // blastFile >> seqBend; -// mothurOut(toString(seqBend), ""); mothurOutEndLine(); +// m->mothurOut(toString(seqBend), ""); m->mothurOutEndLine(); // for(int i=0;i BlastDB::findClosestSequences(Sequence* seq, int n) { return topMatches; } catch(exception& e) { - errorOut(e, "BlastDB", "findClosestSequences"); + m->errorOut(e, "BlastDB", "findClosestSequences"); exit(1); } @@ -139,7 +139,7 @@ vector BlastDB::findClosestMegaBlast(Sequence* seq, int n) { return topMatches; } catch(exception& e) { - errorOut(e, "BlastDB", "findClosest"); + m->errorOut(e, "BlastDB", "findClosest"); exit(1); } } @@ -158,7 +158,7 @@ void BlastDB::addSequence(Sequence seq) { count++; } catch(exception& e) { - errorOut(e, "BlastDB", "addSequence"); + m->errorOut(e, "BlastDB", "addSequence"); exit(1); } } @@ -166,7 +166,7 @@ void BlastDB::addSequence(Sequence seq) { void BlastDB::generateDB() { try { - //mothurOut("Generating the temporary BLAST database...\t"); cout.flush(); + //m->mothurOut("Generating the temporary BLAST database...\t"); cout.flush(); path = globaldata->argv; path = path.substr(0, (path.find_last_of('m'))); @@ -174,10 +174,10 @@ void BlastDB::generateDB() { string formatdbCommand = path + "blast/bin/formatdb -p F -o T -i " + dbFileName; // format the database, -o option gives us the ability system(formatdbCommand.c_str()); // to get the right sequence names, i think. -p F // option tells formatdb that seqs are DNA, not prot - //mothurOut("DONE."); mothurOutEndLine(); mothurOutEndLine(); cout.flush(); + //m->mothurOut("DONE."); m->mothurOutEndLine(); m->mothurOutEndLine(); cout.flush(); } catch(exception& e) { - errorOut(e, "BlastDB", "generateDB"); + m->errorOut(e, "BlastDB", "generateDB"); exit(1); } } diff --git a/boneh.cpp b/boneh.cpp index dc1475a..b4ce2ba 100644 --- a/boneh.cpp +++ b/boneh.cpp @@ -44,7 +44,7 @@ EstOutput Boneh::getValues(SAbundVector* sabund){ bool valid = false; double sum = 0; double n = (double)sabund->getNumSeqs(); - if(m==0){ m=n; } + if(f==0){ f=n; } double f1 = (double)sabund->get(1); @@ -66,10 +66,10 @@ EstOutput Boneh::getValues(SAbundVector* sabund){ sum = 0; for(int j = 1; j < sabund->size(); j++) { for (int i = 0; i < sabund->get(j); i++) { - sum += pow(1 - j / n, n) * (1 - pow(1 - j / n, m)); + sum += pow(1 - j / n, n) * (1 - pow(1 - j / n, f)); } } - sum += v * pow(1 - f1/(n*v), n) * (1 - pow(1 - f1/(n*v), m)); + sum += v * pow(1 - f1/(n*v), n) * (1 - pow(1 - f1/(n*v), f)); } data[0] = sum; @@ -77,7 +77,7 @@ EstOutput Boneh::getValues(SAbundVector* sabund){ return data; } catch(exception& e) { - errorOut(e, "Boneh", "getValues"); + m->errorOut(e, "Boneh", "getValues"); exit(1); } } diff --git a/boneh.h b/boneh.h index 7e328b1..d2d06c0 100644 --- a/boneh.h +++ b/boneh.h @@ -20,12 +20,12 @@ class Boneh : public Calculator { public: - Boneh(int size) : m(size), Calculator("boneh", 1, false) {}; + Boneh(int size) : f(size), Calculator("boneh", 1, false) {}; EstOutput getValues(SAbundVector*); EstOutput getValues(vector) {return data;}; private: double getV(double, double, double); - int m; + int f; }; diff --git a/bootstrap.cpp b/bootstrap.cpp index 649a602..833f8f4 100644 --- a/bootstrap.cpp +++ b/bootstrap.cpp @@ -32,7 +32,7 @@ EstOutput Bootstrap::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "Bootstrap", "getValues"); + m->errorOut(e, "Bootstrap", "getValues"); exit(1); } } diff --git a/bootstrapsharedcommand.cpp b/bootstrapsharedcommand.cpp index bfd3e98..b44ce4b 100644 --- a/bootstrapsharedcommand.cpp +++ b/bootstrapsharedcommand.cpp @@ -22,7 +22,7 @@ //********************************************************************************************************************** -BootSharedCommand::BootSharedCommand(string option){ +BootSharedCommand::BootSharedCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -58,8 +58,8 @@ BootSharedCommand::BootSharedCommand(string option){ //make sure the user has already run the read.otu command if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the bootstrap.shared command."); mothurOutEndLine(); abort = true; } - else if (globaldata->getGroupFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the bootstrap.shared command."); mothurOutEndLine(); abort = true; } + 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; } } //check for optional parameter and set defaults @@ -144,7 +144,7 @@ BootSharedCommand::BootSharedCommand(string option){ } catch(exception& e) { - errorOut(e, "BootSharedCommand", "BootSharedCommand"); + m->errorOut(e, "BootSharedCommand", "BootSharedCommand"); exit(1); } } @@ -153,17 +153,17 @@ BootSharedCommand::BootSharedCommand(string option){ void BootSharedCommand::help(){ try { - mothurOut("The bootstrap.shared command can only be executed after a successful read.otu command.\n"); - mothurOut("The bootstrap.shared command parameters are groups, calc, iters and label.\n"); - mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n"); - 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"); - mothurOut("The bootstrap.shared command should be in the following format: bootstrap.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels, iters=yourIters).\n"); - mothurOut("Example bootstrap.shared(groups=A-B-C, calc=jabund-sorabund, iters=100).\n"); - mothurOut("The default value for groups is all the groups in your groupfile.\n"); - mothurOut("The default value for calc is jclass-thetayc. The default for iters is 1000.\n"); + 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) { - errorOut(e, "BootSharedCommand", "help"); + m->errorOut(e, "BootSharedCommand", "help"); exit(1); } } @@ -222,7 +222,7 @@ int BootSharedCommand::execute(){ if(allLines == 1 || labels.count(order->getLabel()) == 1){ - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); process(order); processedLabels.insert(order->getLabel()); @@ -235,7 +235,7 @@ int BootSharedCommand::execute(){ delete order; order = input->getSharedOrderVector(lastLabel); - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); process(order); processedLabels.insert(order->getLabel()); @@ -257,12 +257,12 @@ int BootSharedCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -270,7 +270,7 @@ int BootSharedCommand::execute(){ if (needToRun == true) { if (order != NULL) { delete order; } order = input->getSharedOrderVector(lastLabel); - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); process(order); delete order; @@ -278,11 +278,17 @@ int BootSharedCommand::execute(){ //reset groups parameter globaldata->Groups.clear(); + + 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; } catch(exception& e) { - errorOut(e, "BootSharedCommand", "execute"); + m->errorOut(e, "BootSharedCommand", "execute"); exit(1); } } @@ -354,24 +360,24 @@ void BootSharedCommand::createTree(ostream* out, Tree* t){ } catch(exception& e) { - errorOut(e, "BootSharedCommand", "createTree"); + m->errorOut(e, "BootSharedCommand", "createTree"); exit(1); } } /***********************************************************/ void BootSharedCommand::printSims() { try { - mothurOut("simsMatrix"); mothurOutEndLine(); - for (int m = 0; m < simMatrix.size(); m++) { + m->mothurOut("simsMatrix"); m->mothurOutEndLine(); + for (int k = 0; k < simMatrix.size(); k++) { for (int n = 0; n < simMatrix.size(); n++) { - mothurOut(simMatrix[m][n]); mothurOut("\t"); + m->mothurOut(toString(simMatrix[k][n])); m->mothurOut("\t"); } - mothurOutEndLine(); + m->mothurOutEndLine(); } } catch(exception& e) { - errorOut(e, "BootSharedCommand", "printSims"); + m->errorOut(e, "BootSharedCommand", "printSims"); exit(1); } } @@ -386,9 +392,10 @@ void BootSharedCommand::process(SharedOrderVector* order) { //create a new filename outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[z]->getName() + ".boot" + order->getLabel() + ".tre"; openOutputFile(outputFile, *(out[z])); + outputNames.push_back(outputFile); } - mothurOut("Generating bootstrap trees..."); cout.flush(); + m->mothurOut("Generating bootstrap trees..."); cout.flush(); //create a file for each calculator with the 1000 trees in it. for (int p = 0; p < iters; p++) { @@ -438,7 +445,7 @@ void BootSharedCommand::process(SharedOrderVector* order) { } } - mothurOut("\tDone."); mothurOutEndLine(); + 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(); @@ -447,7 +454,7 @@ void BootSharedCommand::process(SharedOrderVector* order) { //create consensus trees for each bootstrapped tree set for (int k = 0; k < trees.size(); k++) { - mothurOut("Generating consensus tree for " + treeCalculators[k]->getName()); mothurOutEndLine(); + m->mothurOut("Generating consensus tree for " + treeCalculators[k]->getName()); m->mothurOutEndLine(); //set global data to calc trees globaldata->gTree = trees[k]; @@ -457,6 +464,9 @@ void BootSharedCommand::process(SharedOrderVector* order) { 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(); @@ -470,7 +480,7 @@ void BootSharedCommand::process(SharedOrderVector* order) { } catch(exception& e) { - errorOut(e, "BootSharedCommand", "process"); + m->errorOut(e, "BootSharedCommand", "process"); exit(1); } } diff --git a/bootstrapsharedcommand.h b/bootstrapsharedcommand.h index 6b63233..aa0c325 100644 --- a/bootstrapsharedcommand.h +++ b/bootstrapsharedcommand.h @@ -58,7 +58,7 @@ private: set labels; //holds labels to be used string outputFile, calc, groups, label, outputDir; int numGroups, iters; - vector Estimators, Groups; //holds estimators to be used + vector Estimators, Groups, outputNames; //holds estimators to be used }; diff --git a/bstick.cpp b/bstick.cpp index 5660997..d064ebe 100644 --- a/bstick.cpp +++ b/bstick.cpp @@ -67,8 +67,8 @@ EstOutput BStick::getValues(SAbundVector* rank){ data[1] = 0.886/sqrt(rdata.size()); data[2] = 1.031/sqrt(rdata.size()); - /*mothurOut(critVal); mothurOutEndLine(); - mothurOut("If D-Statistic is less than the critical value then the data fits the Broken Stick model w/ 95% confidence.\n\n");*/ + /*m->mothurOut(critVal); m->mothurOutEndLine(); + m->mothurOut("If D-Statistic is less than the critical value then the data fits the Broken Stick model w/ 95% confidence.\n\n");*/ if (isnan(data[0]) || isinf(data[0])) { data[0] = 0; } @@ -78,7 +78,7 @@ EstOutput BStick::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "BStick", "getValues"); + m->errorOut(e, "BStick", "getValues"); exit(1); } } diff --git a/calculator.cpp b/calculator.cpp index 7f7296b..3aa6a57 100644 --- a/calculator.cpp +++ b/calculator.cpp @@ -9,833 +9,59 @@ #include "calculator.h" -/*********************************************************************** -void VecCalc::printElements(vector vec){ - try { - for(int i = 0; i < vec.size(); i++) - cout << vec.at(i) << " "; - cout << "\n\n"; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function printElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function printElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/*********************************************************************** - -void VecCalc::printElements(vector vec){ - try { - for(int i = 0; i < vec.size(); i++) - cout << vec.at(i) << " "; - cout << "\n\n"; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function printElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function printElements. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -int VecCalc::findString(vector vec, string str){ - try { - for(int i = 0; i < vec.size(); i++) - if(str.compare(vec.at(i)) == 0) - return i; - return -1; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findString. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function findString. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -double VecCalc::mean(vector vec){ - return sumElements(vec)/vec.size(); -} -/*********************************************************************** -double VecCalc::stError(vector vec){ - try { - double sum = 0; - double m = mean(vec); - for(int i = 0; i < vec.size(); i++) - sum += pow(vec.at(i)-m,2); - return pow(sum/(vec.size()*(vec.size()-1)), .5); - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function stError. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function stError. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} /***********************************************************************/ int VecCalc::sumElements(vector vec){ - try { return sumElements(vec,0); - } - catch(exception& e) { - errorOut(e, "VecCalc", "sumElements"); - exit(1); - } } /***********************************************************************/ int VecCalc::sumElements(vector vec, int index){ - try { + int sum = 0; for(int i = index; i < vec.size(); i++) sum += vec.at(i); return sum; - } - catch(exception& e) { - errorOut(e, "VecCalc", "sumElements"); - exit(1); - } + } /***********************************************************************/ double VecCalc::sumElements(vector vec){ - try { double sum = 0; for(int i = 0; i < vec.size(); i++) sum += vec.at(i); return sum; - } - catch(exception& e) { - errorOut(e, "VecCalc", "sumElements"); - exit(1); - } + } /***********************************************************************/ double VecCalc::sumElements(vector vec, int index){ - try { + double sum = 0; for(int i = index; i < vec.size(); i++) sum += vec.at(i); return sum; - } - catch(exception& e) { - errorOut(e, "VecCalc", "sumElements"); - exit(1); - } -} -/*********************************************************************** -double VecCalc::findMax(vector vec){ - try { - double max = -1000000.0; - for(int i = 0; i < vec.size(); i++) - if(vec.at(i) > max) - max = vec.at(i); - return max; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findMax. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function findMax. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } + } /***********************************************************************/ int VecCalc::numNZ(vector vec){ - try { + int numNZ = 0; for(int i = 0; i < vec.size(); i++) if(vec.at(i) != 0) numNZ++; return numNZ; - } - catch(exception& e) { - errorOut(e, "VecCalc", "numNZ"); - exit(1); - } + } /***********************************************************************/ double VecCalc::numNZ(vector vec){ - try { + double numNZ = 0; for(int i = 0; i < vec.size(); i++) if(vec.at(i) != 0) numNZ++; return numNZ; } - catch(exception& e) { - errorOut(e, "VecCalc", "numNZ"); - exit(1); - } -} -/*********************************************************************** -double VecCalc::numPos(vector vec){ - try { - double numPos = 0; - for(int i = 0 ; i < vec.size(); i++) - if(vec.at(i) > 0) - numPos++; - return numPos; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function numPos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function numPos. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -double VecCalc::findMaxDiff(vector vec1, vector vec2){ - try { - double maxDiff = -10000000000.0; - for(int i = 0; i < vec1.size(); i++) - if(fabs(vec1.at(i)-vec2.at(i)) > maxDiff) - maxDiff = fabs(vec1.at(i)-vec2.at(i)); - return maxDiff; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findMaxDiff. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function findMaxDiff. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -double VecCalc::findDStat(vector vec1, vector vec2, double num){ - try { - double mDiff = findMaxDiff(vec1, vec2); - return (mDiff+.5)/num; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findDStat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function findDStat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::findQuartiles(vector vec){ - try { - vector quartiles; - double max = vec.at(vec.size()-1); - double r1 = max/4; - double r2 = max*3/4; - bool r1found = false; - bool r2found = false; - for(int i = 0; i < vec.size(); i++) - { - if(vec.at(i) > r1 && !r1found) - { - quartiles.push_back(i); - r1found = true; - } - if(vec.at(i) > r2 && !r2found) - { - quartiles.push_back(i); - i = vec.size(); - } - } - return quartiles; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function findQuartiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function findQuartiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::add(vector vec, double x){ - try { - vector newVec; - for(int i = 0; i < vec.size(); i++) - newVec.push_back(vec.at(i)+x); - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function add. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function add. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::multiply(vector vec, double x){ - try { - vector newVec; - for(int i = 0; i < vec.size(); i++) - newVec.push_back(vec.at(i)*x); - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function multiply. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function multiply. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::power(vector vec, double p){ - try { - vector newVec; - for(int i = 0; i < vec.size(); i++) - newVec.push_back(pow(vec.at(i), p)); - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function power. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function power. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::addVecs(vector vec1, vector vec2) //Vectors must be the same size. -{ try { - vector newVec; - for(int i = 0; i < vec1.size(); i++) - newVec.push_back(vec1.at(i)+vec2.at(i)); - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function addVecs. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function addVecs. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::multVecs(vector vec1, vector vec2) //Vectors must be the same size. -{ try { - vector newVec; - for(int i = 0; i < vec1.size(); i++) - newVec.push_back(vec1.at(i)*vec2.at(i)); - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function multVecs. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function multVecs. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::remDup(vector vec){ - try { - vector newVec; - newVec.push_back(vec.at(0)); - for(int i = 1; i < vec.size(); i++) - if(vec.at(i) != vec.at(i-1)) - newVec.push_back(vec.at(i)); - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function remDup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function remDup. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::genCVec(vector vec1){ - try { - vector vec2; - double sum = 0; - for(int i = 0; i < vec1.size(); i++) - { - sum += vec1.at(i); - vec2.push_back(sum); - } - return vec2; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genCVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function genCVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::genRelVec(vector vec){ - try { - vector newVec; - double sum = sumElements(vec); - for(int i = 0; i < vec.size(); i++) - newVec.push_back(vec.at(i)/sum); - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genRelVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function genRelVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::genDiffVec(vector vec1, vector vec2){ - try { - vector newVec; - for(int i = 0; i < vec1.size(); i++) - newVec.push_back(vec1.at(i)-vec2.at(i)); - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genDiffVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function genDiffVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::genCSVec(vector vec){ - try { - vector newVec; - double curInd = vec.at(vec.size()-1); - double sumSpec = 0; - double cSumSpec = 0; - for(int i = vec.size()-1; i >= 0; i--) - { - if(vec.at(i) == curInd) - sumSpec++; - else - { - cSumSpec += sumSpec; - newVec.push_back(cSumSpec); - sumSpec = 1; - curInd = vec.at(i); - } - if(i == 0) - newVec.push_back(cSumSpec + sumSpec); - } - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genCSVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function genCSVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::genTotVec(vector > vec){ - try { - vector newVec = vec.at(0); - for(int i = 1; i < vec.size(); i++) - newVec = addVecs(newVec, vec.at(i)); - return newVec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function genTotVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function genTotVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::quicksort(vector vec){ - try { - sort(vec.rbegin(), vec.rend()); - return vec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function quicksort. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function quicksort. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector > VecCalc::gen2DVec(vector vec, int div, int type){ - try { - vector > vec2D; - int gap = vec.size()/div; - for(int i = 0; i < div; i++) - { - vector inVec; - for(int j = 0; j < gap; j++) - if(type == 0) - inVec.push_back(vec.at(j + i*gap)); //Rows - else - inVec.push_back(vec.at(i + j*div)); //Columns - vec2D.push_back(inVec); - } - return vec2D; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function gen2DVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function gen2DVec. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -vector VecCalc::getSData(char name[]){ - try { - vector vec; - string data; - ifstream file(name); - if(file.is_open()) - { - while(file >> data) - vec.push_back(data); - file.close(); - } - return vec; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the VecCalc class Function getSData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the VecCalc class function getSData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/***********************************************************************/ - -/*********************************************************************** -void BrokenStick::doBStick(vector vec)//vec = The data vector. -{ try { - VecCalc vecCalc; - vec = vecCalc.quicksort(vec); - double numInd = vecCalc.sumElements(vec); - double numSpec = vecCalc.numNZ(vec); - vector cObsVec = vecCalc.genCVec(vec); - vector cExpVec; - vec = vecCalc.power(vec, -1); - double sumExp = 0; - for(int i = 0; i < numSpec; i++) - { - double n = 0; - for(int j = i; j < numSpec; j++) - n += 1/(double)(j+1); - - sumExp += numInd/numSpec*n; - cExpVec.push_back(sumExp); - } - - //Statistical analysis - double maxDiff = vecCalc.findMaxDiff(cObsVec, cExpVec); - double DStatistic = maxDiff/numInd; - - cout << "D-Statistic = " << DStatistic << "\n"; - if(vec.size() > 30) - cout << "Critical value for 95% confidence interval = " << .886/sqrt(vec.size()) << "\n"; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the BrokenStick class Function doBStick. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the BrokenStick class function doBStick. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/*********************************************************************** -double kEq(double k, double spec) -{ - return k/(1-k)*pow(1-k, spec)/(1-pow(1-k, spec)); -} -/***********************************************************************/ -/*void GeometricSeries::doGeomTest(vector vec)//vec = the data vector -{ try { - VecCalc vecCalc; - vec = vecCalc.quicksort(vec);//Sorts vec - double numInd = vecCalc.sumElements(vec);//numInd = The total number of individuals in the data set. - double numSpec = vecCalc.numNZ(vec);//numSpec = the number of nonzero elements in the data set. - double min = -1.0*vecCalc.findMax(vecCalc.multiply(vec, -1)); - double k = .5; - double step = .49999; - while(fabs(min - numInd*kEq(k, numSpec)) > .0001)//This uses a binary search to find the value of k. - { - if(numInd*kEq(k, numSpec) > min) - k += step; - else - k -= step; - step /= 2; - } - cout << "k = " << k << "\n"; - double cK = 1/(1-pow(1-k, numSpec)); - - vector cObsVec = vecCalc.genCVec(vec); - vector cExpVec; - double sumExp = 0; - for(int i = 0; i < vec.size(); i++) - { - sumExp += numInd*cK*k*pow(1-k, i); - cExpVec.push_back(sumExp); - } - double maxDiff = vecCalc.findMaxDiff(cObsVec, cExpVec); - double DStatistic = maxDiff/numInd; - - //Statistical Analysis - cout << "D-Statistic = " << DStatistic << "\n"; - if(vec.size() > 30) - cout << "Critical value for 95% confidence interval = " << .886/sqrt(vec.size()) << "\n"; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the GeometricSeries class Function doGeomTest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the GeometricSeries class function doGeomTest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -}*/ - -/*********************************************************************** -void Jackknifing::doJK(vector vec, double cols)//vec = the data vector if the data table was read left-to-right, top-to-bottom. cols = The number of columns in the data table. -{ try { - VecCalc vecCalc; - SSBPDiversityIndices ssbp; - double rows = vec.size()/cols; - vector > species = vecCalc.gen2DVec(vec, rows, 0);//converts vec into a 2 dimensional vector - vector sumRows; - vector pVals; - - for(int i = 0; i < rows; i++) - sumRows.push_back(vecCalc.sumElements(species.at(i))); - double st = 1/ssbp.getSimp(sumRows);//The observed estimate using the Simpson Index. Can be changed to use other indexes of diversity. - for(int i = 0; i < cols; i++) - { - vector newVec; - for(int j = 0; j < rows; j++) - newVec.push_back(vecCalc.sumElements(species.at(j))-species.at(j).at(i)); - pVals.push_back(cols*st-((cols-1)/ssbp.getSimp(newVec))); - } - - double mean = vecCalc.mean(pVals); - double stErr = vecCalc.stError(pVals);//stErr = standard error - TDTable table; - double confidence = .95; - double confLimit; - cout << "Confidence Level (.8, .9, .95, .98, .99, .998, .999): "; - cin >> confidence; - double confLevels[] = {.80,.90,.95,.98,.99,.998,.999}; - for(int i = 0; i < 7; i++) - if(confidence == confLevels[i]) - { - confLimit = table.getConfLimit(cols-2,i); - i = 7; - } - - //Statistical Analysis - cout << "Lower limit = " << mean - confLimit*stErr << "\n"; - cout << "Upper limit = " << mean + confLimit*stErr << "\n"; - cout << "Observed estimate = " << st << "\n\n"; - cout << "Jackknifed estimate = " << mean << "\n"; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the Jackknifing class Function doJK. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the Jackknifing class function doJK. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -void KS2SampleTest::doKSTest(vector abun1, vector abun2)//abun1 = 1st vector of abundances, abun2 = 2nd vector of abundances -{ try { - VecCalc vecCalc; - double numNZ1 = vecCalc.numNZ(abun1);//Number of nonzero elements in abun1 - double numNZ2 = vecCalc.numNZ(abun2);//Number of nonzero elements in abun2 - abun1 = vecCalc.quicksort(abun1);//Sorts abun1 - abun2 = vecCalc.quicksort(abun2);//Sorts abun2 - abun1 = vecCalc.genRelVec(abun1);//Generates the relative vector for abun1 - abun2 = vecCalc.genRelVec(abun2);//Generates the relative vector for abun2 - - abun1 = vecCalc.genCVec(abun1);//Generates the cumulative vector for abun1 - abun2 = vecCalc.genCVec(abun2);//Generates the cumulative vector for abun2 - - double maxDiff = vecCalc.findMaxDiff(abun1, abun2); - double DStatistic = maxDiff*numNZ1*numNZ2; - - cout << "Null Hypothesis = There is no difference.\n"; - cout << "D-Statistic = " << DStatistic << "\n"; - - double a = pow((numNZ1 + numNZ2)/(numNZ1*numNZ2),.5); - double pVal = exp(-2*pow(maxDiff/a,2)); - - if(numNZ1 > 25 && numNZ2 > 25) //If the sample sizes are both bigger than 25. - cout << "P-Value = " << pVal << "\n\n"; - else - { - cout << "D-Statistic must be higher than the critical value to reject the null hypothesis.\n" ; - cout << "90% Confidence Critical Value = " << 1.22*a*numNZ1*numNZ2 << "\n"; - cout << "95% Confidence Critical Value = " << 1.36*a*numNZ1*numNZ2 << "\n"; - } - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the KS2SampleTest class Function doKSTest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the KS2SampleTest class function doKSTest. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} - -/*********************************************************************** - -void QStatistic::doQStat(vector vec)//vec = The data vector. -{ try { - VecCalc vecCalc; - vector cVec = vecCalc.genCSVec(vec); - vector q = vecCalc.findQuartiles(cVec);//q.at(0) is the index of the first quartile; q.at(1) is the index of the second quartile. - vector nDupVec = vecCalc.remDup(vec);//nDupVec only contains one of every unique element in cVec. - double Q; - if(q.at(0) != 0)//The case if neither quartile is 0 or 1 - Q = (.5*(cVec.at(q.at(0))-cVec.at(q.at(0)-1)) + (cVec.at(q.at(1)-1)-cVec.at(q.at(0))) + .5*(cVec.at(q.at(1))-cVec.at(q.at(1)-1)))/log(nDupVec.at(nDupVec.size()-1-q.at(1))/nDupVec.at(nDupVec.size()-1-q.at(0))); - else if(q.at(0) == 0 && (q.at(1) == 0 || q.at(1) == 1))//The case if the quartiles are both at index 0 or one is at 0 and the other at 1. - Q = (.5*cVec.at(0) + .5*(cVec.at(1)-cVec.at(0)))/log(nDupVec.at(nDupVec.size()-2)/nDupVec.at(nDupVec.size()-1)); - else if(q.at(0) == 0 && q.at(1) > 1) //The case if the lower quartile is at index 0 and upper quartile index is above index 1. - Q = (.5*cVec.at(0) + (cVec.at(q.at(1)-1)-cVec.at(q.at(0))) + .5*(cVec.at(q.at(1))-cVec.at(q.at(1)-1)))/log(nDupVec.at(nDupVec.size()-1-q.at(1))/nDupVec.at(nDupVec.size()-1)); - - cout << "Q = " << Q << "\n"; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the QStatistic class Function doQStat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the QStatistic class function doQStat. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -double SSBPDiversityIndices::getShan(vector vec)//vec = The data vector. -{ try { - VecCalc vecCalc; - double nz = vecCalc.numNZ(vec); - double nSum = vecCalc.sumElements(vec); - double H = 0; - for(int i = 0; i < nz; i++) - H += vec.at(i)/nSum*log(vec.at(i)/nSum); - H *= -1; - return H; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SSBPDiversityIndices class Function getShan. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SSBPDiversityIndices class function getShan. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -double SSBPDiversityIndices::getSimp(vector vec)//vec = The data vector. -{ try { - VecCalc vecCalc; - double nSum = vecCalc.sumElements(vec); - double D = 0; - for(int j = 0; j < vec.size(); j++) - D += vec.at(j)*(vec.at(j)-1)/(nSum*(nSum-1)); - return D; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SSBPDiversityIndices class Function getSimp. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SSBPDiversityIndices class function getSimp. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -double SSBPDiversityIndices::getBP(vector vec)//vec = The data vector. -{ try { - VecCalc vecCalc; - double nSum = vecCalc.sumElements(vec); - return vecCalc.findMax(vec)/nSum; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SSBPDiversityIndices class Function getBP. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SSBPDiversityIndices class function getBP. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -void SSBPDiversityIndices::doSSBP(vector vec)//vec = The data vector. -{ try { - VecCalc vecCalc; - double nz = vecCalc.numNZ(vec); - - //Shannon index - double H = getShan(vec); - cout << "H = " << H << "\n"; - cout << "Eveness = " << H/log(nz) << "\n\n"; - - //Simpson index - double D = getSimp(vec); - cout << "D diversity = " << 1/D << "\n"; - cout << "Eveness = " << 1/D/nz << "\n\n"; - - //Berger-Parker index - double BP = getBP(vec); - cout << "BP index = " << BP << "\n\n"; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SSBPDiversityIndices class Function doSSBP. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SSBPDiversityIndices class function doSSBP. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} /***********************************************************************/ double TDTable::getConfLimit(int row, int col) //Rows are the degrees of freedom -{ try { +{ //Found on http://www.vgtu.lt/leidiniai/elektroniniai/Probability.pdf/Table%203.pdf //Confidence Level .90 .95 .975 .99 .995 .999 .9995 @@ -871,120 +97,10 @@ double TDTable::getConfLimit(int row, int col) //Rows are the degrees of freedom {1.310, 1.697, 2.042, 2.457, 2.750, 3.385, 3.646}}; return values[row][col]; - } - catch(exception& e) { - errorOut(e, "TDTable", "getConfLimit"); - exit(1); - } + } -/*********************************************************************** -double KOSTable::getConfLimit(int index) //Table of Critical values for N = 4-20 for One-Sample Kolmogorov-Smirnov Test -{ try { - //Confidence Level = .05 - //Sample size = 4-20. - //Found on http://www.utdallas.edu/~herve/MolinAbdi1998-LillieforsTechReport.pdf +/***********************************************************************/ - double values[21] = {.9011, - .6372, - .5203, - .4506, - 0.3754, - 0.3427, - 0.3245, - 0.3041, - 0.2875, - 0.2744, - 0.2616, - 0.2506, - 0.2426, - 0.2337, - 0.2257, - 0.2196, - 0.2128, - 0.2071, - 0.2018, - 0.1965, - 0.1920, - }; - return values[index]; - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the TDTable class Function getConfLimit. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the TDTable class function getConfLimit. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*********************************************************************** -void TrunLN::doTrunLN(vector indVec, vector specVec) //indVec = individuals vector, specVec = species vector -{ - VecCalc vecCalc; - double numSpec = vecCalc.sumElements(specVec); //numSpec = The total number of species - double numInd = vecCalc.sumElements(vecCalc.multVecs(indVec,specVec)); //numInd = The total number of individuals - - double obsMean = 0; - for(int i = 0; i < indVec.size(); i++) - obsMean += log10(indVec.at(i)); - obsMean /= numSpec; //obsMean = observed mean of the individuals vector - cout << "obsMean = " << obsMean << "\n"; - double variance = 0; - for(int t = 0; t < indVec.size(); t++) - variance += pow(log10(indVec.at(t))-obsMean,2)/numSpec; - - double rO = 0; - for(int k = 0; k < indVec.size(); k++) - rO += log10(indVec.at(k)); - rO /= indVec.size(); - double veilLine = .5;//The desired veil line. - double auxFunc = -(obsMean-rO)/(obsMean-log10(veilLine)); - double uX = obsMean-auxFunc*(obsMean-log10(veilLine)); - double vX = variance + auxFunc*pow(obsMean-log10(veilLine),2); - double z = (log10(veilLine)-uX)/pow(vX, .5); - double p = .5*(erf(z)+1); - double specRichness = numSpec/(1-p); - - double numUnseen = .5*(erf((log10(.5)-uX)/pow(vX,.5))+1)*specRichness; - - - vector cExp; - for(int i = 1; i < 8; i++) - { - double a = pow(10, i-1)+.5; - double b = log10(a); - double c = (b - uX)/pow(vX,.5); - double d = .5*(erf(c)+1); - double numS = d*specRichness; - double toPush = numS - numUnseen; - cExp.push_back(toPush); - } - vector cObs; - double sumOct = 0; - for(int i = 0; i < 8; i++) - { - sumOct = 0; - for(int r = 0; r < indVec.size(); r++) - { - if(indVec.at(r) < pow(10, i-1)+.5) - sumOct += specVec.at(r); - else - { - cObs.push_back(sumOct); - sumOct = specVec.at(r); - r = indVec.size(); - } - if(r == indVec.size()-1) - cObs.push_back(sumOct); - } - } - //Statistical Analysis - double d = vecCalc.findDStat(cExp, cObs, numSpec); - cout << "DStat = " << d << "\n"; - cout << ".05 confidence value = " << .89196/sqrt(numSpec) << "\n"; - cout << ".01 confidence value = " << 1.0471/sqrt(numSpec) << "\n\n"; -} -/***********************************************************************/ diff --git a/calculator.h b/calculator.h index ffc92b9..8d9b8f0 100644 --- a/calculator.h +++ b/calculator.h @@ -7,6 +7,7 @@ #include "sharedsabundvector.h" #include "rabundvector.hpp" #include "uvest.h" +#include "mothurout.h" /* The calculator class is the parent class for all the different estimators implemented in mothur except the tree calculators. It has 2 pure functions EstOutput getValues(SAbundVector*), which works on a single group, and @@ -20,9 +21,9 @@ typedef vector EstOutput; class Calculator { public: - Calculator(){}; + Calculator(){ m = MothurOut::getInstance(); } virtual ~Calculator(){}; - Calculator(string n, int c, bool m) : name(n), cols(c), multiple(m) {}; + Calculator(string n, int c, bool f) : name(n), cols(c), multiple(f) {}; virtual EstOutput getValues(SAbundVector*) = 0; virtual EstOutput getValues(vector) = 0; virtual void print(ostream& f) { f.setf(ios::fixed, ios::floatfield); f.setf(ios::showpoint); @@ -31,6 +32,7 @@ public: virtual int getCols() { return cols; } virtual bool getMultiple() { return multiple; } protected: + MothurOut* m; EstOutput data; string name; int cols; diff --git a/ccode.cpp b/ccode.cpp index 28e9723..00a30e5 100644 --- a/ccode.cpp +++ b/ccode.cpp @@ -38,8 +38,6 @@ void Ccode::printHeader(ostream& out) { void Ccode::print(ostream& out, ostream& outAcc) { try { - mothurOutEndLine(); - ofstream out2; openOutputFileAppend(mapInfo, out2); @@ -111,7 +109,7 @@ void Ccode::print(ostream& out, ostream& outAcc) { out << endl; if (results) { - mothurOut(querySeq->getName() + " was found have at least one chimeric window."); mothurOutEndLine(); + m->mothurOut(querySeq->getName() + " was found have at least one chimeric window."); m->mothurOutEndLine(); outAcc << querySeq->getName() << endl; } @@ -121,7 +119,7 @@ void Ccode::print(ostream& out, ostream& outAcc) { } catch(exception& e) { - errorOut(e, "Ccode", "print"); + m->errorOut(e, "Ccode", "print"); exit(1); } } @@ -224,7 +222,7 @@ int Ccode::getChimeras(Sequence* query) { return 0; } catch(exception& e) { - errorOut(e, "Ccode", "getChimeras"); + m->errorOut(e, "Ccode", "getChimeras"); exit(1); } } @@ -306,7 +304,7 @@ void Ccode::trimSequences(Sequence* query) { //check to make sure that is not whole seq - if ((rearPos - frontPos - 1) <= 0) { mothurOut("Error, when I trim your sequences, the entire sequence is trimmed."); mothurOutEndLine(); exit(1); } + if ((rearPos - frontPos - 1) <= 0) { m->mothurOut("Error, when I trim your sequences, the entire sequence is trimmed."); m->mothurOutEndLine(); exit(1); } map tempTrim; tempTrim[frontPos] = rearPos; @@ -326,7 +324,7 @@ void Ccode::trimSequences(Sequence* query) { spotMap = newMap; } catch(exception& e) { - errorOut(e, "Ccode", "trimSequences"); + m->errorOut(e, "Ccode", "trimSequences"); exit(1); } } @@ -341,13 +339,13 @@ vector Ccode::findWindows() { //default is wanted = 10% of total length if (windowSizes > length) { - mothurOut("You have slected a window larger than your sequence length after all filters, masks and trims have been done. I will use the default 10% of sequence length."); + m->mothurOut("You have slected a window larger than your sequence length after all filters, masks and trims have been done. I will use the default 10% of sequence length."); windowSizes = length / 10; }else if (windowSizes == 0) { windowSizes = length / 10; } else if (windowSizes > (length * 0.20)) { - mothurOut("You have selected a window that is larger than 20% of your sequence length. This is not recommended, but I will continue anyway."); mothurOutEndLine(); + m->mothurOut("You have selected a window that is larger than 20% of your sequence length. This is not recommended, but I will continue anyway."); m->mothurOutEndLine(); }else if (windowSizes < (length * 0.05)) { - mothurOut("You have selected a window that is smaller than 5% of your sequence length. This is not recommended, but I will continue anyway."); mothurOutEndLine(); + m->mothurOut("You have selected a window that is smaller than 5% of your sequence length. This is not recommended, but I will continue anyway."); m->mothurOutEndLine(); } //save starting points of each window @@ -361,7 +359,7 @@ vector Ccode::findWindows() { return win; } catch(exception& e) { - errorOut(e, "Ccode", "findWindows"); + m->errorOut(e, "Ccode", "findWindows"); exit(1); } } @@ -416,7 +414,7 @@ int Ccode::getDiff(string seqA, string seqB) { } catch(exception& e) { - errorOut(e, "Ccode", "getDiff"); + m->errorOut(e, "Ccode", "getDiff"); exit(1); } } @@ -486,12 +484,12 @@ void Ccode::removeBadReferenceSeqs(vector& seqs) { seqs = goodSeqs; }else { //warn, but dont remove any - mothurOut(querySeq->getName() + " does not have an adaquate number of reference sequences that are within 20% and 0.5% similarity. I will continue, but please check."); mothurOutEndLine(); + m->mothurOut(querySeq->getName() + " does not have an adaquate number of reference sequences that are within 20% and 0.5% similarity. I will continue, but please check."); m->mothurOutEndLine(); } } catch(exception& e) { - errorOut(e, "Ccode", "removeBadReferenceSeqs"); + m->errorOut(e, "Ccode", "removeBadReferenceSeqs"); exit(1); } } @@ -531,7 +529,7 @@ vector Ccode::findClosest(Sequence* q, int numWanted) { } catch(exception& e) { - errorOut(e, "Ccode", "findClosestSides"); + m->errorOut(e, "Ccode", "findClosestSides"); exit(1); } } @@ -618,7 +616,7 @@ void Ccode::getAverageRef(vector ref) { } catch(exception& e) { - errorOut(e, "Ccode", "getAverageRef"); + m->errorOut(e, "Ccode", "getAverageRef"); exit(1); } } @@ -687,7 +685,7 @@ void Ccode::getAverageQuery (vector ref, Sequence* query) { } } catch(exception& e) { - errorOut(e, "Ccode", "getAverageQuery"); + m->errorOut(e, "Ccode", "getAverageQuery"); exit(1); } } @@ -713,7 +711,7 @@ void Ccode::findVarianceRef() { } } catch(exception& e) { - errorOut(e, "Ccode", "findVarianceRef"); + m->errorOut(e, "Ccode", "findVarianceRef"); exit(1); } } @@ -738,7 +736,7 @@ void Ccode::findVarianceQuery() { } catch(exception& e) { - errorOut(e, "Ccode", "findVarianceQuery"); + m->errorOut(e, "Ccode", "findVarianceQuery"); exit(1); } } @@ -800,7 +798,7 @@ void Ccode::determineChimeras() { } catch(exception& e) { - errorOut(e, "Ccode", "determineChimeras"); + m->errorOut(e, "Ccode", "determineChimeras"); exit(1); } } @@ -845,13 +843,13 @@ float Ccode::getT(int numseq) { else if (numseq > 2) tvalue = 2.353; else if (numseq > 1) tvalue = 2.920; else if (numseq <= 1) { - mothurOut("Two or more reference sequences are required, your data will be flawed.\n"); mothurOutEndLine(); + m->mothurOut("Two or more reference sequences are required, your data will be flawed.\n"); m->mothurOutEndLine(); } return tvalue; } catch(exception& e) { - errorOut(e, "Ccode", "getT"); + m->errorOut(e, "Ccode", "getT"); exit(1); } } @@ -897,13 +895,13 @@ float Ccode::getF(int numseq) { else if (numseq > 1) fvalue = 18.5; else if (numseq > 0) fvalue = 161; else if (numseq <= 0) { - mothurOut("Two or more reference sequences are required, your data will be flawed.\n"); mothurOutEndLine(); + m->mothurOut("Two or more reference sequences are required, your data will be flawed.\n"); m->mothurOutEndLine(); } return fvalue; } catch(exception& e) { - errorOut(e, "Ccode", "getF"); + m->errorOut(e, "Ccode", "getF"); exit(1); } } diff --git a/chao1.cpp b/chao1.cpp index 590c20e..ad1faa2 100644 --- a/chao1.cpp +++ b/chao1.cpp @@ -70,7 +70,7 @@ EstOutput Chao1::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "Chao1", "getValues"); + m->errorOut(e, "Chao1", "getValues"); exit(1); } } diff --git a/chimera.cpp b/chimera.cpp index e7253ec..820b475 100644 --- a/chimera.cpp +++ b/chimera.cpp @@ -50,11 +50,11 @@ string Chimera::createFilter(vector seqs, float t) { //cout << "a = " << a[i] << " t = " << t[i] << " g = " << g[i] << " c = " << c[i] << endl; } - mothurOut("Filter removed " + toString(numColRemoved) + " columns."); mothurOutEndLine(); + m->mothurOut("Filter removed " + toString(numColRemoved) + " columns."); m->mothurOutEndLine(); return filterString; } catch(exception& e) { - errorOut(e, "Chimera", "createFilter"); + m->errorOut(e, "Chimera", "createFilter"); exit(1); } } @@ -80,7 +80,7 @@ map Chimera::runFilter(Sequence* seq) { return maskMap; } catch(exception& e) { - errorOut(e, "Chimera", "runFilter"); + m->errorOut(e, "Chimera", "runFilter"); exit(1); } } @@ -88,9 +88,10 @@ map Chimera::runFilter(Sequence* seq) { vector Chimera::readSeqs(string file) { try { - mothurOut("Reading sequences... "); cout.flush(); + m->mothurOut("Reading sequences... "); cout.flush(); ifstream in; openInputFile(file, in); + vector container; int count = 0; length = 0; @@ -110,12 +111,12 @@ vector Chimera::readSeqs(string file) { } in.close(); - mothurOut("Done."); mothurOutEndLine(); + m->mothurOut("Done."); m->mothurOutEndLine(); return container; } catch(exception& e) { - errorOut(e, "Chimera", "readSeqs"); + m->errorOut(e, "Chimera", "readSeqs"); exit(1); } } @@ -143,7 +144,7 @@ void Chimera::setMask(string filename) { } } catch(exception& e) { - errorOut(e, "Chimera", "setMask"); + m->errorOut(e, "Chimera", "setMask"); exit(1); } } @@ -186,7 +187,7 @@ vector< vector > Chimera::readQuantiles() { } catch(exception& e) { - errorOut(e, "Chimera", "readQuantiles"); + m->errorOut(e, "Chimera", "readQuantiles"); exit(1); } } @@ -204,14 +205,14 @@ Sequence* Chimera::getSequence(string name) { } } - if(spot == -1) { mothurOut("Error: Could not find sequence."); mothurOutEndLine(); return NULL; } + if(spot == -1) { m->mothurOut("Error: Could not find sequence."); m->mothurOutEndLine(); return NULL; } temp = new Sequence(templateSeqs[spot]->getName(), templateSeqs[spot]->getAligned()); return temp; } catch(exception& e) { - errorOut(e, "Chimera", "getSequence"); + m->errorOut(e, "Chimera", "getSequence"); exit(1); } } diff --git a/chimera.h b/chimera.h index 8c00aec..f6a5180 100644 --- a/chimera.h +++ b/chimera.h @@ -88,10 +88,10 @@ class Chimera { public: - Chimera(){}; - Chimera(string); - Chimera(string, bool, string); - Chimera(string, string); + Chimera(){ m = MothurOut::getInstance(); } + Chimera(string) { m = MothurOut::getInstance(); } + Chimera(string, bool, string) { m = MothurOut::getInstance(); } + Chimera(string, string) { m = MothurOut::getInstance(); } virtual ~Chimera(){ for (int i = 0; i < templateSeqs.size(); i++) { delete templateSeqs[i]; } }; virtual void setFilter(bool f) { filter = f; } virtual void setCorrection(bool c) { correction = c; } @@ -138,6 +138,7 @@ class Chimera { float divR; string seqMask, quanfile, filterString, name, outputDir, templateFileName; Sequence* getSequence(string); //find sequence from name + MothurOut* m; }; /***********************************************************************/ diff --git a/chimeracheckrdp.cpp b/chimeracheckrdp.cpp index 0a2ea59..3e6dacd 100644 --- a/chimeracheckrdp.cpp +++ b/chimeracheckrdp.cpp @@ -19,7 +19,7 @@ ChimeraCheckRDP::~ChimeraCheckRDP() { delete kmer; } catch(exception& e) { - errorOut(e, "ChimeraCheckRDP", "~AlignSim"); + m->errorOut(e, "ChimeraCheckRDP", "~AlignSim"); exit(1); } } @@ -27,7 +27,7 @@ ChimeraCheckRDP::~ChimeraCheckRDP() { void ChimeraCheckRDP::print(ostream& out, ostream& outAcc) { try { - mothurOut("Processing: " + querySeq->getName()); mothurOutEndLine(); + m->mothurOut("Processing: " + querySeq->getName()); m->mothurOutEndLine(); out << querySeq->getName() << endl; out << "IS scores: " << '\t'; @@ -50,7 +50,7 @@ void ChimeraCheckRDP::print(ostream& out, ostream& outAcc) { } } catch(exception& e) { - errorOut(e, "ChimeraCheckRDP", "print"); + m->errorOut(e, "ChimeraCheckRDP", "print"); exit(1); } } @@ -58,7 +58,7 @@ void ChimeraCheckRDP::print(ostream& out, ostream& outAcc) { void ChimeraCheckRDP::doPrep() { try { templateDB = new AlignmentDB(templateFileName, "kmer", kmerSize, 0.0,0.0,0.0,0.0); - mothurOutEndLine(); + m->mothurOutEndLine(); kmer = new Kmer(kmerSize); @@ -67,7 +67,7 @@ void ChimeraCheckRDP::doPrep() { } } catch(exception& e) { - errorOut(e, "ChimeraCheckRDP", "doPrep"); + m->errorOut(e, "ChimeraCheckRDP", "doPrep"); exit(1); } } @@ -89,7 +89,7 @@ int ChimeraCheckRDP::getChimeras(Sequence* query) { return 0; } catch(exception& e) { - errorOut(e, "ChimeraCheckRDP", "getChimeras"); + m->errorOut(e, "ChimeraCheckRDP", "getChimeras"); exit(1); } } @@ -118,14 +118,14 @@ vector ChimeraCheckRDP::findIS() { int start = seq.length() / 10; //for each window - for (int m = start; m < (seq.length() - start); m+=increment) { + for (int f = start; f < (seq.length() - start); f+=increment) { - if ((m - kmerSize) < 0) { mothurOut("Your sequence is too short for your kmerSize."); mothurOutEndLine(); exit(1); } + if ((f - kmerSize) < 0) { m->mothurOut("Your sequence is too short for your kmerSize."); m->mothurOutEndLine(); exit(1); } sim temp; - string fragLeft = seq.substr(0, m); //left side of breakpoint - string fragRight = seq.substr(m); //right side of breakpoint + string fragLeft = seq.substr(0, f); //left side of breakpoint + string fragRight = seq.substr(f); //right side of breakpoint //make a sequence of the left side and right side Sequence* left = new Sequence(queryName, fragLeft); @@ -145,7 +145,7 @@ vector ChimeraCheckRDP::findIS() { //right side is tricky - since the counts grow on eachother to find the correct counts of only the right side you must subtract the counts of the left side //iterate through left sides map to subtract the number of times you saw things before you got the the right side map rightside = queryKmerInfo[queryKmerInfo.size()-1]; - for (map::iterator itleft = queryKmerInfo[m-kmerSize].begin(); itleft != queryKmerInfo[m-kmerSize].end(); itleft++) { + for (map::iterator itleft = queryKmerInfo[f-kmerSize].begin(); itleft != queryKmerInfo[f-kmerSize].end(); itleft++) { int howManyTotal = queryKmerInfo[queryKmerInfo.size()-1][itleft->first]; //times that kmer was seen in total //itleft->second is times it was seen in left side, so howmanytotal - leftside should give you right side @@ -158,7 +158,7 @@ vector ChimeraCheckRDP::findIS() { } map closerightside = closeRightKmerInfo[closeRightKmerInfo.size()-1]; - for (map::iterator itright = closeRightKmerInfo[m-kmerSize].begin(); itright != closeRightKmerInfo[m-kmerSize].end(); itright++) { + for (map::iterator itright = closeRightKmerInfo[f-kmerSize].begin(); itright != closeRightKmerInfo[f-kmerSize].end(); itright++) { int howManyTotal = closeRightKmerInfo[(closeRightKmerInfo.size()-1)][itright->first]; //times that kmer was seen in total //itleft->second is times it was seen in left side, so howmanytotal - leftside should give you right side @@ -171,7 +171,7 @@ vector ChimeraCheckRDP::findIS() { } - int nLeft = calcKmers(closeLeftKmerInfo[m-kmerSize], queryKmerInfo[m-kmerSize]); + int nLeft = calcKmers(closeLeftKmerInfo[f-kmerSize], queryKmerInfo[f-kmerSize]); int nRight = calcKmers(closerightside, rightside); @@ -181,7 +181,7 @@ vector ChimeraCheckRDP::findIS() { temp.leftParent = closestLeft.getName(); temp.rightParent = closestRight.getName(); temp.score = is; - temp.midpoint = m; + temp.midpoint = f; isValues.push_back(temp); @@ -193,7 +193,7 @@ vector ChimeraCheckRDP::findIS() { } catch(exception& e) { - errorOut(e, "ChimeraCheckRDP", "findIS"); + m->errorOut(e, "ChimeraCheckRDP", "findIS"); exit(1); } } @@ -215,7 +215,7 @@ void ChimeraCheckRDP::readName(string namefile) { } catch(exception& e) { - errorOut(e, "ChimeraCheckRDP", "readName"); + m->errorOut(e, "ChimeraCheckRDP", "readName"); exit(1); } } @@ -252,7 +252,7 @@ int ChimeraCheckRDP::calcKmers(map query, map subject) { } catch(exception& e) { - errorOut(e, "ChimeraCheckRDP", "calcKmers"); + m->errorOut(e, "ChimeraCheckRDP", "calcKmers"); exit(1); } } @@ -310,7 +310,7 @@ void ChimeraCheckRDP::makeSVGpic(vector info) { } catch(exception& e) { - errorOut(e, "ChimeraCheckRDP", "makeSVGpic"); + m->errorOut(e, "ChimeraCheckRDP", "makeSVGpic"); exit(1); } } diff --git a/chimerarealigner.cpp b/chimerarealigner.cpp index fa9dd56..487e7ca 100644 --- a/chimerarealigner.cpp +++ b/chimerarealigner.cpp @@ -12,7 +12,7 @@ #include "nast.hpp" //*************************************************************************************************************** -ChimeraReAligner::ChimeraReAligner(vector t, int m, int mm) : match(m), misMatch(mm) { templateSeqs = t; } +ChimeraReAligner::ChimeraReAligner(vector t, int ms, int mm) : match(ms), misMatch(mm) { templateSeqs = t; m = MothurOut::getInstance(); } //*************************************************************************************************************** ChimeraReAligner::~ChimeraReAligner() {} //*************************************************************************************************************** @@ -78,7 +78,7 @@ void ChimeraReAligner::reAlign(Sequence* query, vector parents) { } catch(exception& e) { - errorOut(e, "ChimeraReAligner", "reAlign"); + m->errorOut(e, "ChimeraReAligner", "reAlign"); exit(1); } } @@ -96,14 +96,14 @@ Sequence* ChimeraReAligner::getSequence(string name) { } } - if(spot == -1) { mothurOut("Error: Could not find sequence."); mothurOutEndLine(); return NULL; } + if(spot == -1) { m->mothurOut("Error: Could not find sequence."); m->mothurOutEndLine(); return NULL; } temp = new Sequence(templateSeqs[spot]->getName(), templateSeqs[spot]->getAligned()); return temp; } catch(exception& e) { - errorOut(e, "ChimeraReAligner", "getSequence"); + m->errorOut(e, "ChimeraReAligner", "getSequence"); exit(1); } } diff --git a/chimerarealigner.h b/chimerarealigner.h index 2b53841..4cee6eb 100644 --- a/chimerarealigner.h +++ b/chimerarealigner.h @@ -30,6 +30,7 @@ class ChimeraReAligner { int match, misMatch; Sequence* getSequence(string); //find sequence from name + MothurOut* m; }; /***********************************************************/ diff --git a/chimeraseqscommand.cpp b/chimeraseqscommand.cpp index 1758cf6..86d6d50 100644 --- a/chimeraseqscommand.cpp +++ b/chimeraseqscommand.cpp @@ -17,7 +17,7 @@ //*************************************************************************************************************** -ChimeraSeqsCommand::ChimeraSeqsCommand(string option){ +ChimeraSeqsCommand::ChimeraSeqsCommand(string option) { try { abort = false; @@ -91,7 +91,7 @@ ChimeraSeqsCommand::ChimeraSeqsCommand(string option){ //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; mothurOut("fasta is a required parameter for the chimera.seqs command."); mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the chimera.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"){ @@ -198,15 +198,15 @@ ChimeraSeqsCommand::ChimeraSeqsCommand(string option){ else if (temp == "not found") { temp = "20"; } convert(temp, numwanted); - if ((search != "distance") && (search != "blast") && (search != "kmer")) { mothurOut(search + " is not a valid search."); mothurOutEndLine(); abort = true; } + if ((search != "distance") && (search != "blast") && (search != "kmer")) { m->mothurOut(search + " is not a valid search."); m->mothurOutEndLine(); abort = true; } - if (((method != "bellerophon")) && (templatefile == "")) { mothurOut("You must provide a template file with the pintail, ccode, chimeraslayer or chimeracheck methods."); mothurOutEndLine(); abort = true; } + if (((method != "bellerophon")) && (templatefile == "")) { m->mothurOut("You must provide a template file with the pintail, ccode, chimeraslayer or chimeracheck methods."); m->mothurOutEndLine(); abort = true; } } } catch(exception& e) { - errorOut(e, "ChimeraSeqsCommand", "ChimeraSeqsCommand"); + m->errorOut(e, "ChimeraSeqsCommand", "ChimeraSeqsCommand"); exit(1); } } @@ -216,51 +216,51 @@ void ChimeraSeqsCommand::help(){ try { //"fasta", "filter", "correction", "processors", "method", "window", "increment", "template", "conservation", "quantile", "mask", "numwanted", "ksize", "svg", "name" - //mothurOut("chimera.seqs ASSUMES that your sequences are ALIGNED and if using a template that the template file sequences are the same length as the fasta file sequences.\n\n"); - mothurOut("The chimera.seqs command reads a fastafile and creates list of potentially chimeric sequences.\n"); - mothurOut("The chimera.seqs command parameters are fasta, filter, correction, processors, mask, method, window, increment, template, conservation, quantile, numwanted, ksize, svg, name, iters, search, realign.\n"); - mothurOut("The fasta parameter is always required and template is required if using pintail, ccode or chimeracheck.\n"); - mothurOut("The filter parameter allows you to specify if you would like to apply a vertical and 50% soft filter. \n"); - 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.\n"); - mothurOut("The processors parameter allows you to specify how many processors you would like to use. The default is 1. \n"); - mothurOut("The method parameter allows you to specify the method for finding chimeric sequences. The default is pintail. Options include bellerophon, ccode and chimeracheck \n"); - 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"); - mothurOut("The window parameter allows you to specify the window size for searching for chimeras. \n"); - mothurOut("The increment parameter allows you to specify how far you move each window while finding chimeric sequences.\n"); - mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences. \n"); - mothurOut("The conservation parameter allows you to enter a frequency file containing the highest bases frequency at each place in the alignment.\n"); - mothurOut("The quantile parameter allows you to enter a file containing quantiles for a template files sequences.\n"); - mothurOut("The numwanted parameter allows you to specify how many sequences you would each query sequence compared with.\n"); - mothurOut("The ksize parameter allows you to input kmersize. \n"); - mothurOut("The svg parameter allows you to specify whether or not you would like a svg file outputted for each query sequence.\n"); - mothurOut("The name parameter allows you to enter a file containing names of sequences you would like .svg files for.\n"); - mothurOut("The iters parameter allows you to specify the number of bootstrap iters to do with the chimeraslayer method.\n"); - mothurOut("The minsim parameter allows you .... \n"); - mothurOut("The mincov parameter allows you to specify minimum coverage by closest matches found in template. Default is 70, meaning 70%. \n"); - mothurOut("The minbs parameter allows you to specify minimum bootstrap support for calling a sequence chimeric. Default is 90, meaning 90%. \n"); - mothurOut("The minsnp parameter allows you to specify percent of SNPs to sample on each side of breakpoint for computing bootstrap support (default: 10) \n"); - mothurOut("The search parameter allows you to specify search method for finding the closest parent. Choices are distance, blast, and kmer, default distance. -used only by chimeraslayer. \n"); - mothurOut("The realign parameter allows you to realign the query to the potential paretns. Choices are true or false, default false. -used only by chimeraslayer. \n"); - mothurOut("NOT ALL PARAMETERS ARE USED BY ALL METHODS. Please look below for method specifics.\n\n"); - mothurOut("Details for each method: \n"); - mothurOut("\tpintail: \n"); - mothurOut("\t\tparameters: fasta=required, template=required, filter=F, mask=no mask, processors=1, window=300, increment=25, conservation=not required, but will improve speed, quantile=not required, but will greatly improve speed. \n"); - mothurOut("\t\tIf you have run chimera.seqs using pintail a .quan and .freq file will be created for your template, if you have not provided them for use in future command executions.\n"); - mothurOut("\tbellerophon: \n"); - mothurOut("\t\tparameters: fasta=required, filter=F, processors=1, window=1/4 length of seq, increment=25, correction=T. \n"); - mothurOut("\tccode: \n"); - mothurOut("\t\tparameters: fasta=required, template=required, filter=F, mask=no mask, processors=1, window=10% of length, numwanted=20\n"); - mothurOut("\tchimeracheck: \n"); - mothurOut("\t\tparameters: fasta=required, template=required, processors=1, increment=10, ksize=7, svg=F, name=none\n\n"); - mothurOut("\tchimeraslayer: \n"); - mothurOut("\t\tparameters: fasta=required, template=required, processors=1, increment=10, mask=no mask, numwanted=10, match=5, mismatch=-4, divergence=1.0, minsim=90, parents=5, iters=1000, window=100. \n\n"); - mothurOut("The chimera.seqs command should be in the following format: \n"); - mothurOut("chimera.seqs(fasta=yourFastaFile, filter=yourFilter, correction=yourCorrection, processors=yourProcessors, method=bellerophon) \n"); - mothurOut("Example: chimera.seqs(fasta=AD.align, filter=True, correction=true, method=bellerophon, window=200) \n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); + //m->mothurOut("chimera.seqs ASSUMES that your sequences are ALIGNED and if using a template that the template file sequences are the same length as the fasta file sequences.\n\n"); + m->mothurOut("The chimera.seqs command reads a fastafile and creates list of potentially chimeric sequences.\n"); + m->mothurOut("The chimera.seqs command parameters are fasta, filter, correction, processors, mask, method, window, increment, template, conservation, quantile, numwanted, ksize, svg, name, iters, search, realign.\n"); + m->mothurOut("The fasta parameter is always required and template is required if using pintail, ccode or chimeracheck.\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 correction parameter allows you to put more emphasis on the distance between highly similar sequences and less emphasis on the differences between remote homologs.\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 method parameter allows you to specify the method for finding chimeric sequences. The default is pintail. Options include bellerophon, ccode and chimeracheck \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. \n"); + m->mothurOut("The window parameter allows you to specify the window size for searching for chimeras. \n"); + m->mothurOut("The increment parameter allows you to specify how far you move each window while finding chimeric sequences.\n"); + m->mothurOut("The template parameter allows you to enter a template file containing known non-chimeric sequences. \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.\n"); + m->mothurOut("The numwanted parameter allows you to specify how many sequences you would each query sequence compared with.\n"); + m->mothurOut("The ksize parameter allows you to input kmersize. \n"); + m->mothurOut("The svg parameter allows you to specify whether or not you would like a svg file outputted for each query sequence.\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("The iters parameter allows you to specify the number of bootstrap iters to do with the chimeraslayer method.\n"); + m->mothurOut("The minsim parameter allows you .... \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: 10) \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. -used only by chimeraslayer. \n"); + m->mothurOut("The realign parameter allows you to realign the query to the potential paretns. Choices are true or false, default false. -used only by chimeraslayer. \n"); + m->mothurOut("NOT ALL PARAMETERS ARE USED BY ALL METHODS. Please look below for method specifics.\n\n"); + m->mothurOut("Details for each method: \n"); + m->mothurOut("\tpintail: \n"); + m->mothurOut("\t\tparameters: fasta=required, template=required, filter=F, mask=no mask, processors=1, window=300, increment=25, conservation=not required, but will improve speed, quantile=not required, but will greatly improve speed. \n"); + m->mothurOut("\t\tIf you have run chimera.seqs using pintail a .quan and .freq file will be created for your template, if you have not provided them for use in future command executions.\n"); + m->mothurOut("\tbellerophon: \n"); + m->mothurOut("\t\tparameters: fasta=required, filter=F, processors=1, window=1/4 length of seq, increment=25, correction=T. \n"); + m->mothurOut("\tccode: \n"); + m->mothurOut("\t\tparameters: fasta=required, template=required, filter=F, mask=no mask, processors=1, window=10% of length, numwanted=20\n"); + m->mothurOut("\tchimeracheck: \n"); + m->mothurOut("\t\tparameters: fasta=required, template=required, processors=1, increment=10, ksize=7, svg=F, name=none\n\n"); + m->mothurOut("\tchimeraslayer: \n"); + m->mothurOut("\t\tparameters: fasta=required, template=required, processors=1, increment=10, mask=no mask, numwanted=10, match=5, mismatch=-4, divergence=1.0, minsim=90, parents=5, iters=1000, window=100. \n\n"); + m->mothurOut("The chimera.seqs command should be in the following format: \n"); + m->mothurOut("chimera.seqs(fasta=yourFastaFile, filter=yourFilter, correction=yourCorrection, processors=yourProcessors, method=bellerophon) \n"); + m->mothurOut("Example: chimera.seqs(fasta=AD.align, filter=True, correction=true, method=bellerophon, window=200) \n"); + m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); } catch(exception& e) { - errorOut(e, "ChimeraSeqsCommand", "help"); + m->errorOut(e, "ChimeraSeqsCommand", "help"); exit(1); } } @@ -283,10 +283,10 @@ int ChimeraSeqsCommand::execute(){ else if (method == "ccode") { chimera = new Ccode(fastafile, outputDir); } else if (method == "chimeracheck") { chimera = new ChimeraCheckRDP(fastafile, outputDir); } else if (method == "chimeraslayer") { chimera = new ChimeraSlayer(search, realign, fastafile); } - else { mothurOut("Not a valid method."); mothurOutEndLine(); return 0; } + else { m->mothurOut("Not a valid method."); m->mothurOutEndLine(); return 0; } //set user options - if (maskfile == "default") { mothurOut("I am using the default 236627 EU009184.1 Shigella dysenteriae str. FBD013."); mothurOutEndLine(); } + if (maskfile == "default") { m->mothurOut("I am using the default 236627 EU009184.1 Shigella dysenteriae str. FBD013."); m->mothurOutEndLine(); } chimera->setCons(consfile); chimera->setQuantiles(quanfile); @@ -309,19 +309,13 @@ int ChimeraSeqsCommand::execute(){ chimera->setMinBS(minBS); chimera->setMinSNP(minSNP); chimera->setIters(iters); - chimera->setTemplateFile(templatefile); + string outputFileName = outputDir + getRootName(getSimpleName(fastafile)) + method + maskfile + ".chimeras"; string accnosFileName = outputDir + getRootName(getSimpleName(fastafile)) + method + maskfile + ".accnos"; - + bool hasAccnos = true; - if ((method != "bellerophon") && (method != "chimeracheck")) { - if (chimera->getUnaligned()) { - mothurOut("Your template sequences are different lengths, please correct."); mothurOutEndLine(); - delete chimera; - return 0; - } - }else if (method == "bellerophon") {//run bellerophon separately since you need to read entire fastafile to run it + if (method == "bellerophon") {//run bellerophon separately since you need to read entire fastafile to run it chimera->getChimeras(); ofstream out; @@ -334,9 +328,29 @@ int ChimeraSeqsCommand::execute(){ out.close(); out2.close(); + //delete accnos file if its blank + if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); + if (hasAccnos) { m->mothurOut(accnosFileName); m->mothurOutEndLine(); } + m->mothurOutEndLine(); + return 0; } + //reads template + chimera->setTemplateFile(templatefile); + + if (method != "chimeracheck") { + if (chimera->getUnaligned()) { + m->mothurOut("Your template sequences are different lengths, please correct."); m->mothurOutEndLine(); + delete chimera; + return 0; + } + } + //some methods need to do prep work before processing the chimeras chimera->doPrep(); @@ -349,7 +363,7 @@ int ChimeraSeqsCommand::execute(){ chimera->printHeader(outHeader); outHeader.close(); - + //break up file #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) if(processors == 1){ @@ -362,6 +376,9 @@ int ChimeraSeqsCommand::execute(){ driver(lines[0], outputFileName, fastafile, accnosFileName); + //delete accnos file if its blank + if (isBlank(accnosFileName)) { remove(accnosFileName.c_str()); hasAccnos = false; } + }else{ vector positions; processIDS.resize(0); @@ -394,17 +411,31 @@ int ChimeraSeqsCommand::execute(){ createProcesses(outputFileName, fastafile, accnosFileName); rename((outputFileName + toString(processIDS[0]) + ".temp").c_str(), outputFileName.c_str()); - rename((accnosFileName + toString(processIDS[0]) + ".temp").c_str(), accnosFileName.c_str()); - //append alignment and report files + //append output files for(int i=1;i nonBlankAccnosFiles; + //delete blank accnos files generated with multiple processes + for(int i=0;imothurOut("Output File Names: "); + //if ((filter) && (method == "bellerophon")) { m->mothurOut( //if (outputDir == "") { fastafile = getRootName(fastafile) + "filter.fasta"; } // else { fastafile = outputDir + getRootName(getSimpleName(fastafile)) + "filter.fasta"; } @@ -429,15 +463,23 @@ int ChimeraSeqsCommand::execute(){ delete chimera; - if (method == "chimeracheck") { remove(accnosFileName.c_str()); mothurOutEndLine(); mothurOut("This method does not determine if a sequence is chimeric, but allows you to make that determination based on the IS values."); mothurOutEndLine(); } + if (method == "chimeracheck") { remove(accnosFileName.c_str()); m->mothurOutEndLine(); m->mothurOut("This method does not determine if a sequence is chimeric, but allows you to make that determination based on the IS values."); m->mothurOutEndLine(); } + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); + if (hasAccnos) { m->mothurOut(accnosFileName); m->mothurOutEndLine(); } + m->mothurOutEndLine(); + + - mothurOutEndLine(); mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); mothurOutEndLine(); + m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences."); m->mothurOutEndLine(); return 0; } catch(exception& e) { - errorOut(e, "ChimeraSeqsCommand", "execute"); + m->errorOut(e, "ChimeraSeqsCommand", "execute"); exit(1); } }//********************************************************************************************************************** @@ -462,7 +504,7 @@ int ChimeraSeqsCommand::driver(linePair* line, string outputFName, string filena if (candidateSeq->getName() != "") { //incase there is a commented sequence at the end of a file if ((candidateSeq->getAligned().length() != templateSeqsLength) && (method != "chimeracheck")) { //chimeracheck does not require seqs to be aligned - mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); mothurOutEndLine(); + m->mothurOut(candidateSeq->getName() + " is not the same length as the template sequences. Skipping."); m->mothurOutEndLine(); }else{ //find chimeras chimera->getChimeras(candidateSeq); @@ -474,10 +516,10 @@ int ChimeraSeqsCommand::driver(linePair* line, string outputFName, string filena delete candidateSeq; //report progress - if((i+1) % 100 == 0){ mothurOut("Processing sequence: " + toString(i+1)); mothurOutEndLine(); } + if((i+1) % 100 == 0){ m->mothurOut("Processing sequence: " + toString(i+1)); m->mothurOutEndLine(); } } //report progress - if((line->numSeqs) % 100 != 0){ mothurOut("Processing sequence: " + toString(line->numSeqs)); mothurOutEndLine(); } + if((line->numSeqs) % 100 != 0){ m->mothurOut("Processing sequence: " + toString(line->numSeqs)); m->mothurOutEndLine(); } out.close(); out2.close(); @@ -486,7 +528,7 @@ int ChimeraSeqsCommand::driver(linePair* line, string outputFName, string filena return 1; } catch(exception& e) { - errorOut(e, "ChimeraSeqsCommand", "driver"); + m->errorOut(e, "ChimeraSeqsCommand", "driver"); exit(1); } } @@ -509,7 +551,7 @@ void ChimeraSeqsCommand::createProcesses(string outputFileName, string filename, }else if (pid == 0){ driver(lines[process], outputFileName + toString(getpid()) + ".temp", filename, accnos + toString(getpid()) + ".temp"); exit(0); - }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); } + }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } } //force parent to wait until all the processes are done @@ -520,7 +562,7 @@ void ChimeraSeqsCommand::createProcesses(string outputFileName, string filename, #endif } catch(exception& e) { - errorOut(e, "ChimeraSeqsCommand", "createProcesses"); + m->errorOut(e, "ChimeraSeqsCommand", "createProcesses"); exit(1); } } @@ -545,7 +587,7 @@ void ChimeraSeqsCommand::appendOutputFiles(string temp, string filename) { output.close(); } catch(exception& e) { - errorOut(e, "ChimeraSeqsCommand", "appendOuputFiles"); + m->errorOut(e, "ChimeraSeqsCommand", "appendOuputFiles"); exit(1); } } diff --git a/chimeraslayer.cpp b/chimeraslayer.cpp index 6ca8c29..f865107 100644 --- a/chimeraslayer.cpp +++ b/chimeraslayer.cpp @@ -99,11 +99,11 @@ void ChimeraSlayer::doPrep() { //run filter on template for (int i = 0; i < templateSeqs.size(); i++) { runFilter(templateSeqs[i]); } - mothurOutEndLine(); mothurOut("It took " + toString(time(NULL) - start) + " secs to filter."); mothurOutEndLine(); + m->mothurOutEndLine(); m->mothurOut("It took " + toString(time(NULL) - start) + " secs to filter."); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "ChimeraSlayer", "doprep"); + m->errorOut(e, "ChimeraSlayer", "doprep"); exit(1); } } @@ -111,9 +111,9 @@ void ChimeraSlayer::doPrep() { ChimeraSlayer::~ChimeraSlayer() { delete decalc; if (searchMethod == "kmer") { delete databaseRight; delete databaseLeft; } } //*************************************************************************************************************** void ChimeraSlayer::printHeader(ostream& out) { - mothurOutEndLine(); - mothurOut("Only reporting sequence supported by " + toString(minBS) + "% of bootstrapped results."); - mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Only reporting sequence supported by " + toString(minBS) + "% of bootstrapped results."); + m->mothurOutEndLine(); out << "Name\tLeftParent\tRightParent\tDivQLAQRB\tPerIDQLAQRB\tBootStrapA\tDivQLBQRA\tPerIDQLBQRA\tBootStrapB\tFlag\tLeftWindow\tRightWindow\n"; } @@ -129,7 +129,7 @@ void ChimeraSlayer::print(ostream& out, ostream& outAcc) { if (chimeraFlag == "yes") { if ((chimeraResults[0].bsa >= minBS) || (chimeraResults[0].bsb >= minBS)) { - mothurOut(querySeq->getName() + "\tyes"); mothurOutEndLine(); + m->mothurOut(querySeq->getName() + "\tyes"); m->mothurOutEndLine(); outAcc << querySeq->getName() << endl; } } @@ -140,7 +140,7 @@ void ChimeraSlayer::print(ostream& out, ostream& outAcc) { } catch(exception& e) { - errorOut(e, "ChimeraSlayer", "print"); + m->errorOut(e, "ChimeraSlayer", "print"); exit(1); } } @@ -247,7 +247,7 @@ int ChimeraSlayer::getChimeras(Sequence* query) { return 0; } catch(exception& e) { - errorOut(e, "ChimeraSlayer", "getChimeras"); + m->errorOut(e, "ChimeraSlayer", "getChimeras"); exit(1); } } @@ -282,7 +282,7 @@ void ChimeraSlayer::printBlock(data_struct data, ostream& out){ } catch(exception& e) { - errorOut(e, "ChimeraSlayer", "printBlock"); + m->errorOut(e, "ChimeraSlayer", "printBlock"); exit(1); } } diff --git a/classify.cpp b/classify.cpp index 346c764..2db1973 100644 --- a/classify.cpp +++ b/classify.cpp @@ -17,7 +17,7 @@ /**************************************************************************************************/ Classify::Classify(string tfile, string tempFile, string method, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch) : taxFile(tfile), templateFile(tempFile) { try { - + m = MothurOut::getInstance(); readTaxonomy(taxFile); int start = time(NULL); @@ -30,7 +30,7 @@ Classify::Classify(string tfile, string tempFile, string method, int kmerSize, f inFASTA.close(); } - mothurOut("Generating search database... "); cout.flush(); + m->mothurOut("Generating search database... "); cout.flush(); bool needToGenerate = true; string kmerDBName; @@ -45,8 +45,8 @@ Classify::Classify(string tfile, string tempFile, string method, int kmerSize, f else if(method == "blast") { database = new BlastDB(gapOpen, gapExtend, match, misMatch); } else if(method == "distance") { database = new DistanceDB(); } else { - mothurOut(method + " is not a valid search option. I will run the command using kmer, ksize=8."); - mothurOutEndLine(); + m->mothurOut(method + " is not a valid search option. I will run the command using kmer, ksize=8."); + m->mothurOutEndLine(); database = new KmerDB(tempFile, 8); } @@ -84,12 +84,12 @@ Classify::Classify(string tfile, string tempFile, string method, int kmerSize, f database->setNumSeqs(names.size()); - mothurOut("DONE."); mothurOutEndLine(); - mothurOut("It took " + toString(time(NULL) - start) + " seconds generate search database. "); mothurOutEndLine(); + m->mothurOut("DONE."); m->mothurOutEndLine(); + m->mothurOut("It took " + toString(time(NULL) - start) + " seconds generate search database. "); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "Classify", "Classify"); + m->errorOut(e, "Classify", "Classify"); exit(1); } } @@ -103,8 +103,8 @@ void Classify::readTaxonomy(string file) { ifstream inTax; openInputFile(file, inTax); - mothurOutEndLine(); - mothurOut("Reading in the " + file + " taxonomy...\t"); cout.flush(); + m->mothurOutEndLine(); + m->mothurOut("Reading in the " + file + " taxonomy...\t"); cout.flush(); string name, taxInfo; //read template seqs and save @@ -121,12 +121,12 @@ void Classify::readTaxonomy(string file) { phyloTree->assignHeirarchyIDs(0); inTax.close(); - mothurOut("DONE."); - mothurOutEndLine(); cout.flush(); + m->mothurOut("DONE."); + m->mothurOutEndLine(); cout.flush(); } catch(exception& e) { - errorOut(e, "Classify", "readTaxonomy"); + m->errorOut(e, "Classify", "readTaxonomy"); exit(1); } } @@ -152,7 +152,7 @@ vector Classify::parseTax(string tax) { return taxons; } catch(exception& e) { - errorOut(e, "Classify", "parseTax"); + m->errorOut(e, "Classify", "parseTax"); exit(1); } } diff --git a/classify.h b/classify.h index 5c5a7ac..1a34362 100644 --- a/classify.h +++ b/classify.h @@ -48,6 +48,7 @@ protected: void readTaxonomy(string); vector parseTax(string); + MothurOut* m; }; /**************************************************************************************************/ diff --git a/classifyseqscommand.cpp b/classifyseqscommand.cpp index 51578e3..7a9a5e9 100644 --- a/classifyseqscommand.cpp +++ b/classifyseqscommand.cpp @@ -15,7 +15,7 @@ //********************************************************************************************************************** -ClassifySeqsCommand::ClassifySeqsCommand(string option){ +ClassifySeqsCommand::ClassifySeqsCommand(string option) { try { abort = false; @@ -67,14 +67,14 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option){ //check for required parameters templateFileName = validParameter.validFile(parameters, "template", true); if (templateFileName == "not found") { - mothurOut("template is a required parameter for the classify.seqs command."); - mothurOutEndLine(); + m->mothurOut("template is a required parameter for the classify.seqs command."); + m->mothurOutEndLine(); abort = true; } else if (templateFileName == "not open") { abort = true; } fastaFileName = validParameter.validFile(parameters, "fasta", false); - if (fastaFileName == "not found") { mothurOut("fasta is a required parameter for the classify.seqs command."); mothurOutEndLine(); abort = true; } + if (fastaFileName == "not found") { m->mothurOut("fasta is a required parameter for the classify.seqs command."); m->mothurOutEndLine(); abort = true; } else { splitAtDash(fastaFileName, fastaFileNames); @@ -90,7 +90,7 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option){ ifstream in; ableToOpen = openInputFile(fastaFileNames[i], in); if (ableToOpen == 1) { - mothurOut(fastaFileNames[i] + " will be disregarded."); mothurOutEndLine(); + m->mothurOut(fastaFileNames[i] + " will be disregarded."); m->mothurOutEndLine(); //erase from file list fastaFileNames.erase(fastaFileNames.begin()+i); i--; @@ -99,14 +99,14 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option){ } //make sure there is at least one valid file left - if (fastaFileNames.size() == 0) { mothurOut("no valid files."); mothurOutEndLine(); abort = true; } + if (fastaFileNames.size() == 0) { m->mothurOut("no valid files."); m->mothurOutEndLine(); abort = true; } } taxonomyFileName = validParameter.validFile(parameters, "taxonomy", true); if (taxonomyFileName == "not found") { - mothurOut("taxonomy is a required parameter for the classify.seqs command."); - mothurOutEndLine(); + m->mothurOut("taxonomy is a required parameter for the classify.seqs command."); + m->mothurOutEndLine(); abort = true; } else if (taxonomyFileName == "not open") { abort = true; } @@ -129,13 +129,13 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option){ int ableToOpen; ifstream in; ableToOpen = openInputFile(namefileNames[i], in); - if (ableToOpen == 1) { mothurOut("Unable to match name file with fasta file."); mothurOutEndLine(); abort = true; } + if (ableToOpen == 1) { m->mothurOut("Unable to match name file with fasta file."); m->mothurOutEndLine(); abort = true; } in.close(); } } if (namefile != "") { - if (namefileNames.size() != fastaFileNames.size()) { abort = true; mothurOut("If you provide a name file, you must have one for each fasta file."); mothurOutEndLine(); } + if (namefileNames.size() != fastaFileNames.size()) { abort = true; m->mothurOut("If you provide a name file, you must have one for each fasta file."); m->mothurOutEndLine(); } } //check for optional parameter and set defaults @@ -178,14 +178,14 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option){ if ((method == "bayesian") && (search != "kmer")) { - mothurOut("The bayesian method requires the kmer search." + search + "will be disregarded." ); mothurOutEndLine(); + m->mothurOut("The bayesian method requires the kmer search." + search + "will be disregarded." ); m->mothurOutEndLine(); search = "kmer"; } } } catch(exception& e) { - errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand"); + m->errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand"); exit(1); } } @@ -203,31 +203,31 @@ ClassifySeqsCommand::~ClassifySeqsCommand(){ void ClassifySeqsCommand::help(){ try { - mothurOut("The classify.seqs command reads a fasta file containing sequences and creates a .taxonomy file and a .tax.summary file.\n"); - mothurOut("The classify.seqs command parameters are template, fasta, name, search, ksize, method, taxonomy, processors, match, mismatch, gapopen, gapextend, numwanted and probs.\n"); - 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"); - 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"); - 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"); - mothurOut("The method parameter allows you to specify classification method to use. Your options are: bayesian and knn. The default is bayesian.\n"); - mothurOut("The ksize parameter allows you to specify the kmer size for finding most similar template to candidate. The default is 8.\n"); - mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n"); - mothurOut("The match parameter allows you to specify the bonus for having the same base. The default is 1.0.\n"); - mothurOut("The mistmatch parameter allows you to specify the penalty for having different bases. The default is -1.0.\n"); - mothurOut("The gapopen parameter allows you to specify the penalty for opening a gap in an alignment. The default is -2.0.\n"); - mothurOut("The gapextend parameter allows you to specify the penalty for extending a gap in an alignment. The default is -1.0.\n"); - mothurOut("The numwanted parameter allows you to specify the number of sequence matches you want with the knn method. The default is 10.\n"); - mothurOut("The cutoff parameter allows you to specify a bootstrap confidence threshold for your taxonomy. The default is 0.\n"); - mothurOut("The probs parameter shut off the bootstrapping results for the bayesian method. The default is true, meaning you want the bootstrapping to be run.\n"); - 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"); - mothurOut("The classify.seqs command should be in the following format: \n"); - mothurOut("classify.seqs(template=yourTemplateFile, fasta=yourFastaFile, method=yourClassificationMethod, search=yourSearchmethod, ksize=yourKmerSize, taxonomy=yourTaxonomyFile, processors=yourProcessors) \n"); - mothurOut("Example classify.seqs(fasta=amazon.fasta, template=core.filtered, method=knn, search=gotoh, ksize=8, processors=2)\n"); - mothurOut("The .taxonomy file consists of 2 columns: 1 = your sequence name, 2 = the taxonomy for your sequence. \n"); - mothurOut("The .tax.summary is a summary of the different taxonomies represented in your fasta file. \n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); + 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 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"); + 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 shut off the bootstrapping results for the bayesian method. The default is true, meaning you want the bootstrapping to be run.\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) { - errorOut(e, "ClassifySeqsCommand", "help"); + m->errorOut(e, "ClassifySeqsCommand", "help"); exit(1); } } @@ -242,11 +242,12 @@ int ClassifySeqsCommand::execute(){ if(method == "bayesian"){ classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters); } else if(method == "knn"){ classify = new Knn(taxonomyFileName, templateFileName, search, kmerSize, gapOpen, gapExtend, match, misMatch, numWanted); } else { - mothurOut(search + " is not a valid method option. I will run the command using bayesian."); - mothurOutEndLine(); + m->mothurOut(search + " is not a valid method option. I will run the command using bayesian."); + m->mothurOutEndLine(); classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters); } + vector outputNames; for (int s = 0; s < fastaFileNames.size(); s++) { @@ -265,13 +266,16 @@ int ClassifySeqsCommand::execute(){ inNames.close(); } - mothurOut("Classifying sequences from " + fastaFileNames[s] + " ..." ); mothurOutEndLine(); + m->mothurOut("Classifying sequences from " + fastaFileNames[s] + " ..." ); m->mothurOutEndLine(); if (outputDir == "") { outputDir += hasPath(fastaFileNames[s]); } string newTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + getRootName(getSimpleName(taxonomyFileName)) + "taxonomy"; string tempTaxonomyFile = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + "taxonomy.temp"; string taxSummary = outputDir + getRootName(getSimpleName(fastaFileNames[s])) + getRootName(getSimpleName(taxonomyFileName)) + "tax.summary"; + outputNames.push_back(newTaxonomyFile); + outputNames.push_back(taxSummary); + int start = time(NULL); int numFastaSeqs = 0; for (int i = 0; i < lines.size(); i++) { delete lines[i]; } lines.clear(); @@ -352,7 +356,7 @@ int ClassifySeqsCommand::execute(){ itNames = nameMap.find(name); if (itNames == nameMap.end()) { - mothurOut(name + " is not in your name file please correct."); mothurOutEndLine(); exit(1); + m->mothurOut(name + " is not in your name file please correct."); m->mothurOutEndLine(); exit(1); }else{ for (int i = 0; i < itNames->second; i++) { taxaBrowser.addSeqToTree(name+toString(i), taxon); //add it as many times as there are identical seqs @@ -399,15 +403,21 @@ int ClassifySeqsCommand::execute(){ remove(newTaxonomyFile.c_str()); rename(unclass.c_str(), newTaxonomyFile.c_str()); - mothurOutEndLine(); - mothurOut("It took " + toString(time(NULL) - start) + " secs to classify " + toString(numFastaSeqs) + " sequences."); mothurOutEndLine(); mothurOutEndLine(); + 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(); + + + m->mothurOutEndLine(); + m->mothurOut("It took " + toString(time(NULL) - start) + " secs to classify " + toString(numFastaSeqs) + " sequences."); m->mothurOutEndLine(); m->mothurOutEndLine(); } delete classify; return 0; } catch(exception& e) { - errorOut(e, "ClassifySeqsCommand", "execute"); + m->errorOut(e, "ClassifySeqsCommand", "execute"); exit(1); } } @@ -436,7 +446,7 @@ string ClassifySeqsCommand::addUnclassifieds(string tax, int maxlevel) { return newTax; } catch(exception& e) { - errorOut(e, "ClassifySeqsCommand", "addUnclassifieds"); + m->errorOut(e, "ClassifySeqsCommand", "addUnclassifieds"); exit(1); } } @@ -459,7 +469,7 @@ void ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile }else if (pid == 0){ driver(lines[process], taxFileName + toString(getpid()) + ".temp", tempTaxFile + toString(getpid()) + ".temp", filename); exit(0); - }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); } + }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } } //force parent to wait until all the processes are done @@ -470,7 +480,7 @@ void ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile #endif } catch(exception& e) { - errorOut(e, "ClassifySeqsCommand", "createProcesses"); + m->errorOut(e, "ClassifySeqsCommand", "createProcesses"); exit(1); } } @@ -493,7 +503,7 @@ void ClassifySeqsCommand::appendTaxFiles(string temp, string filename) { output.close(); } catch(exception& e) { - errorOut(e, "ClassifySeqsCommand", "appendTaxFiles"); + m->errorOut(e, "ClassifySeqsCommand", "appendTaxFiles"); exit(1); } } @@ -536,7 +546,7 @@ int ClassifySeqsCommand::driver(linePair* line, string taxFName, string tempTFNa delete candidateSeq; if((i+1) % 100 == 0){ - mothurOut("Classifying sequence " + toString(i+1)); mothurOutEndLine(); + m->mothurOut("Classifying sequence " + toString(i+1)); m->mothurOutEndLine(); } } @@ -547,7 +557,7 @@ int ClassifySeqsCommand::driver(linePair* line, string taxFName, string tempTFNa return 1; } catch(exception& e) { - errorOut(e, "ClassifySeqsCommand", "driver"); + m->errorOut(e, "ClassifySeqsCommand", "driver"); exit(1); } } diff --git a/classifyseqscommand.h b/classifyseqscommand.h index 19fc8a0..890085e 100644 --- a/classifyseqscommand.h +++ b/classifyseqscommand.h @@ -28,7 +28,7 @@ class ClassifySeqsCommand : public Command { public: - ClassifySeqsCommand(string); + ClassifySeqsCommand(string); ~ClassifySeqsCommand(); int execute(); void help(); diff --git a/cluster.cpp b/cluster.cpp index c6a9ca4..bd5986e 100644 --- a/cluster.cpp +++ b/cluster.cpp @@ -14,8 +14,8 @@ /***********************************************************************/ -Cluster::Cluster(RAbundVector* rav, ListVector* lv, SparseMatrix* dm, float c, string m) : -rabund(rav), list(lv), dMatrix(dm), method(m) +Cluster::Cluster(RAbundVector* rav, ListVector* lv, SparseMatrix* dm, float c, string f) : +rabund(rav), list(lv), dMatrix(dm), method(f) { /* cout << "sizeof(MatData): " << sizeof(MatData) << endl; @@ -59,6 +59,7 @@ rabund(rav), list(lv), dMatrix(dm), method(m) //save so you can modify as it changes in average neighbor cutoff = c; + m = MothurOut::getInstance(); } /***********************************************************************/ @@ -77,7 +78,7 @@ void Cluster::getRowColCells() { nColCells = colCells.size(); } catch(exception& e) { - errorOut(e, "Cluster", "getRowColCells"); + m->errorOut(e, "Cluster", "getRowColCells"); exit(1); } @@ -142,7 +143,7 @@ void Cluster::clusterBins(){ // cout << '\t' << rabund->get(smallRow) << '\t' << rabund->get(smallCol) << endl; } catch(exception& e) { - errorOut(e, "Cluster", "clusterBins"); + m->errorOut(e, "Cluster", "clusterBins"); exit(1); } @@ -163,7 +164,7 @@ void Cluster::clusterNames(){ // cout << '\t' << list->get(smallRow) << '\t' << list->get(smallCol) << endl; } catch(exception& e) { - errorOut(e, "Cluster", "clusterNames"); + m->errorOut(e, "Cluster", "clusterNames"); exit(1); } @@ -213,10 +214,10 @@ void Cluster::update(double& cutOFF){ } //if not merged it you need it for warning if ((!merged) && (method == "average")) { - //mothurOut("Warning: trying to merge cell " + toString(rowCells[i]->row+1) + " " + toString(rowCells[i]->column+1) + " distance " + toString(rowCells[i]->dist) + " with value above cutoff. Results may vary from using cutoff at cluster command instead of read.dist."); mothurOutEndLine(); + //m->mothurOut("Warning: trying to merge cell " + toString(rowCells[i]->row+1) + " " + toString(rowCells[i]->column+1) + " distance " + toString(rowCells[i]->dist) + " with value above cutoff. Results may vary from using cutoff at cluster command instead of read.dist."); m->mothurOutEndLine(); if (cutOFF > rowCells[i]->dist) { cutOFF = rowCells[i]->dist; - //mothurOut("changing cutoff to " + toString(cutOFF)); mothurOutEndLine(); + //m->mothurOut("changing cutoff to " + toString(cutOFF)); m->mothurOutEndLine(); } } @@ -233,10 +234,10 @@ void Cluster::update(double& cutOFF){ if (foundCol[i] == 0) { if (method == "average") { if (!((colCells[i]->row == smallRow) && (colCells[i]->column == smallCol))) { - //mothurOut("Warning: merging cell " + toString(colCells[i]->row+1) + " " + toString(colCells[i]->column+1) + " distance " + toString(colCells[i]->dist) + " value above cutoff. Results may vary from using cutoff at cluster command instead of read.dist."); mothurOutEndLine(); + //m->mothurOut("Warning: merging cell " + toString(colCells[i]->row+1) + " " + toString(colCells[i]->column+1) + " distance " + toString(colCells[i]->dist) + " value above cutoff. Results may vary from using cutoff at cluster command instead of read.dist."); m->mothurOutEndLine(); if (cutOFF > colCells[i]->dist) { cutOFF = colCells[i]->dist; - //mothurOut("changing cutoff to " + toString(cutOFF)); mothurOutEndLine(); + //m->mothurOut("changing cutoff to " + toString(cutOFF)); m->mothurOutEndLine(); } } } @@ -245,14 +246,14 @@ void Cluster::update(double& cutOFF){ } } catch(exception& e) { - errorOut(e, "Cluster", "update"); + m->errorOut(e, "Cluster", "update"); exit(1); } } /***********************************************************************/ -void Cluster::setMapWanted(bool m) { +void Cluster::setMapWanted(bool f) { try { - mapWanted = m; + mapWanted = f; //initialize map for (int i = 0; i < list->getNumBins(); i++) { @@ -273,7 +274,7 @@ void Cluster::setMapWanted(bool m) { } catch(exception& e) { - errorOut(e, "Cluster", "setMapWanted"); + m->errorOut(e, "Cluster", "setMapWanted"); exit(1); } } @@ -295,7 +296,7 @@ try { } catch(exception& e) { - errorOut(e, "Cluster", "updateMap"); + m->errorOut(e, "Cluster", "updateMap"); exit(1); } } diff --git a/cluster.hpp b/cluster.hpp index 6d7fc47..72d3611 100644 --- a/cluster.hpp +++ b/cluster.hpp @@ -4,6 +4,7 @@ #include "mothur.h" #include "sparsematrix.hpp" +#include "mothurout.h" class RAbundVector; class ListVector; @@ -46,6 +47,7 @@ protected: MatVec colCells; ull nRowCells; ull nColCells; + MothurOut* m; }; /***********************************************************************/ diff --git a/clustercommand.cpp b/clustercommand.cpp index e4e2d21..5d9c7bc 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -11,9 +11,10 @@ //********************************************************************************************************************** //This function checks to make sure the cluster command has no errors and then clusters based on the method chosen. -ClusterCommand::ClusterCommand(string option){ +ClusterCommand::ClusterCommand(string option) { try{ globaldata = GlobalData::getInstance(); + abort = false; //allow user to run help @@ -41,7 +42,7 @@ ClusterCommand::ClusterCommand(string option){ //error checking to make sure they read a distance file if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) { - mothurOut("Before you use the cluster command, you first need to read in a distance matrix."); mothurOutEndLine(); + m->mothurOut("Before you use the cluster command, you first need to read in a distance matrix."); m->mothurOutEndLine(); abort = true; } @@ -64,7 +65,7 @@ ClusterCommand::ClusterCommand(string option){ if (method == "not found") { method = "furthest"; } if ((method == "furthest") || (method == "nearest") || (method == "average")) { } - else { mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average."); mothurOutEndLine(); abort = true; } + else { m->mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average."); m->mothurOutEndLine(); abort = true; } showabund = validParameter.validFile(parameters, "showabund", false); if (showabund == "not found") { showabund = "T"; } @@ -95,11 +96,15 @@ ClusterCommand::ClusterCommand(string option){ openOutputFile(fileroot+ tag + ".sabund", sabundFile); openOutputFile(fileroot+ tag + ".rabund", rabundFile); openOutputFile(fileroot+ tag + ".list", listFile); + + outputNames.push_back(fileroot+ tag + ".sabund"); + outputNames.push_back(fileroot+ tag + ".rabund"); + outputNames.push_back(fileroot+ tag + ".list"); } } } catch(exception& e) { - errorOut(e, "ClusterCommand", "ClusterCommand"); + m->errorOut(e, "ClusterCommand", "ClusterCommand"); exit(1); } } @@ -108,14 +113,14 @@ ClusterCommand::ClusterCommand(string option){ void ClusterCommand::help(){ try { - mothurOut("The cluster command can only be executed after a successful read.dist command.\n"); - mothurOut("The cluster command parameter options are method, cuttoff, precision, showabund and timing. No parameters are required.\n"); - mothurOut("The cluster command should be in the following format: \n"); - mothurOut("cluster(method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"); - mothurOut("The acceptable cluster methods are furthest, nearest and average. If no method is provided then furthest is assumed.\n\n"); + 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, 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) { - errorOut(e, "ClusterCommand", "help"); + m->errorOut(e, "ClusterCommand", "help"); exit(1); } } @@ -150,7 +155,7 @@ int ClusterCommand::execute(){ while (matrix->getSmallDist() < cutoff && matrix->getNNodes() > 0){ if (print_start && isTrue(timing)) { - mothurOut("Clustering (" + tag + ") dist " + toString(matrix->getSmallDist()) + "/" + m->mothurOut("Clustering (" + tag + ") dist " + toString(matrix->getSmallDist()) + "/" + toString(roundDist(matrix->getSmallDist(), precision)) + "\t(precision: " + toString(precision) + ", Nodes: " + toString(matrix->getNNodes()) + ")"); cout.flush(); @@ -177,7 +182,7 @@ int ClusterCommand::execute(){ } if (print_start && isTrue(timing)) { - mothurOut("Clustering (" + tag + ") for distance " + toString(previousDist) + "/" + toString(rndPreviousDist) + m->mothurOut("Clustering (" + tag + ") for distance " + toString(previousDist) + "/" + toString(rndPreviousDist) + "\t(precision: " + toString(precision) + ", Nodes: " + toString(matrix->getNNodes()) + ")"); cout.flush(); print_start = false; @@ -206,17 +211,23 @@ int ClusterCommand::execute(){ rabundFile.close(); listFile.close(); - if (saveCutoff != cutoff) { mothurOut("changed cutoff to " + toString(cutoff)); mothurOutEndLine(); } + if (saveCutoff != cutoff) { m->mothurOut("changed cutoff to " + toString(cutoff)); m->mothurOutEndLine(); } + + 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(); + //if (isTrue(timing)) { - mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster"); mothurOutEndLine(); + m->mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster"); m->mothurOutEndLine(); //} return 0; } catch(exception& e) { - errorOut(e, "ClusterCommand", "execute"); + m->errorOut(e, "ClusterCommand", "execute"); exit(1); } } @@ -226,8 +237,8 @@ int ClusterCommand::execute(){ void ClusterCommand::printData(string label){ try { if (isTrue(timing)) { - mothurOut("\tTime: " + toString(time(NULL) - start) + "\tsecs for " + toString(oldRAbund.getNumBins()) - + "\tclusters. Updates: " + toString(loops)); mothurOutEndLine(); + m->mothurOut("\tTime: " + toString(time(NULL) - start) + "\tsecs for " + toString(oldRAbund.getNumBins()) + + "\tclusters. Updates: " + toString(loops)); m->mothurOutEndLine(); } print_start = true; loops = 0; @@ -244,7 +255,7 @@ void ClusterCommand::printData(string label){ oldList.print(listFile); } catch(exception& e) { - errorOut(e, "ClusterCommand", "printData"); + m->errorOut(e, "ClusterCommand", "printData"); exit(1); } diff --git a/clustercommand.h b/clustercommand.h index 5c21efc..5c57b69 100644 --- a/clustercommand.h +++ b/clustercommand.h @@ -29,7 +29,7 @@ class ClusterCommand : public Command { public: - ClusterCommand(string); + ClusterCommand(string); ~ClusterCommand(); int execute(); void help(); @@ -56,6 +56,7 @@ private: unsigned long loops; void printData(string label); + vector outputNames; }; #endif diff --git a/collect.cpp b/collect.cpp index 34191a0..08426a8 100644 --- a/collect.cpp +++ b/collect.cpp @@ -52,7 +52,7 @@ void Collect::getCurve(int increment = 1){ delete ccd; } catch(exception& e) { - errorOut(e, "Collect", "getCurve"); + m->errorOut(e, "Collect", "getCurve"); exit(1); } } @@ -158,7 +158,7 @@ try { } catch(exception& e) { - errorOut(e, "Collect", "getSharedCurve"); + m->errorOut(e, "Collect", "getSharedCurve"); exit(1); } } diff --git a/collect.h b/collect.h index 134edf0..0db1504 100644 --- a/collect.h +++ b/collect.h @@ -9,6 +9,7 @@ #include "sharedordervector.h" #include "datavector.hpp" #include "globaldata.hpp" +#include "mothurout.h" /***********************************************************************/ @@ -16,9 +17,9 @@ class Collect { public: Collect(OrderVector* order, vector disp) : - numSeqs(order->getNumSeqs()), order(order), displays(disp), label(order->getLabel()) {}; + numSeqs(order->getNumSeqs()), order(order), displays(disp), label(order->getLabel()) { m = MothurOut::getInstance(); }; Collect(SharedOrderVector* sharedorder, vector disp) : - numSeqs(sharedorder->getNumSeqs()), sharedorder(sharedorder), displays(disp), label(sharedorder->getLabel()) {}; + numSeqs(sharedorder->getNumSeqs()), sharedorder(sharedorder), displays(disp), label(sharedorder->getLabel()) { m = MothurOut::getInstance(); } ~Collect(){ }; void getCurve(int); @@ -34,6 +35,7 @@ private: void getGroupComb(); vector groupComb; bool validGroup(vector, string); + MothurOut* m; }; diff --git a/collectcommand.cpp b/collectcommand.cpp index 473d2db..d8da50e 100644 --- a/collectcommand.cpp +++ b/collectcommand.cpp @@ -31,7 +31,7 @@ //********************************************************************************************************************** -CollectCommand::CollectCommand(string option){ +CollectCommand::CollectCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -61,7 +61,7 @@ CollectCommand::CollectCommand(string option){ 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() == "")) { mothurOut("You must read a list, sabund, rabund or shared file before you can use the collect.single command."); mothurOutEndLine(); abort = true; } + 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; } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -98,7 +98,7 @@ CollectCommand::CollectCommand(string option){ } catch(exception& e) { - errorOut(e, "CollectCommand", "CollectCommand"); + m->errorOut(e, "CollectCommand", "CollectCommand"); exit(1); } } @@ -106,19 +106,19 @@ CollectCommand::CollectCommand(string option){ void CollectCommand::help(){ try { - mothurOut("The collect.single command can only be executed after a successful read.otu command. WITH ONE EXECEPTION. \n"); - 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"); - mothurOut("The collect.single command parameters are label, freq, calc and abund. No parameters are required. \n"); - mothurOut("The collect.single command should be in the following format: \n"); - mothurOut("collect.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n"); - mothurOut("Example collect(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-chao-ace-jack).\n"); - mothurOut("The default values for freq is 100, and calc are sobs-chao-ace-jack-shannon-npshannon-simpson.\n"); + 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("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); - mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\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. freq), '=' and parameters (i.e.yourFreq).\n\n"); } catch(exception& e) { - errorOut(e, "CollectCommand", "help"); + m->errorOut(e, "CollectCommand", "help"); exit(1); } } @@ -134,6 +134,8 @@ int CollectCommand::execute(){ if (abort == true) { return 0; } + vector outputNames; + if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } else { inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } @@ -144,7 +146,7 @@ int CollectCommand::execute(){ globaldata->inputFileName = inputFileNames[p]; if (inputFileNames.size() > 1) { - mothurOutEndLine(); mothurOut("Processing group " + groups[p]); mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); } validCalculator = new ValidCalculators(); @@ -153,44 +155,64 @@ int CollectCommand::execute(){ if (validCalculator->isValidCalculator("single", Estimators[i]) == true) { if (Estimators[i] == "sobs") { cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs"))); + outputNames.push_back(fileNameRoot+"sobs"); }else if (Estimators[i] == "chao") { cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao"))); + outputNames.push_back(fileNameRoot+"chao"); }else if (Estimators[i] == "nseqs") { cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs"))); + outputNames.push_back(fileNameRoot+"nseqs"); }else if (Estimators[i] == "coverage") { cDisplays.push_back(new CollectDisplay(new Coverage(), new OneColumnFile(fileNameRoot+"coverage"))); + outputNames.push_back(fileNameRoot+"coverage"); }else if (Estimators[i] == "ace") { cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace"))); + outputNames.push_back(fileNameRoot+"ace"); }else if (Estimators[i] == "jack") { cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack"))); + outputNames.push_back(fileNameRoot+"jack"); }else if (Estimators[i] == "shannon") { cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon"))); + outputNames.push_back(fileNameRoot+"shannon"); }else if (Estimators[i] == "npshannon") { cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon"))); + outputNames.push_back(fileNameRoot+"np_shannon"); }else if (Estimators[i] == "simpson") { cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson"))); + outputNames.push_back(fileNameRoot+"simpson"); }else if (Estimators[i] == "bootstrap") { cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap"))); + outputNames.push_back(fileNameRoot+"bootstrap"); }else if (Estimators[i] == "geometric") { cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geometric"))); + outputNames.push_back(fileNameRoot+"geometric"); }else if (Estimators[i] == "qstat") { cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat"))); + outputNames.push_back(fileNameRoot+"qstat"); }else if (Estimators[i] == "logseries") { cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logseries"))); + outputNames.push_back(fileNameRoot+"logseries"); }else if (Estimators[i] == "bergerparker") { cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker"))); + outputNames.push_back(fileNameRoot+"bergerparker"); }else if (Estimators[i] == "bstick") { cDisplays.push_back(new CollectDisplay(new BStick(), new ThreeColumnFile(fileNameRoot+"bstick"))); + outputNames.push_back(fileNameRoot+"bstick"); }else if (Estimators[i] == "goodscoverage") { cDisplays.push_back(new CollectDisplay(new GoodsCoverage(), new OneColumnFile(fileNameRoot+"goodscoverage"))); + outputNames.push_back(fileNameRoot+"goodscoverage"); }else if (Estimators[i] == "efron") { cDisplays.push_back(new CollectDisplay(new Efron(size), new OneColumnFile(fileNameRoot+"efron"))); + outputNames.push_back(fileNameRoot+"efron"); }else if (Estimators[i] == "boneh") { cDisplays.push_back(new CollectDisplay(new Boneh(size), new OneColumnFile(fileNameRoot+"boneh"))); + outputNames.push_back(fileNameRoot+"boneh"); }else if (Estimators[i] == "solow") { cDisplays.push_back(new CollectDisplay(new Solow(size), new OneColumnFile(fileNameRoot+"solow"))); + outputNames.push_back(fileNameRoot+"solow"); }else if (Estimators[i] == "shen") { cDisplays.push_back(new CollectDisplay(new Shen(size, abund), new OneColumnFile(fileNameRoot+"shen"))); + outputNames.push_back(fileNameRoot+"shen"); } } } @@ -217,7 +239,7 @@ int CollectCommand::execute(){ cCurve->getCurve(freq); delete cCurve; - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); @@ -234,7 +256,7 @@ int CollectCommand::execute(){ cCurve->getCurve(freq); delete cCurve; - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); @@ -252,12 +274,12 @@ int CollectCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -266,7 +288,7 @@ int CollectCommand::execute(){ if (order != NULL) { delete order; } order = (input->getOrderVector(lastLabel)); - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); cCurve = new Collect(order, cDisplays); cCurve->getCurve(freq); @@ -282,12 +304,16 @@ int CollectCommand::execute(){ delete validCalculator; } - + 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; } catch(exception& e) { - errorOut(e, "CollectCommand", "execute"); + m->errorOut(e, "CollectCommand", "execute"); exit(1); } } @@ -347,7 +373,7 @@ vector CollectCommand::parseSharedFile(string filename) { return filenames; } catch(exception& e) { - errorOut(e, "CollectCommand", "parseSharedFile"); + m->errorOut(e, "CollectCommand", "parseSharedFile"); exit(1); } } diff --git a/collectsharedcommand.cpp b/collectsharedcommand.cpp index 2f12282..0c937f6 100644 --- a/collectsharedcommand.cpp +++ b/collectsharedcommand.cpp @@ -36,7 +36,7 @@ //********************************************************************************************************************** -CollectSharedCommand::CollectSharedCommand(string option){ +CollectSharedCommand::CollectSharedCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -69,8 +69,8 @@ CollectSharedCommand::CollectSharedCommand(string option){ //make sure the user has already run the read.otu command if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); mothurOutEndLine(); abort = true; } - else if (globaldata->getGroupFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); mothurOutEndLine(); abort = true; } + 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; } } @@ -124,46 +124,67 @@ CollectSharedCommand::CollectSharedCommand(string option){ 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"); }else if (Estimators[i] == "sharedsobs") { cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs"))); + outputNames.push_back(fileNameRoot+"shared.sobs"); }else if (Estimators[i] == "sharedace") { cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace"))); + outputNames.push_back(fileNameRoot+"shared.ace"); }else if (Estimators[i] == "jabund") { cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund"))); + outputNames.push_back(fileNameRoot+"jabund"); }else if (Estimators[i] == "sorabund") { cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund"))); + outputNames.push_back(fileNameRoot+"sorabund"); }else if (Estimators[i] == "jclass") { cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass"))); + outputNames.push_back(fileNameRoot+"jclass"); }else if (Estimators[i] == "sorclass") { cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass"))); + outputNames.push_back(fileNameRoot+"sorclass"); }else if (Estimators[i] == "jest") { cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest"))); + outputNames.push_back(fileNameRoot+"jest"); }else if (Estimators[i] == "sorest") { cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest"))); + outputNames.push_back(fileNameRoot+"sorest"); }else if (Estimators[i] == "thetayc") { cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc"))); + outputNames.push_back(fileNameRoot+"thetayc"); }else if (Estimators[i] == "thetan") { cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan"))); + outputNames.push_back(fileNameRoot+"thetan"); }else if (Estimators[i] == "kstest") { cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest"))); + outputNames.push_back(fileNameRoot+"kstest"); }else if (Estimators[i] == "whittaker") { cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker"))); + outputNames.push_back(fileNameRoot+"whittaker"); }else if (Estimators[i] == "sharednseqs") { cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs"))); + outputNames.push_back(fileNameRoot+"shared.nseqs"); }else if (Estimators[i] == "ochiai") { cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai"))); + outputNames.push_back(fileNameRoot+"ochiai"); }else if (Estimators[i] == "anderberg") { cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg"))); + outputNames.push_back(fileNameRoot+"anderberg"); }else if (Estimators[i] == "skulczynski") { cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski"))); + outputNames.push_back(fileNameRoot+"kulczynski"); }else if (Estimators[i] == "kulczynskicody") { cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody"))); + outputNames.push_back(fileNameRoot+"kulczynskicody"); }else if (Estimators[i] == "lennon") { cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon"))); + outputNames.push_back(fileNameRoot+"lennon"); }else if (Estimators[i] == "morisitahorn") { cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn"))); + outputNames.push_back(fileNameRoot+"morisitahorn"); }else if (Estimators[i] == "braycurtis") { cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis"))); + outputNames.push_back(fileNameRoot+"braycurtis"); } } } @@ -172,7 +193,7 @@ CollectSharedCommand::CollectSharedCommand(string option){ } catch(exception& e) { - errorOut(e, "CollectSharedCommand", "CollectSharedCommand"); + m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand"); exit(1); } } @@ -180,23 +201,23 @@ CollectSharedCommand::CollectSharedCommand(string option){ void CollectSharedCommand::help(){ try { - mothurOut("The collect.shared command can only be executed after a successful read.otu command.\n"); - mothurOut("The collect.shared command parameters are label, freq, calc and groups. No parameters are required \n"); - mothurOut("The collect.shared command should be in the following format: \n"); - mothurOut("collect.shared(label=yourLabel, freq=yourFreq, calc=yourEstimators, groups=yourGroups).\n"); - 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"); - mothurOut("The default values for freq is 100 and calc are sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan.\n"); - mothurOut("The default value for groups is all the groups in your groupfile.\n"); + 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"); validCalculator->printCalc("shared", cout); - mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - 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"); - mothurOut("If you use sharedchao and run into memory issues, set all to false. \n"); - 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"); - mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\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. list), '=' and parameters (i.e.yourListfile).\n\n"); } catch(exception& e) { - errorOut(e, "CollectSharedCommand", "help"); + m->errorOut(e, "CollectSharedCommand", "help"); exit(1); } } @@ -248,7 +269,7 @@ int CollectSharedCommand::execute(){ cCurve->getSharedCurve(freq); delete cCurve; - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); } @@ -265,7 +286,7 @@ int CollectSharedCommand::execute(){ cCurve->getSharedCurve(freq); delete cCurve; - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); @@ -285,12 +306,12 @@ int CollectSharedCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -303,7 +324,7 @@ int CollectSharedCommand::execute(){ cCurve->getSharedCurve(freq); delete cCurve; - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); delete order; } @@ -312,10 +333,16 @@ int CollectSharedCommand::execute(){ //reset groups parameter globaldata->Groups.clear(); + 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; } catch(exception& e) { - errorOut(e, "CollectSharedCommand", "execute"); + m->errorOut(e, "CollectSharedCommand", "execute"); exit(1); } } diff --git a/collectsharedcommand.h b/collectsharedcommand.h index 10efcc8..da43adc 100644 --- a/collectsharedcommand.h +++ b/collectsharedcommand.h @@ -48,7 +48,7 @@ private: bool abort, allLines, all; set labels; //holds labels to be used string label, calc, groups, outputDir; - vector Estimators, Groups; + vector Estimators, Groups, outputNames; }; diff --git a/command.hpp b/command.hpp index 1dd5e87..b6bf5cd 100644 --- a/command.hpp +++ b/command.hpp @@ -16,13 +16,17 @@ #include "mothur.h" #include "optionparser.h" #include "validparameter.h" +#include "mothurout.h" class Command { public: + Command() { m = MothurOut::getInstance(); } virtual int execute() = 0; virtual void help() = 0; virtual ~Command() { } + protected: + MothurOut* m; }; #endif diff --git a/commandfactory.cpp b/commandfactory.cpp index baef216..dd97b2f 100644 --- a/commandfactory.cpp +++ b/commandfactory.cpp @@ -80,6 +80,8 @@ CommandFactory* CommandFactory::getInstance() { /***********************************************************/ CommandFactory::CommandFactory(){ string s = ""; + m = MothurOut::getInstance(); + command = new NoCommand(s); outputDir = ""; inputDir = ""; @@ -169,67 +171,67 @@ Command* CommandFactory::getCommand(string commandName, string optionString){ else { optionString += "inputdir=" + inputDir; } } - if(commandName == "read.dist") { command = new ReadDistCommand(optionString); } - else if(commandName == "read.otu") { command = new ReadOtuCommand(optionString); } - else if(commandName == "read.tree") { command = new ReadTreeCommand(optionString); } - else if(commandName == "cluster") { command = new ClusterCommand(optionString); } - 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 == "quit") { command = new QuitCommand(optionString); } - else if(commandName == "collect.single") { command = new CollectCommand(optionString); } - else if(commandName == "collect.shared") { command = new CollectSharedCommand(optionString); } - else if(commandName == "rarefaction.single") { command = new RareFactCommand(optionString); } - else if(commandName == "rarefaction.shared") { command = new RareFactSharedCommand(optionString); } - else if(commandName == "summary.single") { command = new SummaryCommand(optionString); } - else if(commandName == "summary.shared") { command = new SummarySharedCommand(optionString); } - else if(commandName == "unifrac.weighted") { command = new UnifracWeightedCommand(optionString); } - else if(commandName == "unifrac.unweighted") { command = new UnifracUnweightedCommand(optionString); } - else if(commandName == "get.group") { command = new GetgroupCommand(optionString); } - else if(commandName == "get.label") { command = new GetlabelCommand(optionString); } - else if(commandName == "get.sabund") { command = new GetSAbundCommand(optionString); } - else if(commandName == "get.rabund") { command = new GetRAbundCommand(optionString); } - else if(commandName == "libshuff") { command = new LibShuffCommand(optionString); } - else if(commandName == "heatmap.bin") { command = new HeatMapCommand(optionString); } - else if(commandName == "heatmap.sim") { command = new HeatMapSimCommand(optionString); } - else if(commandName == "filter.seqs") { command = new FilterSeqsCommand(optionString); } - else if(commandName == "venn") { command = new VennCommand(optionString); } - else if(commandName == "bin.seqs") { command = new BinSeqCommand(optionString); } - else if(commandName == "get.oturep") { command = new GetOTURepCommand(optionString); } - else if(commandName == "tree.shared") { command = new TreeGroupCommand(optionString); } - else if(commandName == "dist.shared") { command = new MatrixOutputCommand(optionString); } - else if(commandName == "bootstrap.shared") { command = new BootSharedCommand(optionString); } - //else if(commandName == "consensus") { command = new ConcensusCommand(optionString); } - else if(commandName == "dist.seqs") { command = new DistanceCommand(optionString); } - else if(commandName == "align.seqs") { command = new AlignCommand(optionString); } - else if(commandName == "summary.seqs") { command = new SeqSummaryCommand(optionString); } - else if(commandName == "screen.seqs") { command = new ScreenSeqsCommand(optionString); } - else if(commandName == "reverse.seqs") { command = new ReverseSeqsCommand(optionString); } - else if(commandName == "trim.seqs") { command = new TrimSeqsCommand(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 == "merge.files") { command = new MergeFileCommand(optionString); } - else if(commandName == "system") { command = new SystemCommand(optionString); } - else if(commandName == "align.check") { command = new AlignCheckCommand(optionString); } - else if(commandName == "get.sharedseqs") { command = new GetSharedOTUCommand(optionString); } - else if(commandName == "get.otulist") { command = new GetListCountCommand(optionString); } - else if(commandName == "hcluster") { command = new HClusterCommand(optionString); } - else if(commandName == "classify.seqs") { command = new ClassifySeqsCommand(optionString); } - else if(commandName == "phylotype") { command = new PhylotypeCommand(optionString); } - else if(commandName == "mgcluster") { command = new MGClusterCommand(optionString); } - else if(commandName == "pre.cluster") { command = new PreClusterCommand(optionString); } - else if(commandName == "pcoa") { command = new PCACommand(optionString); } - else if(commandName == "otu.hierarchy") { command = new OtuHierarchyCommand(optionString); } - else if(commandName == "set.dir") { command = new SetDirectoryCommand(optionString); } - else if(commandName == "parse.list") { command = new ParseListCommand(optionString); } - else { command = new NoCommand(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); } + else 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 == "quit") { command = new QuitCommand(optionString); } + else if(commandName == "collect.single") { command = new CollectCommand(optionString); } + else if(commandName == "collect.shared") { command = new CollectSharedCommand(optionString); } + else if(commandName == "rarefaction.single") { command = new RareFactCommand(optionString); } + else if(commandName == "rarefaction.shared") { command = new RareFactSharedCommand(optionString); } + else if(commandName == "summary.single") { command = new SummaryCommand(optionString); } + else if(commandName == "summary.shared") { command = new SummarySharedCommand(optionString); } + else if(commandName == "unifrac.weighted") { command = new UnifracWeightedCommand(optionString); } + else if(commandName == "unifrac.unweighted") { command = new UnifracUnweightedCommand(optionString); } + else if(commandName == "get.group") { command = new GetgroupCommand(optionString); } + else if(commandName == "get.label") { command = new GetlabelCommand(optionString); } + else if(commandName == "get.sabund") { command = new GetSAbundCommand(optionString); } + else if(commandName == "get.rabund") { command = new GetRAbundCommand(optionString); } + else if(commandName == "libshuff") { command = new LibShuffCommand(optionString); } + else if(commandName == "heatmap.bin") { command = new HeatMapCommand(optionString); } + else if(commandName == "heatmap.sim") { command = new HeatMapSimCommand(optionString); } + else if(commandName == "filter.seqs") { command = new FilterSeqsCommand(optionString); } + else if(commandName == "venn") { command = new VennCommand(optionString); } + else if(commandName == "bin.seqs") { command = new BinSeqCommand(optionString); } + else if(commandName == "get.oturep") { command = new GetOTURepCommand(optionString); } + else if(commandName == "tree.shared") { command = new TreeGroupCommand(optionString); } + else if(commandName == "dist.shared") { command = new MatrixOutputCommand(optionString); } + else if(commandName == "bootstrap.shared") { command = new BootSharedCommand(optionString); } + //else if(commandName == "consensus") { command = new ConcensusCommand(optionString); } + else if(commandName == "dist.seqs") { command = new DistanceCommand(optionString); } + else if(commandName == "align.seqs") { command = new AlignCommand(optionString); } + else if(commandName == "summary.seqs") { command = new SeqSummaryCommand(optionString); } + else if(commandName == "screen.seqs") { command = new ScreenSeqsCommand(optionString); } + else if(commandName == "reverse.seqs") { command = new ReverseSeqsCommand(optionString); } + else if(commandName == "trim.seqs") { command = new TrimSeqsCommand(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 == "merge.files") { command = new MergeFileCommand(optionString); } + else if(commandName == "system") { command = new SystemCommand(optionString); } + else if(commandName == "align.check") { command = new AlignCheckCommand(optionString); } + else if(commandName == "get.sharedseqs") { command = new GetSharedOTUCommand(optionString); } + else if(commandName == "get.otulist") { command = new GetListCountCommand(optionString); } + else if(commandName == "hcluster") { command = new HClusterCommand(optionString); } + else if(commandName == "classify.seqs") { command = new ClassifySeqsCommand(optionString); } + else if(commandName == "phylotype") { command = new PhylotypeCommand(optionString); } + else if(commandName == "mgcluster") { command = new MGClusterCommand(optionString); } + else if(commandName == "pre.cluster") { command = new PreClusterCommand(optionString); } + else if(commandName == "pcoa") { command = new PCACommand(optionString); } + else if(commandName == "otu.hierarchy") { command = new OtuHierarchyCommand(optionString); } + else if(commandName == "set.dir") { command = new SetDirectoryCommand(optionString); } + else if(commandName == "parse.list") { command = new ParseListCommand(optionString); } + else { command = new NoCommand(optionString); } return command; } catch(exception& e) { - errorOut(e, "CommandFactory", "getCommand"); + m->errorOut(e, "CommandFactory", "getCommand"); exit(1); } } @@ -245,7 +247,7 @@ Command* CommandFactory::getCommand(){ return command; } catch(exception& e) { - errorOut(e, "CommandFactory", "getCommand"); + m->errorOut(e, "CommandFactory", "getCommand"); exit(1); } } @@ -257,17 +259,17 @@ bool CommandFactory::isValidCommand(string command) { if ((commands.find(command)) != (commands.end())) { return true; }else{ - mothurOut(command + " is not a valid command in Mothur. Valid commands are "); + m->mothurOut(command + " is not a valid command in Mothur. Valid commands are "); for (it = commands.begin(); it != commands.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } } catch(exception& e) { - errorOut(e, "CommandFactory", "isValidCommand"); + m->errorOut(e, "CommandFactory", "isValidCommand"); exit(1); } } @@ -282,7 +284,7 @@ void CommandFactory::printCommands(ostream& out) { out << endl; } catch(exception& e) { - errorOut(e, "CommandFactory", "printCommands"); + m->errorOut(e, "CommandFactory", "printCommands"); exit(1); } } diff --git a/commandfactory.hpp b/commandfactory.hpp index d84be62..e1f62da 100644 --- a/commandfactory.hpp +++ b/commandfactory.hpp @@ -11,6 +11,7 @@ */ #include "mothur.h" +#include "mothurout.h"; class Command; @@ -27,6 +28,7 @@ public: private: Command* command; + MothurOut* m; map commands; map::iterator it; string outputDir, inputDir; diff --git a/commandoptionparser.cpp b/commandoptionparser.cpp index f013a25..df216da 100644 --- a/commandoptionparser.cpp +++ b/commandoptionparser.cpp @@ -16,6 +16,8 @@ //This Function parses through the command line and pulls out the command then sends the options to the parseGlobalData CommandOptionParser::CommandOptionParser(string input){ try { + m = MothurOut::getInstance(); + int openParen = input.find_first_of('('); int closeParen = input.find_last_of(')'); optionString = ""; @@ -25,14 +27,14 @@ CommandOptionParser::CommandOptionParser(string input){ commandString = input.substr(0, openParen); //commandString contains everything before "(" optionString = input.substr((openParen+1), (closeParen-openParen-1)); //optionString contains everything between "(" and ")". } - else if (openParen == -1) { mothurOut("You are missing ("); mothurOutEndLine(); } - else if (closeParen == -1) { mothurOut("You are missing )"); mothurOutEndLine(); } + else if (openParen == -1) { m->mothurOut("You are missing ("); m->mothurOutEndLine(); } + else if (closeParen == -1) { m->mothurOut("You are missing )"); m->mothurOutEndLine(); } //GlobalData* globaldata = GlobalData::getInstance(); //globaldata->parseGlobalData(commandString, optionString); //parser to separate and check options } catch(exception& e) { - errorOut(e, "CommandOptionParser", "CommandOptionParser"); + m->errorOut(e, "CommandOptionParser", "CommandOptionParser"); exit(1); } } diff --git a/commandoptionparser.hpp b/commandoptionparser.hpp index 44df8f7..0c3a6f3 100644 --- a/commandoptionparser.hpp +++ b/commandoptionparser.hpp @@ -2,6 +2,7 @@ #define COMMANDOPTIONPARSER_HPP #include "mothur.h" +#include "mothurout.h" //********************************************************************************************************************** @@ -13,6 +14,7 @@ public: private: string commandString, optionString; + MothurOut* m; }; //********************************************************************************************************************** diff --git a/completelinkage.cpp b/completelinkage.cpp index df6371a..86e9054 100644 --- a/completelinkage.cpp +++ b/completelinkage.cpp @@ -26,7 +26,7 @@ bool CompleteLinkage::updateDistance(MatData& colCell, MatData& rowCell) { return(changed); } catch(exception& e) { - errorOut(e, "CompleteLinkage", "updateDistance"); + m->errorOut(e, "CompleteLinkage", "updateDistance"); exit(1); } } diff --git a/consensuscommand.cpp b/consensuscommand.cpp index 8c34068..dc27801 100644 --- a/consensuscommand.cpp +++ b/consensuscommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -ConcensusCommand::ConcensusCommand(string fileroot){ +ConcensusCommand::ConcensusCommand(string fileroot) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -22,7 +22,7 @@ ConcensusCommand::ConcensusCommand(string fileroot){ } catch(exception& e) { - errorOut(e, "ConcensusCommand", "ConcensusCommand"); + m->errorOut(e, "ConcensusCommand", "ConcensusCommand"); exit(1); } } @@ -31,17 +31,17 @@ ConcensusCommand::ConcensusCommand(string fileroot){ void ConcensusCommand::help(){ try { - mothurOut("The consensus command can only be executed after a successful read.tree command.\n"); - mothurOut("The consensus command has no parameters.\n"); - mothurOut("The consensus command should be in the following format: consensus().\n"); - mothurOut("The consensus command output two files: .consensus.tre and .consensuspairs.\n"); - mothurOut("The .consensus.tre file contains the consensus tree of the trees in your input file.\n"); - mothurOut("The branch lengths are the percentage of trees in your input file that had the given pair.\n"); - 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"); - 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"); + 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) { - errorOut(e, "ConcensusCommand", "help"); + m->errorOut(e, "ConcensusCommand", "help"); exit(1); } } @@ -148,7 +148,7 @@ int ConcensusCommand::execute(){ return 0; } catch(exception& e) { - errorOut(e, "ConcensusCommand", "execute"); + m->errorOut(e, "ConcensusCommand", "execute"); exit(1); } } @@ -180,7 +180,7 @@ int ConcensusCommand::buildConcensusTree(vector nodeSet) { } catch(exception& e) { - errorOut(e, "ConcensusCommand", "buildConcensusTree"); + m->errorOut(e, "ConcensusCommand", "buildConcensusTree"); exit(1); } } @@ -251,7 +251,7 @@ void ConcensusCommand::getSets() { } catch(exception& e) { - errorOut(e, "ConcensusCommand", "getSets"); + m->errorOut(e, "ConcensusCommand", "getSets"); exit(1); } } @@ -268,7 +268,7 @@ vector ConcensusCommand::getSmallest(map< vector, int> nodes) { return smallest; } catch(exception& e) { - errorOut(e, "ConcensusCommand", "getSmallest"); + m->errorOut(e, "ConcensusCommand", "getSmallest"); exit(1); } } @@ -306,7 +306,7 @@ vector ConcensusCommand::getNextAvailableSet(vector bigset, vect } catch(exception& e) { - errorOut(e, "ConcensusCommand", "getNextAvailableSet"); + m->errorOut(e, "ConcensusCommand", "getNextAvailableSet"); exit(1); } } @@ -373,7 +373,7 @@ int ConcensusCommand::getSubgroupRating(vector group) { return rate; } catch(exception& e) { - errorOut(e, "ConcensusCommand", "getSubgroupRating"); + m->errorOut(e, "ConcensusCommand", "getSubgroupRating"); exit(1); } } @@ -397,7 +397,7 @@ vector ConcensusCommand::getRestSet(vector bigset, vectorerrorOut(e, "ConcensusCommand", "getRestSet"); exit(1); } } @@ -424,7 +424,7 @@ bool ConcensusCommand::isSubset(vector bigset, vector subset) { } catch(exception& e) { - errorOut(e, "ConcensusCommand", "isSubset"); + m->errorOut(e, "ConcensusCommand", "isSubset"); exit(1); } } @@ -442,7 +442,7 @@ int ConcensusCommand::findSpot(string node) { } catch(exception& e) { - errorOut(e, "ConcensusCommand", "findSpot"); + m->errorOut(e, "ConcensusCommand", "findSpot"); exit(1); } } diff --git a/coverage.cpp b/coverage.cpp index 16d2644..aebe66f 100644 --- a/coverage.cpp +++ b/coverage.cpp @@ -20,7 +20,7 @@ EstOutput Coverage::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "Coverage", "getValues"); + m->errorOut(e, "Coverage", "getValues"); exit(1); } } diff --git a/database.cpp b/database.cpp index 5f82bc1..f587f42 100644 --- a/database.cpp +++ b/database.cpp @@ -16,6 +16,7 @@ Database::Database(){ longest = 0; numSeqs = 0; + m = MothurOut::getInstance(); } /**************************************************************************************************/ diff --git a/database.hpp b/database.hpp index 7fd29b3..994c845 100644 --- a/database.hpp +++ b/database.hpp @@ -58,6 +58,7 @@ public: protected: + MothurOut* m; int numSeqs, longest; float searchScore; vector results; diff --git a/datavector.hpp b/datavector.hpp index b3c7c90..0b09e0d 100644 --- a/datavector.hpp +++ b/datavector.hpp @@ -3,6 +3,7 @@ #include "mothur.h" +#include "mothurout.h" /* This class is parent to listvector, ordervector, rabundvector, sabundvector, sharedordervector, sharedrabundvector, sharedsabundvector. The child classes all contain OTU information in different forms. */ @@ -19,7 +20,7 @@ class SharedRAbundVector; class DataVector { public: - DataVector(){};// : maxRank(0), numBins(0), numSeqs(0){}; + DataVector(){ m = MothurOut::getInstance(); }// : maxRank(0), numBins(0), numSeqs(0){}; DataVector(string l) : label(l) {}; DataVector(const DataVector& dv) : label(dv.label){};//, maxRank(dv.maxRank), numBins(dv.numBins), numSeqs(dv.numSeqs) {}; DataVector(ifstream&); @@ -42,6 +43,7 @@ public: protected: string label; + MothurOut* m; // int maxRank; // int numBins; // int numSeqs; diff --git a/decalc.cpp b/decalc.cpp index c5f0c26..d4c4eb5 100644 --- a/decalc.cpp +++ b/decalc.cpp @@ -15,9 +15,9 @@ //*************************************************************************************************************** -void DeCalculator::setMask(string m) { +void DeCalculator::setMask(string ms) { try { - seqMask = m; + seqMask = ms; int count = 0; maskMap.clear(); @@ -40,7 +40,7 @@ void DeCalculator::setMask(string m) { } } catch(exception& e) { - errorOut(e, "DeCalculator", "setMask"); + m->errorOut(e, "DeCalculator", "setMask"); exit(1); } } @@ -62,7 +62,7 @@ void DeCalculator::runMask(Sequence* seq) { seq->setUnaligned(tempQuery); } catch(exception& e) { - errorOut(e, "DeCalculator", "runMask"); + m->errorOut(e, "DeCalculator", "runMask"); exit(1); } } @@ -90,7 +90,7 @@ void DeCalculator::trimSeqs(Sequence* query, Sequence* subject, map& t } catch(exception& e) { - errorOut(e, "DeCalculator", "trimSeqs"); + m->errorOut(e, "DeCalculator", "trimSeqs"); exit(1); } } @@ -106,7 +106,7 @@ vector DeCalculator::findWindows(Sequence* query, int front, int back, int if (size == 0) { if (cutoff > 1200) { size = 300; } else{ size = (cutoff / 4); } } else if (size > (cutoff / 4)) { - mothurOut("You have selected too large a window size for sequence " + query->getName() + ". I will choose an appropriate window size."); mothurOutEndLine(); + m->mothurOut("You have selected too large a window size for sequence " + query->getName() + ". I will choose an appropriate window size."); m->mothurOutEndLine(); size = (cutoff / 4); } @@ -158,7 +158,7 @@ vector DeCalculator::findWindows(Sequence* query, int front, int back, int } catch(exception& e) { - errorOut(e, "DeCalculator", "findWindows"); + m->errorOut(e, "DeCalculator", "findWindows"); exit(1); } } @@ -200,7 +200,7 @@ vector DeCalculator::calcObserved(Sequence* query, Sequence* subject, vec return temp; } catch(exception& e) { - errorOut(e, "DeCalculator", "calcObserved"); + m->errorOut(e, "DeCalculator", "calcObserved"); exit(1); } } @@ -232,7 +232,7 @@ float DeCalculator::calcDist(Sequence* query, Sequence* subject, int front, int return dist; } catch(exception& e) { - errorOut(e, "DeCalculator", "calcDist"); + m->errorOut(e, "DeCalculator", "calcDist"); exit(1); } } @@ -255,7 +255,7 @@ vector DeCalculator::calcExpected(vector qav, float coef) { } catch(exception& e) { - errorOut(e, "DeCalculator", "calcExpected"); + m->errorOut(e, "DeCalculator", "calcExpected"); exit(1); } } @@ -279,7 +279,7 @@ float DeCalculator::calcDE(vector obs, vector exp) { return de; } catch(exception& e) { - errorOut(e, "DeCalculator", "calcDE"); + m->errorOut(e, "DeCalculator", "calcDE"); exit(1); } } @@ -345,7 +345,7 @@ vector DeCalculator::calcFreq(vector seqs, string filename) { } catch(exception& e) { - errorOut(e, "DeCalculator", "calcFreq"); + m->errorOut(e, "DeCalculator", "calcFreq"); exit(1); } } @@ -375,7 +375,7 @@ vector DeCalculator::findQav(vector window, int size, vector return averages; } catch(exception& e) { - errorOut(e, "DeCalculator", "findQav"); + m->errorOut(e, "DeCalculator", "findQav"); exit(1); } } @@ -394,7 +394,7 @@ vector< vector > DeCalculator::getQuantiles(vector seqs, //for each sequence for(int i = start; i < end; i++){ - mothurOut("Processing sequence " + toString(i)); mothurOutEndLine(); + m->mothurOut("Processing sequence " + toString(i)); m->mothurOutEndLine(); Sequence* query = new Sequence(seqs[i]->getName(), seqs[i]->getAligned()); //compare to every other sequence in template @@ -443,7 +443,7 @@ vector< vector > DeCalculator::getQuantiles(vector seqs, } catch(exception& e) { - errorOut(e, "DeCalculator", "getQuantiles"); + m->errorOut(e, "DeCalculator", "getQuantiles"); exit(1); } } @@ -485,7 +485,7 @@ void DeCalculator::removeObviousOutliers(vector< vector >& quantiles //while you still have guys to eliminate while (contributions.size() > 0) { - mothurOut("Removing scores contributed by sequence " + toString(largestContrib) + " in your template file."); mothurOutEndLine(); + m->mothurOut("Removing scores contributed by sequence " + toString(largestContrib) + " in your template file."); m->mothurOutEndLine(); //remove from quantiles all scores that were made using this largestContrib for (int i = 0; i < quantiles.size(); i++) { @@ -516,7 +516,7 @@ cout << "high = " << high << endl; for(int i = 0; i < marked.size(); i++) { if (marked[i] > high) { - mothurOut("Removing scores contributed by sequence " + toString(marked[i]) + " in your template file."); mothurOutEndLine(); + m->mothurOut("Removing scores contributed by sequence " + toString(marked[i]) + " in your template file."); m->mothurOutEndLine(); for (int i = 0; i < quantiles.size(); i++) { removeContrib(marked[i], quantiles[i]); } @@ -560,7 +560,7 @@ cout << "high = " << high << endl; } catch(exception& e) { - errorOut(e, "DeCalculator", "removeObviousOutliers"); + m->errorOut(e, "DeCalculator", "removeObviousOutliers"); exit(1); } } @@ -592,7 +592,7 @@ cout << largest->second << '\t' << largest->first->score << '\t' << largest->fir } catch(exception& e) { - errorOut(e, "DeCalculator", "sortContrib"); + m->errorOut(e, "DeCalculator", "sortContrib"); exit(1); } } @@ -618,7 +618,7 @@ int DeCalculator::findLargestContrib(vector seen) { } catch(exception& e) { - errorOut(e, "DeCalculator", "findLargestContribs"); + m->errorOut(e, "DeCalculator", "findLargestContribs"); exit(1); } } @@ -637,7 +637,7 @@ void DeCalculator::removeContrib(int bad, vector& quan) { } catch(exception& e) { - errorOut(e, "DeCalculator", "removeContrib"); + m->errorOut(e, "DeCalculator", "removeContrib"); exit(1); } } @@ -655,7 +655,7 @@ float DeCalculator::findAverage(vector myVector) { } catch(exception& e) { - errorOut(e, "DeCalculator", "findAverage"); + m->errorOut(e, "DeCalculator", "findAverage"); exit(1); } } @@ -675,7 +675,7 @@ float DeCalculator::getCoef(vector obs, vector qav) { return coef; } catch(exception& e) { - errorOut(e, "DeCalculator", "getCoef"); + m->errorOut(e, "DeCalculator", "getCoef"); exit(1); } } @@ -833,7 +833,7 @@ vector DeCalculator::findClosest(Sequence* querySeq, vectorerrorOut(e, "DeCalculator", "findClosest"); exit(1); } } @@ -865,7 +865,7 @@ Sequence* DeCalculator::findClosest(Sequence* querySeq, vector db) { return seqsMatch; } catch(exception& e) { - errorOut(e, "DeCalculator", "findClosest"); + m->errorOut(e, "DeCalculator", "findClosest"); exit(1); } } @@ -945,7 +945,7 @@ map DeCalculator::trimSeqs(Sequence* query, vector topMatch if (pos < rearPos) { rearPos = pos; } //check to make sure that is not whole seq - if ((rearPos - frontPos - 1) <= 0) { mothurOut("Error, when I trim your sequences, the entire sequence is trimmed."); mothurOutEndLine(); exit(1); } + if ((rearPos - frontPos - 1) <= 0) { m->mothurOut("Error, when I trim your sequences, the entire sequence is trimmed."); m->mothurOutEndLine(); exit(1); } //cout << query->getName() << " front = " << frontPos << " rear = " << rearPos << endl; //trim query string newAligned = query->getAligned(); @@ -968,7 +968,7 @@ map DeCalculator::trimSeqs(Sequence* query, vector topMatch return trimmedPos; } catch(exception& e) { - errorOut(e, "DeCalculator", "trimSequences"); + m->errorOut(e, "DeCalculator", "trimSequences"); exit(1); } diff --git a/decalc.h b/decalc.h index 48a72bb..da663e8 100644 --- a/decalc.h +++ b/decalc.h @@ -36,7 +36,7 @@ class DeCalculator { public: - DeCalculator() {}; + DeCalculator() { m = MothurOut::getInstance(); } ~DeCalculator() {}; vector findClosest(Sequence*, vector, int&, vector&); //takes querySeq, a reference db, numWanted and indexes @@ -71,6 +71,7 @@ class DeCalculator { set h; int alignLength; map maskMap; + MothurOut* m; }; diff --git a/deconvolutecommand.cpp b/deconvolutecommand.cpp index 00c4084..fcfd320 100644 --- a/deconvolutecommand.cpp +++ b/deconvolutecommand.cpp @@ -10,7 +10,7 @@ #include "deconvolutecommand.h" /**************************************************************************************/ -DeconvoluteCommand::DeconvoluteCommand(string option) { +DeconvoluteCommand::DeconvoluteCommand(string option) { try { abort = false; @@ -59,7 +59,7 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { //check for required parameters inFastaName = validParameter.validFile(parameters, "fasta", true); if (inFastaName == "not open") { abort = true; } - else if (inFastaName == "not found") { inFastaName = ""; mothurOut("fasta is a required parameter for the unique.seqs command."); mothurOutEndLine(); abort = true; } + else if (inFastaName == "not found") { inFastaName = ""; m->mothurOut("fasta is a required parameter for the unique.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"){ @@ -74,7 +74,7 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { } catch(exception& e) { - errorOut(e, "DeconvoluteCommand", "DeconvoluteCommand"); + m->errorOut(e, "DeconvoluteCommand", "DeconvoluteCommand"); exit(1); } } @@ -82,15 +82,15 @@ DeconvoluteCommand::DeconvoluteCommand(string option) { void DeconvoluteCommand::help(){ try { - mothurOut("The unique.seqs command reads a fastafile and creates a namesfile.\n"); - 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"); - mothurOut("If the sequence is unique the second column will just contain its name. \n"); - mothurOut("The unique.seqs command parameter is fasta and it is required.\n"); - mothurOut("The unique.seqs command should be in the following format: \n"); - mothurOut("unique.seqs(fasta=yourFastaFile) \n"); + 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) { - errorOut(e, "DeconvoluteCommand", "help"); + m->errorOut(e, "DeconvoluteCommand", "help"); exit(1); } } @@ -113,10 +113,18 @@ int DeconvoluteCommand::execute() { fastamap.printCondensedFasta(outFastaFile); fastamap.printNamesFile(outNameFile); + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + m->mothurOut(outFastaFile); m->mothurOutEndLine(); + m->mothurOut(outNameFile); m->mothurOutEndLine(); + m->mothurOutEndLine(); + + + return 0; } catch(exception& e) { - errorOut(e, "DeconvoluteCommand", "execute"); + m->errorOut(e, "DeconvoluteCommand", "execute"); exit(1); } } diff --git a/deconvolutecommand.h b/deconvolutecommand.h index 4cb6aac..9c8fd22 100644 --- a/deconvolutecommand.h +++ b/deconvolutecommand.h @@ -19,7 +19,7 @@ class DeconvoluteCommand : public Command { public: - DeconvoluteCommand(string); + DeconvoluteCommand(string); ~DeconvoluteCommand() { }; int execute(); void help(); diff --git a/display.h b/display.h index 5963975..8671fa6 100644 --- a/display.h +++ b/display.h @@ -22,8 +22,10 @@ public: virtual bool getAll() { bool a; return a; } virtual string getName() { return ""; }; virtual ~Display() {} + Display() { m = MothurOut::getInstance(); } -private: +protected: + MothurOut* m; }; diff --git a/dist.h b/dist.h index 6a461f5..b914d0d 100644 --- a/dist.h +++ b/dist.h @@ -17,12 +17,13 @@ class Dist { public: - Dist(){dist = 0;} + Dist(){dist = 0; m = MothurOut::getInstance(); } virtual ~Dist() {} virtual void calcDist(Sequence, Sequence) = 0; double getDist() { return dist; } protected: double dist; + MothurOut* m; }; /**************************************************************************************************/ diff --git a/distancecommand.cpp b/distancecommand.cpp index c615b80..13f56eb 100644 --- a/distancecommand.cpp +++ b/distancecommand.cpp @@ -16,11 +16,11 @@ //********************************************************************************************************************** -DistanceCommand::DistanceCommand(string option){ +DistanceCommand::DistanceCommand(string option) { try { abort = false; Estimators.clear(); - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -56,7 +56,7 @@ DistanceCommand::DistanceCommand(string option){ //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { mothurOut("fasta is a required parameter for the dist.seqs command."); mothurOutEndLine(); abort = 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; } else{ ifstream inFASTA; @@ -92,7 +92,7 @@ DistanceCommand::DistanceCommand(string option){ output = validParameter.validFile(parameters, "output", false); if(output == "not found"){ output = "column"; } - if ((output != "column") && (output != "lt") && (output != "square")) { mothurOut(output + " is not a valid output form. Options are column, lt and square. I will use column."); mothurOutEndLine(); output = "column"; } + if ((output != "column") && (output != "lt") && (output != "square")) { m->mothurOut(output + " is not a valid output form. Options are column, lt and square. I will use column."); m->mothurOutEndLine(); output = "column"; } ValidCalculators validCalculator; @@ -118,7 +118,7 @@ DistanceCommand::DistanceCommand(string option){ } catch(exception& e) { - errorOut(e, "DistanceCommand", "DistanceCommand"); + m->errorOut(e, "DistanceCommand", "DistanceCommand"); exit(1); } } @@ -137,21 +137,21 @@ DistanceCommand::~DistanceCommand(){ void DistanceCommand::help(){ try { - mothurOut("The dist.seqs command reads a file containing sequences and creates a distance file.\n"); - mothurOut("The dist.seqs command parameters are fasta, calc, countends, output, cutoff and processors. \n"); - mothurOut("The fasta parameter is required.\n"); - 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"); - 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"); - mothurOut("The cutoff parameter allows you to specify maximum distance to keep. The default is 1.0.\n"); - mothurOut("The output parameter allows you to specify format of your distance matrix. Options are column, lt, and square. The default is column.\n"); - mothurOut("The processors parameter allows you to specify number of processors to use. The default is 1.\n"); - mothurOut("The dist.seqs command should be in the following format: \n"); - mothurOut("dist.seqs(fasta=yourFastaFile, calc=yourCalc, countends=yourEnds, cutoff= yourCutOff, processors=yourProcessors) \n"); - mothurOut("Example dist.seqs(fasta=amazon.fasta, calc=eachgap, countends=F, cutoff= 2.0, processors=3).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. calc), '=' and parameters (i.e.yourCalc).\n\n"); + 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, calc, countends, output, cutoff and processors. \n"); + m->mothurOut("The fasta parameter is required.\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 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) { - errorOut(e, "DistanceCommand", "help"); + m->errorOut(e, "DistanceCommand", "help"); exit(1); } } @@ -213,11 +213,16 @@ int DistanceCommand::execute(){ delete distCalculator; + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outputFile); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "DistanceCommand", "execute"); + m->errorOut(e, "DistanceCommand", "execute"); exit(1); } } @@ -238,7 +243,7 @@ void DistanceCommand::createProcesses(string filename) { }else if (pid == 0){ driver(lines[process]->start, lines[process]->end, filename + toString(getpid()) + ".temp", cutoff); exit(0); - }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); } + }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } } //force parent to wait until all the processes are done @@ -249,7 +254,7 @@ void DistanceCommand::createProcesses(string filename) { #endif } catch(exception& e) { - errorOut(e, "DistanceCommand", "createProcesses"); + m->errorOut(e, "DistanceCommand", "createProcesses"); exit(1); } } @@ -295,18 +300,18 @@ int DistanceCommand::driver(int startLine, int endLine, string dFileName, float if (output == "lt") { outFile << endl; } if(i % 100 == 0){ - mothurOut(toString(i) + "\t" + toString(time(NULL) - startTime)); mothurOutEndLine(); + m->mothurOut(toString(i) + "\t" + toString(time(NULL) - startTime)); m->mothurOutEndLine(); } } - mothurOut(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)); mothurOutEndLine(); + m->mothurOut(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)); m->mothurOutEndLine(); outFile.close(); return 1; } catch(exception& e) { - errorOut(e, "DistanceCommand", "driver"); + m->errorOut(e, "DistanceCommand", "driver"); exit(1); } } @@ -390,7 +395,7 @@ void DistanceCommand::convertMatrix(string outputFile) { } catch(exception& e) { - errorOut(e, "DistanceCommand", "convertMatrix"); + m->errorOut(e, "DistanceCommand", "convertMatrix"); exit(1); } } @@ -413,7 +418,7 @@ void DistanceCommand::appendFiles(string temp, string filename) { output.close(); } catch(exception& e) { - errorOut(e, "DistanceCommand", "appendFiles"); + m->errorOut(e, "DistanceCommand", "appendFiles"); exit(1); } } diff --git a/distancecommand.h b/distancecommand.h index 7521ac7..dedcc79 100644 --- a/distancecommand.h +++ b/distancecommand.h @@ -20,7 +20,7 @@ class DistanceCommand : public Command { public: - DistanceCommand(string); + DistanceCommand(string); ~DistanceCommand(); int execute(); void help(); diff --git a/distancedb.cpp b/distancedb.cpp index 25641eb..0c1aeeb 100644 --- a/distancedb.cpp +++ b/distancedb.cpp @@ -21,7 +21,7 @@ DistanceDB::DistanceDB() { distCalculator = new eachGapDist(); } catch(exception& e) { - errorOut(e, "DistanceDB", "DistanceDB"); + m->errorOut(e, "DistanceDB", "DistanceDB"); exit(1); } } @@ -29,14 +29,14 @@ DistanceDB::DistanceDB() { void DistanceDB::addSequence(Sequence seq) { try { //are the template sequences aligned - if (!isAligned(seq.getAligned())) { templateAligned = false; mothurOut(seq.getName() + " is not aligned. Sequences must be aligned to use the distance method."); mothurOutEndLine(); } + if (!isAligned(seq.getAligned())) { templateAligned = false; m->mothurOut(seq.getName() + " is not aligned. Sequences must be aligned to use the distance method."); m->mothurOutEndLine(); } if (templateSeqsLength == 0) { templateSeqsLength = seq.getAligned().length(); } data.push_back(seq); } catch(exception& e) { - errorOut(e, "DistanceDB", "addSequence"); + m->errorOut(e, "DistanceDB", "addSequence"); exit(1); } } @@ -49,7 +49,7 @@ vector DistanceDB::findClosestSequences(Sequence* query, int numWanted){ string sequence = query->getAligned(); vector dists; - if (numWanted > data.size()) { mothurOut("numwanted is larger than the number of template sequences, using 10."); mothurOutEndLine(); numWanted = 10; } + if (numWanted > data.size()) { m->mothurOut("numwanted is larger than the number of template sequences, using 10."); m->mothurOutEndLine(); numWanted = 10; } if (sequence.length() != templateSeqsLength) { templateSameLength = false; } @@ -72,14 +72,14 @@ vector DistanceDB::findClosestSequences(Sequence* query, int numWanted){ } }else{ - mothurOut("cannot find closest matches using distance method for " + query->getName() + " without aligned template sequences of the same length."); mothurOutEndLine(); + m->mothurOut("cannot find closest matches using distance method for " + query->getName() + " without aligned template sequences of the same length."); m->mothurOutEndLine(); exit(1); } return topMatches; } catch(exception& e) { - errorOut(e, "DistanceDB", "findClosestSequence"); + m->errorOut(e, "DistanceDB", "findClosestSequence"); exit(1); } } @@ -98,7 +98,7 @@ bool DistanceDB::isAligned(string seq){ return aligned; } catch(exception& e) { - errorOut(e, "DistanceDB", "isAligned"); + m->errorOut(e, "DistanceDB", "isAligned"); exit(1); } } diff --git a/efron.cpp b/efron.cpp index 9ddcdfa..7e1cba8 100644 --- a/efron.cpp +++ b/efron.cpp @@ -16,18 +16,18 @@ EstOutput Efron::getValues(SAbundVector* rank){ data.resize(1,0); double n = (double)rank->getNumSeqs(); - if(m > n || m == 0) { m = n; } + if(f > n || f == 0) { f = n; } double sum = 0; for(int i = 1; i < rank->size(); i++){ - sum += pow(-1., i+1) * pow(((double)m / n), i) * (double)(rank->get(i)); + sum += pow(-1., i+1) * pow(((double)f / n), i) * (double)(rank->get(i)); } data[0] = sum; return data; } catch(exception& e) { - errorOut(e, "Efron", "getValues"); + m->errorOut(e, "Efron", "getValues"); exit(1); } } diff --git a/efron.h b/efron.h index 782e72e..44aee5a 100644 --- a/efron.h +++ b/efron.h @@ -20,11 +20,11 @@ class Efron : public Calculator { public: - Efron(int size) : m(size), Calculator("efron", 1, false) {}; + Efron(int size) : f(size), Calculator("efron", 1, false) {}; EstOutput getValues(SAbundVector*); EstOutput getValues(vector) {return data;}; private: - int m; + int f; }; diff --git a/engine.cpp b/engine.cpp index 18e1a59..fdd017a 100644 --- a/engine.cpp +++ b/engine.cpp @@ -18,9 +18,10 @@ Engine::Engine(){ try { cFactory = CommandFactory::getInstance(); + mout = MothurOut::getInstance(); } catch(exception& e) { - errorOut(e, "Engine", "Engine"); + mout->errorOut(e, "Engine", "Engine"); exit(1); } } @@ -31,6 +32,7 @@ InteractEngine::InteractEngine(string path){ globaldata = GlobalData::getInstance(); globaldata->argv = path; + } /***********************************************************************/ @@ -49,9 +51,10 @@ bool InteractEngine::getInput(){ while(quitCommandCalled != 1){ - mothurOutEndLine(); + mout->mothurOutEndLine(); - input = getCommand(); + input = getCommand(); + mout->mothurOutEndLine(); //allow user to omit the () on the quit command if (input == "quit") { input = "quit()"; } @@ -68,14 +71,14 @@ bool InteractEngine::getInput(){ quitCommandCalled = command->execute(); }else { - mothurOut("Your input contains errors. Please try again."); - mothurOutEndLine(); + mout->mothurOut("Your input contains errors. Please try again."); + mout->mothurOutEndLine(); } } return 1; } catch(exception& e) { - errorOut(e, "InteractEngine", "getInput"); + mout->errorOut(e, "InteractEngine", "getInput"); exit(1); } } @@ -93,28 +96,28 @@ string Engine::getCommand() { cout << nextCommand << endl; } - mothurOutJustToLog("mothur > " + toString(nextCommand)); + mout->mothurOutJustToLog("mothur > " + toString(nextCommand)); return nextCommand; #else string nextCommand = ""; - mothurOut("mothur > "); + mout->mothurOut("mothur > "); getline(cin, nextCommand); - mothurOutJustToLog("mothur > " + toString(nextCommand)); + mout->mothurOutJustToLog("mothur > " + toString(nextCommand)); return nextCommand; #endif #else string nextCommand = ""; - mothurOut("mothur > "); + mout->mothurOut("mothur > "); getline(cin, nextCommand); - mothurOutJustToLog("mothur > " + toString(nextCommand)); + mout->mothurOutJustToLog("mothur > " + toString(nextCommand)); return nextCommand; #endif - mothurOutEndLine(); + mout->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "Engine", "getCommand"); + mout->errorOut(e, "Engine", "getCommand"); exit(1); } } @@ -129,7 +132,7 @@ BatchEngine::BatchEngine(string path, string batchFileName){ } catch(exception& e) { - errorOut(e, "BatchEngine", "BatchEngine"); + mout->errorOut(e, "BatchEngine", "BatchEngine"); exit(1); } } @@ -144,8 +147,8 @@ bool BatchEngine::getInput(){ try { //check if this is a valid batchfile if (openedBatch == 1) { - mothurOut("unable to open batchfile"); - mothurOutEndLine(); + mout->mothurOut("unable to open batchfile"); + mout->mothurOutEndLine(); return 1; } @@ -163,9 +166,9 @@ bool BatchEngine::getInput(){ if (input[0] != '#') { - mothurOutEndLine(); - mothurOut("mothur > " + input); - mothurOutEndLine(); + mout->mothurOutEndLine(); + mout->mothurOut("mothur > " + input); + mout->mothurOutEndLine(); //allow user to omit the () on the quit command @@ -181,8 +184,8 @@ bool BatchEngine::getInput(){ Command* command = cFactory->getCommand(commandName, options); quitCommandCalled = command->execute(); }else { - mothurOut("Invalid."); - mothurOutEndLine(); + mout->mothurOut("Invalid."); + mout->mothurOutEndLine(); } } @@ -193,7 +196,7 @@ bool BatchEngine::getInput(){ return 1; } catch(exception& e) { - errorOut(e, "BatchEngine", "getInput"); + mout->errorOut(e, "BatchEngine", "getInput"); exit(1); } } @@ -210,10 +213,10 @@ ScriptEngine::ScriptEngine(string path, string commandString){ listOfCommands = commandString.substr(1, (commandString.length()-1)); globaldata->argv = path; - + } catch(exception& e) { - errorOut(e, "ScriptEngine", "ScriptEngine"); + mout->errorOut(e, "ScriptEngine", "ScriptEngine"); exit(1); } } @@ -242,9 +245,9 @@ bool ScriptEngine::getInput(){ if (input == "") { input = "quit()"; } - mothurOutEndLine(); - mothurOut("mothur > " + input); - mothurOutEndLine(); + mout->mothurOutEndLine(); + mout->mothurOut("mothur > " + input); + mout->mothurOutEndLine(); //allow user to omit the () on the quit command @@ -260,8 +263,8 @@ bool ScriptEngine::getInput(){ Command* command = cFactory->getCommand(commandName, options); quitCommandCalled = command->execute(); }else { - mothurOut("Invalid."); - mothurOutEndLine(); + mout->mothurOut("Invalid."); + mout->mothurOutEndLine(); } } @@ -269,7 +272,7 @@ bool ScriptEngine::getInput(){ return 1; } catch(exception& e) { - errorOut(e, "ScriptEngine", "getInput"); + mout->errorOut(e, "ScriptEngine", "getInput"); exit(1); } } @@ -304,7 +307,7 @@ string ScriptEngine::getNextCommand(string& commandString) { return nextcommand; } catch(exception& e) { - errorOut(e, "ScriptEngine", "getNextCommand"); + mout->errorOut(e, "ScriptEngine", "getNextCommand"); exit(1); } } diff --git a/engine.hpp b/engine.hpp index cbcc99a..74687d2 100644 --- a/engine.hpp +++ b/engine.hpp @@ -17,6 +17,7 @@ #include "commandoptionparser.hpp" #include "command.hpp" #include "commandfactory.hpp" +#include "mothurout.h" class GlobalData; @@ -31,6 +32,7 @@ public: protected: vector options; CommandFactory* cFactory; + MothurOut* mout; }; diff --git a/fastamap.cpp b/fastamap.cpp index f5ac122..2831ecb 100644 --- a/fastamap.cpp +++ b/fastamap.cpp @@ -44,7 +44,7 @@ void FastaMap::readFastaFile(string inFileName) { in.close(); } catch(exception& e) { - errorOut(e, "FastaMap", "readFastaFile"); + m->errorOut(e, "FastaMap", "readFastaFile"); exit(1); } } @@ -150,7 +150,7 @@ void FastaMap::printNamesFile(string outFileName){ //prints data outFile.close(); } catch(exception& e) { - errorOut(e, "FastaMap", "printNamesFile"); + m->errorOut(e, "FastaMap", "printNamesFile"); exit(1); } } @@ -169,7 +169,7 @@ void FastaMap::printCondensedFasta(string outFileName){ //prints data out.close(); } catch(exception& e) { - errorOut(e, "FastaMap", "printCondensedFasta"); + m->errorOut(e, "FastaMap", "printCondensedFasta"); exit(1); } } diff --git a/fastamap.h b/fastamap.h index e628aed..e1ff3df 100644 --- a/fastamap.h +++ b/fastamap.h @@ -11,6 +11,7 @@ */ #include "mothur.h" +#include "mothurout.h" /* This class represents the fasta file. It reads a fasta file a populates the internal data structure "data". @@ -21,7 +22,7 @@ a list of the sequences names who have the same sequence and a number of how man class FastaMap { public: - FastaMap() {}; + FastaMap() { m = MothurOut::getInstance(); } ~FastaMap() {}; string getGroupName(string); //pass a sequence name get its group @@ -42,6 +43,7 @@ private: map data; //sequence, groupinfo - condensed representation of file map seqmap; //name, sequence - uncondensed representation of file + MothurOut* m; }; #endif diff --git a/fileoutput.cpp b/fileoutput.cpp index 0d78a2d..117f8ab 100644 --- a/fileoutput.cpp +++ b/fileoutput.cpp @@ -40,7 +40,7 @@ void ThreeColumnFile::initFile(string label){ outFile.setf(ios::showpoint); } catch(exception& e) { - errorOut(e, "ThreeColumnFile", "initFile"); + m->errorOut(e, "ThreeColumnFile", "initFile"); exit(1); } } @@ -60,7 +60,7 @@ void ThreeColumnFile::output(int nSeqs, vector data){ } } catch(exception& e) { - errorOut(e, "ThreeColumnFile", "output"); + m->errorOut(e, "ThreeColumnFile", "output"); exit(1); } } @@ -85,12 +85,12 @@ void ThreeColumnFile::resetFile(){ //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { - mothurOut("Unable to rename " + outName); mothurOutEndLine(); + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); perror(" : "); } } catch(exception& e) { - errorOut(e, "ThreeColumnFile", "resetFile"); + m->errorOut(e, "ThreeColumnFile", "resetFile"); exit(1); } } @@ -134,7 +134,7 @@ void ColumnFile::initFile(string label, vector tags){ outFile.setf(ios::showpoint); } catch(exception& e) { - errorOut(e, "ColumnFile", "initFile"); + m->errorOut(e, "ColumnFile", "initFile"); exit(1); } } @@ -164,7 +164,7 @@ void ColumnFile::output(vector data){ } catch(exception& e) { - errorOut(e, "ColumnFile", "output"); + m->errorOut(e, "ColumnFile", "output"); exit(1); } } @@ -189,12 +189,12 @@ void ColumnFile::resetFile(){ //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { - mothurOut("Unable to rename " + outName); mothurOutEndLine(); + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); perror(" : "); } } catch(exception& e) { - errorOut(e, "ColumnFile", "resetFile"); + m->errorOut(e, "ColumnFile", "resetFile"); exit(1); } } @@ -231,7 +231,7 @@ void SharedThreeColumnFile::initFile(string label){ outFile.setf(ios::showpoint); } catch(exception& e) { - errorOut(e, "SharedThreeColumnFile", "initFile"); + m->errorOut(e, "SharedThreeColumnFile", "initFile"); exit(1); } } @@ -252,7 +252,7 @@ void SharedThreeColumnFile::output(int nSeqs, vector data){ } } catch(exception& e) { - errorOut(e, "SharedThreeColumnFile", "output"); + m->errorOut(e, "SharedThreeColumnFile", "output"); exit(1); } } @@ -277,12 +277,12 @@ void SharedThreeColumnFile::resetFile(){ //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { - mothurOut("Unable to rename " + outName); mothurOutEndLine(); + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); perror(" : "); } } catch(exception& e) { - errorOut(e, "SharedThreeColumnFile", "resetFile"); + m->errorOut(e, "SharedThreeColumnFile", "resetFile"); exit(1); } } @@ -320,7 +320,7 @@ void OneColumnFile::initFile(string label){ outFile.setf(ios::showpoint); } catch(exception& e) { - errorOut(e, "OneColumnFile", "initFile"); + m->errorOut(e, "OneColumnFile", "initFile"); exit(1); } } @@ -340,7 +340,7 @@ void OneColumnFile::output(int nSeqs, vector data){ } } catch(exception& e) { - errorOut(e, "OneColumnFile", "output"); + m->errorOut(e, "OneColumnFile", "output"); exit(1); } } @@ -364,13 +364,13 @@ void OneColumnFile::resetFile(){ //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { - mothurOut("Unable to rename " + outName); mothurOutEndLine(); + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); perror(" : "); } } catch(exception& e) { - errorOut(e, "OneColumnFile", "resetFile"); + m->errorOut(e, "OneColumnFile", "resetFile"); exit(1); } } @@ -409,7 +409,7 @@ void SharedOneColumnFile::initFile(string label){ outFile.setf(ios::showpoint); } catch(exception& e) { - errorOut(e, "SharedOneColumnFile", "initFile"); + m->errorOut(e, "SharedOneColumnFile", "initFile"); exit(1); } } @@ -436,7 +436,7 @@ void SharedOneColumnFile::output(int nSeqs, vector data){ } } catch(exception& e) { - errorOut(e, "SharedOneColumnFile", "output"); + m->errorOut(e, "SharedOneColumnFile", "output"); exit(1); } } @@ -461,12 +461,12 @@ void SharedOneColumnFile::resetFile(){ //checks to make sure user was able to rename and remove successfully if ((renameOk != 0)) { - mothurOut("Unable to rename " + outName); mothurOutEndLine(); + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); perror(" : "); } } catch(exception& e) { - errorOut(e, "SharedOneColumnFile", "resetFile"); + m->errorOut(e, "SharedOneColumnFile", "resetFile"); exit(1); } } diff --git a/fileoutput.h b/fileoutput.h index 17bd7a1..170ee68 100644 --- a/fileoutput.h +++ b/fileoutput.h @@ -2,13 +2,14 @@ #define FILEOUTPUT_H #include "mothur.h" +#include "mothurout.h" /***********************************************************************/ class FileOutput { public: - FileOutput(){}; + FileOutput(){ m = MothurOut::getInstance(); } virtual ~FileOutput(){}; virtual void initFile(string) = 0; @@ -20,6 +21,7 @@ public: protected: int renameOk; + MothurOut* m; }; diff --git a/filterseqscommand.cpp b/filterseqscommand.cpp index 8c61ab2..d45d916 100644 --- a/filterseqscommand.cpp +++ b/filterseqscommand.cpp @@ -12,7 +12,7 @@ /**************************************************************************************/ -FilterSeqsCommand::FilterSeqsCommand(string option){ +FilterSeqsCommand::FilterSeqsCommand(string option) { try { abort = false; @@ -59,7 +59,7 @@ FilterSeqsCommand::FilterSeqsCommand(string option){ //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { mothurOut("fasta is a required parameter for the filter.seqs command."); mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the filter.seqs command."); 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 @@ -96,7 +96,7 @@ FilterSeqsCommand::FilterSeqsCommand(string option){ } catch(exception& e) { - errorOut(e, "FilterSeqsCommand", "FilterSeqsCommand"); + m->errorOut(e, "FilterSeqsCommand", "FilterSeqsCommand"); exit(1); } } @@ -105,21 +105,21 @@ FilterSeqsCommand::FilterSeqsCommand(string option){ void FilterSeqsCommand::help(){ try { - mothurOut("The filter.seqs command reads a file containing sequences and creates a .filter and .filter.fasta file.\n"); - mothurOut("The filter.seqs command parameters are fasta, trump, soft, hard and vertical. \n"); - mothurOut("The fasta parameter is required.\n"); - mothurOut("The trump parameter .... The default is ...\n"); - mothurOut("The soft parameter .... The default is ....\n"); - mothurOut("The hard parameter .... The default is ....\n"); - mothurOut("The vertical parameter .... The default is T.\n"); - mothurOut("The filter.seqs command should be in the following format: \n"); - mothurOut("filter.seqs(fasta=yourFastaFile, trump=yourTrump, soft=yourSoft, hard=yourHard, vertical=yourVertical) \n"); - mothurOut("Example filter.seqs(fasta=abrecovery.fasta, trump=..., soft=..., hard=..., vertical=T).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); + 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 and vertical. \n"); + m->mothurOut("The fasta parameter is required.\n"); + m->mothurOut("The trump parameter .... The default is ...\n"); + m->mothurOut("The soft parameter .... The default is ....\n"); + m->mothurOut("The hard parameter .... The default is ....\n"); + m->mothurOut("The vertical parameter .... The default is T.\n"); + m->mothurOut("The filter.seqs command should be in the following format: \n"); + m->mothurOut("filter.seqs(fasta=yourFastaFile, trump=yourTrump, soft=yourSoft, hard=yourHard, vertical=yourVertical) \n"); + m->mothurOut("Example filter.seqs(fasta=abrecovery.fasta, trump=..., soft=..., hard=..., vertical=T).\n"); + m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); } catch(exception& e) { - errorOut(e, "FilterSeqsCommand", "help"); + m->errorOut(e, "FilterSeqsCommand", "help"); exit(1); } } @@ -207,17 +207,24 @@ int FilterSeqsCommand::execute() { if(filter[i] == '1'){ filteredLength++; } } - mothurOutEndLine(); - mothurOut("Length of filtered alignment: " + toString(filteredLength)); mothurOutEndLine(); - mothurOut("Number of columns removed: " + toString((alignmentLength-filteredLength))); mothurOutEndLine(); - mothurOut("Length of the original alignment: " + toString(alignmentLength)); mothurOutEndLine(); - mothurOut("Number of sequences used to construct filter: " + toString(numSeqs)); mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Length of filtered alignment: " + toString(filteredLength)); m->mothurOutEndLine(); + m->mothurOut("Number of columns removed: " + toString((alignmentLength-filteredLength))); m->mothurOutEndLine(); + m->mothurOut("Length of the original alignment: " + toString(alignmentLength)); m->mothurOutEndLine(); + m->mothurOut("Number of sequences used to construct filter: " + toString(numSeqs)); m->mothurOutEndLine(); + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + m->mothurOut(filterFile); m->mothurOutEndLine(); + m->mothurOut(filteredFasta); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "FilterSeqsCommand", "execute"); + m->errorOut(e, "FilterSeqsCommand", "execute"); exit(1); } } diff --git a/formatcolumn.cpp b/formatcolumn.cpp index a11601b..e13ead5 100644 --- a/formatcolumn.cpp +++ b/formatcolumn.cpp @@ -162,7 +162,7 @@ void FormatColumnMatrix::read(NameAssignment* nameMap){ } catch(exception& e) { - errorOut(e, "FormatColumnMatrix", "read"); + m->errorOut(e, "FormatColumnMatrix", "read"); exit(1); } } diff --git a/formatmatrix.h b/formatmatrix.h index 4ef36d9..30e4276 100644 --- a/formatmatrix.h +++ b/formatmatrix.h @@ -57,7 +57,7 @@ class FormatMatrix { public: - FormatMatrix(){ } + FormatMatrix(){ m = MothurOut::getInstance(); } virtual ~FormatMatrix() {} virtual void read(NameAssignment*){}; @@ -72,6 +72,7 @@ protected: float cutoff; string distFile; vector rowPos; + MothurOut* m; }; //********************************************************************************************************************** diff --git a/formatphylip.cpp b/formatphylip.cpp index d7211cf..aaf540a 100644 --- a/formatphylip.cpp +++ b/formatphylip.cpp @@ -209,7 +209,7 @@ void FormatPhylipMatrix::read(NameAssignment* nameMap){ } catch(exception& e) { - errorOut(e, "FormatPhylipMatrix", "read"); + m->errorOut(e, "FormatPhylipMatrix", "read"); exit(1); } } diff --git a/fullmatrix.cpp b/fullmatrix.cpp index 5612041..0255d07 100644 --- a/fullmatrix.cpp +++ b/fullmatrix.cpp @@ -13,6 +13,7 @@ //This constructor reads a distance matrix file and stores the data in the matrix. FullMatrix::FullMatrix(ifstream& filehandle) { try{ + m = MothurOut::getInstance(); globaldata = GlobalData::getInstance(); groupmap = globaldata->gGroupmap; @@ -25,7 +26,7 @@ FullMatrix::FullMatrix(ifstream& filehandle) { matrix[i].resize(numSeqs, 0.0); } group = groupmap->getGroup(name); - if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + if(group == "not found") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } index.resize(numSeqs); index[0].seqName = name; index[0].groupName = group; @@ -62,7 +63,7 @@ FullMatrix::FullMatrix(ifstream& filehandle) { } catch(exception& e) { - errorOut(e, "FullMatrix", "FullMatrix"); + m->errorOut(e, "FullMatrix", "FullMatrix"); exit(1); } } @@ -84,7 +85,7 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) { index[i].seqName = name; index[i].groupName = group; - if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + if(group == "not found") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } for(int j=0;j> matrix[i][j]; @@ -97,7 +98,7 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) { delete reading; } catch(exception& e) { - errorOut(e, "FullMatrix", "readSquareMatrix"); + m->errorOut(e, "FullMatrix", "readSquareMatrix"); exit(1); } } @@ -119,7 +120,7 @@ void FullMatrix::readLTMatrix(ifstream& filehandle) { index[i].seqName = name; index[i].groupName = group; - if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + if(group == "not found") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } for(int j=0;j> distance; @@ -133,7 +134,7 @@ void FullMatrix::readLTMatrix(ifstream& filehandle) { delete reading; } catch(exception& e) { - errorOut(e, "FullMatrix", "readLTMatrix"); + m->errorOut(e, "FullMatrix", "readLTMatrix"); exit(1); } } @@ -176,7 +177,7 @@ void FullMatrix::sortGroups(int low, int high){ } catch(exception& e) { - errorOut(e, "FullMatrix", "sortGroups"); + m->errorOut(e, "FullMatrix", "sortGroups"); exit(1); } } @@ -214,7 +215,7 @@ void FullMatrix::swapRows(int i, int j) { } catch(exception& e) { - errorOut(e, "FullMatrix", "swapRows"); + m->errorOut(e, "FullMatrix", "swapRows"); exit(1); } } @@ -253,7 +254,7 @@ void FullMatrix::printMatrix(ostream& out) { for (int i = 0; i < numSeqs; i++) { out << i << '\t' << index[i].seqName << endl; } } catch(exception& e) { - errorOut(e, "FullMatrix", "printMatrix"); + m->errorOut(e, "FullMatrix", "printMatrix"); exit(1); } } diff --git a/fullmatrix.h b/fullmatrix.h index 7cb8b15..15fee6e 100644 --- a/fullmatrix.h +++ b/fullmatrix.h @@ -23,7 +23,7 @@ struct Names { class FullMatrix { public: - FullMatrix(){}; + FullMatrix(){ m = MothurOut::getInstance(); } FullMatrix(ifstream&); ~FullMatrix(){}; @@ -53,6 +53,7 @@ private: int numGroups; int numUserGroups; GlobalData* globaldata; + MothurOut* m; }; #endif diff --git a/geom.cpp b/geom.cpp index a52e644..201f8f5 100644 --- a/geom.cpp +++ b/geom.cpp @@ -86,7 +86,7 @@ EstOutput Geom::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "Geom", "getValues"); + m->errorOut(e, "Geom", "getValues"); exit(1); } } diff --git a/getgroupcommand.cpp b/getgroupcommand.cpp index c754f8e..b645517 100644 --- a/getgroupcommand.cpp +++ b/getgroupcommand.cpp @@ -10,7 +10,7 @@ #include "getgroupcommand.h" //********************************************************************************************************************** -GetgroupCommand::GetgroupCommand(string option){ +GetgroupCommand::GetgroupCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -35,7 +35,7 @@ GetgroupCommand::GetgroupCommand(string option){ //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 ((globaldata->getSharedFile() == "")) { mothurOut("You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command."); mothurOutEndLine(); abort = true; } + 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 @@ -51,7 +51,7 @@ GetgroupCommand::GetgroupCommand(string option){ } } catch(exception& e) { - errorOut(e, "GetgroupCommand", "GetgroupCommand"); + m->errorOut(e, "GetgroupCommand", "GetgroupCommand"); exit(1); } } @@ -59,16 +59,16 @@ GetgroupCommand::GetgroupCommand(string option){ void GetgroupCommand::help(){ try { - mothurOut("The get.group command can only be executed after a successful read.otu command.\n"); - //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"); - mothurOut("You may not use any parameters with the get.group command.\n"); - mothurOut("The get.group command should be in the following format: \n"); - mothurOut("get.group()\n"); - mothurOut("Example get.group().\n"); + 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) { - errorOut(e, "GetgroupCommand", "help"); + m->errorOut(e, "GetgroupCommand", "help"); exit(1); } } @@ -94,7 +94,7 @@ int GetgroupCommand::execute(){ holdLabel = label; //output first group - mothurOut(groupN); mothurOutEndLine(); + m->mothurOut(groupN); m->mothurOutEndLine(); out << groupN << '\t' << groupN << endl; //get rest of line @@ -110,7 +110,7 @@ int GetgroupCommand::execute(){ count++; //output next group - mothurOut(groupN); mothurOutEndLine(); + m->mothurOut(groupN); m->mothurOutEndLine(); out << groupN << '\t' << groupN << endl; //fill vector. @@ -123,11 +123,17 @@ int GetgroupCommand::execute(){ in.close(); out.close(); + + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outputFile); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "GetgroupCommand", "execute"); + m->errorOut(e, "GetgroupCommand", "execute"); exit(1); } } diff --git a/getlabelcommand.cpp b/getlabelcommand.cpp index 2ba3054..d306250 100644 --- a/getlabelcommand.cpp +++ b/getlabelcommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -GetlabelCommand::GetlabelCommand(string option){ +GetlabelCommand::GetlabelCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -20,12 +20,12 @@ GetlabelCommand::GetlabelCommand(string option){ if(option == "help") { help(); abort = true; } else { - if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund or rabund before you can use the get.label command."); mothurOutEndLine(); abort = true; } + 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; } } } catch(exception& e) { - errorOut(e, "GetlabelCommand", "GetlabelCommand"); + m->errorOut(e, "GetlabelCommand", "GetlabelCommand"); exit(1); } } @@ -33,14 +33,14 @@ GetlabelCommand::GetlabelCommand(string option){ void GetlabelCommand::help(){ try { - mothurOut("The get.label command can only be executed after a successful read.otu command.\n"); - mothurOut("You may not use any parameters with the get.label command.\n"); - mothurOut("The get.label command should be in the following format: \n"); - mothurOut("get.label()\n"); - mothurOut("Example get.label().\n"); + 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) { - errorOut(e, "GetlabelCommand", "help"); + m->errorOut(e, "GetlabelCommand", "help"); exit(1); } } @@ -67,7 +67,7 @@ int GetlabelCommand::execute(){ if(count > numBins) count = 0; if(count == 0) { - mothurOut(label); mothurOutEndLine(); + m->mothurOut(label); m->mothurOutEndLine(); in >> numBins; } in >> label; @@ -79,7 +79,7 @@ int GetlabelCommand::execute(){ } catch(exception& e) { - errorOut(e, "GetlabelCommand", "execute"); + m->errorOut(e, "GetlabelCommand", "execute"); exit(1); } } diff --git a/getlistcountcommand.cpp b/getlistcountcommand.cpp index fcc42ce..6053f47 100644 --- a/getlistcountcommand.cpp +++ b/getlistcountcommand.cpp @@ -10,13 +10,13 @@ #include "getlistcountcommand.h" //********************************************************************************************************************** -GetListCountCommand::GetListCountCommand(string option){ +GetListCountCommand::GetListCountCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; allLines = 1; labels.clear(); - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -57,7 +57,7 @@ GetListCountCommand::GetListCountCommand(string option){ //check for required parameters listfile = validParameter.validFile(parameters, "list", true); - if ((listfile == "not found") && (globaldata->getListFile() == "")) { mothurOut("You must read a listfile before running the get.listcount command."); mothurOutEndLine(); abort = 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(); } else if (listfile == "not open") { abort = true; } else { globaldata->setListFile(listfile); } @@ -80,7 +80,7 @@ GetListCountCommand::GetListCountCommand(string option){ } } catch(exception& e) { - errorOut(e, "GetListCountCommand", "GetListCountCommand"); + m->errorOut(e, "GetListCountCommand", "GetListCountCommand"); exit(1); } } @@ -88,17 +88,17 @@ GetListCountCommand::GetListCountCommand(string option){ void GetListCountCommand::help(){ try { - mothurOut("The get.listcount command can only be executed after a successful read.otu command of a listfile or providing a list file using the list parameter.\n"); - mothurOut("The get.listcount command parameters are list and label. No parameters are required.\n"); - 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"); - mothurOut("The get.listcount command should be in the following format: get.listcount(list=yourlistFile, label=yourLabels).\n"); - mothurOut("Example get.listcount(list=amazon.fn.list, label=0.10).\n"); - mothurOut("The default value for label is all lines in your inputfile.\n"); - mothurOut("The get.listcount command outputs a .otu file for each distance you specify listing the bin number and the names of the sequences in that bin.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"); + m->mothurOut("The get.listcount 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.listcount command parameters are list 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 get.listcount command should be in the following format: get.listcount(list=yourlistFile, label=yourLabels).\n"); + m->mothurOut("Example get.listcount(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.listcount 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) { - errorOut(e, "GetListCountCommand", "help"); + m->errorOut(e, "GetListCountCommand", "help"); exit(1); } } @@ -163,12 +163,12 @@ int GetListCountCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -184,10 +184,15 @@ int GetListCountCommand::execute(){ delete read; globaldata->gListVector = NULL; + 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; } catch(exception& e) { - errorOut(e, "GetListCountCommand", "execute"); + m->errorOut(e, "GetListCountCommand", "execute"); exit(1); } } @@ -200,8 +205,9 @@ void GetListCountCommand::process(ListVector* list) { if (outputDir == "") { outputDir += hasPath(listfile); } string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + list->getLabel() + ".otu"; openOutputFile(outputFileName, out); + outputNames.push_back(outputFileName); - mothurOut(list->getLabel()); mothurOutEndLine(); + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); //for each bin in the list vector for (int i = 0; i < list->getNumBins(); i++) { @@ -212,7 +218,7 @@ void GetListCountCommand::process(ListVector* list) { out.close(); } catch(exception& e) { - errorOut(e, "GetListCountCommand", "process"); + m->errorOut(e, "GetListCountCommand", "process"); exit(1); } } diff --git a/getlistcountcommand.h b/getlistcountcommand.h index bd9d202..196d245 100644 --- a/getlistcountcommand.h +++ b/getlistcountcommand.h @@ -36,6 +36,7 @@ private: set labels; //holds labels to be used string label, listfile, outputDir; ofstream out; + vector outputNames; void process(ListVector*); }; diff --git a/getoturepcommand.cpp b/getoturepcommand.cpp index 935812b..46a0407 100644 --- a/getoturepcommand.cpp +++ b/getoturepcommand.cpp @@ -36,13 +36,13 @@ inline bool compareGroup(repStruct left, repStruct right){ return (left.group < right.group); } //********************************************************************************************************************** -GetOTURepCommand::GetOTURepCommand(string option){ +GetOTURepCommand::GetOTURepCommand(string option) { try{ globaldata = GlobalData::getInstance(); abort = false; allLines = 1; labels.clear(); - + //allow user to run help if (option == "help") { help(); abort = true; @@ -122,11 +122,11 @@ GetOTURepCommand::GetOTURepCommand(string option){ //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { mothurOut("fasta is a required parameter for the get.oturep command."); mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the get.oturep command."); m->mothurOutEndLine(); abort = true; } else if (fastafile == "not open") { abort = true; } listfile = validParameter.validFile(parameters, "list", true); - if (listfile == "not found") { mothurOut("list is a required parameter for the get.oturep command."); mothurOutEndLine(); abort = true; } + if (listfile == "not found") { m->mothurOut("list is a required parameter for the get.oturep command."); m->mothurOutEndLine(); abort = true; } else if (listfile == "not open") { abort = true; } phylipfile = validParameter.validFile(parameters, "phylip", true); @@ -143,8 +143,8 @@ GetOTURepCommand::GetOTURepCommand(string option){ if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } - if ((phylipfile == "") && (columnfile == "")) { mothurOut("When executing a get.oturep command you must enter a phylip or a column."); mothurOutEndLine(); abort = true; } - else if ((phylipfile != "") && (columnfile != "")) { mothurOut("When executing a get.oturep command you must enter ONLY ONE of the following: phylip or column."); mothurOutEndLine(); abort = true; } + 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; } } @@ -169,12 +169,12 @@ GetOTURepCommand::GetOTURepCommand(string option){ sorted = validParameter.validFile(parameters, "sorted", false); if (sorted == "not found"){ sorted = ""; } if ((sorted != "") && (sorted != "name") && (sorted != "bin") && (sorted != "size") && (sorted != "group")) { - mothurOut(sorted + " is not a valid option for the sorted parameter. The only options are: name, bin, size and group. I will not sort."); mothurOutEndLine(); + 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 = ""; } if ((sorted == "group") && (groupfile == "")) { - mothurOut("You must provide a groupfile to sort by group. I will not sort."); mothurOutEndLine(); + m->mothurOut("You must provide a groupfile to sort by group. I will not sort."); m->mothurOutEndLine(); sorted = ""; } @@ -190,7 +190,7 @@ GetOTURepCommand::GetOTURepCommand(string option){ } } catch(exception& e) { - errorOut(e, "GetOTURepCommand", "GetOTURepCommand"); + m->errorOut(e, "GetOTURepCommand", "GetOTURepCommand"); exit(1); } } @@ -199,21 +199,21 @@ GetOTURepCommand::GetOTURepCommand(string option){ void GetOTURepCommand::help(){ try { - mothurOut("The get.oturep command parameters are phylip, column, list, fasta, name, group, large, cutoff, precision, sorted and label. The fasta and list parameters are required, as well as phylip or column and name.\n"); - 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"); - 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"); - 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"); - 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"); - mothurOut("Example get.oturep(phylip=amazon.dist, fasta=amazon.fasta, list=amazon.fn.list, group=amazon.groups).\n"); - mothurOut("The default value for label is all labels in your inputfile.\n"); - 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"); - 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"); - 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"); - mothurOut("If you provide a groupfile, then it also appends the names of the groups present in that bin.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); + m->mothurOut("The get.oturep command parameters are phylip, column, list, fasta, name, group, large, cutoff, precision, 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 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) { - errorOut(e, "GetOTURepCommand", "help"); + m->errorOut(e, "GetOTURepCommand", "help"); exit(1); } } @@ -234,7 +234,7 @@ int GetOTURepCommand::execute(){ //read distance files if (format == "column") { readMatrix = new ReadColumnMatrix(distFile); } else if (format == "phylip") { readMatrix = new ReadPhylipMatrix(distFile); } - else { mothurOut("File format error."); mothurOutEndLine(); return 0; } + else { m->mothurOut("File format error."); m->mothurOutEndLine(); return 0; } readMatrix->setCutoff(cutoff); @@ -266,7 +266,7 @@ int GetOTURepCommand::execute(){ //process file and set up indexes if (format == "column") { formatMatrix = new FormatColumnMatrix(distFile); } else if (format == "phylip") { formatMatrix = new FormatPhylipMatrix(distFile); } - else { mothurOut("File format error."); mothurOutEndLine(); return 0; } + else { m->mothurOut("File format error."); m->mothurOutEndLine(); return 0; } formatMatrix->setCutoff(cutoff); @@ -308,7 +308,7 @@ int GetOTURepCommand::execute(){ nameToIndex[names[j]] = i; } } - } else { mothurOut("error, no listvector."); mothurOutEndLine(); } + } else { m->mothurOut("error, no listvector."); m->mothurOutEndLine(); } fasta = new FastaMap(); @@ -336,7 +336,7 @@ int GetOTURepCommand::execute(){ while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if (allLines == 1 || labels.count(list->getLabel()) == 1){ - mothurOut(list->getLabel() + "\t" + toString(list->size())); mothurOutEndLine(); + m->mothurOut(list->getLabel() + "\t" + toString(list->size())); m->mothurOutEndLine(); error = process(list); if (error == 1) { return 0; } //there is an error in hte input files, abort command @@ -349,7 +349,7 @@ int GetOTURepCommand::execute(){ delete list; list = input->getListVector(lastLabel); - mothurOut(list->getLabel() + "\t" + toString(list->size())); mothurOutEndLine(); + m->mothurOut(list->getLabel() + "\t" + toString(list->size())); m->mothurOutEndLine(); error = process(list); if (error == 1) { return 0; } //there is an error in hte input files, abort command @@ -369,12 +369,12 @@ int GetOTURepCommand::execute(){ //output error messages about any remaining user labels bool needToRun = false; for (set::iterator it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(list->getLabel()) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -382,7 +382,7 @@ int GetOTURepCommand::execute(){ if (needToRun == true) { if (list != NULL) { delete list; } list = input->getListVector(lastLabel); - mothurOut(list->getLabel() + "\t" + toString(list->size())); mothurOutEndLine(); + m->mothurOut(list->getLabel() + "\t" + toString(list->size())); m->mothurOutEndLine(); error = process(list); delete list; if (error == 1) { return 0; } //there is an error in hte input files, abort command @@ -402,10 +402,15 @@ int GetOTURepCommand::execute(){ delete groupMap; globaldata->gGroupmap = NULL; } + 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; } catch(exception& e) { - errorOut(e, "GetOTURepCommand", "execute"); + m->errorOut(e, "GetOTURepCommand", "execute"); exit(1); } } @@ -439,7 +444,7 @@ void GetOTURepCommand::readNamesFile() { } catch(exception& e) { - errorOut(e, "GetOTURepCommand", "readNamesFile"); + m->errorOut(e, "GetOTURepCommand", "readNamesFile"); exit(1); } } @@ -461,7 +466,7 @@ string GetOTURepCommand::findRep(int bin, string& group, ListVector* thisList, i for (size_t i = 0; i < names.size(); i++) { string groupName = groupMap->getGroup(names[i]); if (groupName == "not found") { - mothurOut(names[i] + " is missing from your group file. Please correct. "); mothurOutEndLine(); + m->mothurOut(names[i] + " is missing from your group file. Please correct. "); m->mothurOutEndLine(); groupError = true; } else { groups[groupName] = groupName; @@ -539,7 +544,7 @@ string GetOTURepCommand::findRep(int bin, string& group, ListVector* thisList, i } } catch(exception& e) { - errorOut(e, "GetOTURepCommand", "FindRep"); + m->errorOut(e, "GetOTURepCommand", "FindRep"); exit(1); } } @@ -554,10 +559,12 @@ int GetOTURepCommand::process(ListVector* processList) { string outputFileName = outputDir + getRootName(getSimpleName(listfile)) + processList->getLabel() + ".rep.fasta"; openOutputFile(outputFileName, out); vector reps; + outputNames.push_back(outputFileName); ofstream newNamesOutput; string outputNamesFile = outputDir + getRootName(getSimpleName(listfile)) + processList->getLabel() + ".rep.names"; openOutputFile(outputNamesFile, newNamesOutput); + outputNames.push_back(outputNamesFile); //for each bin in the list vector for (int i = 0; i < processList->size(); i++) { @@ -585,7 +592,7 @@ int GetOTURepCommand::process(ListVector* processList) { reps.push_back(newRep); } }else { - mothurOut(nameRep + " is missing from your fasta or name file. Please correct. "); mothurOutEndLine(); + m->mothurOut(nameRep + " is missing from your fasta or name file. Please correct. "); m->mothurOutEndLine(); remove(outputFileName.c_str()); remove(outputNamesFile.c_str()); return 1; @@ -617,7 +624,7 @@ int GetOTURepCommand::process(ListVector* processList) { } catch(exception& e) { - errorOut(e, "GetOTURepCommand", "process"); + m->errorOut(e, "GetOTURepCommand", "process"); exit(1); } } @@ -647,7 +654,7 @@ SeqMap GetOTURepCommand::getMap(int row) { return rowMap; } catch(exception& e) { - errorOut(e, "GetOTURepCommand", "getMap"); + m->errorOut(e, "GetOTURepCommand", "getMap"); exit(1); } } diff --git a/getoturepcommand.h b/getoturepcommand.h index ceea898..7890d93 100644 --- a/getoturepcommand.h +++ b/getoturepcommand.h @@ -59,6 +59,7 @@ private: bool abort, allLines, groupError, large; set labels; //holds labels to be used map nameToIndex; //maps sequence name to index in sparsematrix + vector outputNames; float cutoff; int precision; vector seqVec; // contains maps with sequence index and distance diff --git a/getrabundcommand.cpp b/getrabundcommand.cpp index df9754b..5a192c5 100644 --- a/getrabundcommand.cpp +++ b/getrabundcommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -GetRAbundCommand::GetRAbundCommand(string option){ +GetRAbundCommand::GetRAbundCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -43,7 +43,7 @@ GetRAbundCommand::GetRAbundCommand(string option){ } //make sure the user has already run the read.otu command - if (globaldata->getListFile() == "") { mothurOut("You must read a listfile before you can use the get.rabund command."); mothurOutEndLine(); abort = true; } + if (globaldata->getListFile() == "") { m->mothurOut("You must read a listfile before you can use the get.rabund command."); m->mothurOutEndLine(); abort = true; } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -73,7 +73,7 @@ GetRAbundCommand::GetRAbundCommand(string option){ } catch(exception& e) { - errorOut(e, "GetRAbundCommand", "GetRAbundCommand"); + m->errorOut(e, "GetRAbundCommand", "GetRAbundCommand"); exit(1); } } @@ -81,18 +81,18 @@ GetRAbundCommand::GetRAbundCommand(string option){ void GetRAbundCommand::help(){ try { - mothurOut("The get.rabund command can only be executed after a successful read.otu of a listfile.\n"); - mothurOut("The get.rabund command parameters are label and sorted. No parameters are required.\n"); - 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"); - mothurOut("The sorted parameters allows you to print the rabund results sorted by abundance or not. The default is sorted.\n"); - mothurOut("The get.rabund command should be in the following format: get.rabund(label=yourLabels, sorted=yourSorted).\n"); - mothurOut("Example get.rabund(sorted=F).\n"); - mothurOut("The default value for label is all labels in your inputfile.\n"); - mothurOut("The get.rabund command outputs a .rabund file containing the lines you selected.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n"); + 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) { - errorOut(e, "GetRAbundCommand", "help"); + m->errorOut(e, "GetRAbundCommand", "help"); exit(1); } } @@ -125,7 +125,7 @@ int GetRAbundCommand::execute(){ while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(list->getLabel()) == 1){ - mothurOut(list->getLabel()); mothurOutEndLine(); + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); rabund = new RAbundVector(); *rabund = (list->getRAbundVector()); @@ -144,7 +144,7 @@ int GetRAbundCommand::execute(){ delete list; list = input->getListVector(lastLabel); - mothurOut(list->getLabel()); mothurOutEndLine(); + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); rabund = new RAbundVector(); *rabund = (list->getRAbundVector()); @@ -170,12 +170,12 @@ int GetRAbundCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -184,7 +184,7 @@ int GetRAbundCommand::execute(){ if (list != NULL) { delete list; } list = input->getListVector(lastLabel); - mothurOut(list->getLabel()); mothurOutEndLine(); + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); rabund = new RAbundVector(); *rabund = (list->getRAbundVector()); @@ -194,13 +194,19 @@ int GetRAbundCommand::execute(){ delete rabund; delete list; } + + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(filename); m->mothurOutEndLine(); + m->mothurOutEndLine(); + out.close(); return 0; } catch(exception& e) { - errorOut(e, "GetRAbundCommand", "execute"); + m->errorOut(e, "GetRAbundCommand", "execute"); exit(1); } } diff --git a/getsabundcommand.cpp b/getsabundcommand.cpp index 10b998e..d9197fe 100644 --- a/getsabundcommand.cpp +++ b/getsabundcommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -GetSAbundCommand::GetSAbundCommand(string option){ +GetSAbundCommand::GetSAbundCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -43,7 +43,7 @@ GetSAbundCommand::GetSAbundCommand(string option){ } //make sure the user has already run the read.otu command - if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "")) { mothurOut("You must read a list or rabund before you can use the get.sabund command."); mothurOutEndLine(); abort = true; } + 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 // ...at some point should added some additional type checking... @@ -68,7 +68,7 @@ GetSAbundCommand::GetSAbundCommand(string option){ } catch(exception& e) { - errorOut(e, "GetSAbundCommand", "GetSAbundCommand"); + m->errorOut(e, "GetSAbundCommand", "GetSAbundCommand"); exit(1); } } @@ -76,17 +76,17 @@ GetSAbundCommand::GetSAbundCommand(string option){ void GetSAbundCommand::help(){ try { - mothurOut("The get.sabund command can only be executed after a successful read.otu of a listfile or rabundfile.\n"); - mothurOut("The get.sabund command parameters is label. No parameters are required.\n"); - 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"); - mothurOut("The get.sabund command should be in the following format: get.sabund(label=yourLabels).\n"); - mothurOut("Example get.sabund().\n"); - mothurOut("The default value for label is all labels in your inputfile.\n"); - mothurOut("The get.sabund command outputs a .sabund file containing the labels you selected.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n"); + 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) { - errorOut(e, "GetSAbundCommand", "help"); + m->errorOut(e, "GetSAbundCommand", "help"); exit(1); } } @@ -118,7 +118,7 @@ int GetSAbundCommand::execute(){ while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(order->getLabel()) == 1){ - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); sabund = new SAbundVector(); *sabund = (order->getSAbundVector()); sabund->print(out); @@ -134,7 +134,7 @@ int GetSAbundCommand::execute(){ delete order; order = (input->getOrderVector(lastLabel)); - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); sabund = new SAbundVector(); *sabund = (order->getSAbundVector()); sabund->print(out); @@ -158,12 +158,12 @@ int GetSAbundCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -172,7 +172,7 @@ int GetSAbundCommand::execute(){ if (order != NULL) { delete order; } order = (input->getOrderVector(lastLabel)); - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); sabund = new SAbundVector(); *sabund = (order->getSAbundVector()); sabund->print(out); @@ -182,11 +182,17 @@ int GetSAbundCommand::execute(){ globaldata->gorder = NULL; out.close(); + + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(filename); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "GetSAbundCommand", "execute"); + m->errorOut(e, "GetSAbundCommand", "execute"); exit(1); } } diff --git a/getseqscommand.cpp b/getseqscommand.cpp index d63dc79..ec05390 100644 --- a/getseqscommand.cpp +++ b/getseqscommand.cpp @@ -13,10 +13,10 @@ //********************************************************************************************************************** -GetSeqsCommand::GetSeqsCommand(string option){ +GetSeqsCommand::GetSeqsCommand(string option) { try { abort = false; - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -97,7 +97,7 @@ GetSeqsCommand::GetSeqsCommand(string option){ //check for required parameters accnosfile = validParameter.validFile(parameters, "accnos", true); if (accnosfile == "not open") { abort = true; } - else if (accnosfile == "not found") { accnosfile = ""; mothurOut("You must provide an accnos file."); mothurOutEndLine(); abort = true; } + else if (accnosfile == "not found") { accnosfile = ""; m->mothurOut("You must provide an accnos file."); m->mothurOutEndLine(); abort = true; } fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } @@ -119,17 +119,17 @@ GetSeqsCommand::GetSeqsCommand(string option){ if (listfile == "not open") { abort = true; } else if (listfile == "not found") { listfile = ""; } - if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "")) { mothurOut("You must provide one of the following: fasta, name, group, alignreport or listfile."); mothurOutEndLine(); abort = true; } + if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport or listfile."); m->mothurOutEndLine(); abort = true; } int okay = 2; if (outputDir != "") { okay++; } - if (parameters.size() > okay) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport or listfile."); mothurOutEndLine(); abort = true; } + if (parameters.size() > okay) { m->mothurOut("You may only enter one of the following: fasta, name, group, alignreport or listfile."); m->mothurOutEndLine(); abort = true; } } } catch(exception& e) { - errorOut(e, "GetSeqsCommand", "GetSeqsCommand"); + m->errorOut(e, "GetSeqsCommand", "GetSeqsCommand"); exit(1); } } @@ -137,15 +137,15 @@ GetSeqsCommand::GetSeqsCommand(string option){ void GetSeqsCommand::help(){ try { - mothurOut("The get.seqs command reads an .accnos file and one of the following file types: fasta, name, group, list or alignreport file.\n"); - mothurOut("It outputs a file containing only the sequences in the .accnos file.\n"); - mothurOut("The get.seqs command parameters are accnos, fasta, name, group, list and alignreport. You must provide accnos and one of the other parameters.\n"); - mothurOut("The get.seqs command should be in the following format: get.seqs(accnos=yourAccnos, fasta=yourFasta).\n"); - mothurOut("Example get.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); + m->mothurOut("The get.seqs command reads an .accnos file and one of the following file types: fasta, name, group, list 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 and alignreport. You must provide accnos and one of the other parameters.\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) { - errorOut(e, "GetSeqsCommand", "help"); + m->errorOut(e, "GetSeqsCommand", "help"); exit(1); } } @@ -167,11 +167,18 @@ int GetSeqsCommand::execute(){ else if (alignfile != "") { readAlign(); } else if (listfile != "") { readList(); } + if (outputNames.size() != 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(); + } + return 0; } catch(exception& e) { - errorOut(e, "GetSeqsCommand", "execute"); + m->errorOut(e, "GetSeqsCommand", "execute"); exit(1); } } @@ -184,6 +191,7 @@ void GetSeqsCommand::readFasta(){ ofstream out; openOutputFile(outputFileName, out); + ifstream in; openInputFile(fastafile, in); string name; @@ -210,13 +218,13 @@ void GetSeqsCommand::readFasta(){ out.close(); if (wroteSomething == false) { - mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "GetSeqsCommand", "readFasta"); + m->errorOut(e, "GetSeqsCommand", "readFasta"); exit(1); } } @@ -275,13 +283,13 @@ void GetSeqsCommand::readList(){ out.close(); if (wroteSomething == false) { - mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "GetSeqsCommand", "readList"); + m->errorOut(e, "GetSeqsCommand", "readList"); exit(1); } } @@ -292,6 +300,7 @@ void GetSeqsCommand::readName(){ string outputFileName = outputDir + getRootName(getSimpleName(namefile)) + "pick" + getExtension(namefile); ofstream out; openOutputFile(outputFileName, out); + ifstream in; openInputFile(namefile, in); @@ -357,13 +366,13 @@ void GetSeqsCommand::readName(){ out.close(); if (wroteSomething == false) { - mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "GetSeqsCommand", "readName"); + m->errorOut(e, "GetSeqsCommand", "readName"); exit(1); } } @@ -375,6 +384,7 @@ void GetSeqsCommand::readGroup(){ string outputFileName = outputDir + getRootName(getSimpleName(groupfile)) + "pick" + getExtension(groupfile); ofstream out; openOutputFile(outputFileName, out); + ifstream in; openInputFile(groupfile, in); @@ -402,13 +412,13 @@ void GetSeqsCommand::readGroup(){ out.close(); if (wroteSomething == false) { - mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "GetSeqsCommand", "readGroup"); + m->errorOut(e, "GetSeqsCommand", "readGroup"); exit(1); } } @@ -421,6 +431,7 @@ void GetSeqsCommand::readAlign(){ string outputFileName = outputDir + getRootName(getSimpleName(alignfile)) + "pick.align.report"; ofstream out; openOutputFile(outputFileName, out); + ifstream in; openInputFile(alignfile, in); @@ -468,13 +479,13 @@ void GetSeqsCommand::readAlign(){ out.close(); if (wroteSomething == false) { - mothurOut("Your file does not contain any sequence from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file does not contain any sequence from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "GetSeqsCommand", "readAlign"); + m->errorOut(e, "GetSeqsCommand", "readAlign"); exit(1); } } @@ -498,7 +509,7 @@ void GetSeqsCommand::readAccnos(){ } catch(exception& e) { - errorOut(e, "GetSeqsCommand", "readAccnos"); + m->errorOut(e, "GetSeqsCommand", "readAccnos"); exit(1); } } diff --git a/getseqscommand.h b/getseqscommand.h index 24f3968..809109c 100644 --- a/getseqscommand.h +++ b/getseqscommand.h @@ -16,13 +16,14 @@ class GetSeqsCommand : public Command { public: - GetSeqsCommand(string); + GetSeqsCommand(string); ~GetSeqsCommand(){}; int execute(); void help(); private: set names; + vector outputNames; string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, outputDir; bool abort; diff --git a/getsharedotucommand.cpp b/getsharedotucommand.cpp index 0497589..2e553d9 100644 --- a/getsharedotucommand.cpp +++ b/getsharedotucommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -GetSharedOTUCommand::GetSharedOTUCommand(string option){ +GetSharedOTUCommand::GetSharedOTUCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -83,7 +83,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option){ if (groupfile == "not open") { abort = true; } else if (groupfile == "not found") { groupfile = ""; } - if ((listfile == "") || (groupfile == "")) { mothurOut("The list and group parameters are required."); mothurOutEndLine(); abort = true; } + if ((listfile == "") || (groupfile == "")) { m->mothurOut("The list and group parameters are required."); m->mothurOutEndLine(); abort = true; } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -123,7 +123,7 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option){ } catch(exception& e) { - errorOut(e, "GetSharedOTUCommand", "GetSharedOTUCommand"); + m->errorOut(e, "GetSharedOTUCommand", "GetSharedOTUCommand"); exit(1); } } @@ -131,24 +131,24 @@ GetSharedOTUCommand::GetSharedOTUCommand(string option){ void GetSharedOTUCommand::help(){ try { - mothurOut("The get.sharedseqs command parameters are list, group, label, unique, shared, output and fasta. The list and group parameters are required.\n"); - mothurOut("The label parameter allows you to select what distance levels you would like output files for, and are separated by dashes.\n"); - 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"); - mothurOut("If you enter your groups under the unique parameter mothur will return the otus that contain ONLY sequences from those groups.\n"); - 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"); - 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"); - 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"); - mothurOut("The output parameter allows you to output the list of names without the group and bin number added. \n"); - 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"); - 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"); - mothurOut("The get.sharedseqs command should be in the following format: get.sabund(label=yourLabels, groups=yourGroups, fasta=yourFastafile, output=yourOutput).\n"); - mothurOut("Example get.sharedseqs(list=amazon.fn.list, label=unique-0.01, group=forest-pasture, fasta=amazon.fasta, output=accnos).\n"); - mothurOut("The output to the screen is the distance and the number of otus at that distance for the groups you specified.\n"); - mothurOut("The default value for label is all labels in your inputfile. The default for groups is all groups in your file.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n"); + 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.sabund(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) { - errorOut(e, "GetSharedOTUCommand", "help"); + m->errorOut(e, "GetSharedOTUCommand", "help"); exit(1); } } @@ -211,7 +211,7 @@ int GetSharedOTUCommand::execute(){ list = new ListVector(in); if(allLines == 1 || labels.count(list->getLabel()) == 1){ - mothurOut(list->getLabel()); + m->mothurOut(list->getLabel()); process(list); processedLabels.insert(list->getLabel()); @@ -221,7 +221,7 @@ int GetSharedOTUCommand::execute(){ if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = list->getLabel(); - mothurOut(lastlist->getLabel()); + m->mothurOut(lastlist->getLabel()); process(lastlist); processedLabels.insert(lastlist->getLabel()); @@ -243,18 +243,18 @@ int GetSharedOTUCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } //run last label if you need to if (needToRun == true) { - mothurOut(lastlist->getLabel()); + m->mothurOut(lastlist->getLabel()); process(lastlist); processedLabels.insert(lastlist->getLabel()); @@ -266,11 +266,19 @@ int GetSharedOTUCommand::execute(){ globaldata->Groups.clear(); if (lastlist != NULL) { delete lastlist; } + + + 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; } catch(exception& e) { - errorOut(e, "GetSharedOTUCommand", "execute"); + m->errorOut(e, "GetSharedOTUCommand", "execute"); exit(1); } } @@ -300,8 +308,8 @@ void GetSharedOTUCommand::process(ListVector* shared) { bool uniqueOTU = true; map atLeastOne; - for (int m = 0; m < Groups.size(); m++) { - atLeastOne[Groups[m]] = 0; + for (int f = 0; f < Groups.size(); f++) { + atLeastOne[Groups[f]] = 0; } vector namesOfSeqsInThisBin; @@ -317,7 +325,7 @@ void GetSharedOTUCommand::process(ListVector* shared) { namesOfSeqsInThisBin.push_back((name + "\t" + seqGroup + "\t" + toString(i+1))); }else { namesOfSeqsInThisBin.push_back(name); } - if (seqGroup == "not found") { mothurOut(name + " is not in your groupfile. Please correct."); mothurOutEndLine(); exit(1); } + if (seqGroup == "not found") { m->mothurOut(name + " is not in your groupfile. Please correct."); m->mothurOutEndLine(); exit(1); } //is this seq in one of hte groups we care about it = groupFinder.find(seqGroup); @@ -331,7 +339,7 @@ void GetSharedOTUCommand::process(ListVector* shared) { namesOfSeqsInThisBin.push_back((names + "\t" + seqGroup + "\t" + toString(i+1))); }else { namesOfSeqsInThisBin.push_back(names); } - if (seqGroup == "not found") { mothurOut(names + " is not in your groupfile. Please correct."); mothurOutEndLine(); exit(1); } + if (seqGroup == "not found") { m->mothurOut(names + " is not in your groupfile. Please correct."); m->mothurOutEndLine(); exit(1); } //is this seq in one of hte groups we care about it = groupFinder.find(seqGroup); @@ -382,8 +390,11 @@ void GetSharedOTUCommand::process(ListVector* shared) { } outputString += groupString + "."; - mothurOut(outputString); mothurOutEndLine(); - }else { mothurOut("\t" + toString(num)); mothurOutEndLine(); } + m->mothurOut(outputString); m->mothurOutEndLine(); + }else { + m->mothurOut("\t" + toString(num)); m->mothurOutEndLine(); + outputNames.push_back(outputFileNames); + } //if fasta file provided output new fasta file if ((fastafile != "") && wroteSomething) { @@ -391,6 +402,7 @@ void GetSharedOTUCommand::process(ListVector* shared) { string outputFileFasta = outputDir + getRootName(getSimpleName(fastafile)) + shared->getLabel() + userGroups + ".shared.fasta"; ofstream outFasta; openOutputFile(outputFileFasta, outFasta); + outputNames.push_back(outputFileFasta); for (int k = 0; k < seqs.size(); k++) { //if this is a sequence we want, output it @@ -413,7 +425,7 @@ void GetSharedOTUCommand::process(ListVector* shared) { } catch(exception& e) { - errorOut(e, "GetSharedOTUCommand", "process"); + m->errorOut(e, "GetSharedOTUCommand", "process"); exit(1); } } diff --git a/getsharedotucommand.h b/getsharedotucommand.h index 5b5516c..c12cc13 100644 --- a/getsharedotucommand.h +++ b/getsharedotucommand.h @@ -39,6 +39,7 @@ class GetSharedOTUCommand : public Command { map groupFinder; map::iterator it; vector seqs; + vector outputNames; void process(ListVector*); diff --git a/globaldata.cpp b/globaldata.cpp index 8f8d1ad..58d00ff 100644 --- a/globaldata.cpp +++ b/globaldata.cpp @@ -47,6 +47,7 @@ void GlobalData::setFormat(string Format) { format = Format; } /******************************************************/ GlobalData::GlobalData() { + m = MothurOut::getInstance(); //option definitions should go here... clear(); gListVector = NULL; @@ -126,7 +127,7 @@ void GlobalData::newRead() { names.clear(); } catch(exception& e) { - errorOut(e, "GlobalData", "newRead"); + m->errorOut(e, "GlobalData", "newRead"); exit(1); } } @@ -152,7 +153,7 @@ GlobalData::~GlobalData() { if (nameMap != NULL) { delete nameMap; nameMap = NULL; } } catch(exception& e) { - errorOut(e, "GlobalData", "~GlobalData"); + m->errorOut(e, "GlobalData", "~GlobalData"); exit(1); } } diff --git a/globaldata.hpp b/globaldata.hpp index f3b9b9a..b4b8e0d 100644 --- a/globaldata.hpp +++ b/globaldata.hpp @@ -84,7 +84,7 @@ public: void newRead(); private: - + MothurOut* m; string phylipfile, columnfile, listfile, rabundfile, sabundfile, namefile, groupfile, orderfile, treefile, sharedfile, format, distfile; static GlobalData* _uniqueInstance; diff --git a/goodscoverage.cpp b/goodscoverage.cpp index 8e823e4..75baa7b 100644 --- a/goodscoverage.cpp +++ b/goodscoverage.cpp @@ -26,7 +26,7 @@ EstOutput GoodsCoverage::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "GoodsCoverage", "getValues"); + m->errorOut(e, "GoodsCoverage", "getValues"); exit(1); } } diff --git a/gotohoverlap.cpp b/gotohoverlap.cpp index f6fef1d..ea27df0 100644 --- a/gotohoverlap.cpp +++ b/gotohoverlap.cpp @@ -25,8 +25,8 @@ /**************************************************************************************************/ -GotohOverlap::GotohOverlap(float gO, float gE, float m, float mm, int r) : - gapOpen(gO), gapExtend(gE), match(m), mismatch(mm), Alignment(r) { +GotohOverlap::GotohOverlap(float gO, float gE, float f, float mm, int r) : + gapOpen(gO), gapExtend(gE), match(f), mismatch(mm), Alignment(r) { try { for(int i=1;ierrorOut(e, "GotohOverlap", "GotohOverlap"); exit(1); } } @@ -94,7 +94,7 @@ void GotohOverlap::align(string A, string B){ } catch(exception& e) { - errorOut(e, "GotohOverlap", "align"); + m->errorOut(e, "GotohOverlap", "align"); exit(1); } } diff --git a/groupmap.cpp b/groupmap.cpp index 598e301..8d0662f 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -12,6 +12,7 @@ /************************************************************/ GroupMap::GroupMap(string filename) { + m = MothurOut::getInstance(); groupFileName = filename; openInputFile(filename, fileHandle); index = 0; @@ -33,7 +34,7 @@ int GroupMap::readMap() { it = groupmap.find(seqName); - if (it != groupmap.end()) { error = 1; mothurOut("Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); mothurOutEndLine(); } + if (it != groupmap.end()) { error = 1; m->mothurOut("Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); m->mothurOutEndLine(); } else { groupmap[seqName] = seqGroup; //store data in map seqsPerGroup[seqGroup]++; //increment number of seqs in that group @@ -89,7 +90,7 @@ bool GroupMap::isValidGroup(string groupname) { return false; } catch(exception& e) { - errorOut(e, "GroupMap", "isValidGroup"); + m->errorOut(e, "GroupMap", "isValidGroup"); exit(1); } } @@ -107,7 +108,7 @@ int GroupMap::getNumSeqs(string group) { } catch(exception& e) { - errorOut(e, "GroupMap", "getNumSeqs"); + m->errorOut(e, "GroupMap", "getNumSeqs"); exit(1); } } @@ -125,7 +126,7 @@ vector GroupMap::getNamesSeqs(){ return names; } catch(exception& e) { - errorOut(e, "GroupMap", "getNamesSeqs"); + m->errorOut(e, "GroupMap", "getNamesSeqs"); exit(1); } } diff --git a/groupmap.h b/groupmap.h index a99ad11..8a1cfff 100644 --- a/groupmap.h +++ b/groupmap.h @@ -10,6 +10,7 @@ */ #include "mothur.h" +#include "mothurout.h" /* This class is a representation of the groupfile. It is used by all the shared commands to determine what group a certain sequence belongs to. */ @@ -31,6 +32,7 @@ public: int getNumSeqs(string); //return the number of seqs in a given group private: + MothurOut* m; ifstream fileHandle; string groupFileName; int index; diff --git a/hcluster.cpp b/hcluster.cpp index ee6040b..7da10a2 100644 --- a/hcluster.cpp +++ b/hcluster.cpp @@ -13,8 +13,9 @@ #include "sparsematrix.hpp" /***********************************************************************/ -HCluster::HCluster(RAbundVector* rav, ListVector* lv, string m, string d, NameAssignment* n, float c) : rabund(rav), list(lv), method(m), distfile(d), nameMap(n), cutoff(c) { +HCluster::HCluster(RAbundVector* rav, ListVector* lv, string ms, string d, NameAssignment* n, float c) : rabund(rav), list(lv), method(ms), distfile(d), nameMap(n), cutoff(c) { try { + m = MothurOut::getInstance(); mapWanted = false; exitedBreak = false; numSeqs = list->getNumSeqs(); @@ -32,7 +33,7 @@ HCluster::HCluster(RAbundVector* rav, ListVector* lv, string m, string d, NameAs } } catch(exception& e) { - errorOut(e, "HCluster", "HCluster"); + m->errorOut(e, "HCluster", "HCluster"); exit(1); } } @@ -49,7 +50,7 @@ void HCluster::clusterBins(){ //cout << '\t' << rabund->get(clusterArray[smallRow].smallChild) << '\t' << rabund->get(clusterArray[smallCol].smallChild) << endl; } catch(exception& e) { - errorOut(e, "HCluster", "clusterBins"); + m->errorOut(e, "HCluster", "clusterBins"); exit(1); } @@ -71,7 +72,7 @@ void HCluster::clusterNames(){ } catch(exception& e) { - errorOut(e, "HCluster", "clusterNames"); + m->errorOut(e, "HCluster", "clusterNames"); exit(1); } @@ -86,7 +87,7 @@ int HCluster::getUpmostParent(int node){ return node; } catch(exception& e) { - errorOut(e, "HCluster", "getUpmostParent"); + m->errorOut(e, "HCluster", "getUpmostParent"); exit(1); } } @@ -116,7 +117,7 @@ void HCluster::printInfo(){ } catch(exception& e) { - errorOut(e, "HCluster", "getUpmostParent"); + m->errorOut(e, "HCluster", "getUpmostParent"); exit(1); } } @@ -184,7 +185,7 @@ int HCluster::makeActive() { return linkValue; } catch(exception& e) { - errorOut(e, "HCluster", "makeActive"); + m->errorOut(e, "HCluster", "makeActive"); exit(1); } } @@ -253,7 +254,7 @@ void HCluster::updateArrayandLinkTable() { } } catch(exception& e) { - errorOut(e, "HCluster", "updateArrayandLinkTable"); + m->errorOut(e, "HCluster", "updateArrayandLinkTable"); exit(1); } } @@ -299,14 +300,14 @@ bool HCluster::update(int row, int col, float distance){ //printInfo(); } catch(exception& e) { - errorOut(e, "HCluster", "update"); + m->errorOut(e, "HCluster", "update"); exit(1); } } /***********************************************************************/ -void HCluster::setMapWanted(bool m) { +void HCluster::setMapWanted(bool ms) { try { - mapWanted = m; + mapWanted = ms; //initialize map for (int i = 0; i < list->getNumBins(); i++) { @@ -327,7 +328,7 @@ void HCluster::setMapWanted(bool m) { } catch(exception& e) { - errorOut(e, "HCluster", "setMapWanted"); + m->errorOut(e, "HCluster", "setMapWanted"); exit(1); } } @@ -348,7 +349,7 @@ try { seq2Bin[names] = clusterArray[smallCol].smallChild; } catch(exception& e) { - errorOut(e, "HCluster", "updateMap"); + m->errorOut(e, "HCluster", "updateMap"); exit(1); } } @@ -366,7 +367,7 @@ vector HCluster::getSeqs(){ return sameSeqs; } catch(exception& e) { - errorOut(e, "HCluster", "getSeqs"); + m->errorOut(e, "HCluster", "getSeqs"); exit(1); } } @@ -424,7 +425,7 @@ vector HCluster::getSeqsFNNN(){ return sameSeqs; } catch(exception& e) { - errorOut(e, "HCluster", "getSeqsFNNN"); + m->errorOut(e, "HCluster", "getSeqsFNNN"); exit(1); } } @@ -495,7 +496,7 @@ vector HCluster::getSeqsAN(){ return temp; } catch(exception& e) { - errorOut(e, "HCluster", "getSeqsAN"); + m->errorOut(e, "HCluster", "getSeqsAN"); exit(1); } } @@ -649,7 +650,7 @@ void HCluster::combineFile() { sort(mergedMin.begin(), mergedMin.end(), compareSequenceDistance); } catch(exception& e) { - errorOut(e, "HCluster", "combineFile"); + m->errorOut(e, "HCluster", "combineFile"); exit(1); } } @@ -725,7 +726,7 @@ seqDist HCluster::getNextDist(char* buffer, int& index, int size){ return next; } catch(exception& e) { - errorOut(e, "HCluster", "getNextDist"); + m->errorOut(e, "HCluster", "getNextDist"); exit(1); } } @@ -767,7 +768,7 @@ void HCluster::processFile() { rename(outTemp.c_str(), distfile.c_str()); } catch(exception& e) { - errorOut(e, "HCluster", "processFile"); + m->errorOut(e, "HCluster", "processFile"); exit(1); } } diff --git a/hcluster.h b/hcluster.h index 7fc8177..5005ec6 100644 --- a/hcluster.h +++ b/hcluster.h @@ -68,6 +68,7 @@ protected: vector mergedMin; string partialDist; + MothurOut* m; }; diff --git a/hclustercommand.cpp b/hclustercommand.cpp index 365c80e..e6875b6 100644 --- a/hclustercommand.cpp +++ b/hclustercommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** //This function checks to make sure the cluster command has no errors and then clusters based on the method chosen. -HClusterCommand::HClusterCommand(string option){ +HClusterCommand::HClusterCommand(string option) { try{ globaldata = GlobalData::getInstance(); abort = false; @@ -87,8 +87,8 @@ HClusterCommand::HClusterCommand(string option){ if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } - if ((phylipfile == "") && (columnfile == "")) { mothurOut("When executing a hcluster command you must enter a phylip or a column."); mothurOutEndLine(); abort = true; } - else if ((phylipfile != "") && (columnfile != "")) { mothurOut("When executing a hcluster command you must enter ONLY ONE of the following: phylip or column."); mothurOutEndLine(); abort = true; } + if ((phylipfile == "") && (columnfile == "")) { m->mothurOut("When executing a hcluster command you must enter a phylip or a column."); 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; } @@ -113,7 +113,7 @@ HClusterCommand::HClusterCommand(string option){ if (method == "not found") { method = "furthest"; } if ((method == "furthest") || (method == "nearest") || (method == "average")) { } - else { mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average."); mothurOutEndLine(); abort = true; } + else { m->mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average."); m->mothurOutEndLine(); abort = true; } showabund = validParameter.validFile(parameters, "showabund", false); if (showabund == "not found") { showabund = "T"; } @@ -138,11 +138,15 @@ HClusterCommand::HClusterCommand(string option){ openOutputFile(fileroot+ tag + ".sabund", sabundFile); openOutputFile(fileroot+ tag + ".rabund", rabundFile); openOutputFile(fileroot+ tag + ".list", listFile); + + outputNames.push_back(fileroot+ tag + ".sabund"); + outputNames.push_back(fileroot+ tag + ".rabund"); + outputNames.push_back(fileroot+ tag + ".list"); } } } catch(exception& e) { - errorOut(e, "HClusterCommand", "HClusterCommand"); + m->errorOut(e, "HClusterCommand", "HClusterCommand"); exit(1); } } @@ -151,15 +155,15 @@ HClusterCommand::HClusterCommand(string option){ void HClusterCommand::help(){ try { - 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"); - 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"); - mothurOut("The name parameter allows you to enter your name file and is required if your distance file is in column format. \n"); - mothurOut("The hcluster command should be in the following format: \n"); - mothurOut("hcluster(column=youDistanceFile, name=yourNameFile, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"); - mothurOut("The acceptable hcluster methods are furthest and nearest, but we hope to add average in the future.\n\n"); + 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 and nearest, but we hope to add average in the future.\n\n"); } catch(exception& e) { - errorOut(e, "HClusterCommand", "help"); + m->errorOut(e, "HClusterCommand", "help"); exit(1); } } @@ -196,14 +200,14 @@ int HClusterCommand::execute(){ list = new ListVector(globaldata->nameMap->getListVector()); } - mothurOut("It took " + toString(time(NULL) - estart) + " seconds to sort. "); mothurOutEndLine(); + m->mothurOut("It took " + toString(time(NULL) - estart) + " seconds to sort. "); m->mothurOutEndLine(); estart = time(NULL); //list vector made by read contains all sequence names if(list != NULL){ rabund = new RAbundVector(list->getRAbundVector()); }else{ - mothurOut("Error: no list vector!"); mothurOutEndLine(); return 0; + m->mothurOut("Error: no list vector!"); m->mothurOutEndLine(); return 0; } float previousDist = 0.00000; @@ -265,13 +269,18 @@ int HClusterCommand::execute(){ rabundFile.close(); listFile.close(); delete cluster; - - mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster. "); mothurOutEndLine(); + + 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(); + + m->mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster. "); m->mothurOutEndLine(); return 0; } catch(exception& e) { - errorOut(e, "HClusterCommand", "execute"); + m->errorOut(e, "HClusterCommand", "execute"); exit(1); } } @@ -281,8 +290,8 @@ int HClusterCommand::execute(){ void HClusterCommand::printData(string label){ try { if (isTrue(timing)) { - mothurOut("\tTime: " + toString(time(NULL) - start) + "\tsecs for " + toString(oldRAbund.getNumBins()) - + "\tclusters. Updates: " + toString(loops)); mothurOutEndLine(); + m->mothurOut("\tTime: " + toString(time(NULL) - start) + "\tsecs for " + toString(oldRAbund.getNumBins()) + + "\tclusters. Updates: " + toString(loops)); m->mothurOutEndLine(); } print_start = true; loops = 0; @@ -299,7 +308,7 @@ void HClusterCommand::printData(string label){ oldList.print(listFile); } catch(exception& e) { - errorOut(e, "HClusterCommand", "printData"); + m->errorOut(e, "HClusterCommand", "printData"); exit(1); } diff --git a/hclustercommand.h b/hclustercommand.h index 443d870..8bbc655 100644 --- a/hclustercommand.h +++ b/hclustercommand.h @@ -53,6 +53,7 @@ private: ofstream sabundFile, rabundFile, listFile; time_t start; unsigned long loops; + vector outputNames; void printData(string label); }; diff --git a/heatmap.cpp b/heatmap.cpp index 2bd020e..d05c700 100644 --- a/heatmap.cpp +++ b/heatmap.cpp @@ -13,20 +13,21 @@ HeatMap::HeatMap(string sort, string scale, string dir){ try { globaldata = GlobalData::getInstance(); + m = MothurOut::getInstance(); // format = globaldata->getFormat(); sorted = sort; scaler = scale; outputDir = dir; } catch(exception& e) { - errorOut(e, "HeatMap", "HeatMap"); + m->errorOut(e, "HeatMap", "HeatMap"); exit(1); } } //********************************************************************************************************************** -void HeatMap::getPic(RAbundVector* rabund) { +string HeatMap::getPic(RAbundVector* rabund) { try { @@ -85,17 +86,17 @@ void HeatMap::getPic(RAbundVector* rabund) { outsvg << "\n\n"; outsvg.close(); - + return filenamesvg; } catch(exception& e) { - errorOut(e, "HeatMap", "getPic"); + m->errorOut(e, "HeatMap", "getPic"); exit(1); } } //********************************************************************************************************************** -void HeatMap::getPic(vector lookup) { +string HeatMap::getPic(vector lookup) { try { //sort lookup so shared bins are on top if (isTrue(sorted) == true) { sortSharedVectors(lookup); } @@ -169,10 +170,12 @@ void HeatMap::getPic(vector lookup) { outsvg << "\n\n"; outsvg.close(); + + return filenamesvg; } catch(exception& e) { - errorOut(e, "HeatMap", "getPic"); + m->errorOut(e, "HeatMap", "getPic"); exit(1); } } @@ -252,7 +255,7 @@ void HeatMap::sortSharedVectors(vector& lookup){ } catch(exception& e) { - errorOut(e, "HeatMap", "sortSharedVectors"); + m->errorOut(e, "HeatMap", "sortSharedVectors"); exit(1); } } @@ -292,7 +295,7 @@ void HeatMap::printLegend(int y, float maxbin) { } catch(exception& e) { - errorOut(e, "HeatMap", "printLegend"); + m->errorOut(e, "HeatMap", "printLegend"); exit(1); } } diff --git a/heatmap.h b/heatmap.h index 438d84b..ffbe946 100644 --- a/heatmap.h +++ b/heatmap.h @@ -22,8 +22,8 @@ class HeatMap { HeatMap(string, string, string); ~HeatMap(){}; - void getPic(RAbundVector*); - void getPic(vector); + string getPic(RAbundVector*); + string getPic(vector); private: void sortSharedVectors(vector& ); @@ -32,6 +32,7 @@ class HeatMap { GlobalData* globaldata; string format, sorted, groupComb, scaler, outputDir; ofstream outsvg; + MothurOut* m; }; diff --git a/heatmapcommand.cpp b/heatmapcommand.cpp index 04f1245..a91ef9d 100644 --- a/heatmapcommand.cpp +++ b/heatmapcommand.cpp @@ -12,7 +12,7 @@ //********************************************************************************************************************** -HeatMapCommand::HeatMapCommand(string option){ +HeatMapCommand::HeatMapCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -45,7 +45,7 @@ HeatMapCommand::HeatMapCommand(string option){ //make sure the user has already run the read.otu command if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "") && (globaldata->getSharedFile() == "")) { - mothurOut("You must read a list, rabund, sabund, or a list and a group, or a shared before you can use the heatmap.bin command."); mothurOutEndLine(); abort = true; + m->mothurOut("You must read a list, rabund, sabund, or a list and a group, or a shared before you can use the heatmap.bin command."); m->mothurOutEndLine(); abort = true; } //check for optional parameter and set defaults @@ -82,7 +82,7 @@ HeatMapCommand::HeatMapCommand(string option){ } catch(exception& e) { - errorOut(e, "HeatMapCommand", "HeatMapCommand"); + m->errorOut(e, "HeatMapCommand", "HeatMapCommand"); exit(1); } } @@ -91,23 +91,23 @@ HeatMapCommand::HeatMapCommand(string option){ void HeatMapCommand::help(){ try { - mothurOut("The heatmap.bin command can only be executed after a successful read.otu command.\n"); - mothurOut("The heatmap.bin command parameters are groups, sorted, scale label. No parameters are required.\n"); - mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n"); - mothurOut("The sorted parameter allows you to choose to see the file with the shared otus at the top or the otus in the order they appear in your input file. \n"); - mothurOut("The scale parameter allows you to choose the range of color your bin information will be displayed with.\n"); - 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"); - mothurOut("The heatmap.bin command should be in the following format: heatmap.bin(groups=yourGroups, sorted=yourSorted, label=yourLabels).\n"); - mothurOut("Example heatmap.bin(groups=A-B-C, sorted=F, scale=log10).\n"); - mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"); - mothurOut("The default value for sorted is T meaning you want the shared otus on top, you may change it to F meaning the exact representation of your input file.\n"); - mothurOut("The default value for scale is log10; your other options are log2 and linear.\n"); - mothurOut("The heatmap.bin command outputs a .svg file for each label you specify.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); + 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 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 choose to see the file with the shared otus at the top or the otus in the order they appear in your input file. \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 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 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=F, 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 sorted is T meaning you want the shared otus on top, you may change it to F meaning the exact representation of your input file.\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) { - errorOut(e, "HeatMapCommand", "help"); + m->errorOut(e, "HeatMapCommand", "help"); exit(1); } } @@ -161,8 +161,8 @@ int HeatMapCommand::execute(){ if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); - heatmap->getPic(lookup); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + outputNames.push_back(heatmap->getPic(lookup)); processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); @@ -173,9 +173,9 @@ int HeatMapCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); - heatmap->getPic(lookup); + outputNames.push_back(heatmap->getPic(lookup)); processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); @@ -196,12 +196,12 @@ int HeatMapCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -210,8 +210,8 @@ int HeatMapCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); - heatmap->getPic(lookup); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + outputNames.push_back(heatmap->getPic(lookup)); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } @@ -226,8 +226,8 @@ int HeatMapCommand::execute(){ if(allLines == 1 || labels.count(rabund->getLabel()) == 1){ - mothurOut(rabund->getLabel()); mothurOutEndLine(); - heatmap->getPic(rabund); + m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); + outputNames.push_back(heatmap->getPic(rabund)); processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); @@ -238,9 +238,9 @@ int HeatMapCommand::execute(){ delete rabund; rabund = input->getRAbundVector(lastLabel); - mothurOut(rabund->getLabel()); mothurOutEndLine(); + m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - heatmap->getPic(rabund); + outputNames.push_back(heatmap->getPic(rabund)); processedLabels.insert(rabund->getLabel()); userLabels.erase(rabund->getLabel()); @@ -260,12 +260,12 @@ int HeatMapCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -274,9 +274,9 @@ int HeatMapCommand::execute(){ if (rabund != NULL) { delete rabund; } rabund = input->getRAbundVector(lastLabel); - mothurOut(rabund->getLabel()); mothurOutEndLine(); + m->mothurOut(rabund->getLabel()); m->mothurOutEndLine(); - heatmap->getPic(rabund); + outputNames.push_back(heatmap->getPic(rabund)); delete rabund; globaldata->rabund = NULL; } @@ -284,10 +284,16 @@ int HeatMapCommand::execute(){ globaldata->rabund = NULL; delete input; globaldata->ginput = NULL; + + 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; } catch(exception& e) { - errorOut(e, "HeatMapCommand", "execute"); + m->errorOut(e, "HeatMapCommand", "execute"); exit(1); } } diff --git a/heatmapcommand.h b/heatmapcommand.h index 83f6c0f..47838d8 100644 --- a/heatmapcommand.h +++ b/heatmapcommand.h @@ -40,7 +40,7 @@ private: bool abort, allLines; set labels; //holds labels to be used string format, groups, sorted, scale, label, outputDir; - vector Groups; + vector Groups, outputNames; }; diff --git a/heatmapsim.cpp b/heatmapsim.cpp index b29e98b..9a12550 100644 --- a/heatmapsim.cpp +++ b/heatmapsim.cpp @@ -22,18 +22,21 @@ //********************************************************************************************************************** HeatMapSim::HeatMapSim(string dir) : outputDir(dir) { globaldata = GlobalData::getInstance(); + m = MothurOut::getInstance(); } //********************************************************************************************************************** -void HeatMapSim::getPic(vector lookup, vector calcs) { +vector HeatMapSim::getPic(vector lookup, vector calcs) { try { EstOutput data; vector sims; + vector outputNames; //make file for each calculator selected for (int m = 0; m < calcs.size(); m++) { string filenamesvg = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + lookup[0]->getLabel() + calcs[m]->getName() + ".heatmap.sim.svg"; openOutputFile(filenamesvg, outsvg); + outputNames.push_back(filenamesvg); //svg image outsvg << "\n"; @@ -94,15 +97,15 @@ void HeatMapSim::getPic(vector lookup, vector } - + return outputNames; } catch(exception& e) { - errorOut(e, "HeatMapSim", "getPic"); + m->errorOut(e, "HeatMapSim", "getPic"); exit(1); } } //********************************************************************************************************************** -void HeatMapSim::getPic(vector< vector > dists, vector groups) { +string HeatMapSim::getPic(vector< vector > dists, vector groups) { try { vector sims; @@ -161,9 +164,11 @@ void HeatMapSim::getPic(vector< vector > dists, vector groups) { outsvg << "\n\n"; outsvg.close(); + return filenamesvg; + } catch(exception& e) { - errorOut(e, "HeatMapSim", "getPic"); + m->errorOut(e, "HeatMapSim", "getPic"); exit(1); } } @@ -202,7 +207,7 @@ void HeatMapSim::printLegend(int y, float maxSim) { } catch(exception& e) { - errorOut(e, "HeatMapSim", "printLegend"); + m->errorOut(e, "HeatMapSim", "printLegend"); exit(1); } } diff --git a/heatmapsim.h b/heatmapsim.h index ffafb7d..bb78e42 100644 --- a/heatmapsim.h +++ b/heatmapsim.h @@ -23,8 +23,8 @@ class HeatMapSim { HeatMapSim(string); ~HeatMapSim(){}; - void getPic(vector, vector); - void getPic(vector< vector >, vector); + vector getPic(vector, vector); + string getPic(vector< vector >, vector); private: void printLegend(int, float); @@ -32,6 +32,7 @@ class HeatMapSim { GlobalData* globaldata; string format, groupComb, outputDir; ofstream outsvg; + MothurOut* m; }; diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp index cef7906..1b4b9d7 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -22,7 +22,7 @@ //********************************************************************************************************************** -HeatMapSimCommand::HeatMapSimCommand(string option){ +HeatMapSimCommand::HeatMapSimCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -30,7 +30,7 @@ HeatMapSimCommand::HeatMapSimCommand(string option){ labels.clear(); Groups.clear(); Estimators.clear(); - + //allow user to run help if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; } @@ -101,11 +101,11 @@ HeatMapSimCommand::HeatMapSimCommand(string option){ //error checking on files - if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == ""))) { mothurOut("You must run the read.otu command or provide a distance file before running the heatmap.sim command."); mothurOutEndLine(); abort = true; } - else if ((phylipfile != "") && (columnfile != "")) { mothurOut("When running the heatmap.sim command with a distance file you may not use both the column and the phylip parameters."); mothurOutEndLine(); abort = true; } + 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; } + 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 == "") { mothurOut("You need to provide a namefile if you are going to use the column format."); mothurOutEndLine(); abort = true; } + if (namefile == "") { 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"; } @@ -180,7 +180,7 @@ HeatMapSimCommand::HeatMapSimCommand(string option){ } catch(exception& e) { - errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand"); + m->errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand"); exit(1); } } @@ -189,27 +189,27 @@ HeatMapSimCommand::HeatMapSimCommand(string option){ void HeatMapSimCommand::help(){ try { - mothurOut("The heatmap.sim command can only be executed after a successful read.otu command, or by providing a distance file.\n"); - mothurOut("The heatmap.sim command parameters are phylip, column, name, groups, calc and label. No parameters are required.\n"); - mothurOut("There are two ways to use the heatmap.sim command. The first is with the read.otu command. \n"); - mothurOut("With the read.otu command you may use the groups, label and calc parameters. \n"); - mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n"); - 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"); - mothurOut("The heatmap.sim command should be in the following format: heatmap.sim(groups=yourGroups, calc=yourCalc, label=yourLabels).\n"); - mothurOut("Example heatmap.sim(groups=A-B-C, calc=jabund).\n"); - 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 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); - mothurOut("The default value for calc is jclass-thetayc.\n"); - mothurOut("The heatmap.sim command outputs a .svg file for each calculator you choose at each label you specify.\n"); - mothurOut("The second way to use the heatmap.sim command is with a distance file representing the distance bewteen your groups. \n"); - 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"); - mothurOut("The heatmap.sim command should be in the following format: heatmap.sim(phylip=yourDistanceFile).\n"); - mothurOut("Example heatmap.sim(phylip=amazonGroups.dist).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); + 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) { - errorOut(e, "HeatMapSimCommand", "help"); + m->errorOut(e, "HeatMapSimCommand", "help"); exit(1); } } @@ -239,11 +239,16 @@ int HeatMapSimCommand::execute(){ delete heatmap; delete validCalculator; - + + 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; } catch(exception& e) { - errorOut(e, "HeatMapSimCommand", "execute"); + m->errorOut(e, "HeatMapSimCommand", "execute"); exit(1); } } @@ -252,7 +257,7 @@ int HeatMapSimCommand::execute(){ int HeatMapSimCommand::runCommandShared() { try { //if the users entered no valid calculators don't execute command - if (heatCalculators.size() == 0) { mothurOut("No valid calculators."); mothurOutEndLine(); return 0; } + if (heatCalculators.size() == 0) { m->mothurOut("No valid calculators."); m->mothurOutEndLine(); return 0; } //you have groups read = new ReadOTUFile(globaldata->inputFileName); @@ -262,7 +267,7 @@ int HeatMapSimCommand::runCommandShared() { lookup = input->getSharedRAbundVectors(); string lastLabel = lookup[0]->getLabel(); - if (lookup.size() < 2) { mothurOut("You have not provided enough valid groups. I cannot run the command."); mothurOutEndLine(); return 0;} + if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0;} //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; @@ -273,8 +278,9 @@ int HeatMapSimCommand::runCommandShared() { if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); - heatmap->getPic(lookup, heatCalculators); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + vector outfilenames = heatmap->getPic(lookup, heatCalculators); + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); @@ -286,8 +292,9 @@ int HeatMapSimCommand::runCommandShared() { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); - heatmap->getPic(lookup, heatCalculators); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + vector outfilenames = heatmap->getPic(lookup, heatCalculators); + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); @@ -309,12 +316,12 @@ int HeatMapSimCommand::runCommandShared() { set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -323,8 +330,10 @@ int HeatMapSimCommand::runCommandShared() { for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); - heatmap->getPic(lookup, heatCalculators); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); + vector outfilenames = heatmap->getPic(lookup, heatCalculators); + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } @@ -338,7 +347,7 @@ int HeatMapSimCommand::runCommandShared() { return 0; } catch(exception& e) { - errorOut(e, "HeatMapSimCommand", "runCommandShared"); + m->errorOut(e, "HeatMapSimCommand", "runCommandShared"); exit(1); } } @@ -455,12 +464,12 @@ int HeatMapSimCommand::runCommandDist() { } - heatmap->getPic(matrix, names); //vector>, vector + outputNames.push_back(heatmap->getPic(matrix, names)); //vector>, vector return 0; } catch(exception& e) { - errorOut(e, "HeatMapSimCommand", "runCommandDist"); + m->errorOut(e, "HeatMapSimCommand", "runCommandDist"); exit(1); } } diff --git a/heatmapsimcommand.h b/heatmapsimcommand.h index 838babd..a260180 100644 --- a/heatmapsimcommand.h +++ b/heatmapsimcommand.h @@ -40,7 +40,7 @@ private: bool abort, allLines; set labels; //holds labels to be used string format, groups, label, calc, phylipfile, columnfile, namefile, outputDir; - vector Estimators, Groups; + vector Estimators, Groups, outputNames; int runCommandShared(); int runCommandDist(); diff --git a/helpcommand.cpp b/helpcommand.cpp index 948c317..608ff3e 100644 --- a/helpcommand.cpp +++ b/helpcommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -HelpCommand::HelpCommand(string option){ +HelpCommand::HelpCommand(string option) { validCommands = CommandFactory::getInstance(); } @@ -25,9 +25,9 @@ HelpCommand::~HelpCommand(){} int HelpCommand::execute(){ validCommands->printCommands(cout); - mothurOut("For more information about a specific command type 'commandName(help)' i.e. 'read.dist(help)'"); mothurOutEndLine(); + m->mothurOut("For more information about a specific command type 'commandName(help)' i.e. 'read.dist(help)'"); m->mothurOutEndLine(); - mothurOutEndLine(); mothurOut("For further assistance please refer to the Mothur manual on our wiki at http://www.mothur.org/wiki, or contact Pat Schloss at mothur.bugs@gmail.com.\n"); + m->mothurOutEndLine(); m->mothurOut("For further assistance please refer to the Mothur manual on our wiki at http://www.mothur.org/wiki, or contact Pat Schloss at mothur.bugs@gmail.com.\n"); return 0; } diff --git a/inputdata.cpp b/inputdata.cpp index bf783a3..8e54ab7 100644 --- a/inputdata.cpp +++ b/inputdata.cpp @@ -15,7 +15,7 @@ /***********************************************************************/ InputData::InputData(string fName, string f) : format(f){ - + m = MothurOut::getInstance(); openInputFile(fName, fileHandle); filename = fName; @@ -34,7 +34,7 @@ InputData::~InputData(){ InputData::InputData(string fName, string orderFileName, string f) : format(f){ try { - + m = MothurOut::getInstance(); ifstream ofHandle; openInputFile(orderFileName, ofHandle); string name; @@ -52,7 +52,7 @@ InputData::InputData(string fName, string orderFileName, string f) : format(f){ openInputFile(fName, fileHandle); } catch(exception& e) { - errorOut(e, "InputData", "InputData"); + m->errorOut(e, "InputData", "InputData"); exit(1); } } @@ -73,7 +73,7 @@ ListVector* InputData::getListVector(){ } } catch(exception& e) { - errorOut(e, "InputData", "getListVector"); + m->errorOut(e, "InputData", "getListVector"); exit(1); } } @@ -111,7 +111,7 @@ ListVector* InputData::getListVector(string label){ } } catch(exception& e) { - errorOut(e, "InputData", "getListVector"); + m->errorOut(e, "InputData", "getListVector"); exit(1); } } @@ -134,7 +134,7 @@ SharedListVector* InputData::getSharedListVector(){ } } catch(exception& e) { - errorOut(e, "InputData", "getSharedListVector"); + m->errorOut(e, "InputData", "getSharedListVector"); exit(1); } } @@ -172,7 +172,7 @@ SharedListVector* InputData::getSharedListVector(string label){ } } catch(exception& e) { - errorOut(e, "InputData", "getSharedListVector"); + m->errorOut(e, "InputData", "getSharedListVector"); exit(1); } } @@ -196,7 +196,7 @@ SharedOrderVector* InputData::getSharedOrderVector(){ } } catch(exception& e) { - errorOut(e, "InputData", "getSharedOrderVector"); + m->errorOut(e, "InputData", "getSharedOrderVector"); exit(1); } } @@ -235,7 +235,7 @@ SharedOrderVector* InputData::getSharedOrderVector(string label){ } } catch(exception& e) { - errorOut(e, "InputData", "getSharedOrderVector"); + m->errorOut(e, "InputData", "getSharedOrderVector"); exit(1); } } @@ -275,7 +275,7 @@ OrderVector* InputData::getOrderVector(){ } } catch(exception& e) { - errorOut(e, "InputData", "getOrderVector"); + m->errorOut(e, "InputData", "getOrderVector"); exit(1); } } @@ -378,7 +378,7 @@ OrderVector* InputData::getOrderVector(string label){ } } catch(exception& e) { - errorOut(e, "InputData", "getOrderVector"); + m->errorOut(e, "InputData", "getOrderVector"); exit(1); } } @@ -408,7 +408,7 @@ vector InputData::getSharedRAbundVectors(){ } catch(exception& e) { - errorOut(e, "InputData", "getSharedRAbundVectors"); + m->errorOut(e, "InputData", "getSharedRAbundVectors"); exit(1); } } @@ -466,7 +466,7 @@ vector InputData::getSharedRAbundVectors(string label){ } catch(exception& e) { - errorOut(e, "InputData", "getSharedRAbundVectors"); + m->errorOut(e, "InputData", "getSharedRAbundVectors"); exit(1); } } @@ -505,7 +505,7 @@ SAbundVector* InputData::getSAbundVector(){ } } catch(exception& e) { - errorOut(e, "InputData", "getSAbundVector"); + m->errorOut(e, "InputData", "getSAbundVector"); exit(1); } } @@ -607,7 +607,7 @@ SAbundVector* InputData::getSAbundVector(string label){ } } catch(exception& e) { - errorOut(e, "InputData", "getSAbundVector"); + m->errorOut(e, "InputData", "getSAbundVector"); exit(1); } } @@ -644,7 +644,7 @@ RAbundVector* InputData::getRAbundVector(){ } } catch(exception& e) { - errorOut(e, "InputData", "getRAbundVector"); + m->errorOut(e, "InputData", "getRAbundVector"); exit(1); } } @@ -745,7 +745,7 @@ RAbundVector* InputData::getRAbundVector(string label){ } } catch(exception& e) { - errorOut(e, "InputData", "getRAbundVector"); + m->errorOut(e, "InputData", "getRAbundVector"); exit(1); } } diff --git a/inputdata.h b/inputdata.h index 6d2d004..251df5b 100644 --- a/inputdata.h +++ b/inputdata.h @@ -41,6 +41,7 @@ private: RAbundVector* rabund; map orderMap; string filename; + MothurOut* m; }; diff --git a/jackknife.cpp b/jackknife.cpp index 35f0910..7f61366 100644 --- a/jackknife.cpp +++ b/jackknife.cpp @@ -25,7 +25,7 @@ void Jackknife::getAMatrix(void){ } } catch(exception& e) { - errorOut(e, "Jackknife", "getAMatrix"); + m->errorOut(e, "Jackknife", "getAMatrix"); exit(1); } } @@ -53,7 +53,7 @@ double Jackknife::CN(double z){ return n; } catch(exception& e) { - errorOut(e, "Jackknife", "CN"); + m->errorOut(e, "Jackknife", "CN"); exit(1); } } @@ -144,7 +144,7 @@ EstOutput Jackknife::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "Jackknife", "getValues"); + m->errorOut(e, "Jackknife", "getValues"); exit(1); } } diff --git a/kmerdb.cpp b/kmerdb.cpp index 2560a44..7f7f265 100644 --- a/kmerdb.cpp +++ b/kmerdb.cpp @@ -42,7 +42,7 @@ KmerDB::KmerDB(string fastaFileName, int kSize) : Database(), kmerSize(kSize) { } catch(exception& e) { - errorOut(e, "KmerDB", "KmerDB"); + m->errorOut(e, "KmerDB", "KmerDB"); exit(1); } @@ -94,7 +94,7 @@ vector KmerDB::findClosestSequences(Sequence* candidateSeq, int num){ return topMatches; } catch(exception& e) { - errorOut(e, "KmerDB", "findClosestSequences"); + m->errorOut(e, "KmerDB", "findClosestSequences"); exit(1); } } @@ -118,7 +118,7 @@ void KmerDB::generateDB(){ } catch(exception& e) { - errorOut(e, "KmerDB", "generateDB"); + m->errorOut(e, "KmerDB", "generateDB"); exit(1); } @@ -143,7 +143,7 @@ void KmerDB::addSequence(Sequence seq) { count++; } catch(exception& e) { - errorOut(e, "KmerDB", "addSequence"); + m->errorOut(e, "KmerDB", "addSequence"); exit(1); } } @@ -170,7 +170,7 @@ void KmerDB::readKmerDB(ifstream& kmerDBFile){ } catch(exception& e) { - errorOut(e, "KmerDB", "readKmerDB"); + m->errorOut(e, "KmerDB", "readKmerDB"); exit(1); } } @@ -183,7 +183,7 @@ int KmerDB::getCount(int kmer) { else { return kmerLocations[kmer].size(); } // kmer is in vector range } catch(exception& e) { - errorOut(e, "KmerDB", "getCount"); + m->errorOut(e, "KmerDB", "getCount"); exit(1); } } @@ -200,7 +200,7 @@ vector KmerDB::getSequencesWithKmer(int kmer) { return seqs; } catch(exception& e) { - errorOut(e, "KmerDB", "getSequencesWithKmer"); + m->errorOut(e, "KmerDB", "getSequencesWithKmer"); exit(1); } } diff --git a/knn.cpp b/knn.cpp index 706d243..c11626a 100644 --- a/knn.cpp +++ b/knn.cpp @@ -28,23 +28,23 @@ string Knn::getTaxonomy(Sequence* seq) { //is this sequence in the taxonomy file if (it == taxonomy.end()) { //error not in file - mothurOut("Error: sequence " + names[closest[i]] + " is not in the taxonomy file. It will be eliminated as a match to sequence " + seq->getName() + "."); mothurOutEndLine(); + m->mothurOut("Error: sequence " + names[closest[i]] + " is not in the taxonomy file. It will be eliminated as a match to sequence " + seq->getName() + "."); m->mothurOutEndLine(); }else{ closestNames.push_back(it->first); } } if (closestNames.size() == 0) { - mothurOut("Error: All the matches for sequence " + seq->getName() + " have been eliminated. " + seq->getName() + " will be disregarded."); mothurOutEndLine(); + m->mothurOut("Error: All the matches for sequence " + seq->getName() + " have been eliminated. " + seq->getName() + " will be disregarded."); m->mothurOutEndLine(); tax = "bad seq"; }else{ tax = findCommonTaxonomy(closestNames); - if (tax == "") { mothurOut("There are no common levels for sequence " + seq->getName() + ". " + seq->getName() + " will be disregarded."); mothurOutEndLine(); tax = "bad seq"; } + if (tax == "") { m->mothurOut("There are no common levels for sequence " + seq->getName() + ". " + seq->getName() + " will be disregarded."); m->mothurOutEndLine(); tax = "bad seq"; } } simpleTax = tax; return tax; } catch(exception& e) { - errorOut(e, "Knn", "getTaxonomy"); + m->errorOut(e, "Knn", "getTaxonomy"); exit(1); } } @@ -92,7 +92,7 @@ string Knn::findCommonTaxonomy(vector closest) { return common; } catch(exception& e) { - errorOut(e, "Knn", "findCommonTaxonomy"); + m->errorOut(e, "Knn", "findCommonTaxonomy"); exit(1); } } diff --git a/libshuff.cpp b/libshuff.cpp index cd4570e..5f1bdef 100644 --- a/libshuff.cpp +++ b/libshuff.cpp @@ -17,13 +17,14 @@ void swap(int& i,int& j){ int t = i; i = j; j = t; } Libshuff::Libshuff(FullMatrix* D, int it, float step, float co) : matrix(D), iters(it), stepSize(step), cutOff(co){ try{ + m = MothurOut::getInstance(); groupNames = matrix->getGroups(); groupSizes = matrix->getSizes(); numGroups = matrix->getNumGroups(); initializeGroups(matrix); } catch(exception& e) { - errorOut(e, "Libshuff", "Libshuff"); + m->errorOut(e, "Libshuff", "Libshuff"); exit(1); } } @@ -49,7 +50,7 @@ void Libshuff::initializeGroups(FullMatrix* matrix){ } } catch(exception& e) { - errorOut(e, "Libshuff", "initializeGroups"); + m->errorOut(e, "Libshuff", "initializeGroups"); exit(1); } } @@ -78,7 +79,7 @@ vector Libshuff::getMinX(int x){ return minX; } catch(exception& e) { - errorOut(e, "Libshuff", "getMinX"); + m->errorOut(e, "Libshuff", "getMinX"); exit(1); } } @@ -99,7 +100,7 @@ vector Libshuff::getMinXY(int x, int y){ return minXY; } catch(exception& e) { - errorOut(e, "Libshuff", "getMinXY"); + m->errorOut(e, "Libshuff", "getMinXY"); exit(1); } } @@ -125,7 +126,7 @@ void Libshuff::randomizeGroups(int x, int y){ for(int k=0;kerrorOut(e, "Libshuff", "randomizeGroups"); exit(1); } } diff --git a/libshuff.h b/libshuff.h index 6412f16..ef0e1b0 100644 --- a/libshuff.h +++ b/libshuff.h @@ -42,6 +42,7 @@ protected: float stepSize; int numGroups; + MothurOut* m; }; #endif diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp index cfccdf6..93db3be 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -20,13 +20,12 @@ //********************************************************************************************************************** -LibShuffCommand::LibShuffCommand(string option){ +LibShuffCommand::LibShuffCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; Groups.clear(); - //allow user to run help if(option == "help") { help(); abort = true; } @@ -53,7 +52,7 @@ LibShuffCommand::LibShuffCommand(string option){ //make sure the user has already run the read.dist command if ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL)) { - mothurOut("You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. "); mothurOutEndLine(); abort = true;; + 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;; } //check for optional parameter and set defaults @@ -105,7 +104,7 @@ LibShuffCommand::LibShuffCommand(string option){ } catch(exception& e) { - errorOut(e, "LibShuffCommand", "LibShuffCommand"); + m->errorOut(e, "LibShuffCommand", "LibShuffCommand"); exit(1); } } @@ -113,20 +112,20 @@ LibShuffCommand::LibShuffCommand(string option){ void LibShuffCommand::help(){ try { - mothurOut("The libshuff command can only be executed after a successful read.dist command including a groupfile.\n"); - mothurOut("The libshuff command parameters are groups, iters, step, form and cutoff. No parameters are required.\n"); - 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"); - 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"); - 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"); - 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"); - mothurOut("The libshuff command should be in the following format: libshuff(groups=yourGroups, iters=yourIters, cutOff=yourCutOff, form=yourForm, step=yourStep).\n"); - mothurOut("Example libshuff(groups=A-B-C, iters=500, form=discrete, step=0.01, cutOff=2.0).\n"); - 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"); - mothurOut("The libshuff command output two files: .coverage and .slsummary their descriptions are in the manual.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters).\n\n"); + 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) { - errorOut(e, "LibShuffCommand", "help"); + m->errorOut(e, "LibShuffCommand", "help"); exit(1); } } @@ -167,7 +166,7 @@ int LibShuffCommand::execute(){ reading->finish(); delete reading; - mothurOutEndLine(); + m->mothurOutEndLine(); printSummaryFile(); printCoverageFile(); @@ -178,10 +177,15 @@ int LibShuffCommand::execute(){ //delete globaldata's copy of the gmatrix to free up memory delete globaldata->gMatrix; globaldata->gMatrix = NULL; + 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; } catch(exception& e) { - errorOut(e, "LibShuffCommand", "execute"); + m->errorOut(e, "LibShuffCommand", "execute"); exit(1); } } @@ -194,6 +198,7 @@ void LibShuffCommand::printCoverageFile() { ofstream outCov; summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage"; openOutputFile(summaryFile, outCov); + outputNames.push_back(summaryFile); outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint); //cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); @@ -268,7 +273,7 @@ void LibShuffCommand::printCoverageFile() { outCov.close(); } catch(exception& e) { - errorOut(e, "LibShuffCommand", "printCoverageFile"); + m->errorOut(e, "LibShuffCommand", "printCoverageFile"); exit(1); } } @@ -281,12 +286,13 @@ void LibShuffCommand::printSummaryFile() { ofstream outSum; summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary"; openOutputFile(summaryFile, outSum); + outputNames.push_back(summaryFile); outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint); cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); cout << setw(20) << left << "Comparison" << '\t' << setprecision(8) << "dCXYScore" << '\t' << "Significance" << endl; - mothurOutJustToLog("Comparison\tdCXYScore\tSignificance"); mothurOutEndLine(); + m->mothurOutJustToLog("Comparison\tdCXYScore\tSignificance"); m->mothurOutEndLine(); outSum << setw(20) << left << "Comparison" << '\t' << setprecision(8) << "dCXYScore" << '\t' << "Significance" << endl; int precision = (int)log10(iters); @@ -297,22 +303,22 @@ void LibShuffCommand::printSummaryFile() { 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; - mothurOutJustToLog(groupNames[i]+"-"+groupNames[j] + "\t" + toString(savedDXYValues[spoti][spotj]) + "\t" + toString((pValueCounts[i][j]/(float)iters))); mothurOutEndLine(); + m->mothurOutJustToLog(groupNames[i]+"-"+groupNames[j] + "\t" + toString(savedDXYValues[spoti][spotj]) + "\t" + toString((pValueCounts[i][j]/(float)iters))); m->mothurOutEndLine(); outSum << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[spoti][spotj] << '\t' << setprecision(precision) << pValueCounts[i][j]/(float)iters << endl; } else{ cout << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[spoti][spotj] << '\t' << '<' <mothurOutJustToLog(groupNames[i]+"-"+groupNames[j] + "\t" + toString(savedDXYValues[spoti][spotj]) + "\t" + toString((1/(float)iters))); m->mothurOutEndLine(); outSum << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[spoti][spotj] << '\t' << '<' <mothurOutJustToLog(groupNames[j]+"-"+groupNames[i] + "\t" + toString(savedDXYValues[spotj][spoti]) + "\t" + toString((pValueCounts[j][i]/(float)iters))); m->mothurOutEndLine(); outSum << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[spotj][spoti] << '\t' << setprecision (precision) << pValueCounts[j][i]/(float)iters << endl; } else{ cout << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[spotj][spoti] << '\t' << '<' <mothurOutJustToLog(groupNames[j]+"-"+groupNames[i] + "\t" + toString(savedDXYValues[spotj][spoti]) + "\t" + toString((1/(float)iters))); m->mothurOutEndLine(); outSum << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[spotj][spoti] << '\t' << '<' <errorOut(e, "LibShuffCommand", "printSummaryFile"); exit(1); } } @@ -341,7 +347,7 @@ void LibShuffCommand::setGroups() { //check that groups are valid for (int i = 0; i < globaldata->Groups.size(); i++) { if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) { - mothurOut(globaldata->Groups[i] + " is not a valid group, and will be disregarded."); mothurOutEndLine(); + m->mothurOut(globaldata->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); } @@ -353,7 +359,7 @@ void LibShuffCommand::setGroups() { for (int i=0; i < numGroups; i++) { globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]); } - 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."); mothurOutEndLine(); + 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 { //users wants all groups numGroups = globaldata->gGroupmap->getNumGroups(); @@ -376,7 +382,7 @@ void LibShuffCommand::setGroups() { } catch(exception& e) { - errorOut(e, "LibShuffCommand", "setGroups"); + m->errorOut(e, "LibShuffCommand", "setGroups"); exit(1); } } diff --git a/libshuffcommand.h b/libshuffcommand.h index da5f9e8..5155cbd 100644 --- a/libshuffcommand.h +++ b/libshuffcommand.h @@ -44,7 +44,7 @@ private: bool abort; string outputFile, groups, userform, savegroups, outputDir; - vector Groups; //holds groups to be used + vector Groups, outputNames; //holds groups to be used }; #endif diff --git a/listseqscommand.cpp b/listseqscommand.cpp index d0b00bd..f3710c9 100644 --- a/listseqscommand.cpp +++ b/listseqscommand.cpp @@ -13,7 +13,7 @@ //********************************************************************************************************************** -ListSeqsCommand::ListSeqsCommand(string option){ +ListSeqsCommand::ListSeqsCommand(string option) { try { abort = false; @@ -107,17 +107,17 @@ ListSeqsCommand::ListSeqsCommand(string option){ else if (listfile == "not found") { listfile = ""; } - if ((fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == "")) { mothurOut("You must provide a file."); mothurOutEndLine(); abort = true; } + if ((fastafile == "") && (namefile == "") && (listfile == "") && (groupfile == "") && (alignfile == "")) { m->mothurOut("You must provide a file."); m->mothurOutEndLine(); abort = true; } int okay = 1; if (outputDir != "") { okay++; } - if (parameters.size() > okay) { mothurOut("You may only enter one file."); mothurOutEndLine(); abort = true; } + if (parameters.size() > okay) { m->mothurOut("You may only enter one file."); m->mothurOutEndLine(); abort = true; } } } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "ListSeqsCommand"); + m->errorOut(e, "ListSeqsCommand", "ListSeqsCommand"); exit(1); } } @@ -125,14 +125,14 @@ ListSeqsCommand::ListSeqsCommand(string option){ void ListSeqsCommand::help(){ try { - mothurOut("The list.seqs command reads a fasta, name, group, list or alignreport file and outputs a .accnos file containing sequence names.\n"); - mothurOut("The list.seqs command parameters are fasta, name, group and alignreport. You must provide one of these parameters.\n"); - mothurOut("The list.seqs command should be in the following format: list.seqs(fasta=yourFasta).\n"); - mothurOut("Example list.seqs(fasta=amazon.fasta).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); + m->mothurOut("The list.seqs command reads a fasta, name, group, list or alignreport file and outputs a .accnos file containing sequence names.\n"); + m->mothurOut("The list.seqs command parameters are fasta, name, group 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) { - errorOut(e, "ListSeqsCommand", "help"); + m->errorOut(e, "ListSeqsCommand", "help"); exit(1); } } @@ -167,11 +167,16 @@ int ListSeqsCommand::execute(){ } out.close(); + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "execute"); + m->errorOut(e, "ListSeqsCommand", "execute"); exit(1); } } @@ -196,7 +201,7 @@ void ListSeqsCommand::readFasta(){ } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readFasta"); + m->errorOut(e, "ListSeqsCommand", "readFasta"); exit(1); } } @@ -227,7 +232,7 @@ void ListSeqsCommand::readList(){ } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readList"); + m->errorOut(e, "ListSeqsCommand", "readList"); exit(1); } } @@ -261,7 +266,7 @@ void ListSeqsCommand::readName(){ } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readName"); + m->errorOut(e, "ListSeqsCommand", "readName"); exit(1); } } @@ -287,7 +292,7 @@ void ListSeqsCommand::readGroup(){ } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readGroup"); + m->errorOut(e, "ListSeqsCommand", "readGroup"); exit(1); } } @@ -327,7 +332,7 @@ void ListSeqsCommand::readAlign(){ } catch(exception& e) { - errorOut(e, "ListSeqsCommand", "readAlign"); + m->errorOut(e, "ListSeqsCommand", "readAlign"); exit(1); } } diff --git a/listvector.cpp b/listvector.cpp index e123298..94ca026 100644 --- a/listvector.cpp +++ b/listvector.cpp @@ -36,7 +36,7 @@ ListVector::ListVector(string id, vector lv) : DataVector(id), data(lv){ } } catch(exception& e) { - errorOut(e, "ListVector", "ListVector"); + m->errorOut(e, "ListVector", "ListVector"); exit(1); } } @@ -59,7 +59,7 @@ ListVector::ListVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), numS gobble(f); } catch(exception& e) { - errorOut(e, "ListVector", "ListVector"); + m->errorOut(e, "ListVector", "ListVector"); exit(1); } } @@ -79,7 +79,7 @@ void ListVector::set(int binNumber, string seqNames){ numSeqs += (nNames_new - nNames_old); } catch(exception& e) { - errorOut(e, "ListVector", "set"); + m->errorOut(e, "ListVector", "set"); exit(1); } } @@ -104,7 +104,7 @@ void ListVector::push_back(string seqNames){ numSeqs += nNames; } catch(exception& e) { - errorOut(e, "ListVector", "push_back"); + m->errorOut(e, "ListVector", "push_back"); exit(1); } } @@ -144,7 +144,7 @@ void ListVector::print(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "ListVector", "print"); + m->errorOut(e, "ListVector", "print"); exit(1); } } @@ -175,7 +175,7 @@ RAbundVector ListVector::getRAbundVector(){ return rav; } catch(exception& e) { - errorOut(e, "ListVector", "getRAbundVector"); + m->errorOut(e, "ListVector", "getRAbundVector"); exit(1); } } @@ -196,7 +196,7 @@ SAbundVector ListVector::getSAbundVector(){ return sav; } catch(exception& e) { - errorOut(e, "ListVector", "getSAbundVector"); + m->errorOut(e, "ListVector", "getSAbundVector"); exit(1); } } @@ -238,7 +238,7 @@ OrderVector ListVector::getOrderVector(map* orderMap = NULL){ } else{ if(orderMap->count(seqName) == 0){ - mothurOut(seqName + " not found, check *.names file\n"); + m->mothurOut(seqName + " not found, check *.names file\n"); exit(1); } @@ -248,7 +248,7 @@ OrderVector ListVector::getOrderVector(map* orderMap = NULL){ } if(orderMap->count(seqName) == 0){ - mothurOut(seqName + " not found, check *.names file\n"); + m->mothurOut(seqName + " not found, check *.names file\n"); exit(1); } ov.set((*orderMap)[seqName], i); @@ -261,7 +261,7 @@ OrderVector ListVector::getOrderVector(map* orderMap = NULL){ } } catch(exception& e) { - errorOut(e, "ListVector", "getOrderVector"); + m->errorOut(e, "ListVector", "getOrderVector"); exit(1); } } diff --git a/logsd.cpp b/logsd.cpp index 62faf8e..009a404 100644 --- a/logsd.cpp +++ b/logsd.cpp @@ -85,7 +85,7 @@ EstOutput LogSD::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "LogSD", "getValues"); + m->errorOut(e, "LogSD", "getValues"); exit(1); } } diff --git a/maligner.cpp b/maligner.cpp index 91b0fa7..76689e9 100644 --- a/maligner.cpp +++ b/maligner.cpp @@ -13,7 +13,7 @@ /***********************************************************************/ Maligner::Maligner(vector temp, int num, int match, int misMatch, float div, int ms, int minCov, string mode, Database* dataLeft, Database* dataRight) : - db(temp), numWanted(num), matchScore(match), misMatchPenalty(misMatch), minDivR(div), minSimilarity(ms), minCoverage(minCov), searchMethod(mode), databaseLeft(dataLeft), databaseRight(dataRight) {} + db(temp), numWanted(num), matchScore(match), misMatchPenalty(misMatch), minDivR(div), minSimilarity(ms), minCoverage(minCov), searchMethod(mode), databaseLeft(dataLeft), databaseRight(dataRight) { m = MothurOut::getInstance(); } /***********************************************************************/ string Maligner::getResults(Sequence* q, DeCalculator* decalc) { try { @@ -32,7 +32,7 @@ string Maligner::getResults(Sequence* q, DeCalculator* decalc) { refSeqs = getBlastSeqs(query, numWanted); //fills indexes }else if (searchMethod == "kmer") { refSeqs = getKmerSeqs(query, numWanted); //fills indexes - }else { mothurOut("not valid search."); exit(1); } //should never get here + }else { m->mothurOut("not valid search."); exit(1); } //should never get here refSeqs = minCoverageFilter(refSeqs); @@ -56,7 +56,7 @@ string Maligner::getResults(Sequence* q, DeCalculator* decalc) { return chimera; } catch(exception& e) { - errorOut(e, "Maligner", "getResults"); + m->errorOut(e, "Maligner", "getResults"); exit(1); } } @@ -130,7 +130,7 @@ string Maligner::chimeraMaligner(int chimeraPenalty, DeCalculator* decalc) { return chimera; } catch(exception& e) { - errorOut(e, "Maligner", "chimeraMaligner"); + m->errorOut(e, "Maligner", "chimeraMaligner"); exit(1); } } @@ -172,7 +172,7 @@ vector Maligner::minCoverageFilter(vector ref){ return newRefs; } catch(exception& e) { - errorOut(e, "Maligner", "minCoverageFilter"); + m->errorOut(e, "Maligner", "minCoverageFilter"); exit(1); } } @@ -189,7 +189,7 @@ int Maligner::computeChimeraPenalty() { } catch(exception& e) { - errorOut(e, "Maligner", "computeChimeraPenalty"); + m->errorOut(e, "Maligner", "computeChimeraPenalty"); exit(1); } } @@ -241,7 +241,7 @@ void Maligner::verticalFilter(vector seqs) { spotMap = newMap; } catch(exception& e) { - errorOut(e, "Maligner", "verticalFilter"); + m->errorOut(e, "Maligner", "verticalFilter"); exit(1); } } @@ -268,12 +268,12 @@ vector< vector > Maligner::buildScoreMatrix(int cols, int rows) { return m; } catch(exception& e) { - errorOut(e, "Maligner", "buildScoreMatrix"); + m->errorOut(e, "Maligner", "buildScoreMatrix"); exit(1); } } //*************************************************************************************************************** -void Maligner::fillScoreMatrix(vector >& m, vector seqs, int penalty) { +void Maligner::fillScoreMatrix(vector >& ms, vector seqs, int penalty) { try{ //get matrix dimensions @@ -287,11 +287,11 @@ void Maligner::fillScoreMatrix(vector >& m, vector >& m, vector m[i][j].score) { - m[i][j].score = sumScore; - m[i][j].prev = prevIndex; + if (sumScore > ms[i][j].score) { + ms[i][j].score = sumScore; + ms[i][j].prev = prevIndex; } } } @@ -333,17 +333,17 @@ void Maligner::fillScoreMatrix(vector >& m, vectorerrorOut(e, "Maligner", "fillScoreMatrix"); exit(1); } } //*************************************************************************************************************** -vector Maligner::extractHighestPath(vector > m) { +vector Maligner::extractHighestPath(vector > ms) { try { //get matrix dimensions int numCols = query->getAligned().length(); - int numRows = m.size(); + int numRows = ms.size(); //find highest score scoring matrix @@ -352,9 +352,9 @@ vector Maligner::extractHighestPath(vector > for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) { - if (m[i][j].score > highestScore) { - highestScore = m[i][j].score; - highestStruct = m[i][j]; + if (ms[i][j].score > highestScore) { + highestScore = ms[i][j].score; + highestStruct = ms[i][j]; } } } @@ -366,7 +366,7 @@ vector Maligner::extractHighestPath(vector > int score = highestStruct.score; while (pos >= 0 && score > 0) { - score_struct temp = m[rowIndex][pos]; + score_struct temp = ms[rowIndex][pos]; score = temp.score; if (score > 0) { path.push_back(temp); } @@ -381,7 +381,7 @@ vector Maligner::extractHighestPath(vector > } catch(exception& e) { - errorOut(e, "Maligner", "extractHighestPath"); + m->errorOut(e, "Maligner", "extractHighestPath"); exit(1); } } @@ -424,7 +424,7 @@ vector Maligner::mapTraceRegionsToAlignment(vector p } catch(exception& e) { - errorOut(e, "Maligner", "mapTraceRegionsToAlignment"); + m->errorOut(e, "Maligner", "mapTraceRegionsToAlignment"); exit(1); } } @@ -442,7 +442,7 @@ string Maligner::constructChimericSeq(vector trace, vectorerrorOut(e, "Maligner", "constructChimericSeq"); exit(1); } } @@ -451,9 +451,9 @@ float Maligner::computePercentID(string queryAlign, string chimera) { try { if (queryAlign.length() != chimera.length()) { - mothurOut("Error, alignment strings are of different lengths: "); mothurOutEndLine(); - mothurOut(toString(queryAlign.length())); mothurOutEndLine(); mothurOutEndLine(); mothurOutEndLine(); mothurOutEndLine(); - mothurOut(toString(chimera.length())); mothurOutEndLine(); + m->mothurOut("Error, alignment strings are of different lengths: "); m->mothurOutEndLine(); + m->mothurOut(toString(queryAlign.length())); m->mothurOutEndLine(); m->mothurOutEndLine(); m->mothurOutEndLine(); m->mothurOutEndLine(); + m->mothurOut(toString(chimera.length())); m->mothurOutEndLine(); return -1.0; } @@ -478,7 +478,7 @@ float Maligner::computePercentID(string queryAlign, string chimera) { } catch(exception& e) { - errorOut(e, "Maligner", "computePercentID"); + m->errorOut(e, "Maligner", "computePercentID"); exit(1); } } @@ -504,7 +504,7 @@ vector Maligner::getBlastSeqs(Sequence* q, int num) { vector tempIndexesRight = database->findClosestMegaBlast(queryRight, num+1); vector tempIndexesLeft = database->findClosestMegaBlast(queryLeft, num+1); - //if ((tempIndexesRight.size() != (num+1)) || (tempIndexesLeft.size() != (num+1))) { mothurOut("megablast returned " + toString(tempIndexesRight.size()) + " results for the right end, and " + toString(tempIndexesLeft.size()) + " for the left end. Needed " + toString(num+1) + ". Unable to porcess sequence " + q->getName()); mothurOutEndLine(); return refResults; } + //if ((tempIndexesRight.size() != (num+1)) || (tempIndexesLeft.size() != (num+1))) { m->mothurOut("megablast returned " + toString(tempIndexesRight.size()) + " results for the right end, and " + toString(tempIndexesLeft.size()) + " for the left end. Needed " + toString(num+1) + ". Unable to porcess sequence " + q->getName()); m->mothurOutEndLine(); return refResults; } vector smaller; vector larger; @@ -560,7 +560,7 @@ vector Maligner::getBlastSeqs(Sequence* q, int num) { return refResults; } catch(exception& e) { - errorOut(e, "Maligner", "getBlastSeqs"); + m->errorOut(e, "Maligner", "getBlastSeqs"); exit(1); } } @@ -616,7 +616,7 @@ vector Maligner::getKmerSeqs(Sequence* q, int num) { return refResults; } catch(exception& e) { - errorOut(e, "Maligner", "getBlastSeqs"); + m->errorOut(e, "Maligner", "getBlastSeqs"); exit(1); } } diff --git a/maligner.h b/maligner.h index 13aa917..a4c959b 100644 --- a/maligner.h +++ b/maligner.h @@ -54,6 +54,7 @@ class Maligner { string chimeraMaligner(int, DeCalculator*); vector getBlastSeqs(Sequence*, int); vector getKmerSeqs(Sequence*, int); + MothurOut* m; }; diff --git a/matrixoutputcommand.cpp b/matrixoutputcommand.cpp index 87e6489..078f411 100644 --- a/matrixoutputcommand.cpp +++ b/matrixoutputcommand.cpp @@ -22,7 +22,7 @@ //********************************************************************************************************************** -MatrixOutputCommand::MatrixOutputCommand(string option){ +MatrixOutputCommand::MatrixOutputCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -57,8 +57,8 @@ MatrixOutputCommand::MatrixOutputCommand(string option){ //make sure the user has already run the read.otu command if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the dist.shared command."); mothurOutEndLine(); abort = true; } - else if (globaldata->getGroupFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the dist.shared command."); mothurOutEndLine(); abort = true; } + 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; } } //check for optional parameter and set defaults @@ -71,7 +71,7 @@ MatrixOutputCommand::MatrixOutputCommand(string option){ } output = validParameter.validFile(parameters, "output", false); if(output == "not found"){ output = "lt"; } - if ((output != "lt") && (output != "square")) { mothurOut(output + " is not a valid output form. Options are lt and square. I will use lt."); mothurOutEndLine(); 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 == "") { @@ -129,7 +129,7 @@ MatrixOutputCommand::MatrixOutputCommand(string option){ } catch(exception& e) { - errorOut(e, "MatrixOutputCommand", "MatrixOutputCommand"); + m->errorOut(e, "MatrixOutputCommand", "MatrixOutputCommand"); exit(1); } } @@ -138,21 +138,21 @@ MatrixOutputCommand::MatrixOutputCommand(string option){ void MatrixOutputCommand::help(){ try { - mothurOut("The dist.shared command can only be executed after a successful read.otu command.\n"); - mothurOut("The dist.shared command parameters are groups, calc, output and label. No parameters are required.\n"); - mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n"); - 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"); - mothurOut("The dist.shared command should be in the following format: dist.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels).\n"); - mothurOut("The output parameter allows you to specify format of your distance matrix. Options are lt, and square. The default is lt.\n"); - mothurOut("Example dist.shared(groups=A-B-C, calc=jabund-sorabund).\n"); - mothurOut("The default value for groups is all the groups in your groupfile.\n"); - mothurOut("The default value for calc is jclass and thetayc.\n"); + 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); - mothurOut("The dist.shared command outputs a .dist file for each calculator you specify at each distance you choose.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); + 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) { - errorOut(e, "MatrixOutputCommand", "help"); + m->errorOut(e, "MatrixOutputCommand", "help"); exit(1); } } @@ -176,7 +176,7 @@ int MatrixOutputCommand::execute(){ if (abort == true) { return 0; } //if the users entered no valid calculators don't execute command - if (matrixCalculators.size() == 0) { mothurOut("No valid calculators."); mothurOutEndLine(); return 0; } + if (matrixCalculators.size() == 0) { m->mothurOut("No valid calculators."); m->mothurOutEndLine(); return 0; } //you have groups read = new ReadOTUFile(globaldata->inputFileName); @@ -190,7 +190,7 @@ int MatrixOutputCommand::execute(){ set processedLabels; set userLabels = labels; - if (lookup.size() < 2) { mothurOut("You have not provided enough valid groups. I cannot run the command."); mothurOutEndLine(); return 0;} + if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0;} numGroups = lookup.size(); @@ -198,7 +198,7 @@ int MatrixOutputCommand::execute(){ while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); process(lookup); processedLabels.insert(lookup[0]->getLabel()); @@ -211,7 +211,7 @@ int MatrixOutputCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); process(lookup); processedLabels.insert(lookup[0]->getLabel()); @@ -232,12 +232,12 @@ int MatrixOutputCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -246,7 +246,7 @@ int MatrixOutputCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); process(lookup); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } @@ -254,11 +254,17 @@ int MatrixOutputCommand::execute(){ //reset groups parameter globaldata->Groups.clear(); + + 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; } catch(exception& e) { - errorOut(e, "MatrixOutputCommand", "execute"); + m->errorOut(e, "MatrixOutputCommand", "execute"); exit(1); } } @@ -290,7 +296,7 @@ void MatrixOutputCommand::printSims(ostream& out) { } } catch(exception& e) { - errorOut(e, "MatrixOutputCommand", "printSims"); + m->errorOut(e, "MatrixOutputCommand", "printSims"); exit(1); } } @@ -332,6 +338,8 @@ void MatrixOutputCommand::process(vector thisLookup){ exportFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + matrixCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + "." + output + ".dist"; openOutputFile(exportFileName, out); + outputNames.push_back(exportFileName); + printSims(out); out.close(); @@ -341,7 +349,7 @@ void MatrixOutputCommand::process(vector thisLookup){ } catch(exception& e) { - errorOut(e, "MatrixOutputCommand", "process"); + m->errorOut(e, "MatrixOutputCommand", "process"); exit(1); } } diff --git a/matrixoutputcommand.h b/matrixoutputcommand.h index ff7519e..521104c 100644 --- a/matrixoutputcommand.h +++ b/matrixoutputcommand.h @@ -49,7 +49,7 @@ private: bool abort, allLines; set labels; //holds labels to be used string outputFile, calc, groups, label, outputDir; - vector Estimators, Groups; //holds estimators to be used + vector Estimators, Groups, outputNames; //holds estimators to be used }; diff --git a/mergefilecommand.cpp b/mergefilecommand.cpp index 0a8c0d8..7e17b05 100644 --- a/mergefilecommand.cpp +++ b/mergefilecommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -MergeFileCommand::MergeFileCommand(string option){ +MergeFileCommand::MergeFileCommand(string option) { try { abort = false; @@ -39,7 +39,7 @@ MergeFileCommand::MergeFileCommand(string option){ if (inputDir == "not found"){ inputDir = ""; } string fileList = validParameter.validFile(parameters, "input", false); - if(fileList == "not found") { mothurOut("you must enter two or more file names"); mothurOutEndLine(); abort=true; } + if(fileList == "not found") { m->mothurOut("you must enter two or more file names"); m->mothurOutEndLine(); abort=true; } else{ splitAtDash(fileList, fileNames); } //if the user changes the output directory command factory will send this info to us in the output parameter @@ -49,7 +49,7 @@ MergeFileCommand::MergeFileCommand(string option){ numInputFiles = fileNames.size(); ifstream testFile; if(numInputFiles == 0){ - mothurOut("you must enter two or more file names and you entered " + toString(fileNames.size()) + " file names"); mothurOutEndLine(); + m->mothurOut("you must enter two or more file names and you entered " + toString(fileNames.size()) + " file names"); m->mothurOutEndLine(); abort=true; } else{ @@ -66,13 +66,13 @@ MergeFileCommand::MergeFileCommand(string option){ } outputFileName = validParameter.validFile(parameters, "output", false); - if (outputFileName == "not found") { mothurOut("you must enter an output file name"); mothurOutEndLine(); abort=true; } + if (outputFileName == "not found") { m->mothurOut("you must enter an output file name"); m->mothurOutEndLine(); abort=true; } else if (outputDir != "") { outputFileName = outputDir + getSimpleName(outputFileName); } } } catch(exception& e) { - errorOut(e, "MergeFileCommand", "MergeFileCommand"); + m->errorOut(e, "MergeFileCommand", "MergeFileCommand"); exit(1); } } @@ -106,10 +106,16 @@ int MergeFileCommand::execute(){ } outputFile.close(); + + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "MergeFileCommand", "execute"); + m->errorOut(e, "MergeFileCommand", "execute"); exit(1); } } @@ -118,10 +124,10 @@ int MergeFileCommand::execute(){ void MergeFileCommand::help(){ try { - mothurOut("The merge.file command..."); mothurOutEndLine(); + m->mothurOut("The merge.file command..."); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "MergeFileCommand", "help"); + m->errorOut(e, "MergeFileCommand", "help"); exit(1); } } diff --git a/mgclustercommand.cpp b/mgclustercommand.cpp index d240de6..bf0b82b 100644 --- a/mgclustercommand.cpp +++ b/mgclustercommand.cpp @@ -10,7 +10,7 @@ #include "mgclustercommand.h" //********************************************************************************************************************** -MGClusterCommand::MGClusterCommand(string option){ +MGClusterCommand::MGClusterCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -72,7 +72,7 @@ MGClusterCommand::MGClusterCommand(string option){ if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } - if ((blastfile == "")) { mothurOut("When executing a mgcluster command you must provide a blastfile."); mothurOutEndLine(); abort = true; } + if ((blastfile == "")) { m->mothurOut("When executing a mgcluster command you must provide a blastfile."); m->mothurOutEndLine(); abort = true; } //check for optional parameter and set defaults string temp; @@ -88,7 +88,7 @@ MGClusterCommand::MGClusterCommand(string option){ if (method == "not found") { method = "furthest"; } if ((method == "furthest") || (method == "nearest") || (method == "average")) { } - else { mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average."); mothurOutEndLine(); abort = true; } + else { m->mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average."); m->mothurOutEndLine(); abort = true; } temp = validParameter.validFile(parameters, "length", false); if (temp == "not found") { temp = "5"; } convert(temp, length); @@ -108,7 +108,7 @@ MGClusterCommand::MGClusterCommand(string option){ } catch(exception& e) { - errorOut(e, "MGClusterCommand", "MGClusterCommand"); + m->errorOut(e, "MGClusterCommand", "MGClusterCommand"); exit(1); } } @@ -116,23 +116,23 @@ MGClusterCommand::MGClusterCommand(string option){ void MGClusterCommand::help(){ try { - mothurOut("The mgcluster command parameter options are blast, name, cutoff, precision, method, merge, min, length, penalty and hcluster. The blast parameter is required.\n"); - mothurOut("The mgcluster command reads a blast and name file and clusters the sequences into OPF units similiar to the OTUs.\n"); - mothurOut("This command outputs a .list, .rabund and .sabund file that can be used with mothur other commands to estimate richness.\n"); - mothurOut("The cutoff parameter is used to specify the maximum distance you would like to cluster to. The default is 0.70.\n"); - mothurOut("The precision parameter's default value is 100. \n"); - mothurOut("The acceptable mgcluster methods are furthest, nearest and average. If no method is provided then furthest is assumed.\n\n"); - 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"); - mothurOut("The length parameter is used to specify the minimum overlap required. The default is 5.\n"); - mothurOut("The penalty parameter is used to adjust the error rate. The default is 0.10.\n"); - 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"); - 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"); - mothurOut("The mgcluster command should be in the following format: \n"); - mothurOut("mgcluster(blast=yourBlastfile, name=yourNameFile, cutoff=yourCutOff).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. balst), '=' and parameters (i.e.yourBlastfile).\n\n"); + 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) { - errorOut(e, "MGClusterCommand", "help"); + m->errorOut(e, "MGClusterCommand", "help"); exit(1); } } @@ -323,13 +323,20 @@ int MGClusterCommand::execute(){ globaldata->setListFile(fileroot+ tag + ".list"); globaldata->setFormat("list"); - - mothurOut("It took " + toString(time(NULL) - start) + " seconds to cluster."); mothurOutEndLine(); + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + m->mothurOut(fileroot+ tag + ".list"); m->mothurOutEndLine(); + m->mothurOut(fileroot+ tag + ".rabund"); m->mothurOutEndLine(); + m->mothurOut(fileroot+ tag + ".sabund"); m->mothurOutEndLine(); + m->mothurOutEndLine(); + + m->mothurOut("It took " + toString(time(NULL) - start) + " seconds to cluster."); m->mothurOutEndLine(); return 0; } catch(exception& e) { - errorOut(e, "MGClusterCommand", "execute"); + m->errorOut(e, "MGClusterCommand", "execute"); exit(1); } } @@ -345,7 +352,7 @@ void MGClusterCommand::printData(ListVector* mergedList){ sabund.print(sabundFile); } catch(exception& e) { - errorOut(e, "MGClusterCommand", "printData"); + m->errorOut(e, "MGClusterCommand", "printData"); exit(1); } } @@ -430,7 +437,7 @@ ListVector* MGClusterCommand::mergeOPFs(map binInfo, float dist){ } catch(exception& e) { - errorOut(e, "MGClusterCommand", "mergeOPFs"); + m->errorOut(e, "MGClusterCommand", "mergeOPFs"); exit(1); } } @@ -448,7 +455,7 @@ void MGClusterCommand::sortHclusterFiles(string unsortedDist, string unsortedOve overlapFile = sortedOverlapFile; } catch(exception& e) { - errorOut(e, "MGClusterCommand", "sortHclusterFiles"); + m->errorOut(e, "MGClusterCommand", "sortHclusterFiles"); exit(1); } } diff --git a/mothur.cpp b/mothur.cpp index 7acf389..ba058ba 100644 --- a/mothur.cpp +++ b/mothur.cpp @@ -10,76 +10,81 @@ #include "mothur.h" #include "engine.hpp" #include "globaldata.hpp" +#include "mothurout.h" /**************************************************************************************************/ GlobalData* GlobalData::_uniqueInstance = 0; CommandFactory* CommandFactory::_uniqueInstance = 0; +MothurOut* MothurOut::_uniqueInstance = 0; int main(int argc, char *argv[]){ + MothurOut* m = MothurOut::getInstance(); try { - string log = "mothur.logFile"; - remove(log.c_str()); + //string log = "mothur.logFile"; + //remove(log.c_str()); time_t ltime = time(NULL); /* calendar time */ string logFileName = "mothur." + toString(ltime) + ".logfile"; + m->setFileName(logFileName); + //version #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) system("clear"); #if defined (__APPLE__) || (__MACH__) - mothurOutJustToLog("Mac version"); - mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutJustToLog("Mac version"); + m->mothurOutEndLine(); m->mothurOutEndLine(); #else - mothurOutJustToLog("Linux version"); - mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutJustToLog("Linux version"); + >m->mothurOutEndLine(); m->mothurOutEndLine(); #endif #else system("CLS"); - mothurOutJustToLog("Windows version"); - mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutJustToLog("Windows version"); + m->mothurOutEndLine(); m->mothurOutEndLine(); #endif #ifdef USE_READLINE - mothurOutJustToLog("Using ReadLine"); - mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutJustToLog("Using ReadLine"); + m->mothurOutEndLine(); m->mothurOutEndLine(); #endif //header - mothurOut("mothur v.1.8"); - mothurOutEndLine(); - mothurOut("Last updated: 2/02/2010"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("by"); - mothurOutEndLine(); - mothurOut("Patrick D. Schloss"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("Department of Microbiology & Immunology"); - mothurOutEndLine(); - mothurOut("University of Michigan"); - mothurOutEndLine(); - mothurOut("pschloss@umich.edu"); - mothurOutEndLine(); - mothurOut("http://www.mothur.org"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("When using, please cite:"); - mothurOutEndLine(); - mothurOut("Schloss, P.D., et al., Introducing mothur: Open-source, platform-independent, community-supported software for describing and comparing microbial communities. Appl Environ Microbiol, 2009. 75(23):7537-41."); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("Distributed under the GNU General Public License"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("Type 'help()' for information on the commands that are available"); - mothurOutEndLine(); - mothurOutEndLine(); - mothurOut("Type 'quit()' to exit program"); - mothurOutEndLine(); + m->mothurOut("mothur v.1.8"); + m->mothurOutEndLine(); + m->mothurOut("Last updated: 2/02/2010"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("by"); + m->mothurOutEndLine(); + m->mothurOut("Patrick D. Schloss"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Department of Microbiology & Immunology"); + m->mothurOutEndLine(); + m->mothurOut("University of Michigan"); + m->mothurOutEndLine(); + m->mothurOut("pschloss@umich.edu"); + m->mothurOutEndLine(); + m->mothurOut("http://www.mothur.org"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("When using, please cite:"); + m->mothurOutEndLine(); + m->mothurOut("Schloss, P.D., et al., Introducing mothur: Open-source, platform-independent, community-supported software for describing and comparing microbial communities. Appl Environ Microbiol, 2009. 75(23):7537-41."); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Distributed under the GNU General Public License"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Type 'help()' for information on the commands that are available"); + m->mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("Type 'quit()' to exit program"); + m->mothurOutEndLine(); //srand(54321); @@ -93,20 +98,20 @@ int main(int argc, char *argv[]){ input = argv[1]; if (input[0] == '#') { - mothurOutJustToLog("Script Mode"); - mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutJustToLog("Script Mode"); + m->mothurOutEndLine(); m->mothurOutEndLine(); mothur = new ScriptEngine(argv[0], argv[1]); }else{ - mothurOutJustToLog("Batch Mode"); - mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutJustToLog("Batch Mode"); + m->mothurOutEndLine(); m->mothurOutEndLine(); mothur = new BatchEngine(argv[0], argv[1]); } } else{ - mothurOutJustToLog("Interactive Mode"); - mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutJustToLog("Interactive Mode"); + m->mothurOutEndLine(); m->mothurOutEndLine(); mothur = new InteractEngine(argv[0]); } @@ -114,17 +119,17 @@ int main(int argc, char *argv[]){ while(bail == 0) { bail = mothur->getInput(); } string outputDir = mothur->getOutputDir(); - logFileName = outputDir + logFileName; + string newlogFileName = outputDir + logFileName; - //need this because mothur.h makes the logfile, but doesn't know where to put it - rename(log.c_str(), logFileName.c_str()); //logfile with timestamp + //need this because m->mothurOut makes the logfile, but doesn't know where to put it + rename(logFileName.c_str(), newlogFileName.c_str()); //logfile with timestamp delete mothur; return 0; } catch(exception& e) { - errorOut(e, "mothur", "main"); + m->errorOut(e, "mothur", "main"); exit(1); } } diff --git a/mothur.h b/mothur.h index 5f8a2fe..db11ed1 100644 --- a/mothur.h +++ b/mothur.h @@ -198,7 +198,7 @@ inline int openOutputFileAppend(string fileName, ofstream& fileHandle){ fileHandle.open(fileName.c_str(), ios::app); if(!fileHandle) { - cout << "Error: Could not open " << fileName << endl; + cout << "Error: Could not open " << fileName << endl; return 1; } else { @@ -240,74 +240,6 @@ inline string getline(ifstream& fileHandle) { } } -/**************************************************************************************************/ - -inline void mothurOut(string message) { - try{ - ofstream out; - string logFileName = "mothur.logFile"; - openOutputFileAppend(logFileName, out); - - cout << message; - out << message; - - out.close(); - } - catch(exception& e) { - cout << "Error in mothur class mothurOut" << endl; - exit(1); - } -} -/**************************************************************************************************/ - -inline void mothurOut(string message, string precision) { - try{ - ofstream out; - string logFileName = "mothur.logFile"; - openOutputFileAppend(logFileName, out); - - cout << precision << message; - out << precision << message; - - out.close(); - } - catch(exception& e) { - cout << "Error in mothur class mothurOut" << endl; - exit(1); - } -} - -/**************************************************************************************************/ - -inline void mothurOutEndLine() { - try { - ofstream out; - string logFileName = "mothur.logFile"; - openOutputFileAppend(logFileName, out); - - cout << endl; - out << endl; - - out.close(); - } - catch(exception& e) { - cout << "error in mothur mothurOutEndLine" << endl; - exit(1); - } -} - - -/**************************************************************************************************/ - -inline void errorOut(exception& e, string object, string function) { - - mothurOut("Error: "); - mothurOut(toString(e.what())); - mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry."); - mothurOutEndLine(); - -} - /***********************************************************************/ inline bool isTrue(string f){ @@ -475,7 +407,7 @@ inline bool isBlank(string fileName){ ifstream fileHandle; fileHandle.open(fileName.c_str()); if(!fileHandle) { - mothurOut("Error: Could not open " + fileName); mothurOutEndLine(); + cout << "Error: Could not open " << fileName << endl; return false; }else { //check for blank file @@ -488,6 +420,7 @@ inline bool isBlank(string fileName){ inline string getFullPathName(string fileName){ try{ + string path = hasPath(fileName); string newFileName; int pos; @@ -535,7 +468,7 @@ inline string getFullPathName(string fileName){ }else if (path[(pos-1)] == '/') { //you want the current working dir ./ path = path.substr(0, pos); }else if (pos == 1) { break; - }else { mothurOut("cannot resolve path for " + fileName); mothurOutEndLine(); return fileName; } + }else { cout << "cannot resolve path for " << fileName << endl; return fileName; } } for (int i = index; i >= 0; i--) { @@ -575,7 +508,7 @@ inline string getFullPathName(string fileName){ }else if (path[(pos-1)] == '\\') { //you want the current working dir ./ path = path.substr(0, pos); }else if (pos == 1) { break; - }else { mothurOut("cannot resolve path for " + fileName); mothurOutEndLine(); return fileName; } + }else { cout << "cannot resolve path for " << fileName << endl; return fileName; } } for (int i = index; i >= 0; i--) { @@ -588,11 +521,9 @@ inline string getFullPathName(string fileName){ } } catch(exception& e) { - errorOut(e, "getFullPathName", "getFullPathName"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function getFullPathName. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } - - + } } /***********************************************************************/ @@ -613,18 +544,19 @@ inline int openInputFile(string fileName, ifstream& fileHandle, string m){ /***********************************************************************/ inline int openInputFile(string fileName, ifstream& fileHandle){ + //get full path name string completeFileName = getFullPathName(fileName); fileHandle.open(completeFileName.c_str()); if(!fileHandle) { - mothurOut("Error: Could not open " + completeFileName); mothurOutEndLine(); + cout << "Error: Could not open " << completeFileName << endl; return 1; } else { //check for blank file gobble(fileHandle); - if (fileHandle.eof()) { mothurOut(completeFileName + " is blank. Please correct."); mothurOutEndLine(); return 1; } + if (fileHandle.eof()) { cout << completeFileName << " is blank. Please correct." << endl; return 1; } return 0; } @@ -656,12 +588,12 @@ inline int renameFile(string oldName, string newName){ /***********************************************************************/ inline int openOutputFile(string fileName, ofstream& fileHandle){ - + string completeFileName = getFullPathName(fileName); fileHandle.open(completeFileName.c_str(), ios::trunc); if(!fileHandle) { - mothurOut("Error: Could not open " + completeFileName); mothurOutEndLine(); + cout << "Error: Could not open " << completeFileName << endl; return 1; } else { @@ -707,9 +639,9 @@ inline void splitAtDash(string& estim, vector& container) { container.push_back(estim); } catch(exception& e) { - errorOut(e, "mothur", "splitAtDash"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtDash. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /***********************************************************************/ @@ -729,9 +661,9 @@ inline void splitAtDash(string& estim, set& container) { container.insert(estim); } catch(exception& e) { - errorOut(e, "mothur", "splitAtDash"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtDash. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /***********************************************************************/ //This function parses the line options and puts them in a set @@ -753,9 +685,9 @@ inline void splitAtDash(string& estim, set& container) { container.insert(lineNum); } catch(exception& e) { - errorOut(e, "mothur", "splitAtDash"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtDash. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /***********************************************************************/ //This function parses the a string and puts peices in a vector @@ -774,9 +706,9 @@ inline void splitAtComma(string& estim, vector& container) { container.push_back(estim); } catch(exception& e) { - errorOut(e, "mothur", "splitAtComma"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtComma. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /***********************************************************************/ @@ -793,9 +725,9 @@ inline void splitAtComma(string& prefix, string& suffix){ } catch(exception& e) { - errorOut(e, "mothur", "splitAtComma"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtComma. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /***********************************************************************/ @@ -813,9 +745,9 @@ inline void splitAtEquals(string& key, string& value){ } } catch(exception& e) { - errorOut(e, "mothur", "splitAtEquals"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function splitAtEquals. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /**************************************************************************************************/ @@ -827,9 +759,9 @@ inline bool inUsersGroups(string groupname, vector Groups) { return false; } catch(exception& e) { - errorOut(e, "mothur", "inUsersGroups"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function inUsersGroups. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /**************************************************************************************************/ //returns true if any of the strings in first vector are in second vector @@ -842,72 +774,17 @@ inline bool inUsersGroups(vector groupnames, vector Groups) { return false; } catch(exception& e) { - errorOut(e, "mothur", "inUsersGroups"); - exit(1); - } -} - -/**************************************************************************************************/ - -inline void mothurOutJustToLog(string message) { - try { - ofstream out; - string logFileName = "mothur.logFile"; - openOutputFileAppend(logFileName, out); - - out << message; - - out.close(); - } - catch(exception& e) { - errorOut(e, "mothur", "mothurOutJustToLog"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function inUsersGroups. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } -} - - -/**************************************************************************************************/ - -inline void mothurOut(float num) { - try { - ofstream out; - string logFileName = "mothur.logFile"; - openOutputFileAppend(logFileName, out); - - cout << num; - out << num; - - out.close(); - } - catch(exception& e) { - cout << "Error in mothur class mothurOut float" << endl; - exit(1); - } -} -/***********************************************************************/ -inline void mothurOut(double value) { - try { - ofstream out; - string logFileName = "mothur.logFile"; - openOutputFileAppend(logFileName, out); - - cout << value; - out << value; - - out.close(); - } - catch(exception& e) { - cout << "Error in mothur class mothurOut double" << endl; - exit(1); - } + } } - /***********************************************************************/ //this function determines if the user has given us labels that are smaller than the given label. //if so then it returns true so that the calling function can run the previous valid distance. //it's a "smart" distance function. It also checks for invalid labels. inline bool anyLabelsToProcess(string label, set& userLabels, string errorOff) { try { + set::iterator it; vector orderFloat; map userMap; //the conversion process removes trailing 0's which we need to put back @@ -931,7 +808,7 @@ inline bool anyLabelsToProcess(string label, set& userLabels, string err orderFloat.push_back(-1.0); userMap["unique"] = -1.0; }else { - if (errorOff == "") { mothurOut(*it + " is not a valid label."); mothurOutEndLine(); } + if (errorOff == "") { cout << *it << " is not a valid label." << endl; } userLabels.erase(*it); it--; } @@ -949,11 +826,11 @@ inline bool anyLabelsToProcess(string label, set& userLabels, string err if (orderFloat[i] < labelFloat) { smaller = true; if (orderFloat[i] == -1) { - if (errorOff == "") { mothurOut("Your file does not include the label unique."); mothurOutEndLine(); } + if (errorOff == "") { cout << "Your file does not include the label unique." << endl; } userLabels.erase("unique"); } else { - if (errorOff == "") { mothurOut("Your file does not include the label "); mothurOutEndLine(); } + if (errorOff == "") { cout << "Your file does not include the label " << endl; } string s = ""; for (it2 = userMap.begin(); it2!= userMap.end(); it2++) { if (it2->second == orderFloat[i]) { @@ -963,7 +840,7 @@ inline bool anyLabelsToProcess(string label, set& userLabels, string err break; } } - if (errorOff == "") { mothurOut(s + ". I will use the next smallest distance. "); mothurOutEndLine(); } + if (errorOff == "") {cout << s << ". I will use the next smallest distance. " << endl; } } //since they are sorted once you find a bigger one stop looking }else { break; } @@ -973,9 +850,9 @@ inline bool anyLabelsToProcess(string label, set& userLabels, string err } catch(exception& e) { - errorOut(e, "mothur", "anyLabelsToProcess"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function anyLabelsToProcess. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /**************************************************************************************************/ @@ -997,9 +874,9 @@ inline void appendFiles(string temp, string filename) { output.close(); } catch(exception& e) { - errorOut(e, "mothur", "appendFiles"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function appendFiles. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /**************************************************************************************************/ @@ -1060,9 +937,9 @@ inline string sortFile(string distFile){ return outfile; } catch(exception& e) { - errorOut(e, "mothur", "sortFile"); + cout << "Standard Error: " << e.what() << " has occurred in the mothur.h function sortfile. Please contact Pat Schloss at mothur.bugs@gmail.com." << "\n"; exit(1); - } + } } /**************************************************************************************************/ #endif diff --git a/nameassignment.cpp b/nameassignment.cpp index bc088f4..42d374d 100644 --- a/nameassignment.cpp +++ b/nameassignment.cpp @@ -5,7 +5,7 @@ //********************************************************************************************************************** NameAssignment::NameAssignment(string nameMapFile){ - + m = MothurOut::getInstance(); openInputFile(nameMapFile, fileHandle); } @@ -36,7 +36,7 @@ void NameAssignment::readMap(){ } catch(exception& e) { - errorOut(e, "NameAssignment", "readMap"); + m->errorOut(e, "NameAssignment", "readMap"); exit(1); } } @@ -51,7 +51,7 @@ void NameAssignment::push_back(string name) { list.push_back(name); } catch(exception& e) { - errorOut(e, "NameAssignment", "push_back"); + m->errorOut(e, "NameAssignment", "push_back"); exit(1); } } @@ -75,7 +75,7 @@ void NameAssignment::print(ostream& out){ } } catch(exception& e) { - errorOut(e, "NameAssignment", "print"); + m->errorOut(e, "NameAssignment", "print"); exit(1); } } diff --git a/nameassignment.hpp b/nameassignment.hpp index 3ccb425..758a080 100644 --- a/nameassignment.hpp +++ b/nameassignment.hpp @@ -18,6 +18,7 @@ private: ifstream fileHandle; ListVector list; map reverse; + MothurOut* m; }; diff --git a/nast.cpp b/nast.cpp index c91c9fa..4a0b74a 100644 --- a/nast.cpp +++ b/nast.cpp @@ -23,12 +23,13 @@ Nast::Nast(Alignment* method, Sequence* cand, Sequence* temp) : alignment(method), candidateSeq(cand), templateSeq(temp) { try { + m = MothurOut::getInstance(); maxInsertLength = 0; pairwiseAlignSeqs(); // This is part A in Fig. 2 of DeSantis et al. regapSequences(); // This is parts B-F in Fig. 2 of DeSantis et al. } catch(exception& e) { - errorOut(e, "Nast", "Nast"); + m->errorOut(e, "Nast", "Nast"); exit(1); } } @@ -78,7 +79,7 @@ void Nast::pairwiseAlignSeqs(){ // Here we call one of the pairwise alignment me templateSeq->setPairwise(tempAln); // the candidate and template sequences } catch(exception& e) { - errorOut(e, "Nast", "pairwiseAlignSeqs"); + m->errorOut(e, "Nast", "pairwiseAlignSeqs"); exit(1); } } @@ -199,7 +200,7 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl } } catch(exception& e) { - errorOut(e, "Nast", "removeExtraGaps"); + m->errorOut(e, "Nast", "removeExtraGaps"); exit(1); } } @@ -302,14 +303,14 @@ void Nast::regapSequences(){ //This is essentially part B in Fig 2. of DeSantis // would skip the gaps and not progress through full alignment sequence // not tested yet - mothurOut("We're into D " + toString(fullAlignIndex) + " " + toString(pairwiseAlignIndex)); mothurOutEndLine(); + m->mothurOut("We're into D " + toString(fullAlignIndex) + " " + toString(pairwiseAlignIndex)); m->mothurOutEndLine(); pairwiseAlignIndex++; } else{ // everything has a gap - not possible // not tested yet - mothurOut("We're into F " + toString(fullAlignIndex) + " " + toString(pairwiseAlignIndex)); mothurOutEndLine(); + m->mothurOut("We're into F " + toString(fullAlignIndex) + " " + toString(pairwiseAlignIndex)); m->mothurOutEndLine(); pairwiseAlignIndex++; fullAlignIndex++; } @@ -345,7 +346,7 @@ void Nast::regapSequences(){ //This is essentially part B in Fig 2. of DeSantis candidateSeq->setAligned(candAln); } catch(exception& e) { - errorOut(e, "Nast", "regapSequences"); + m->errorOut(e, "Nast", "regapSequences"); exit(1); } } @@ -380,7 +381,7 @@ float Nast::getSimilarityScore(){ } catch(exception& e) { - errorOut(e, "Nast", "getSimilarityScore"); + m->errorOut(e, "Nast", "getSimilarityScore"); exit(1); } } diff --git a/nast.hpp b/nast.hpp index bc2467f..9428aed 100644 --- a/nast.hpp +++ b/nast.hpp @@ -19,6 +19,7 @@ */ #include "mothur.h" +#include "mothurout.h" class Alignment; class Sequence; @@ -43,6 +44,7 @@ private: Sequence* templateSeq; int maxInsertLength; + MothurOut* m; }; /**************************************************************************************************/ diff --git a/needlemanoverlap.cpp b/needlemanoverlap.cpp index 80ba4ca..d13925e 100644 --- a/needlemanoverlap.cpp +++ b/needlemanoverlap.cpp @@ -24,8 +24,8 @@ /**************************************************************************************************/ -NeedlemanOverlap::NeedlemanOverlap(float gO, float m, float mm, int r) :// note that we don't have a gap extend -gap(gO), match(m), mismatch(mm), Alignment(r) { // the gap openning penalty is assessed for +NeedlemanOverlap::NeedlemanOverlap(float gO, float f, float mm, int r) :// note that we don't have a gap extend +gap(gO), match(f), mismatch(mm), Alignment(r) { // the gap openning penalty is assessed for try { // every gapped position for(int i=1;ierrorOut(e, "NeedlemanOverlap", "NeedlemanOverlap"); exit(1); } } @@ -54,7 +54,7 @@ void NeedlemanOverlap::align(string A, string B){ seqA = ' ' + A; lA = seqA.length(); // algorithm requires a dummy space at the beginning of each string seqB = ' ' + B; lB = seqB.length(); // algorithm requires a dummy space at the beginning of each string - if (lA > nRows) { mothurOut("One of your candidate sequences is longer than you longest template sequence. Your longest template sequence is " + toString(nRows) + ". Your candidate is " + toString(lA) + "."); mothurOutEndLine(); } + if (lA > nRows) { m->mothurOut("One of your candidate sequences is longer than you longest template sequence. Your longest template sequence is " + toString(nRows) + ". Your candidate is " + toString(lA) + "."); m->mothurOutEndLine(); } for(int i=1;ierrorOut(e, "NeedlemanOverlap", "align"); exit(1); } diff --git a/nocommands.cpp b/nocommands.cpp index b519d77..459ac5c 100644 --- a/nocommands.cpp +++ b/nocommands.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -NoCommand::NoCommand(string option){} +NoCommand::NoCommand(string option) {} //********************************************************************************************************************** @@ -21,7 +21,7 @@ NoCommand::~NoCommand(){} int NoCommand::execute(){ //Could choose to give more help here?fdsah - mothurOut("Invalid command.\n"); + cout << "Invalid command.\n"; CommandFactory* valid = CommandFactory::getInstance(); valid->printCommands(cout); diff --git a/npshannon.cpp b/npshannon.cpp index fda649c..f14f922 100644 --- a/npshannon.cpp +++ b/npshannon.cpp @@ -43,7 +43,7 @@ EstOutput NPShannon::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "NPShannon", "getValues"); + m->errorOut(e, "NPShannon", "getValues"); exit(1); } } diff --git a/optionparser.cpp b/optionparser.cpp index 8f0e29d..c50d5a3 100644 --- a/optionparser.cpp +++ b/optionparser.cpp @@ -13,7 +13,7 @@ OptionParser::OptionParser(string option) { try { - + m = MothurOut::getInstance(); if (option != "") { string key, value; @@ -30,7 +30,7 @@ OptionParser::OptionParser(string option) { } } catch(exception& e) { - errorOut(e, "OptionParser", "parse"); + m->errorOut(e, "OptionParser", "parse"); exit(1); } } diff --git a/optionparser.h b/optionparser.h index dab14de..7707e73 100644 --- a/optionparser.h +++ b/optionparser.h @@ -13,6 +13,7 @@ #include "mothur.h" +#include "mothurout.h" /***********************************************************************/ @@ -24,6 +25,7 @@ public: map getParameters(); private: map parameters; + MothurOut* m; }; /***********************************************************************/ diff --git a/ordervector.cpp b/ordervector.cpp index 360c898..27c1e93 100644 --- a/ordervector.cpp +++ b/ordervector.cpp @@ -47,7 +47,7 @@ OrderVector::OrderVector(ifstream& f) : DataVector() { updateStats(); } catch(exception& e) { - errorOut(e, "OrderVector", "OrderVector"); + m->errorOut(e, "OrderVector", "OrderVector"); exit(1); } } @@ -112,7 +112,7 @@ void OrderVector::print(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "OrderVector", "print"); + m->errorOut(e, "OrderVector", "print"); exit(1); } } @@ -129,7 +129,7 @@ void OrderVector::print(string prefix, ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "OrderVector", "print"); + m->errorOut(e, "OrderVector", "print"); exit(1); } } @@ -137,7 +137,7 @@ void OrderVector::print(string prefix, ostream& output){ /***********************************************************************/ void OrderVector::resize(int){ - mothurOut("resize() did nothing in class OrderVector"); + m->mothurOut("resize() did nothing in class OrderVector"); } /***********************************************************************/ @@ -179,7 +179,7 @@ RAbundVector OrderVector::getRAbundVector(){ return rav; } catch(exception& e) { - errorOut(e, "OrderVector", "getRAbundVector"); + m->errorOut(e, "OrderVector", "getRAbundVector"); exit(1); } } @@ -228,7 +228,7 @@ void OrderVector::updateStats(){ } } catch(exception& e) { - errorOut(e, "OrderVector", "updateStats"); + m->errorOut(e, "OrderVector", "updateStats"); exit(1); } } diff --git a/otuhierarchycommand.cpp b/otuhierarchycommand.cpp index c39a638..a8a3531 100644 --- a/otuhierarchycommand.cpp +++ b/otuhierarchycommand.cpp @@ -10,9 +10,10 @@ #include "otuhierarchycommand.h" //********************************************************************************************************************** -OtuHierarchyCommand::OtuHierarchyCommand(string option){ +OtuHierarchyCommand::OtuHierarchyCommand(string option) { try { abort = false; + //allow user to run help if(option == "help") { help(); abort = true; } @@ -47,7 +48,7 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option){ } listFile = validParameter.validFile(parameters, "list", true); - if (listFile == "not found") { mothurOut("list is a required parameter for the otu.hierarchy command."); mothurOutEndLine(); abort = 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 the user changes the output directory command factory will send this info to us in the output parameter @@ -59,20 +60,20 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option){ //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") { mothurOut("label is a required parameter for the otu.hierarchy command."); mothurOutEndLine(); abort = true; } + if (label == "not found") { m->mothurOut("label is a required parameter for the otu.hierarchy command."); m->mothurOutEndLine(); abort = true; } else { splitAtDash(label, labels); - if (labels.size() != 2) { mothurOut("You must provide 2 labels."); mothurOutEndLine(); abort = true; } + if (labels.size() != 2) { m->mothurOut("You must provide 2 labels."); m->mothurOutEndLine(); abort = true; } } output = validParameter.validFile(parameters, "output", false); if (output == "not found") { output = "name"; } - if ((output != "name") && (output != "number")) { mothurOut("output options are name and number. I will use name."); mothurOutEndLine(); output = "name"; } + if ((output != "name") && (output != "number")) { m->mothurOut("output options are name and number. I will use name."); m->mothurOutEndLine(); output = "name"; } } } catch(exception& e) { - errorOut(e, "OtuHierarchyCommand", "OtuHierarchyCommand"); + m->errorOut(e, "OtuHierarchyCommand", "OtuHierarchyCommand"); exit(1); } } @@ -80,17 +81,17 @@ OtuHierarchyCommand::OtuHierarchyCommand(string option){ void OtuHierarchyCommand::help(){ try { - mothurOut("The otu.hierarchy command is used to see how otus relate at two distances. \n"); - mothurOut("The otu.hierarchy command parameters are list, label and output. list and label parameters are required. \n"); - 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"); - mothurOut("The otu.hierarchy command should be in the following format: \n"); - mothurOut("otu.hierarchy(list=yourListFile, label=yourLabels).\n"); - mothurOut("Example otu.hierarchy(list=amazon.fn.list, label=0.01-0.03).\n"); - mothurOut("The otu.hierarchy command outputs a .otu.hierarchy file which is described on the wiki.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListFile).\n\n"); + 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) { - errorOut(e, "OtuHierarchyCommand", "help"); + m->errorOut(e, "OtuHierarchyCommand", "help"); exit(1); } } @@ -116,7 +117,7 @@ int OtuHierarchyCommand::execute(){ reverse(lists.begin(), lists.end()); } }else{ - mothurOut("error getting listvectors, unable to read 2 different vectors, check your label inputs."); mothurOutEndLine(); return 0; + m->mothurOut("error getting listvectors, unable to read 2 different vectors, check your label inputs."); m->mothurOutEndLine(); return 0; } //map sequences to bin number in the "little" otu @@ -173,10 +174,15 @@ int OtuHierarchyCommand::execute(){ out.close(); + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outputFileName); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "OtuHierarchyCommand", "execute"); + m->errorOut(e, "OtuHierarchyCommand", "execute"); exit(1); } } @@ -264,12 +270,12 @@ vector OtuHierarchyCommand::getListVectors() { set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -293,7 +299,7 @@ vector OtuHierarchyCommand::getListVectors() { return lists; } catch(exception& e) { - errorOut(e, "OtuHierarchyCommand", "getListVectors"); + m->errorOut(e, "OtuHierarchyCommand", "getListVectors"); exit(1); } } diff --git a/parselistscommand.cpp b/parselistscommand.cpp index ce014fc..4838988 100644 --- a/parselistscommand.cpp +++ b/parselistscommand.cpp @@ -14,7 +14,7 @@ ParseListCommand::ParseListCommand(string option) { try { abort = false; allLines = 1; - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -76,7 +76,7 @@ ParseListCommand::ParseListCommand(string option) { } //do you have all files needed - if ((listfile == "") || (groupfile == "")) { mothurOut("You must enter both a listfile and groupfile for the parse.list command. "); mothurOutEndLine(); abort = true; } + if ((listfile == "") || (groupfile == "")) { m->mothurOut("You must enter both a listfile and groupfile for the parse.list command. "); m->mothurOutEndLine(); abort = true; } //check for optional parameter and set defaults // ...at some point should added some additional type checking... @@ -90,24 +90,24 @@ ParseListCommand::ParseListCommand(string option) { } catch(exception& e) { - errorOut(e, "ParseListCommand", "ParseListCommand"); + m->errorOut(e, "ParseListCommand", "ParseListCommand"); exit(1); } } //********************************************************************************************************************** void ParseListCommand::help(){ try { - mothurOut("The parse.list command reads a list and group file and generates a list file for each group in the groupfile \n"); - mothurOut("The parse.list command parameters are list, group and label.\n"); - mothurOut("The list and group parameters are required.\n"); - mothurOut("The label parameter is used to read specific labels in your input you want to use.\n"); - mothurOut("The parse.list command should be used in the following format: parse.list(list=yourListFile, group=yourGroupFile, label=yourLabels).\n"); - mothurOut("Example: parse.list(list=abrecovery.fn.list, group=abrecovery.groups, label=0.03).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); + 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) { - errorOut(e, "ParseListCommand", "help"); + m->errorOut(e, "ParseListCommand", "help"); exit(1); } } @@ -121,6 +121,7 @@ int ParseListCommand::execute(){ //set fileroot string fileroot = outputDir + getRootName(getSimpleName(listfile)); + vector outputNames; //fill filehandles with neccessary ofstreams int i; @@ -130,6 +131,7 @@ int ParseListCommand::execute(){ filehandles[groupMap->namesOfGroups[i]] = temp; string filename = fileroot + groupMap->namesOfGroups[i] + ".list"; + outputNames.push_back(filename); openOutputFile(filename, *temp); } @@ -146,7 +148,7 @@ int ParseListCommand::execute(){ if(allLines == 1 || labels.count(list->getLabel()) == 1){ parse(list); - mothurOut(list->getLabel()); mothurOutEndLine(); + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -159,7 +161,7 @@ int ParseListCommand::execute(){ list = input->getListVector(lastLabel); //get new list vector to process parse(list); - mothurOut(list->getLabel()); mothurOutEndLine(); + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); processedLabels.insert(list->getLabel()); userLabels.erase(list->getLabel()); @@ -179,12 +181,12 @@ int ParseListCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -195,7 +197,7 @@ int ParseListCommand::execute(){ list = input->getListVector(lastLabel); //get new list vector to process parse(list); - mothurOut(list->getLabel()); mothurOutEndLine(); + m->mothurOut(list->getLabel()); m->mothurOutEndLine(); delete list; } @@ -207,10 +209,15 @@ int ParseListCommand::execute(){ 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(); } + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "ParseListCommand", "execute"); + m->errorOut(e, "ParseListCommand", "execute"); exit(1); } } @@ -241,7 +248,7 @@ void ParseListCommand::parse(ListVector* thisList) { for (int j = 0; j < names.size(); j++) { string group = groupMap->getGroup(names[j]); - if (group == "not found") { mothurOut(names[j] + " is not in your groupfile. please correct."); mothurOutEndLine(); exit(1); } + if (group == "not found") { m->mothurOut(names[j] + " is not in your groupfile. please correct."); m->mothurOutEndLine(); exit(1); } itGroup = groupBins.find(group); if(itGroup == groupBins.end()) { @@ -267,7 +274,7 @@ void ParseListCommand::parse(ListVector* thisList) { } catch(exception& e) { - errorOut(e, "ParseListCommand", "parse"); + m->errorOut(e, "ParseListCommand", "parse"); exit(1); } } diff --git a/parsimony.cpp b/parsimony.cpp index db6ed1d..16c7748 100644 --- a/parsimony.cpp +++ b/parsimony.cpp @@ -123,7 +123,7 @@ EstOutput Parsimony::getValues(Tree* t) { return data; } catch(exception& e) { - errorOut(e, "Parsimony", "getValues"); + m->errorOut(e, "Parsimony", "getValues"); exit(1); } } diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index da997c1..393c0f8 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -10,12 +10,12 @@ #include "parsimonycommand.h" /***********************************************************/ -ParsimonyCommand::ParsimonyCommand(string option) { +ParsimonyCommand::ParsimonyCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; Groups.clear(); - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -39,7 +39,7 @@ ParsimonyCommand::ParsimonyCommand(string option) { //are you trying to use parsimony without reading a tree or saying you want random distribution if (randomtree == "") { if (globaldata->gTree.size() == 0) { - 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."); mothurOutEndLine(); abort = true; } + 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; } } //if the user changes the output directory command factory will send this info to us in the output parameter @@ -66,15 +66,18 @@ ParsimonyCommand::ParsimonyCommand(string option) { if(outputDir == "") { outputDir += hasPath(globaldata->getTreeFile()); } output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile()) + ".parsimony", itersString); + outputNames.push_back(outputDir + getSimpleName(globaldata->getTreeFile()) + ".parsimony"); sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".psummary"; openOutputFile(sumFile, outSum); + outputNames.push_back(sumFile); }else { //user wants random distribution savetmap = globaldata->gTreemap; getUserInput(); if(outputDir == "") { outputDir += hasPath(randomtree); } output = new ColumnFile(outputDir+ getSimpleName(randomtree), itersString); + outputNames.push_back(outputDir+ getSimpleName(randomtree)); } //set users groups to analyze @@ -93,7 +96,7 @@ ParsimonyCommand::ParsimonyCommand(string option) { } catch(exception& e) { - errorOut(e, "ParsimonyCommand", "ParsimonyCommand"); + m->errorOut(e, "ParsimonyCommand", "ParsimonyCommand"); exit(1); } } @@ -102,18 +105,18 @@ ParsimonyCommand::ParsimonyCommand(string option) { void ParsimonyCommand::help(){ try { - mothurOut("The parsimony command can only be executed after a successful read.tree command, unless you use the random parameter.\n"); - mothurOut("The parsimony command parameters are random, groups and iters. No parameters are required.\n"); - 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"); - 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"); - mothurOut("The parsimony command should be in the following format: parsimony(random=yourOutputFilename, groups=yourGroups, iters=yourIters).\n"); - mothurOut("Example parsimony(random=out, iters=500).\n"); - 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"); - mothurOut("and iters is 1000. The parsimony command output two files: .parsimony and .psummary their descriptions are in the manual.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. random), '=' and parameters (i.e.yourOutputFilename).\n\n"); + 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 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("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) { - errorOut(e, "ParsimonyCommand", "help"); + m->errorOut(e, "ParsimonyCommand", "help"); exit(1); } } @@ -268,11 +271,17 @@ int ParsimonyCommand::execute() { //reset groups parameter globaldata->Groups.clear(); + 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; } catch(exception& e) { - errorOut(e, "ParsimonyCommand", "execute"); + m->errorOut(e, "ParsimonyCommand", "execute"); exit(1); } } @@ -305,7 +314,7 @@ void ParsimonyCommand::printParsimonyFile() { } } catch(exception& e) { - errorOut(e, "ParsimonyCommand", "printParsimonyFile"); + m->errorOut(e, "ParsimonyCommand", "printParsimonyFile"); exit(1); } } @@ -314,7 +323,7 @@ void ParsimonyCommand::printUSummaryFile() { try { //column headers outSum << "Tree#" << '\t' << "Groups" << '\t' << "ParsScore" << '\t' << "ParsSig" << endl; - mothurOut("Tree#\tGroups\tParsScore\tParsSig"); mothurOutEndLine(); + m->mothurOut("Tree#\tGroups\tParsScore\tParsSig"); m->mothurOutEndLine(); //format output outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint); @@ -326,11 +335,11 @@ void ParsimonyCommand::printUSummaryFile() { if (UScoreSig[a][i] > (1/(float)iters)) { outSum << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << UScoreSig[a][i] << endl; cout << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << UScoreSig[a][i] << endl; - mothurOutJustToLog(toString(i+1) + "\t" + groupComb[a] + "\t" + toString(userTreeScores[a][i]) + "\t" + toString(UScoreSig[a][i])); mothurOutEndLine(); + m->mothurOutJustToLog(toString(i+1) + "\t" + groupComb[a] + "\t" + toString(userTreeScores[a][i]) + "\t" + toString(UScoreSig[a][i])); m->mothurOutEndLine(); }else { outSum << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << "<" << (1/float(iters)) << endl; cout << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(itersString.length()) << '\t' << "<" << (1/float(iters)) << endl; - mothurOutJustToLog(toString(i+1) + "\t" + groupComb[a] + "\t" + toString(userTreeScores[a][i]) + "\t" + toString((1/float(iters)))); mothurOutEndLine(); + m->mothurOutJustToLog(toString(i+1) + "\t" + groupComb[a] + "\t" + toString(userTreeScores[a][i]) + "\t" + toString((1/float(iters)))); m->mothurOutEndLine(); } } } @@ -338,7 +347,7 @@ void ParsimonyCommand::printUSummaryFile() { outSum.close(); } catch(exception& e) { - errorOut(e, "ParsimonyCommand", "printUSummaryFile"); + m->errorOut(e, "ParsimonyCommand", "printUSummaryFile"); exit(1); } } @@ -350,18 +359,18 @@ void ParsimonyCommand::getUserInput() { //create treemap tmap = new TreeMap(); - mothurOut("Please enter the number of groups you would like to analyze: "); + m->mothurOut("Please enter the number of groups you would like to analyze: "); cin >> numGroups; - mothurOutJustToLog(toString(numGroups)); mothurOutEndLine(); + m->mothurOutJustToLog(toString(numGroups)); m->mothurOutEndLine(); int num, count; count = 1; numEachGroup.resize(numGroups, 0); for (int i = 1; i <= numGroups; i++) { - mothurOut("Please enter the number of sequences in group " + toString(i) + ": "); + m->mothurOut("Please enter the number of sequences in group " + toString(i) + ": "); cin >> num; - mothurOutJustToLog(toString(num)); mothurOutEndLine(); + m->mothurOutJustToLog(toString(num)); m->mothurOutEndLine(); //set tmaps seqsPerGroup tmap->seqsPerGroup[toString(i)] = num; @@ -387,7 +396,7 @@ void ParsimonyCommand::getUserInput() { } catch(exception& e) { - errorOut(e, "ParsimonyCommand", "getUserInput"); + m->errorOut(e, "ParsimonyCommand", "getUserInput"); exit(1); } } diff --git a/parsimonycommand.h b/parsimonycommand.h index f855d86..071aea8 100644 --- a/parsimonycommand.h +++ b/parsimonycommand.h @@ -56,7 +56,7 @@ private: bool abort; string groups, itersString; - vector Groups; //holds groups to be used + vector Groups, outputNames; //holds groups to be used void printParsimonyFile(); void printUSummaryFile(); diff --git a/pcacommand.cpp b/pcacommand.cpp index c17053e..644473a 100644 --- a/pcacommand.cpp +++ b/pcacommand.cpp @@ -12,7 +12,7 @@ //********************************************************************************************************************** -PCACommand::PCACommand(string option){ +PCACommand::PCACommand(string option) { try { abort = false; @@ -61,12 +61,12 @@ PCACommand::PCACommand(string option){ } //error checking on files - if (phylipfile == "") { mothurOut("You must provide a distance file before running the pca command."); mothurOutEndLine(); abort = true; } + if (phylipfile == "") { m->mothurOut("You must provide a distance file before running the pca command."); m->mothurOutEndLine(); abort = true; } } } catch(exception& e) { - errorOut(e, "PCACommand", "PCACommand"); + m->errorOut(e, "PCACommand", "PCACommand"); exit(1); } } @@ -74,10 +74,10 @@ PCACommand::PCACommand(string option){ void PCACommand::help(){ try { - mothurOut("The pca command..."); mothurOutEndLine(); + m->mothurOut("The pca command..."); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "PCACommand", "help"); + m->errorOut(e, "PCACommand", "help"); exit(1); } } @@ -129,10 +129,15 @@ int PCACommand::execute(){ output(fbase, names, G, d); + 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; } catch(exception& e) { - errorOut(e, "PCACommand", "execute"); + m->errorOut(e, "PCACommand", "execute"); exit(1); } } @@ -152,7 +157,7 @@ void PCACommand::get_comment(istream& f, char begin, char end){ d = f.peek(); } catch(exception& e) { - errorOut(e, "PCACommand", "get_comment"); + m->errorOut(e, "PCACommand", "get_comment"); exit(1); } } @@ -201,7 +206,7 @@ void PCACommand::read_phylip(istream& f, int square_m, vector& name_list } } catch(exception& e) { - errorOut(e, "PCACommand", "read_phylip"); + m->errorOut(e, "PCACommand", "read_phylip"); exit(1); } @@ -243,7 +248,7 @@ void PCACommand::read(string fname, vector& names, vector read_phylip(f, m, names, D); } catch(exception& e) { - errorOut(e, "PCACommand", "read"); + m->errorOut(e, "PCACommand", "read"); exit(1); } } @@ -275,7 +280,7 @@ void PCACommand::matrix_mult(vector > first, vectorerrorOut(e, "PCACommand", "matrix_mult"); exit(1); } @@ -309,7 +314,7 @@ void PCACommand::recenter(double offset, vector > D, vectorerrorOut(e, "PCACommand", "recenter"); exit(1); } @@ -402,7 +407,7 @@ void PCACommand::tred2(vector >& a, vector& d, vectorerrorOut(e, "PCACommand", "tred2"); exit(1); } @@ -486,7 +491,7 @@ void PCACommand::qtli(vector& d, vector& e, vectorerrorOut(e, "PCACommand", "qtli"); exit(1); } } @@ -508,10 +513,12 @@ void PCACommand::output(string fnameRoot, vector name_list, vector name_list, vectorerrorOut(e, "PCACommand", "output"); exit(1); } } diff --git a/pcacommand.h b/pcacommand.h index 8a36323..220e91f 100644 --- a/pcacommand.h +++ b/pcacommand.h @@ -27,6 +27,7 @@ private: bool abort; string phylipfile, columnfile, namefile, format, filename, fbase, outputDir; float cutoff, precision; + vector outputNames; void get_comment(istream&, char, char); void read_phylip(istream&, int, vector&, vector >&); diff --git a/phylotree.cpp b/phylotree.cpp index a07cfde..1001542 100644 --- a/phylotree.cpp +++ b/phylotree.cpp @@ -13,6 +13,7 @@ PhyloTree::PhyloTree(){ try { + m = MothurOut::getInstance(); numNodes = 1; numSeqs = 0; tree.push_back(TaxNode("Root")); @@ -20,7 +21,7 @@ PhyloTree::PhyloTree(){ maxLevel = 0; } catch(exception& e) { - errorOut(e, "PhyloTree", "PhyloTree"); + m->errorOut(e, "PhyloTree", "PhyloTree"); exit(1); } } @@ -49,7 +50,7 @@ PhyloTree::PhyloTree(string tfile){ assignHeirarchyIDs(0); } catch(exception& e) { - errorOut(e, "PhyloTree", "PhyloTree"); + m->errorOut(e, "PhyloTree", "PhyloTree"); exit(1); } } @@ -66,7 +67,7 @@ string PhyloTree::getNextTaxon(string& heirarchy){ return currentLevel; } catch(exception& e) { - errorOut(e, "PhyloTree", "getNextTaxon"); + m->errorOut(e, "PhyloTree", "getNextTaxon"); exit(1); } } @@ -123,7 +124,7 @@ void PhyloTree::addSeqToTree(string seqName, string seqTaxonomy){ } catch(exception& e) { - errorOut(e, "PhyloTree", "addSeqToTree"); + m->errorOut(e, "PhyloTree", "addSeqToTree"); exit(1); } } @@ -138,7 +139,7 @@ vector PhyloTree::getGenusNodes() { return genusIndex; } catch(exception& e) { - errorOut(e, "PhyloTree", "getGenusNodes"); + m->errorOut(e, "PhyloTree", "getGenusNodes"); exit(1); } } @@ -161,7 +162,7 @@ void PhyloTree::assignHeirarchyIDs(int index){ } } catch(exception& e) { - errorOut(e, "PhyloTree", "assignHeirarchyIDs"); + m->errorOut(e, "PhyloTree", "assignHeirarchyIDs"); exit(1); } } @@ -215,7 +216,7 @@ void PhyloTree::binUnclassified(){ } catch(exception& e) { - errorOut(e, "PhyloTree", "binUnclassified"); + m->errorOut(e, "PhyloTree", "binUnclassified"); exit(1); } } @@ -234,7 +235,7 @@ string PhyloTree::getFullTaxonomy(string seqName) { return tax; } catch(exception& e) { - errorOut(e, "PhyloTree", "getFullTaxonomy"); + m->errorOut(e, "PhyloTree", "getFullTaxonomy"); exit(1); } } @@ -246,7 +247,7 @@ void PhyloTree::print(ofstream& out){ print(0, out); } catch(exception& e) { - errorOut(e, "PhyloTree", "print"); + m->errorOut(e, "PhyloTree", "print"); exit(1); } } @@ -264,7 +265,7 @@ void PhyloTree::print(int i, ofstream& out){ } catch(exception& e) { - errorOut(e, "PhyloTree", "print"); + m->errorOut(e, "PhyloTree", "print"); exit(1); } } diff --git a/phylotree.h b/phylotree.h index cae0a08..345e2e7 100644 --- a/phylotree.h +++ b/phylotree.h @@ -11,6 +11,7 @@ */ #include "mothur.h" +#include "mothurout.h" /**************************************************************************************************/ @@ -55,6 +56,7 @@ private: int numNodes; int numSeqs; int maxLevel; + MothurOut* m; }; /**************************************************************************************************/ diff --git a/phylotypecommand.cpp b/phylotypecommand.cpp index 2dbd53a..e3b47d8 100644 --- a/phylotypecommand.cpp +++ b/phylotypecommand.cpp @@ -14,7 +14,7 @@ #include "sabundvector.hpp" /**********************************************************************************************************************/ -PhylotypeCommand::PhylotypeCommand(string option){ +PhylotypeCommand::PhylotypeCommand(string option) { try { abort = false; @@ -54,8 +54,8 @@ PhylotypeCommand::PhylotypeCommand(string option){ taxonomyFileName = validParameter.validFile(parameters, "taxonomy", true); if (taxonomyFileName == "not found") { - mothurOut("taxonomy is a required parameter for the phylotype command."); - mothurOutEndLine(); + m->mothurOut("taxonomy is a required parameter for the phylotype command."); + m->mothurOutEndLine(); abort = true; }else if (taxonomyFileName == "not open") { abort = true; } @@ -79,7 +79,7 @@ PhylotypeCommand::PhylotypeCommand(string option){ } } catch(exception& e) { - errorOut(e, "PhylotypeCommand", "PhylotypeCommand"); + m->errorOut(e, "PhylotypeCommand", "PhylotypeCommand"); exit(1); } } @@ -87,19 +87,19 @@ PhylotypeCommand::PhylotypeCommand(string option){ void PhylotypeCommand::help(){ try { - mothurOut("The phylotype command reads a taxonomy file and outputs a .list, .rabund and .sabund file. \n"); - mothurOut("The phylotype command parameter options are taxonomy, cutoff and label. The taxonomy parameter is required.\n"); - 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"); - mothurOut("For example: taxonomy = Bacteria;Bacteroidetes-Chlorobi;Bacteroidetes; - cutoff=2, would truncate the taxonomy to Bacteria;Bacteroidetes-Chlorobi; \n"); - 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"); - 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"); - 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"); - mothurOut("The phylotype command should be in the following format: \n"); - mothurOut("phylotype(taxonomy=yourTaxonomyFile, cutoff=yourCutoff, label=yourLabels) \n"); - mothurOut("Eaxample: phylotype(taxonomy=amazon.taxonomy, cutoff=5, label=1-3-5).\n\n"); + 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) { - errorOut(e, "PhylotypeCommand", "help"); + m->errorOut(e, "PhylotypeCommand", "help"); exit(1); } } @@ -114,6 +114,8 @@ int PhylotypeCommand::execute(){ if (abort == true) { return 0; } + vector outputNames; + //reads in taxonomy file and makes all the taxonomies the same length //by appending the last taxon to a given taxonomy as many times as needed to //make it as long as the longest taxonomy in the file @@ -131,7 +133,7 @@ int PhylotypeCommand::execute(){ for (int i = 0; i < leaves.size(); i++) { currentNodes[leaves[i]] = leaves[i]; } bool done = false; - if (tree->get(leaves[0]).parent == -1) { mothurOut("Empty Tree"); mothurOutEndLine(); done = true; } + if (tree->get(leaves[0]).parent == -1) { m->mothurOut("Empty Tree"); m->mothurOutEndLine(); done = true; } string fileroot = outputDir + getRootName(getSimpleName(taxonomyFileName)); @@ -145,6 +147,10 @@ int PhylotypeCommand::execute(){ string outputRabundFile = fileroot + "tx.rabund"; openOutputFile(outputRabundFile, outRabund); + outputNames.push_back(outputListFile); + outputNames.push_back(outputSabundFile); + outputNames.push_back(outputRabundFile); + int count = 1; //start at leaves of tree and work towards root, processing the labels the user wants while((!done) && ((allLines == 1) || (labels.size() != 0))) { @@ -156,7 +162,7 @@ int PhylotypeCommand::execute(){ if(allLines == 1 || labels.count(level) == 1){ //output level - mothurOut(level); mothurOutEndLine(); + m->mothurOut(level); m->mothurOutEndLine(); ListVector list; list.setLabel(level); @@ -210,11 +216,16 @@ int PhylotypeCommand::execute(){ delete tree; + 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; } catch(exception& e) { - errorOut(e, "PhylotypeCommand", "execute"); + m->errorOut(e, "PhylotypeCommand", "execute"); exit(1); } } diff --git a/pintail.cpp b/pintail.cpp index 90c97c5..a2c7270 100644 --- a/pintail.cpp +++ b/pintail.cpp @@ -32,7 +32,7 @@ Pintail::~Pintail() { delete decalc; } catch(exception& e) { - errorOut(e, "Pintail", "~Pintail"); + m->errorOut(e, "Pintail", "~Pintail"); exit(1); } } @@ -66,13 +66,13 @@ void Pintail::doPrep() { #endif - mothurOut("Getting conservation... "); cout.flush(); + m->mothurOut("Getting conservation... "); cout.flush(); if (consfile == "") { - mothurOut("Calculating probability of conservation for your template sequences. This can take a while... I will output the frequency of the highest base in each position to a .freq file so that you can input them using the conservation parameter next time you run this command. Providing the .freq file will improve speed. "); cout.flush(); + m->mothurOut("Calculating probability of conservation for your template sequences. This can take a while... I will output the frequency of the highest base in each position to a .freq file so that you can input them using the conservation parameter next time you run this command. Providing the .freq file will improve speed. "); cout.flush(); probabilityProfile = decalc->calcFreq(templateSeqs, outputDir + getSimpleName(templateFileName)); - mothurOut("Done."); mothurOutEndLine(); - }else { probabilityProfile = readFreq(); mothurOut("Done."); } - mothurOutEndLine(); + m->mothurOut("Done."); m->mothurOutEndLine(); + }else { probabilityProfile = readFreq(); m->mothurOut("Done."); } + m->mothurOutEndLine(); //make P into Q for (int i = 0; i < probabilityProfile.size(); i++) { probabilityProfile[i] = 1 - probabilityProfile[i]; } //cout << i << '\t' << probabilityProfile[i] << endl; @@ -135,7 +135,7 @@ void Pintail::doPrep() { } } - mothurOut("Calculating quantiles for your template. This can take a while... I will output the quantiles to a .quan file that you can input them using the quantiles parameter next time you run this command. Providing the .quan file will dramatically improve speed. "); cout.flush(); + m->mothurOut("Calculating quantiles for your template. This can take a while... I will output the quantiles to a .quan file that you can input them using the quantiles parameter next time you run this command. Providing the .quan file will dramatically improve speed. "); cout.flush(); if (processors == 1) { quantilesMembers = decalc->getQuantiles(templateSeqs, windowSizesTemplate, window, probabilityProfile, increment, 0, templateSeqs.size()); }else { createProcessesQuan(); } @@ -197,7 +197,7 @@ void Pintail::doPrep() { } - mothurOut("Done."); mothurOutEndLine(); + m->mothurOut("Done."); m->mothurOutEndLine(); } if (reRead) { @@ -212,7 +212,7 @@ void Pintail::doPrep() { } catch(exception& e) { - errorOut(e, "Pintail", "doPrep"); + m->errorOut(e, "Pintail", "doPrep"); exit(1); } } @@ -234,7 +234,7 @@ void Pintail::print(ostream& out, ostream& outAcc) { out << querySeq->getName() << '\t' << "div: " << deviation << "\tstDev: " << DE << "\tchimera flag: " << chimera << endl; if (chimera == "Yes") { - mothurOut(querySeq->getName() + "\tdiv: " + toString(deviation) + "\tstDev: " + toString(DE) + "\tchimera flag: " + chimera); mothurOutEndLine(); + m->mothurOut(querySeq->getName() + "\tdiv: " + toString(deviation) + "\tstDev: " + toString(DE) + "\tchimera flag: " + chimera); m->mothurOutEndLine(); outAcc << querySeq->getName() << endl; } out << "Observed\t"; @@ -250,7 +250,7 @@ void Pintail::print(ostream& out, ostream& outAcc) { } catch(exception& e) { - errorOut(e, "Pintail", "print"); + m->errorOut(e, "Pintail", "print"); exit(1); } } @@ -307,7 +307,7 @@ int Pintail::getChimeras(Sequence* query) { return 0; } catch(exception& e) { - errorOut(e, "Pintail", "getChimeras"); + m->errorOut(e, "Pintail", "getChimeras"); exit(1); } } @@ -349,7 +349,7 @@ vector Pintail::readFreq() { } catch(exception& e) { - errorOut(e, "Pintail", "readFreq"); + m->errorOut(e, "Pintail", "readFreq"); exit(1); } } @@ -366,7 +366,7 @@ Sequence* Pintail::findPairs(Sequence* q) { } catch(exception& e) { - errorOut(e, "Pintail", "findPairs"); + m->errorOut(e, "Pintail", "findPairs"); exit(1); } } @@ -406,7 +406,7 @@ void Pintail::createProcessesQuan() { out.close(); exit(0); - }else { mothurOut("unable to spawn the necessary processes."); mothurOutEndLine(); exit(0); } + }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); } } //force parent to wait until all the processes are done @@ -461,7 +461,7 @@ void Pintail::createProcessesQuan() { #endif } catch(exception& e) { - errorOut(e, "Pintail", "createProcessesQuan"); + m->errorOut(e, "Pintail", "createProcessesQuan"); exit(1); } } diff --git a/preclustercommand.cpp b/preclustercommand.cpp index fa5329b..66efd46 100644 --- a/preclustercommand.cpp +++ b/preclustercommand.cpp @@ -13,7 +13,7 @@ inline bool comparePriority(seqPNode first, seqPNode second) { return (first.numIdentical > second.numIdentical); } //********************************************************************************************************************** -PreClusterCommand::PreClusterCommand(string option){ +PreClusterCommand::PreClusterCommand(string option) { try { abort = false; @@ -60,7 +60,7 @@ PreClusterCommand::PreClusterCommand(string option){ //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { mothurOut("fasta is a required parameter for the pre.cluster command."); mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the pre.cluster command."); 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 @@ -82,7 +82,7 @@ PreClusterCommand::PreClusterCommand(string option){ } catch(exception& e) { - errorOut(e, "PreClusterCommand", "PreClusterCommand"); + m->errorOut(e, "PreClusterCommand", "PreClusterCommand"); exit(1); } } @@ -93,18 +93,18 @@ PreClusterCommand::~PreClusterCommand(){} void PreClusterCommand::help(){ try { - mothurOut("The pre.cluster command groups sequences that are within a given number of base mismatches.\n"); - mothurOut("The pre.cluster command outputs a new fasta and name file.\n"); - mothurOut("The pre.cluster command parameters are fasta, names and diffs. The fasta parameter is required. \n"); - 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"); - mothurOut("The diffs parameter allows you to specify maximum number of mismatched bases allowed between sequences in a grouping. The default is 1.\n"); - mothurOut("The pre.cluster command should be in the following format: \n"); - mothurOut("pre.cluster(fasta=yourFastaFile, names=yourNamesFile, diffs=yourMaxDiffs) \n"); - mothurOut("Example pre.cluster(fasta=amazon.fasta, diffs=2).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); + 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) { - errorOut(e, "PreClusterCommand", "help"); + m->errorOut(e, "PreClusterCommand", "help"); exit(1); } } @@ -118,8 +118,8 @@ int PreClusterCommand::execute(){ //reads fasta file and return number of seqs int numSeqs = readFASTA(); //fills alignSeqs and makes all seqs active - if (numSeqs == 0) { mothurOut("Error reading fasta file...please correct."); mothurOutEndLine(); return 0; } - if (diffs > length) { mothurOut("Error: diffs is greater than your sequence length."); mothurOutEndLine(); return 0; } + if (numSeqs == 0) { m->mothurOut("Error reading fasta file...please correct."); m->mothurOutEndLine(); return 0; } + if (diffs > length) { m->mothurOut("Error: diffs is greater than your sequence length."); m->mothurOutEndLine(); return 0; } //clear sizes since you only needed this info to build the alignSeqs seqPNode structs // sizes.clear(); @@ -167,15 +167,21 @@ int PreClusterCommand::execute(){ string newNamesFile = fileroot + "precluster.names"; - mothurOut("Total number of sequences before precluster was " + toString(alignSeqs.size()) + "."); mothurOutEndLine(); - mothurOut("pre.cluster removed " + toString(count) + " sequences."); mothurOutEndLine(); + m->mothurOut("Total number of sequences before precluster was " + toString(alignSeqs.size()) + "."); m->mothurOutEndLine(); + m->mothurOut("pre.cluster removed " + toString(count) + " sequences."); m->mothurOutEndLine(); printData(newFastaFile, newNamesFile); + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + m->mothurOut(newFastaFile); m->mothurOutEndLine(); + m->mothurOut(newNamesFile); m->mothurOutEndLine(); + m->mothurOutEndLine(); return 0; } catch(exception& e) { - errorOut(e, "PreClusterCommand", "execute"); + m->errorOut(e, "PreClusterCommand", "execute"); exit(1); } } @@ -213,7 +219,7 @@ int PreClusterCommand::readFASTA(){ if (namefile != "") { itSize = sizes.find(seq.getName()); - if (itSize == sizes.end()) { mothurOut(seq.getName() + " is not in your names file, please correct."); mothurOutEndLine(); exit(1); } + if (itSize == sizes.end()) { m->mothurOut(seq.getName() + " is not in your names file, please correct."); m->mothurOutEndLine(); exit(1); } else{ seqPNode tempNode(itSize->second, seq, names[seq.getName()]); alignSeqs.push_back(tempNode); @@ -232,7 +238,7 @@ int PreClusterCommand::readFASTA(){ } catch(exception& e) { - errorOut(e, "PreClusterCommand", "readFASTA"); + m->errorOut(e, "PreClusterCommand", "readFASTA"); exit(1); } } @@ -252,7 +258,7 @@ int PreClusterCommand::calcMisMatches(string seq1, string seq2){ return numBad; } catch(exception& e) { - errorOut(e, "PreClusterCommand", "calcMisMatches"); + m->errorOut(e, "PreClusterCommand", "calcMisMatches"); exit(1); } } @@ -280,7 +286,7 @@ void PreClusterCommand::printData(string newfasta, string newname){ } catch(exception& e) { - errorOut(e, "PreClusterCommand", "printData"); + m->errorOut(e, "PreClusterCommand", "printData"); exit(1); } } @@ -306,7 +312,7 @@ void PreClusterCommand::readNameFile(){ in.close(); } catch(exception& e) { - errorOut(e, "PreClusterCommand", "readNameFile"); + m->errorOut(e, "PreClusterCommand", "readNameFile"); exit(1); } } diff --git a/preclustercommand.h b/preclustercommand.h index 643a367..de6a572 100644 --- a/preclustercommand.h +++ b/preclustercommand.h @@ -30,7 +30,7 @@ struct seqPNode { class PreClusterCommand : public Command { public: - PreClusterCommand(string); + PreClusterCommand(string); ~PreClusterCommand(); int execute(); void help(); diff --git a/progress.cpp b/progress.cpp index 6899e76..186a86e 100644 --- a/progress.cpp +++ b/progress.cpp @@ -18,13 +18,14 @@ const char marker = '|'; Progress::Progress(){ try { - mothurOut("********************#****#****#****#****#****#****#****#****#****#****#"); + m = MothurOut::getInstance(); + m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#"); nTicks = 0; finalPos = 0; } catch(exception& e) { - errorOut(e, "Progress", "Progress"); + m->errorOut(e, "Progress", "Progress"); exit(1); } } @@ -33,17 +34,17 @@ Progress::Progress(){ Progress::Progress(string job, int end){ try { - mothurOut("********************#****#****#****#****#****#****#****#****#****#****#\n"); + m->mothurOut("********************#****#****#****#****#****#****#****#****#****#****#\n"); cout << setw(20) << left << job << setw(1) << marker; - mothurOutJustToLog(job); - mothurOut(toString(marker)); + m->mothurOutJustToLog(job); + m->mothurOut(toString(marker)); cout.flush(); nTicks = 0; finalPos = end; } catch(exception& e) { - errorOut(e, "Progress", "Progress"); + m->errorOut(e, "Progress", "Progress"); exit(1); } } @@ -52,17 +53,17 @@ Progress::Progress(string job, int end){ void Progress::newLine(string job, int end){ try { - mothurOutEndLine(); + m->mothurOutEndLine(); cout << setw(20) << left << job << setw(1) << marker; - mothurOutJustToLog(job); - mothurOut(toString(marker)); + m->mothurOutJustToLog(job); + m->mothurOut(toString(marker)); cout.flush(); nTicks = 0; finalPos = end; } catch(exception& e) { - errorOut(e, "Progress", "newLine"); + m->errorOut(e, "Progress", "newLine"); exit(1); } } @@ -75,14 +76,14 @@ void Progress::update(const int currentPos){ if(ratio > nTicks){ for(int i=nTicks;imothurOut(toString(marker)); cout.flush(); } nTicks = ratio; } } catch(exception& e) { - errorOut(e, "Progress", "update"); + m->errorOut(e, "Progress", "update"); exit(1); } } @@ -92,17 +93,17 @@ void Progress::update(const int currentPos){ void Progress::finish(){ try { for(int i=nTicks;imothurOut(toString(marker)); cout.flush(); } - mothurOutEndLine(); - mothurOut("***********************************************************************\n"); + m->mothurOutEndLine(); + m->mothurOut("***********************************************************************\n"); cout.flush(); } catch(exception& e) { - errorOut(e, "Progress", "finish"); + m->errorOut(e, "Progress", "finish"); exit(1); } } diff --git a/progress.hpp b/progress.hpp index fba393e..f4d4fc3 100644 --- a/progress.hpp +++ b/progress.hpp @@ -2,6 +2,7 @@ #define PROGRESS_H #include "mothur.h" +#include "mothurout.h" class Progress { @@ -14,7 +15,8 @@ public: private: int nTicks; - int finalPos; + int finalPos; + MothurOut* m; }; #endif diff --git a/qstat.cpp b/qstat.cpp index 60e6629..44da363 100644 --- a/qstat.cpp +++ b/qstat.cpp @@ -59,7 +59,7 @@ EstOutput QStat::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "QStat", "getValues"); + m->errorOut(e, "QStat", "getValues"); exit(1); } } diff --git a/quitcommand.cpp b/quitcommand.cpp index 05e2758..8e6fd15 100644 --- a/quitcommand.cpp +++ b/quitcommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -QuitCommand::QuitCommand(string option){ +QuitCommand::QuitCommand(string option) { abort = false; //allow user to run help @@ -22,11 +22,11 @@ QuitCommand::QuitCommand(string option){ void QuitCommand::help(){ try { - mothurOut("The quit command will terminate mothur and should be in the following format: \n"); - mothurOut("quit() or quit\n\n"); + 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) { - errorOut(e, "QuitCommand", "help"); + m->errorOut(e, "QuitCommand", "help"); exit(1); } } diff --git a/rabundvector.cpp b/rabundvector.cpp index e01063d..43dbfac 100644 --- a/rabundvector.cpp +++ b/rabundvector.cpp @@ -41,7 +41,7 @@ RAbundVector::RAbundVector(string id, vector rav) : DataVector(id), data(ra } } catch(exception& e) { - errorOut(e, "RAbundVector", "RAbundVector"); + m->errorOut(e, "RAbundVector", "RAbundVector"); exit(1); } } @@ -56,7 +56,7 @@ RAbundVector::RAbundVector(vector rav, int mr, int nb, int ns) { data = rav; } catch(exception& e) { - errorOut(e, "RAbundVector", "RAbundVector"); + m->errorOut(e, "RAbundVector", "RAbundVector"); exit(1); } } @@ -78,7 +78,7 @@ RAbundVector::RAbundVector(ifstream& f) : DataVector(), maxRank(0), numBins(0), } } catch(exception& e) { - errorOut(e, "RAbundVector", "RAbundVector"); + m->errorOut(e, "RAbundVector", "RAbundVector"); exit(1); } } @@ -103,7 +103,7 @@ void RAbundVector::set(int binNumber, int newBinSize){ numSeqs += (newBinSize - oldBinSize); } catch(exception& e) { - errorOut(e, "RAbundVector", "set"); + m->errorOut(e, "RAbundVector", "set"); exit(1); } } @@ -129,7 +129,7 @@ void RAbundVector::push_back(int binSize){ numSeqs += binSize; } catch(exception& e) { - errorOut(e, "RAbundVector", "push_back"); + m->errorOut(e, "RAbundVector", "push_back"); exit(1); } } @@ -202,7 +202,7 @@ void RAbundVector::nonSortedPrint(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "RAbundVector", "nonSortedPrint"); + m->errorOut(e, "RAbundVector", "nonSortedPrint"); exit(1); } } @@ -218,7 +218,7 @@ void RAbundVector::print(string prefix, ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "RAbundVector", "print"); + m->errorOut(e, "RAbundVector", "print"); exit(1); } } @@ -236,7 +236,7 @@ void RAbundVector::print(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "RAbundVector", "print"); + m->errorOut(e, "RAbundVector", "print"); exit(1); } } @@ -279,7 +279,7 @@ SAbundVector RAbundVector::getSAbundVector() { return sav; } catch(exception& e) { - errorOut(e, "RAbundVector", "getSAbundVector"); + m->errorOut(e, "RAbundVector", "getSAbundVector"); exit(1); } } @@ -302,7 +302,7 @@ OrderVector RAbundVector::getOrderVector(map* nameMap = NULL) { return ov; } catch(exception& e) { - errorOut(e, "RAbundVector", "getOrderVector"); + m->errorOut(e, "RAbundVector", "getOrderVector"); exit(1); } } diff --git a/rarecalc.cpp b/rarecalc.cpp index 8f1d307..9145061 100644 --- a/rarecalc.cpp +++ b/rarecalc.cpp @@ -45,7 +45,7 @@ EstOutput RareCalc::getValues(int n){ return output; } catch(exception& e) { - errorOut(e, "RareCalc", "getValues"); + m->errorOut(e, "RareCalc", "getValues"); exit(1); } } diff --git a/rarecalc.h b/rarecalc.h index a7ad2b7..d30fa16 100644 --- a/rarecalc.h +++ b/rarecalc.h @@ -17,13 +17,14 @@ class RareCalc { public: - RareCalc(RAbundVector* b) : bins(b), numSeqs(b->getNumSeqs()), maxRank(b->getMaxRank()), numBins(b->getNumBins()) { bMatrix = binomial(numSeqs+1); }; + RareCalc(RAbundVector* b) : bins(b), numSeqs(b->getNumSeqs()), maxRank(b->getMaxRank()), numBins(b->getNumBins()) { bMatrix = binomial(numSeqs+1); m = MothurOut::getInstance(); } EstOutput getValues(int); string getName() { return "rarecalc"; } private: RAbundVector* bins; vector > bMatrix; int numSeqs, maxRank, numBins; + MothurOut* m; }; /***********************************************************************/ diff --git a/raredisplay.cpp b/raredisplay.cpp index 6c5a5e5..5922822 100644 --- a/raredisplay.cpp +++ b/raredisplay.cpp @@ -16,7 +16,7 @@ void RareDisplay::init(string label){ this->label = label; } catch(exception& e) { - errorOut(e, "RareDisplay", "init"); + m->errorOut(e, "RareDisplay", "init"); exit(1); } } @@ -49,7 +49,7 @@ void RareDisplay::update(SAbundVector* rank){ } } catch(exception& e) { - errorOut(e, "RareDisplay", "update"); + m->errorOut(e, "RareDisplay", "update"); exit(1); } } @@ -82,7 +82,7 @@ void RareDisplay::update(vector shared, int numSeqs, int nu } } catch(exception& e) { - errorOut(e, "RareDisplay", "update"); + m->errorOut(e, "RareDisplay", "update"); exit(1); } } @@ -95,7 +95,7 @@ void RareDisplay::reset(){ index = 0; } catch(exception& e) { - errorOut(e, "RareDisplay", "reset"); + m->errorOut(e, "RareDisplay", "reset"); exit(1); } } @@ -131,7 +131,7 @@ void RareDisplay::close(){ output->resetFile(); } catch(exception& e) { - errorOut(e, "RareDisplay", "close"); + m->errorOut(e, "RareDisplay", "close"); exit(1); } } diff --git a/rarefact.cpp b/rarefact.cpp index 5cd9b99..6acc24c 100644 --- a/rarefact.cpp +++ b/rarefact.cpp @@ -63,7 +63,7 @@ void Rarefact::getCurve(int increment = 1, int nIters = 1000){ delete rcd; } catch(exception& e) { - errorOut(e, "Rarefact", "getCurve"); + m->errorOut(e, "Rarefact", "getCurve"); exit(1); } } @@ -129,7 +129,7 @@ try { delete rcd; } catch(exception& e) { - errorOut(e, "Rarefact", "getSharedCurve"); + m->errorOut(e, "Rarefact", "getSharedCurve"); exit(1); } } @@ -143,7 +143,7 @@ void Rarefact::mergeVectors(SharedRAbundVector* shared1, SharedRAbundVector* sha } } catch(exception& e) { - errorOut(e, "Rarefact", "mergeVectors"); + m->errorOut(e, "Rarefact", "mergeVectors"); exit(1); } } diff --git a/rarefact.h b/rarefact.h index 9507d5a..9e903ea 100644 --- a/rarefact.h +++ b/rarefact.h @@ -12,9 +12,9 @@ class Rarefact { public: Rarefact(OrderVector* o, vector disp) : - numSeqs(o->getNumSeqs()), order(o), displays(disp), label(o->getLabel()) {}; + numSeqs(o->getNumSeqs()), order(o), displays(disp), label(o->getLabel()) { m = MothurOut::getInstance(); } Rarefact(vector shared, vector disp) : - lookup(shared), displays(disp) { globaldata = GlobalData::getInstance(); }; + lookup(shared), displays(disp) { globaldata = GlobalData::getInstance(); m = MothurOut::getInstance(); } ~Rarefact(){}; void getCurve(int, int); @@ -28,6 +28,7 @@ private: string label; void mergeVectors(SharedRAbundVector*, SharedRAbundVector*); vector lookup; + MothurOut* m; }; diff --git a/rarefactcommand.cpp b/rarefactcommand.cpp index 97d6332..c98b833 100644 --- a/rarefactcommand.cpp +++ b/rarefactcommand.cpp @@ -22,14 +22,14 @@ //********************************************************************************************************************** -RareFactCommand::RareFactCommand(string option){ +RareFactCommand::RareFactCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; allLines = 1; labels.clear(); Estimators.clear(); - + //allow user to run help if(option == "help") { validCalculator = new ValidCalculators(); help(); delete validCalculator; abort = true; } @@ -55,7 +55,7 @@ RareFactCommand::RareFactCommand(string option){ } //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund, rabund or shared file before you can use the rarefact.single command."); mothurOutEndLine(); abort = true; } + 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 optional parameter and set defaults // ...at some point should added some additional type checking... @@ -92,7 +92,7 @@ RareFactCommand::RareFactCommand(string option){ } catch(exception& e) { - errorOut(e, "RareFactCommand", "RareFactCommand"); + m->errorOut(e, "RareFactCommand", "RareFactCommand"); exit(1); } } @@ -100,19 +100,19 @@ RareFactCommand::RareFactCommand(string option){ void RareFactCommand::help(){ try { - mothurOut("The rarefaction.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n"); - 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"); - mothurOut("The rarefaction.single command parameters are label, iters, freq, calc and abund. No parameters are required. \n"); - mothurOut("The rarefaction.single command should be in the following format: \n"); - mothurOut("rarefaction.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n"); - mothurOut("Example rarefaction.single(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-rchao-race-rjack-rbootstrap-rshannon-rnpshannon-rsimpson).\n"); - 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"); + 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 and abund. No parameters are required. \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); - mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\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. freq), '=' and parameters (i.e.yourFreq).\n\n"); } catch(exception& e) { - errorOut(e, "RareFactCommand", "help"); + m->errorOut(e, "RareFactCommand", "help"); exit(1); } } @@ -128,6 +128,8 @@ int RareFactCommand::execute(){ if (abort == true) { return 0; } + vector outputNames; + if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } else { inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } @@ -137,7 +139,7 @@ int RareFactCommand::execute(){ globaldata->inputFileName = inputFileNames[p]; if (inputFileNames.size() > 1) { - mothurOutEndLine(); mothurOut("Processing group " + groups[p]); mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); } int i; validCalculator = new ValidCalculators(); @@ -147,26 +149,36 @@ int RareFactCommand::execute(){ 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"); }else if (Estimators[i] == "chao") { rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao"))); + outputNames.push_back(fileNameRoot+"r_chao"); }else if (Estimators[i] == "ace") { if(abund < 5) abund = 10; rDisplays.push_back(new RareDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"r_ace"))); + outputNames.push_back(fileNameRoot+"r_ace"); }else if (Estimators[i] == "jack") { rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack"))); + outputNames.push_back(fileNameRoot+"r_jack"); }else if (Estimators[i] == "shannon") { rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon"))); + outputNames.push_back(fileNameRoot+"r_shannon"); }else if (Estimators[i] == "npshannon") { rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon"))); + outputNames.push_back(fileNameRoot+"r_npshannon"); }else if (Estimators[i] == "simpson") { rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson"))); + outputNames.push_back(fileNameRoot+"r_simpson"); }else if (Estimators[i] == "bootstrap") { rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap"))); + outputNames.push_back(fileNameRoot+"r_bootstrap"); }else if (Estimators[i] == "coverage") { rDisplays.push_back(new RareDisplay(new Coverage(), new ThreeColumnFile(fileNameRoot+"r_coverage"))); + outputNames.push_back(fileNameRoot+"r_coverage"); }else if (Estimators[i] == "nseqs") { rDisplays.push_back(new RareDisplay(new NSeqs(), new ThreeColumnFile(fileNameRoot+"r_nseqs"))); + outputNames.push_back(fileNameRoot+"r_nseqs"); } } } @@ -195,7 +207,7 @@ int RareFactCommand::execute(){ rCurve->getCurve(freq, nIters); delete rCurve; - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); } @@ -210,7 +222,7 @@ int RareFactCommand::execute(){ rCurve->getCurve(freq, nIters); delete rCurve; - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); processedLabels.insert(order->getLabel()); userLabels.erase(order->getLabel()); @@ -228,12 +240,12 @@ int RareFactCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -246,7 +258,7 @@ int RareFactCommand::execute(){ rCurve->getCurve(freq, nIters); delete rCurve; - mothurOut(order->getLabel()); mothurOutEndLine(); + m->mothurOut(order->getLabel()); m->mothurOutEndLine(); delete order; } @@ -260,10 +272,16 @@ int RareFactCommand::execute(){ } + + 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; } catch(exception& e) { - errorOut(e, "RareFactCommand", "execute"); + m->errorOut(e, "RareFactCommand", "execute"); exit(1); } } @@ -322,7 +340,7 @@ vector RareFactCommand::parseSharedFile(string filename) { return filenames; } catch(exception& e) { - errorOut(e, "RareFactCommand", "parseSharedFile"); + m->errorOut(e, "RareFactCommand", "parseSharedFile"); exit(1); } } diff --git a/rarefactsharedcommand.cpp b/rarefactsharedcommand.cpp index 1d13a56..b53e87d 100644 --- a/rarefactsharedcommand.cpp +++ b/rarefactsharedcommand.cpp @@ -13,7 +13,7 @@ //********************************************************************************************************************** -RareFactSharedCommand::RareFactSharedCommand(string option){ +RareFactSharedCommand::RareFactSharedCommand(string option) { try { globaldata = GlobalData::getInstance(); @@ -43,8 +43,8 @@ RareFactSharedCommand::RareFactSharedCommand(string option){ //make sure the user has already run the read.otu command if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); mothurOutEndLine(); abort = true; } - else if (globaldata->getGroupFile() == "") { mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); mothurOutEndLine(); abort = true; } + 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 output directory command factory will send this info to us in the output parameter @@ -104,8 +104,10 @@ RareFactSharedCommand::RareFactSharedCommand(string option){ 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"); }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"); } } } @@ -115,7 +117,7 @@ RareFactSharedCommand::RareFactSharedCommand(string option){ } catch(exception& e) { - errorOut(e, "RareFactSharedCommand", "RareFactSharedCommand"); + m->errorOut(e, "RareFactSharedCommand", "RareFactSharedCommand"); exit(1); } } @@ -124,20 +126,20 @@ RareFactSharedCommand::RareFactSharedCommand(string option){ void RareFactSharedCommand::help(){ try { - mothurOut("The rarefaction.shared command can only be executed after a successful read.otu command.\n"); - mothurOut("The rarefaction.shared command parameters are label, iters, groups, jumble and calc. No parameters are required.\n"); - mothurOut("The rarefaction command should be in the following format: \n"); - mothurOut("rarefaction.shared(label=yourLabel, iters=yourIters, calc=yourEstimators, jumble=yourJumble, groups=yourGroups).\n"); - mothurOut("Example rarefaction.shared(label=unique-0.01-0.03, iters=10000, groups=B-C, jumble=T, calc=sharedobserved).\n"); - 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"); - mothurOut("The default value for groups is all the groups in your groupfile, and jumble is true.\n"); + 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("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); - mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - 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"); - mothurOut("Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\n"); + 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) { - errorOut(e, "RareFactSharedCommand", "help"); + m->errorOut(e, "RareFactSharedCommand", "help"); exit(1); } } @@ -170,7 +172,7 @@ int RareFactSharedCommand::execute(){ string lastLabel = lookup[0]->getLabel(); if (lookup.size() < 2) { - mothurOut("I cannot run the command without at least 2 valid groups."); + m->mothurOut("I cannot run the command without at least 2 valid groups."); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; } @@ -188,7 +190,7 @@ int RareFactSharedCommand::execute(){ rCurve->getSharedCurve(freq, nIters); delete rCurve; - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); } @@ -199,7 +201,7 @@ int RareFactSharedCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); rCurve = new Rarefact(lookup, rDisplays); rCurve->getSharedCurve(freq, nIters); delete rCurve; @@ -223,12 +225,12 @@ int RareFactSharedCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -237,7 +239,7 @@ int RareFactSharedCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); rCurve = new Rarefact(lookup, rDisplays); rCurve->getSharedCurve(freq, nIters); delete rCurve; @@ -248,11 +250,16 @@ int RareFactSharedCommand::execute(){ //reset groups parameter globaldata->Groups.clear(); + + 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; } catch(exception& e) { - errorOut(e, "RareFactSharedCommand", "execute"); + m->errorOut(e, "RareFactSharedCommand", "execute"); exit(1); } } diff --git a/rarefactsharedcommand.h b/rarefactsharedcommand.h index aa321e8..da26d17 100644 --- a/rarefactsharedcommand.h +++ b/rarefactsharedcommand.h @@ -21,7 +21,7 @@ class GlobalData; class RareFactSharedCommand : public Command { public: - RareFactSharedCommand(string); + RareFactSharedCommand(string); ~RareFactSharedCommand(); int execute(); void help(); @@ -40,7 +40,7 @@ private: bool abort, allLines, jumble; set labels; //holds labels to be used string label, calc, groups, outputDir; - vector Estimators, Groups; + vector Estimators, Groups, outputNames; }; diff --git a/readblast.cpp b/readblast.cpp index a6d23e9..616d4f7 100644 --- a/readblast.cpp +++ b/readblast.cpp @@ -16,12 +16,13 @@ inline bool compareOverlap(seqDist left, seqDist right){ return (left.dist < right.dist); } /*********************************************************************************************/ -ReadBlast::ReadBlast(string file, float c, float p, int l, bool m, bool h) : blastfile(file), cutoff(c), penalty(p), length(l), minWanted(m), hclusterWanted(h) { +ReadBlast::ReadBlast(string file, float c, float p, int l, bool ms, bool h) : blastfile(file), cutoff(c), penalty(p), length(l), minWanted(ms), hclusterWanted(h) { try { + m = MothurOut::getInstance(); matrix = NULL; } catch(exception& e) { - errorOut(e, "ReadBlast", "ReadBlast"); + m->errorOut(e, "ReadBlast", "ReadBlast"); exit(1); } } @@ -98,7 +99,7 @@ void ReadBlast::read(NameAssignment* nameMap) { } } } - }else { mothurOut("Error in your blast file, cannot read."); mothurOutEndLine(); exit(1); } + }else { m->mothurOut("Error in your blast file, cannot read."); m->mothurOutEndLine(); exit(1); } //read file @@ -260,14 +261,14 @@ void ReadBlast::read(NameAssignment* nameMap) { fileHandle.close(); } catch(exception& e) { - errorOut(e, "ReadBlast", "read"); + m->errorOut(e, "ReadBlast", "read"); exit(1); } } /*********************************************************************************************/ void ReadBlast::readNames(NameAssignment* nameMap) { try { - mothurOut("Reading names... "); cout.flush(); + m->mothurOut("Reading names... "); cout.flush(); string name, hold, prevName; int num = 1; @@ -307,11 +308,11 @@ void ReadBlast::readNames(NameAssignment* nameMap) { //nameMap->print(out); //out.close(); - mothurOut(toString(num) + " names read."); mothurOutEndLine(); + m->mothurOut(toString(num) + " names read."); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "ReadBlast", "readNames"); + m->errorOut(e, "ReadBlast", "readNames"); exit(1); } } diff --git a/readblast.h b/readblast.h index 128c144..536d1af 100644 --- a/readblast.h +++ b/readblast.h @@ -40,6 +40,7 @@ private: SparseMatrix* matrix; vector overlap; + MothurOut* m; void readNames(NameAssignment*); }; diff --git a/readcluster.cpp b/readcluster.cpp index 11b8d01..1cf9fc3 100644 --- a/readcluster.cpp +++ b/readcluster.cpp @@ -13,6 +13,7 @@ ReadCluster::ReadCluster(string distfile, float c){ globaldata = GlobalData::getInstance(); + m = MothurOut::getInstance(); distFile = distfile; cutoff = c; } @@ -29,7 +30,7 @@ void ReadCluster::read(NameAssignment* nameMap){ } catch(exception& e) { - errorOut(e, "ReadCluster", "read"); + m->errorOut(e, "ReadCluster", "read"); exit(1); } } @@ -63,7 +64,7 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ } else{ list = new ListVector(nameMap->getListVector()); - if(nameMap->count(name)==0){ mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); } + if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); } } char d; @@ -106,7 +107,7 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ } else{ - if(nameMap->count(name)==0){ mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); } + if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); } for(int j=0;j> distance; @@ -139,7 +140,7 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ } } else{ - if(nameMap->count(name)==0){ mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); } + if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); } for(int j=0;j> distance; @@ -190,7 +191,7 @@ void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){ distFile = outputFile; } catch(exception& e) { - errorOut(e, "ReadCluster", "convertPhylip2Column"); + m->errorOut(e, "ReadCluster", "convertPhylip2Column"); exit(1); } } diff --git a/readcluster.h b/readcluster.h index bcd910c..d578a0f 100644 --- a/readcluster.h +++ b/readcluster.h @@ -34,6 +34,7 @@ private: string OutPutFile, format; ListVector* list; float cutoff; + MothurOut* m; void convertPhylip2Column(NameAssignment*); }; diff --git a/readcolumn.cpp b/readcolumn.cpp index 6b8892b..12a38c2 100644 --- a/readcolumn.cpp +++ b/readcolumn.cpp @@ -127,7 +127,7 @@ void ReadColumnMatrix::read(NameAssignment* nameMap){ } catch(exception& e) { - errorOut(e, "ReadColumnMatrix", "read"); + m->errorOut(e, "ReadColumnMatrix", "read"); exit(1); } } diff --git a/readdistcommand.cpp b/readdistcommand.cpp index 9cb2046..c83ed8a 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -12,7 +12,7 @@ #include "readcolumn.h" #include "readmatrix.hpp" -ReadDistCommand::ReadDistCommand(string option){ +ReadDistCommand::ReadDistCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -108,8 +108,8 @@ ReadDistCommand::ReadDistCommand(string option){ if ((phylipfile != "") && (groupfile != "")) { globaldata->setFormat("matrix"); } - if ((phylipfile == "") && (columnfile == "")) { mothurOut("When executing a read.dist command you must enter a phylip or a column."); mothurOutEndLine(); abort = true; } - else if ((phylipfile != "") && (columnfile != "")) { mothurOut("When executing a read.dist command you must enter ONLY ONE of the following: phylip or column."); mothurOutEndLine(); abort = true; } + if ((phylipfile == "") && (columnfile == "")) { m->mothurOut("When executing a read.dist command you must enter a phylip or a column."); m->mothurOutEndLine(); abort = true; } + else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When executing a read.dist command you must enter ONLY ONE of the following: phylip or column."); m->mothurOutEndLine(); abort = true; } if (columnfile != "") { if (namefile == "") { cout << "You need to provide a namefile if you are going to use the column format." << endl; abort = true; } @@ -158,7 +158,7 @@ ReadDistCommand::ReadDistCommand(string option){ } catch(exception& e) { - errorOut(e, "ReadDistCommand", "ReadDistCommand"); + m->errorOut(e, "ReadDistCommand", "ReadDistCommand"); exit(1); } } @@ -166,19 +166,19 @@ ReadDistCommand::ReadDistCommand(string option){ void ReadDistCommand::help(){ try { - mothurOut("The read.dist command parameter options are phylip or column, group, name, cutoff and precision\n"); - 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"); - mothurOut("For this use the read.dist command should be in the following format: \n"); - mothurOut("read.dist(phylip=yourDistFile, name=yourNameFile, cutoff=yourCutoff, precision=yourPrecision) \n"); - 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"); - 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"); - 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"); - mothurOut("For this use the read.dist command should be in the following format: \n"); - mothurOut("read.dist(phylip=yourPhylipfile, group=yourGroupFile). The cutoff and precision parameters are not valid with this use. \n"); - mothurOut("Note: No spaces between parameter labels (i.e. phylip), '=' and parameters (i.e.yourPhylipfile).\n\n"); + m->mothurOut("The read.dist command parameter options are phylip or column, group, name, 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("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) { - errorOut(e, "ReadDistCommand", "help"); + m->errorOut(e, "ReadDistCommand", "help"); exit(1); } } @@ -203,6 +203,8 @@ int ReadDistCommand::execute(){ time_t start = time(NULL); size_t numDists = 0; + vector outputNames; + if (format == "matrix") { ifstream in; openInputFile(distFileName, in); @@ -211,11 +213,12 @@ int ReadDistCommand::execute(){ //if files don't match... if (matrix->getNumSeqs() < groupMap->getNumSeqs()) { - mothurOut("Your distance file contains " + toString(matrix->getNumSeqs()) + " sequences, and your group file contains " + toString(groupMap->getNumSeqs()) + " sequences."); mothurOutEndLine(); + 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 += hasPath(groupfile); } string newGroupFile = outputDir + getRootName(getSimpleName(groupfile)) + "editted.groups"; + outputNames.push_back(newGroupFile); ofstream outGroups; openOutputFile(newGroupFile, outGroups); @@ -225,7 +228,7 @@ int ReadDistCommand::execute(){ } outGroups.close(); - mothurOut(newGroupFile + " is a new group file containing only the sequence that are in your distance file. I will read this file instead."); mothurOutEndLine(); + m->mothurOut(newGroupFile + " is a new group file containing only the sequence that are in your distance file. I will read this file instead."); m->mothurOutEndLine(); //read new groupfile delete groupMap; groupMap = NULL; @@ -277,14 +280,22 @@ int ReadDistCommand::execute(){ //dist_string = dist_string.append("\t").append(toString(dist_cutoff[i])); // count_string = count_string.append("\t").append(toString(dist_count[i])); // } - //mothurOut(dist_string); mothurOutEndLine(); mothurOut(count_string); mothurOutEndLine(); + //m->mothurOut(dist_string); m->mothurOutEndLine(); m->mothurOut(count_string); m->mothurOutEndLine(); + } + + if (outputNames.size() != 0) { + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); } + m->mothurOutEndLine(); } - mothurOut("It took " + toString(time(NULL) - start) + " secs to read "); mothurOutEndLine(); + + m->mothurOut("It took " + toString(time(NULL) - start) + " secs to read "); m->mothurOutEndLine(); return 0; } catch(exception& e) { - errorOut(e, "ReadDistCommand", "execute"); + m->errorOut(e, "ReadDistCommand", "execute"); exit(1); } } diff --git a/readmatrix.hpp b/readmatrix.hpp index d8f9bd1..2c47832 100644 --- a/readmatrix.hpp +++ b/readmatrix.hpp @@ -21,7 +21,7 @@ class SparseMatrix; class ReadMatrix { public: - ReadMatrix(){ D = new SparseMatrix(); } + ReadMatrix(){ D = new SparseMatrix(); m = MothurOut::getInstance(); } virtual ~ReadMatrix() {} virtual void read(NameAssignment*){}; virtual void read(GlobalData* globaldata){}; @@ -37,6 +37,7 @@ protected: ListVector* list; GlobalData* globaldata; float cutoff; + MothurOut* m; }; diff --git a/readotu.cpp b/readotu.cpp index 84132ae..98a63f0 100644 --- a/readotu.cpp +++ b/readotu.cpp @@ -12,7 +12,7 @@ /***********************************************************************/ ReadOTUFile::ReadOTUFile(string pf): philFile(pf){ - + m = MothurOut::getInstance(); //openInputFile(philFile, fileHandle); } @@ -70,7 +70,7 @@ void ReadOTUFile::read(GlobalData* globaldata){ } } catch(exception& e) { - errorOut(e, "ReadOTUFile", "read"); + m->errorOut(e, "ReadOTUFile", "read"); exit(1); } } diff --git a/readotu.h b/readotu.h index 399316d..6c8d67c 100644 --- a/readotu.h +++ b/readotu.h @@ -39,6 +39,7 @@ private: SAbundVector* sabund; RAbundVector* rabund; GlobalData* globaldata; + MothurOut* m; // InputData* getInput() { return input; } }; diff --git a/readotucommand.cpp b/readotucommand.cpp index 89013e6..4ad63da 100644 --- a/readotucommand.cpp +++ b/readotucommand.cpp @@ -10,7 +10,7 @@ #include "readotucommand.h" //********************************************************************************************************************** -ReadOtuCommand::ReadOtuCommand(string option){ +ReadOtuCommand::ReadOtuCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -142,7 +142,7 @@ ReadOtuCommand::ReadOtuCommand(string option){ //you have not given a file if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "")) { - mothurOut("You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. "); mothurOutEndLine(); abort = true; + m->mothurOut("You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. "); m->mothurOutEndLine(); abort = true; } //check for optional parameter and set defaults @@ -172,7 +172,7 @@ ReadOtuCommand::ReadOtuCommand(string option){ } catch(exception& e) { - errorOut(e, "ReadOtuCommand", "ReadOtuCommand"); + m->errorOut(e, "ReadOtuCommand", "ReadOtuCommand"); exit(1); } } @@ -180,23 +180,23 @@ ReadOtuCommand::ReadOtuCommand(string option){ void ReadOtuCommand::help(){ try { - mothurOut("The read.otu command must be run before you execute a collect.single, rarefaction.single, summary.single, \n"); - mothurOut("collect.shared, rarefaction.shared or summary.shared command. Mothur will generate a .list, .rabund and .sabund upon completion of the cluster command \n"); - mothurOut("or you may use your own. The read.otu command parameter options are list, rabund, sabund, shared, group, order, label and groups.\n"); - 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"); - mothurOut("For this use the read.otu command should be in the following format: read.otu(list=yourListFile, order=yourOrderFile, label=yourLabels).\n"); - mothurOut("The list, rabund or sabund parameter is required, but you may only use one of them.\n"); - mothurOut("The label parameter is used to read specific labels in your input.\n"); - 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"); - 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"); - 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"); - 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"); - mothurOut("You can use the groups parameter to choose only specific groups to be used in the .shared and .rabund files. \n"); - mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); + 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 or summary.shared 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, group, order, 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("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n"); } catch(exception& e) { - errorOut(e, "ReadOtuCommand", "help"); + m->errorOut(e, "ReadOtuCommand", "help"); exit(1); } } @@ -225,6 +225,11 @@ int ReadOtuCommand::execute(){ globaldata->setListFile(""); globaldata->setGroupFile(""); globaldata->setSharedFile(""); + }else { + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(globaldata->getSharedFile()); m->mothurOutEndLine(); + m->mothurOutEndLine(); } delete shared; @@ -232,7 +237,7 @@ int ReadOtuCommand::execute(){ return 0; } catch(exception& e) { - errorOut(e, "ReadOtuCommand", "execute"); + m->errorOut(e, "ReadOtuCommand", "execute"); exit(1); } } diff --git a/readphylip.cpp b/readphylip.cpp index 5f92275..6d7d4d0 100644 --- a/readphylip.cpp +++ b/readphylip.cpp @@ -38,7 +38,7 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){ } else{ list = new ListVector(nameMap->getListVector()); - if(nameMap->count(name)==0){ mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); } + if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); } } char d; @@ -89,7 +89,7 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){ } else{ - if(nameMap->count(name)==0){ mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); } + if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); } for(int j=0;j> distance; @@ -133,7 +133,7 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){ } else{ - if(nameMap->count(name)==0){ mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); mothurOutEndLine(); } + if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); } for(int j=0;j> distance; @@ -162,13 +162,13 @@ void ReadPhylipMatrix::read(NameAssignment* nameMap){ } if(nameMap->size() > 0){ //should probably tell them what is missing if we missed something - mothurOut("missed something\t" + toString(nameMap->size())); mothurOutEndLine(); + m->mothurOut("missed something\t" + toString(nameMap->size())); m->mothurOutEndLine(); } } */ } catch(exception& e) { - errorOut(e, "ReadPhylipMatrix", "read"); + m->errorOut(e, "ReadPhylipMatrix", "read"); exit(1); } } diff --git a/readtree.cpp b/readtree.cpp index cdaa387..661a5a9 100644 --- a/readtree.cpp +++ b/readtree.cpp @@ -13,10 +13,11 @@ ReadTree::ReadTree() { try { globaldata = GlobalData::getInstance(); + m = MothurOut::getInstance(); globaldata->gTree.clear(); } catch(exception& e) { - errorOut(e, "ReadTree", "ReadTree"); + m->errorOut(e, "ReadTree", "ReadTree"); exit(1); } } @@ -28,11 +29,11 @@ int ReadTree::readSpecialChar(istream& f, char c, string name) { char d = f.get(); if(d == EOF){ - mothurOut("Error: Input file ends prematurely, expecting a " + name + "\n"); + m->mothurOut("Error: Input file ends prematurely, expecting a " + name + "\n"); exit(1); } if(d != c){ - mothurOut("Error: Expected " + name + " in input file. Found " + toString(d) + ".\n"); + m->mothurOut("Error: Expected " + name + " in input file. Found " + toString(d) + ".\n"); exit(1); } if(d == ')' && f.peek() == '\n'){ @@ -41,7 +42,7 @@ int ReadTree::readSpecialChar(istream& f, char c, string name) { return d; } catch(exception& e) { - errorOut(e, "ReadTree", "readSpecialChar"); + m->errorOut(e, "ReadTree", "readSpecialChar"); exit(1); } } @@ -54,13 +55,13 @@ int ReadTree::readNodeChar(istream& f) { char d = f.get(); if(d == EOF){ - mothurOut("Error: Input file ends prematurely, expecting a left parenthesis\n"); + m->mothurOut("Error: Input file ends prematurely, expecting a left parenthesis\n"); exit(1); } return d; } catch(exception& e) { - errorOut(e, "ReadTree", "readNodeChar"); + m->errorOut(e, "ReadTree", "readNodeChar"); exit(1); } } @@ -72,14 +73,14 @@ float ReadTree::readBranchLength(istream& f) { float b; if(!(f >> b)){ - mothurOut("Error: Missing branch length in input tree.\n"); + m->mothurOut("Error: Missing branch length in input tree.\n"); exit(1); } gobble(f); return b; } catch(exception& e) { - errorOut(e, "ReadTree", "readBranchLength"); + m->errorOut(e, "ReadTree", "readBranchLength"); exit(1); } } @@ -167,7 +168,7 @@ int ReadNewickTree::read() { return readOk; } catch(exception& e) { - errorOut(e, "ReadNewickTree", "read"); + m->errorOut(e, "ReadNewickTree", "read"); exit(1); } } @@ -208,7 +209,7 @@ void ReadNewickTree::nexusTranslation() { } } catch(exception& e) { - errorOut(e, "ReadNewickTree", "nexusTranslation"); + m->errorOut(e, "ReadNewickTree", "nexusTranslation"); exit(1); } } @@ -228,7 +229,7 @@ int ReadNewickTree::readTreeString() { n = numLeaves; //number of leaves / sequences, we want node 1 to start where the leaves left off lc = readNewickInt(filehandle, n, T); - if (lc == -1) { mothurOut("error with lc"); mothurOutEndLine(); return -1; } //reports an error in reading + if (lc == -1) { m->mothurOut("error with lc"); m->mothurOutEndLine(); return -1; } //reports an error in reading if(filehandle.peek()==','){ readSpecialChar(filehandle,',',"comma"); @@ -239,7 +240,7 @@ int ReadNewickTree::readTreeString() { } if(rooted != 1){ rc = readNewickInt(filehandle, n, T); - if (rc == -1) { mothurOut("error with rc"); mothurOutEndLine(); return -1; } //reports an error in reading + if (rc == -1) { m->mothurOut("error with rc"); m->mothurOutEndLine(); return -1; } //reports an error in reading if(filehandle.peek() == ')'){ readSpecialChar(filehandle,')',"right parenthesis"); } @@ -255,7 +256,7 @@ int ReadNewickTree::readTreeString() { n = T->getIndex(name); if(n!=0){ - mothurOut("Internal error: The only taxon is not taxon 0.\n"); + m->mothurOut("Internal error: The only taxon is not taxon 0.\n"); //exit(1); readOk = -1; return -1; } @@ -274,7 +275,7 @@ int ReadNewickTree::readTreeString() { } catch(exception& e) { - errorOut(e, "ReadNewickTree", "readTreeString"); + m->errorOut(e, "ReadNewickTree", "readTreeString"); exit(1); } } @@ -303,7 +304,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { if(f.peek() == ':'){ readSpecialChar(f,':',"colon"); - if(n >= numNodes){ mothurOut("Error: Too many nodes in input tree\n"); readOk = -1; return -1; } + if(n >= numNodes){ m->mothurOut("Error: Too many nodes in input tree\n"); readOk = -1; return -1; } T->tree[n].setBranchLength(readBranchLength(f)); }else{ @@ -337,7 +338,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { //adds sequence names that are not in group file to the "xxx" group if(group == "not found") { - mothurOut("Name: " + name + " is not in your groupfile, and will be disregarded. \n"); //readOk = -1; return n1; + 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"; @@ -373,7 +374,7 @@ int ReadNewickTree::readNewickInt(istream& f, int& n, Tree* T) { } } catch(exception& e) { - errorOut(e, "ReadNewickTree", "readNewickInt"); + m->errorOut(e, "ReadNewickTree", "readNewickInt"); exit(1); } } diff --git a/readtree.h b/readtree.h index 0cdf8b1..540f80c 100644 --- a/readtree.h +++ b/readtree.h @@ -33,6 +33,7 @@ class ReadTree { protected: GlobalData* globaldata; int numNodes, numLeaves; + MothurOut* m; }; diff --git a/readtreecommand.cpp b/readtreecommand.cpp index a11465d..da66ee1 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -10,11 +10,11 @@ #include "readtreecommand.h" //********************************************************************************************************************** -ReadTreeCommand::ReadTreeCommand(string option){ +ReadTreeCommand::ReadTreeCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -71,12 +71,12 @@ ReadTreeCommand::ReadTreeCommand(string option){ //check for required parameters treefile = validParameter.validFile(parameters, "tree", true); if (treefile == "not open") { abort = true; } - else if (treefile == "not found") { treefile = ""; mothurOut("tree is a required parameter for the read.tree command."); mothurOutEndLine(); 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; } - else if (groupfile == "not found") { groupfile = ""; mothurOut("group is a required parameter for the read.tree command."); mothurOutEndLine(); abort = true; } + else if (groupfile == "not found") { groupfile = ""; m->mothurOut("group is a required parameter for the read.tree command."); m->mothurOutEndLine(); abort = true; } else { globaldata->setGroupFile(groupfile); //read in group map info. @@ -98,7 +98,7 @@ ReadTreeCommand::ReadTreeCommand(string option){ } } catch(exception& e) { - errorOut(e, "ReadTreeCommand", "ReadTreeCommand"); + m->errorOut(e, "ReadTreeCommand", "ReadTreeCommand"); exit(1); } } @@ -106,14 +106,14 @@ ReadTreeCommand::ReadTreeCommand(string option){ void ReadTreeCommand::help(){ try { - mothurOut("The read.tree command must be run before you execute a unifrac.weighted, unifrac.unweighted. \n"); - mothurOut("It also must be run before using the parsimony command, unless you are using the randomtree parameter.\n"); - mothurOut("The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile).\n"); - mothurOut("The tree and group parameters are both required.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n"); + 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 should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile).\n"); + m->mothurOut("The tree and group parameters are both required.\n"); + m->mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n"); } catch(exception& e) { - errorOut(e, "ReadTreeCommand", "help"); + m->errorOut(e, "ReadTreeCommand", "help"); exit(1); } } @@ -135,7 +135,7 @@ int ReadTreeCommand::execute(){ readOk = read->read(); - if (readOk != 0) { mothurOut("Read Terminated."); mothurOutEndLine(); globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; } + if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; } vector T = globaldata->gTree; @@ -160,7 +160,7 @@ int ReadTreeCommand::execute(){ map::iterator it = nameMap.find(treeMap->namesOfSeqs[i]); if (it == nameMap.end()) { - mothurOut(treeMap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); mothurOutEndLine(); + m->mothurOut(treeMap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine(); treeMap->removeSeq(treeMap->namesOfSeqs[i]); i--; //need this because removeSeq removes name from namesOfSeqs } @@ -171,7 +171,7 @@ int ReadTreeCommand::execute(){ return 0; } catch(exception& e) { - errorOut(e, "ReadTreeCommand", "execute"); + m->errorOut(e, "ReadTreeCommand", "execute"); exit(1); } } @@ -198,14 +198,14 @@ int ReadTreeCommand::readNamesFile() { splitAtComma(second, dupNames); for (int i = 0; i < dupNames.size(); i++) { nameMap[dupNames[i]] = dupNames[i]; } - }else { mothurOut(first + " has already been seen in namefile, disregarding names file."); mothurOutEndLine(); in.close(); globaldata->names.clear(); return 1; } + }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); return 1; } } in.close(); return 0; } catch(exception& e) { - errorOut(e, "ReadTreeCommand", "readNamesFile"); + m->errorOut(e, "ReadTreeCommand", "readNamesFile"); exit(1); } } diff --git a/removeseqscommand.cpp b/removeseqscommand.cpp index 19a4bc0..c76c711 100644 --- a/removeseqscommand.cpp +++ b/removeseqscommand.cpp @@ -13,7 +13,7 @@ //********************************************************************************************************************** -RemoveSeqsCommand::RemoveSeqsCommand(string option){ +RemoveSeqsCommand::RemoveSeqsCommand(string option) { try { abort = false; @@ -97,7 +97,7 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option){ //check for required parameters accnosfile = validParameter.validFile(parameters, "accnos", true); if (accnosfile == "not open") { abort = true; } - else if (accnosfile == "not found") { accnosfile = ""; mothurOut("You must provide an accnos file."); mothurOutEndLine(); abort = true; } + else if (accnosfile == "not found") { accnosfile = ""; m->mothurOut("You must provide an accnos file."); m->mothurOutEndLine(); abort = true; } fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } @@ -123,20 +123,20 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option){ string temp = validParameter.validFile(parameters, "dups", false); if (temp == "not found") { temp = "false"; usedDups = ""; } dups = isTrue(temp); - if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "")) { mothurOut("You must provide one of the following: fasta, name, group, alignreport or list."); mothurOutEndLine(); abort = true; } + if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport or list."); m->mothurOutEndLine(); abort = true; } int okay = 2; if (outputDir != "") { okay++; } if (usedDups != "") { okay++; } - if ((usedDups != "") && (namefile == "")) { mothurOut("You may only use dups with the name option."); mothurOutEndLine(); abort = true; } + if ((usedDups != "") && (namefile == "")) { m->mothurOut("You may only use dups with the name option."); m->mothurOutEndLine(); abort = true; } - if (parameters.size() > okay) { mothurOut("You may only enter one of the following: fasta, name, group, alignreport, or list."); mothurOutEndLine(); abort = true; } + if (parameters.size() > okay) { m->mothurOut("You may only enter one of the following: fasta, name, group, alignreport, or list."); m->mothurOutEndLine(); abort = true; } } } catch(exception& e) { - errorOut(e, "RemoveSeqsCommand", "RemoveSeqsCommand"); + m->errorOut(e, "RemoveSeqsCommand", "RemoveSeqsCommand"); exit(1); } } @@ -144,16 +144,16 @@ RemoveSeqsCommand::RemoveSeqsCommand(string option){ void RemoveSeqsCommand::help(){ try { - mothurOut("The remove.seqs command reads an .accnos file and one of the following file types: fasta, name, group, list or alignreport file.\n"); - mothurOut("It outputs a file containing the sequences NOT in the .accnos file.\n"); - mothurOut("The remove.seqs command parameters are accnos, fasta, name, group, list, alignreport and dups. You must provide accnos and one of the file parameters.\n"); - mothurOut("The dups parameter allows you to remove the entire line from a name file if you remove any name from the line. default=false. If dups=true, then remove.seqs outputs a new .accnos file containing all the sequences removed. \n"); - mothurOut("The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n"); - mothurOut("Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); + m->mothurOut("The remove.seqs command reads an .accnos file and one of the following file types: fasta, name, group, list 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, alignreport and dups. You must provide accnos and 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=false. If dups=true, then remove.seqs outputs a new .accnos file containing all the sequences removed. \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) { - errorOut(e, "RemoveSeqsCommand", "help"); + m->errorOut(e, "RemoveSeqsCommand", "help"); exit(1); } } @@ -175,11 +175,18 @@ int RemoveSeqsCommand::execute(){ else if (alignfile != "") { readAlign(); } else if (listfile != "") { readList(); } + if (outputNames.size() != 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(); + } + return 0; } catch(exception& e) { - errorOut(e, "RemoveSeqsCommand", "execute"); + m->errorOut(e, "RemoveSeqsCommand", "execute"); exit(1); } } @@ -216,13 +223,13 @@ void RemoveSeqsCommand::readFasta(){ out.close(); if (wroteSomething == false) { - mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "RemoveSeqsCommand", "readFasta"); + m->errorOut(e, "RemoveSeqsCommand", "readFasta"); exit(1); } } @@ -281,13 +288,13 @@ void RemoveSeqsCommand::readList(){ out.close(); if (wroteSomething == false) { - mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "RemoveSeqsCommand", "readList"); + m->errorOut(e, "RemoveSeqsCommand", "readList"); exit(1); } } @@ -374,16 +381,16 @@ void RemoveSeqsCommand::readName(){ if (dups) { out2.close(); } if (wroteDups == false) { remove(outputFileName2.c_str()); - } + }else { outputNames.push_back(outputFileName2); } if (wroteSomething == false) { - mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "RemoveSeqsCommand", "readName"); + m->errorOut(e, "RemoveSeqsCommand", "readName"); exit(1); } } @@ -419,13 +426,13 @@ void RemoveSeqsCommand::readGroup(){ out.close(); if (wroteSomething == false) { - mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "RemoveSeqsCommand", "readGroup"); + m->errorOut(e, "RemoveSeqsCommand", "readGroup"); exit(1); } } @@ -485,13 +492,13 @@ void RemoveSeqsCommand::readAlign(){ out.close(); if (wroteSomething == false) { - mothurOut("Your file contains only sequences from the .accnos file."); mothurOutEndLine(); + m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); remove(outputFileName.c_str()); - } + }else { outputNames.push_back(outputFileName); } } catch(exception& e) { - errorOut(e, "RemoveSeqsCommand", "readAlign"); + m->errorOut(e, "RemoveSeqsCommand", "readAlign"); exit(1); } } @@ -514,7 +521,7 @@ void RemoveSeqsCommand::readAccnos(){ } catch(exception& e) { - errorOut(e, "RemoveSeqsCommand", "readAccnos"); + m->errorOut(e, "RemoveSeqsCommand", "readAccnos"); exit(1); } } diff --git a/removeseqscommand.h b/removeseqscommand.h index 647cb76..ddda08c 100644 --- a/removeseqscommand.h +++ b/removeseqscommand.h @@ -25,6 +25,7 @@ class RemoveSeqsCommand : public Command { set names; string accnosfile, fastafile, namefile, groupfile, alignfile, listfile, outputDir; bool abort, dups; + vector outputNames; void readFasta(); void readName(); diff --git a/reversecommand.cpp b/reversecommand.cpp index 2742401..4efcbcc 100644 --- a/reversecommand.cpp +++ b/reversecommand.cpp @@ -13,7 +13,7 @@ //*************************************************************************************************************** -ReverseSeqsCommand::ReverseSeqsCommand(string option){ +ReverseSeqsCommand::ReverseSeqsCommand(string option) { try { abort = false; @@ -53,7 +53,7 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option){ //check for required parameters fasta = validParameter.validFile(parameters, "fasta", true); if (fasta == "not open") { abort = true; } - else if (fasta == "not found") { fasta = ""; mothurOut("fasta is a required parameter for the reverse.seqs command."); mothurOutEndLine(); abort = true; } + else if (fasta == "not found") { fasta = ""; m->mothurOut("fasta 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"){ @@ -64,7 +64,7 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option){ } } catch(exception& e) { - errorOut(e, "ReverseSeqsCommand", "ReverseSeqsCommand"); + m->errorOut(e, "ReverseSeqsCommand", "ReverseSeqsCommand"); exit(1); } } @@ -72,13 +72,13 @@ ReverseSeqsCommand::ReverseSeqsCommand(string option){ void ReverseSeqsCommand::help(){ try { - mothurOut("The reverse.seqs command reads a fastafile and ....\n"); - mothurOut("The reverse.seqs command parameter is fasta and it is required.\n"); - mothurOut("The reverse.seqs command should be in the following format: \n"); - mothurOut("reverse.seqs(fasta=yourFastaFile) \n"); + m->mothurOut("The reverse.seqs command reads a fastafile and ....\n"); + m->mothurOut("The reverse.seqs command parameter is fasta and it is 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) { - errorOut(e, "ReverseSeqsCommand", "help"); + m->errorOut(e, "ReverseSeqsCommand", "help"); exit(1); } } @@ -112,11 +112,17 @@ int ReverseSeqsCommand::execute(){ inFASTA.close(); outFASTA.close(); + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(reverseFile); m->mothurOutEndLine(); + m->mothurOutEndLine(); + + return 0; } catch(exception& e) { - errorOut(e, "ReverseSeqsCommand", "execute"); + m->errorOut(e, "ReverseSeqsCommand", "execute"); exit(1); } } diff --git a/sabundvector.cpp b/sabundvector.cpp index 2bb8d69..6e4401b 100644 --- a/sabundvector.cpp +++ b/sabundvector.cpp @@ -29,7 +29,7 @@ SAbundVector::SAbundVector(string id, vector sav) : DataVector(id), data(sa } } catch(exception& e) { - errorOut(e, "SAbundVector", "SAbundVector"); + m->errorOut(e, "SAbundVector", "SAbundVector"); exit(1); } } @@ -44,7 +44,7 @@ SAbundVector::SAbundVector(vector dataVec, int mr, int nb, int ns) { numSeqs = ns; } catch(exception& e) { - errorOut(e, "SAbundVector", "SAbundVector"); + m->errorOut(e, "SAbundVector", "SAbundVector"); exit(1); } } @@ -66,7 +66,7 @@ SAbundVector::SAbundVector(ifstream& f): DataVector(), maxRank(0), numBins(0), n } catch(exception& e) { - errorOut(e, "SAbundVector", "SAbundVector"); + m->errorOut(e, "SAbundVector", "SAbundVector"); exit(1); } } @@ -89,7 +89,7 @@ void SAbundVector::set(int sabund, int abundance){ if(sabund > maxRank) { maxRank = sabund; } } catch(exception& e) { - errorOut(e, "SAbundVector", "set"); + m->errorOut(e, "SAbundVector", "set"); exit(1); } } @@ -114,7 +114,7 @@ void SAbundVector::push_back(int abundance){ numSeqs += (maxRank * abundance); } catch(exception& e) { - errorOut(e, "SAbundVector", "push_back"); + m->errorOut(e, "SAbundVector", "push_back"); exit(1); } } @@ -165,7 +165,7 @@ void SAbundVector::print(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "SAbundVector", "print"); + m->errorOut(e, "SAbundVector", "print"); exit(1); } } @@ -205,7 +205,7 @@ RAbundVector SAbundVector::getRAbundVector(){ return rav; } catch(exception& e) { - errorOut(e, "SAbundVector", "getRAbundVector"); + m->errorOut(e, "SAbundVector", "getRAbundVector"); exit(1); } } @@ -240,7 +240,7 @@ OrderVector SAbundVector::getOrderVector(map* hold = NULL){ return ov; } catch(exception& e) { - errorOut(e, "SAbundVector", "getOrderVector"); + m->errorOut(e, "SAbundVector", "getOrderVector"); exit(1); } } diff --git a/screenseqscommand.cpp b/screenseqscommand.cpp index 48bf171..bb8d1f5 100644 --- a/screenseqscommand.cpp +++ b/screenseqscommand.cpp @@ -12,7 +12,7 @@ //*************************************************************************************************************** -ScreenSeqsCommand::ScreenSeqsCommand(string option){ +ScreenSeqsCommand::ScreenSeqsCommand(string option) { try { abort = false; @@ -76,7 +76,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){ //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); - if (fastafile == "not found") { mothurOut("fasta is a required parameter for the screen.seqs command."); mothurOutEndLine(); abort = true; } + if (fastafile == "not found") { m->mothurOut("fasta is a required parameter for the screen.seqs command."); m->mothurOutEndLine(); abort = true; } else if (fastafile == "not open") { abort = true; } groupfile = validParameter.validFile(parameters, "group", true); @@ -121,7 +121,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){ } catch(exception& e) { - errorOut(e, "ScreenSeqsCommand", "ScreenSeqsCommand"); + m->errorOut(e, "ScreenSeqsCommand", "ScreenSeqsCommand"); exit(1); } } @@ -129,25 +129,25 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option){ void ScreenSeqsCommand::help(){ try { - mothurOut("The screen.seqs command reads a fastafile and creates .....\n"); - mothurOut("The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, and group.\n"); - mothurOut("The fasta parameter is required.\n"); - mothurOut("The start parameter .... The default is -1.\n"); - mothurOut("The end parameter .... The default is -1.\n"); - mothurOut("The maxambig parameter .... The default is -1.\n"); - mothurOut("The maxhomop parameter .... The default is -1.\n"); - mothurOut("The minlength parameter .... The default is -1.\n"); - mothurOut("The maxlength parameter .... The default is -1.\n"); - mothurOut("The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile.\n"); - mothurOut("The screen.seqs command should be in the following format: \n"); - mothurOut("screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig, \n"); - mothurOut("maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength) \n"); - mothurOut("Example screen.seqs(fasta=abrecovery.fasta, name=abrecovery.names, group=abrecovery.groups, start=..., end=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); + 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, and group.\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 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) { - errorOut(e, "ScreenSeqsCommand", "help"); + m->errorOut(e, "ScreenSeqsCommand", "help"); exit(1); } } @@ -203,10 +203,18 @@ int ScreenSeqsCommand::execute(){ goodSeqOut.close(); badSeqOut.close(); inFASTA.close(); + + m->mothurOutEndLine(); + m->mothurOut("Output File Names: "); m->mothurOutEndLine(); + m->mothurOut(goodSeqFile); m->mothurOutEndLine(); + m->mothurOut(badSeqFile); m->mothurOutEndLine(); + m->mothurOutEndLine(); + + return 0; } catch(exception& e) { - errorOut(e, "ScreenSeqsCommand", "execute"); + m->errorOut(e, "ScreenSeqsCommand", "execute"); exit(1); } } @@ -257,8 +265,8 @@ void ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ //we were unable to remove some of the bad sequences if (badSeqNames.size() != 0) { for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) { - mothurOut("Your namefile does not include the sequence " + *it + " please correct."); - mothurOutEndLine(); + m->mothurOut("Your namefile does not include the sequence " + *it + " please correct."); + m->mothurOutEndLine(); } } @@ -294,8 +302,8 @@ void ScreenSeqsCommand::screenNameGroupFile(set badSeqNames){ //we were unable to remove some of the bad sequences if (badSeqGroups.size() != 0) { for (it = badSeqGroups.begin(); it != badSeqGroups.end(); it++) { - mothurOut("Your namefile does not include the sequence " + *it + " please correct."); - mothurOutEndLine(); + m->mothurOut("Your namefile does not include the sequence " + *it + " please correct."); + m->mothurOutEndLine(); } } } @@ -333,8 +341,8 @@ void ScreenSeqsCommand::screenGroupFile(set badSeqNames){ //we were unable to remove some of the bad sequences if (badSeqNames.size() != 0) { for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) { - mothurOut("Your groupfile does not include the sequence " + *it + " please correct."); - mothurOutEndLine(); + m->mothurOut("Your groupfile does not include the sequence " + *it + " please correct."); + m->mothurOutEndLine(); } } @@ -389,8 +397,8 @@ void ScreenSeqsCommand::screenAlignReport(set badSeqNames){ //we were unable to remove some of the bad sequences if (badSeqNames.size() != 0) { for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) { - mothurOut("Your file does not include the sequence " + *it + " please correct."); - mothurOutEndLine(); + m->mothurOut("Your file does not include the sequence " + *it + " please correct."); + m->mothurOutEndLine(); } } diff --git a/secondarystructurecommand.cpp b/secondarystructurecommand.cpp index 8acd696..e23a0ac 100644 --- a/secondarystructurecommand.cpp +++ b/secondarystructurecommand.cpp @@ -12,11 +12,11 @@ //********************************************************************************************************************** -AlignCheckCommand::AlignCheckCommand(string option){ +AlignCheckCommand::AlignCheckCommand(string option) { try { abort = false; haderror = 0; - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -61,11 +61,11 @@ AlignCheckCommand::AlignCheckCommand(string option){ //check for required parameters mapfile = validParameter.validFile(parameters, "map", true); if (mapfile == "not open") { abort = true; } - else if (mapfile == "not found") { mapfile = ""; mothurOut("You must provide an map file."); mothurOutEndLine(); abort = true; } + else if (mapfile == "not found") { mapfile = ""; m->mothurOut("You must provide an map file."); m->mothurOutEndLine(); abort = true; } fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; mothurOut("You must provide an fasta file."); mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { fastafile = ""; m->mothurOut("You must provide an fasta 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"){ @@ -77,7 +77,7 @@ AlignCheckCommand::AlignCheckCommand(string option){ } catch(exception& e) { - errorOut(e, "AlignCheckCommand", "RemoveSeqsCommand"); + m->errorOut(e, "AlignCheckCommand", "RemoveSeqsCommand"); exit(1); } } @@ -85,15 +85,15 @@ AlignCheckCommand::AlignCheckCommand(string option){ void AlignCheckCommand::help(){ try { - mothurOut("The align.check command reads a fasta file and map file.\n"); - mothurOut("It outputs a file containing the secondary structure matches in the .align.check file.\n"); - mothurOut("The align.check command parameters are fasta and map, both are required.\n"); - mothurOut("The align.check command should be in the following format: align.check(fasta=yourFasta, map=yourMap).\n"); - mothurOut("Example align.check(map=silva.ss.map, fasta=amazon.fasta).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n\n"); + 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) { - errorOut(e, "AlignCheckCommand", "help"); + m->errorOut(e, "AlignCheckCommand", "help"); exit(1); } } @@ -135,11 +135,16 @@ int AlignCheckCommand::execute(){ in.close(); out.close(); + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(outfile); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "AlignCheckCommand", "execute"); + m->errorOut(e, "AlignCheckCommand", "execute"); exit(1); } } @@ -167,7 +172,7 @@ void AlignCheckCommand::readMap(){ for(int i=0;imothurOut("Your map file contains an error: line " + toString(i) + " does not match line " + toString(structMap[i]) + "."); m->mothurOutEndLine(); } } } @@ -175,7 +180,7 @@ void AlignCheckCommand::readMap(){ } catch(exception& e) { - errorOut(e, "AlignCheckCommand", "readMap"); + m->errorOut(e, "AlignCheckCommand", "readMap"); exit(1); } } @@ -189,7 +194,7 @@ statData AlignCheckCommand::getStats(string sequence){ int length = sequence.length(); - if (length != seqLength) { mothurOut("your sequences are " + toString(length) + " long, but your map file only contains " + toString(seqLength) + " entries. please correct."); mothurOutEndLine(); haderror = 1; return data; } + if (length != seqLength) { m->mothurOut("your sequences are " + toString(length) + " long, but your map file only contains " + toString(seqLength) + " entries. please correct."); m->mothurOutEndLine(); haderror = 1; return data; } for(int i=1;ierrorOut(e, "AlignCheckCommand", "getStats"); exit(1); } } diff --git a/seqsummarycommand.cpp b/seqsummarycommand.cpp index 8b07b85..49edc36 100644 --- a/seqsummarycommand.cpp +++ b/seqsummarycommand.cpp @@ -12,7 +12,7 @@ //*************************************************************************************************************** -SeqSummaryCommand::SeqSummaryCommand(string option){ +SeqSummaryCommand::SeqSummaryCommand(string option) { try { abort = false; @@ -52,7 +52,7 @@ SeqSummaryCommand::SeqSummaryCommand(string option){ //check for required parameters fastafile = validParameter.validFile(parameters, "fasta", true); if (fastafile == "not open") { abort = true; } - else if (fastafile == "not found") { fastafile = ""; mothurOut("fasta is a required parameter for the summary.seqs command."); mothurOutEndLine(); abort = true; } + else if (fastafile == "not found") { fastafile = ""; m->mothurOut("fasta is a required parameter for the summary.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"){ @@ -63,7 +63,7 @@ SeqSummaryCommand::SeqSummaryCommand(string option){ } } catch(exception& e) { - errorOut(e, "SeqSummaryCommand", "SeqSummaryCommand"); + m->errorOut(e, "SeqSummaryCommand", "SeqSummaryCommand"); exit(1); } } @@ -71,14 +71,14 @@ SeqSummaryCommand::SeqSummaryCommand(string option){ void SeqSummaryCommand::help(){ try { - mothurOut("The summary.seqs command reads a fastafile and ....\n"); - mothurOut("The summary.seqs command parameter is fasta and it is required.\n"); - mothurOut("The summary.seqs command should be in the following format: \n"); - mothurOut("summary.seqs(fasta=yourFastaFile) \n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); + m->mothurOut("The summary.seqs command reads a fastafile and ....\n"); + m->mothurOut("The summary.seqs command parameter is fasta and it is required.\n"); + m->mothurOut("The summary.seqs command should be in the following format: \n"); + m->mothurOut("summary.seqs(fasta=yourFastaFile) \n"); + m->mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFastaFile).\n\n"); } catch(exception& e) { - errorOut(e, "SeqSummaryCommand", "help"); + m->errorOut(e, "SeqSummaryCommand", "help"); exit(1); } } @@ -147,22 +147,28 @@ int SeqSummaryCommand::execute(){ if (startPosition[0] == -1) { startPosition[0] = 0; } if (endPosition[0] == -1) { endPosition[0] = 0; } - mothurOutEndLine(); - mothurOut("\t\tStart\tEnd\tNBases\tAmbigs\tPolymer"); mothurOutEndLine(); - mothurOut("Minimum:\t" + toString(startPosition[0]) + "\t" + toString(endPosition[0]) + "\t" + toString(seqLength[0]) + "\t" + toString(ambigBases[0]) + "\t" + toString(longHomoPolymer[0])); mothurOutEndLine(); - mothurOut("2.5%-tile:\t" + toString(startPosition[ptile0_25]) + "\t" + toString(endPosition[ptile0_25]) + "\t" + toString(seqLength[ptile0_25]) + "\t" + toString(ambigBases[ptile0_25]) + "\t"+ toString(longHomoPolymer[ptile0_25])); mothurOutEndLine(); - mothurOut("25%-tile:\t" + toString(startPosition[ptile25]) + "\t" + toString(endPosition[ptile25]) + "\t" + toString(seqLength[ptile25]) + "\t" + toString(ambigBases[ptile25]) + "\t" + toString(longHomoPolymer[ptile25])); mothurOutEndLine(); - mothurOut("Median: \t" + toString(startPosition[ptile50]) + "\t" + toString(endPosition[ptile50]) + "\t" + toString(seqLength[ptile50]) + "\t" + toString(ambigBases[ptile50]) + "\t" + toString(longHomoPolymer[ptile50])); mothurOutEndLine(); - mothurOut("75%-tile:\t" + toString(startPosition[ptile75]) + "\t" + toString(endPosition[ptile75]) + "\t" + toString(seqLength[ptile75]) + "\t" + toString(ambigBases[ptile75]) + "\t" + toString(longHomoPolymer[ptile75])); mothurOutEndLine(); - mothurOut("97.5%-tile:\t" + toString(startPosition[ptile97_5]) + "\t" + toString(endPosition[ptile97_5]) + "\t" + toString(seqLength[ptile97_5]) + "\t" + toString(ambigBases[ptile97_5]) + "\t" + toString(longHomoPolymer[ptile97_5])); mothurOutEndLine(); - mothurOut("Maximum:\t" + toString(startPosition[ptile100]) + "\t" + toString(endPosition[ptile100]) + "\t" + toString(seqLength[ptile100]) + "\t" + toString(ambigBases[ptile100]) + "\t" + toString(longHomoPolymer[ptile100])); mothurOutEndLine(); - mothurOut("# of Seqs:\t" + toString(numSeqs)); mothurOutEndLine(); + m->mothurOutEndLine(); + m->mothurOut("\t\tStart\tEnd\tNBases\tAmbigs\tPolymer"); m->mothurOutEndLine(); + m->mothurOut("Minimum:\t" + toString(startPosition[0]) + "\t" + toString(endPosition[0]) + "\t" + toString(seqLength[0]) + "\t" + toString(ambigBases[0]) + "\t" + toString(longHomoPolymer[0])); m->mothurOutEndLine(); + m->mothurOut("2.5%-tile:\t" + toString(startPosition[ptile0_25]) + "\t" + toString(endPosition[ptile0_25]) + "\t" + toString(seqLength[ptile0_25]) + "\t" + toString(ambigBases[ptile0_25]) + "\t"+ toString(longHomoPolymer[ptile0_25])); m->mothurOutEndLine(); + m->mothurOut("25%-tile:\t" + toString(startPosition[ptile25]) + "\t" + toString(endPosition[ptile25]) + "\t" + toString(seqLength[ptile25]) + "\t" + toString(ambigBases[ptile25]) + "\t" + toString(longHomoPolymer[ptile25])); m->mothurOutEndLine(); + m->mothurOut("Median: \t" + toString(startPosition[ptile50]) + "\t" + toString(endPosition[ptile50]) + "\t" + toString(seqLength[ptile50]) + "\t" + toString(ambigBases[ptile50]) + "\t" + toString(longHomoPolymer[ptile50])); m->mothurOutEndLine(); + m->mothurOut("75%-tile:\t" + toString(startPosition[ptile75]) + "\t" + toString(endPosition[ptile75]) + "\t" + toString(seqLength[ptile75]) + "\t" + toString(ambigBases[ptile75]) + "\t" + toString(longHomoPolymer[ptile75])); m->mothurOutEndLine(); + m->mothurOut("97.5%-tile:\t" + toString(startPosition[ptile97_5]) + "\t" + toString(endPosition[ptile97_5]) + "\t" + toString(seqLength[ptile97_5]) + "\t" + toString(ambigBases[ptile97_5]) + "\t" + toString(longHomoPolymer[ptile97_5])); m->mothurOutEndLine(); + m->mothurOut("Maximum:\t" + toString(startPosition[ptile100]) + "\t" + toString(endPosition[ptile100]) + "\t" + toString(seqLength[ptile100]) + "\t" + toString(ambigBases[ptile100]) + "\t" + toString(longHomoPolymer[ptile100])); m->mothurOutEndLine(); + m->mothurOut("# of Seqs:\t" + toString(numSeqs)); m->mothurOutEndLine(); outSummary.close(); + + m->mothurOutEndLine(); + m->mothurOut("Output File Name: "); m->mothurOutEndLine(); + m->mothurOut(summaryFile); m->mothurOutEndLine(); + m->mothurOutEndLine(); + return 0; } catch(exception& e) { - errorOut(e, "SeqSummaryCommand", "execute"); + m->errorOut(e, "SeqSummaryCommand", "execute"); exit(1); } } diff --git a/sequence.cpp b/sequence.cpp index 752e081..94caf65 100644 --- a/sequence.cpp +++ b/sequence.cpp @@ -12,6 +12,7 @@ /***********************************************************************/ Sequence::Sequence(){ + m = MothurOut::getInstance(); initialize(); } @@ -81,7 +82,7 @@ string Sequence::getSequenceString(ifstream& fastaFile) { return sequence; } catch(exception& e) { - errorOut(e, "Sequence", "getSequenceString"); + m->errorOut(e, "Sequence", "getSequenceString"); exit(1); } } @@ -103,7 +104,7 @@ string Sequence::getCommentString(ifstream& fastaFile) { return sequence; } catch(exception& e) { - errorOut(e, "Sequence", "getCommentString"); + m->errorOut(e, "Sequence", "getCommentString"); exit(1); } } diff --git a/sequence.hpp b/sequence.hpp index f6d7c86..f48bf13 100644 --- a/sequence.hpp +++ b/sequence.hpp @@ -15,7 +15,7 @@ */ #include "mothur.h" - +#include "mothurout.h" /**************************************************************************************************/ @@ -47,6 +47,7 @@ public: void printSequence(ostream&); private: + MothurOut* m; void initialize(); string getSequenceString(ifstream&); string getCommentString(ifstream&); diff --git a/sequencedb.cpp b/sequencedb.cpp index b3da429..9ddb40f 100644 --- a/sequencedb.cpp +++ b/sequencedb.cpp @@ -15,7 +15,7 @@ /***********************************************************************/ -SequenceDB::SequenceDB() {} +SequenceDB::SequenceDB() { m = MothurOut::getInstance(); } /***********************************************************************/ //the clear function free's the memory SequenceDB::~SequenceDB() { clear(); } @@ -46,7 +46,7 @@ SequenceDB::SequenceDB(ifstream& filehandle) { } catch(exception& e) { - errorOut(e, "SequenceDB", "SequenceDB"); + m->errorOut(e, "SequenceDB", "SequenceDB"); exit(1); } } @@ -67,7 +67,7 @@ string SequenceDB::readName(ifstream& in) { return name; } catch(exception& e) { - errorOut(e, "SequenceDB", "readName"); + m->errorOut(e, "SequenceDB", "readName"); exit(1); } } @@ -96,7 +96,7 @@ string SequenceDB::readSequence(ifstream& in) { return sequence; } catch(exception& e) { - errorOut(e, "SequenceDB", "readSequence"); + m->errorOut(e, "SequenceDB", "readSequence"); exit(1); } } @@ -114,7 +114,7 @@ void SequenceDB::set(int index, string newUnaligned) { data[index] = Sequence(data[index].getName(), newUnaligned); } catch(exception& e) { - errorOut(e, "SequenceDB", "set"); + m->errorOut(e, "SequenceDB", "set"); exit(1); } } @@ -126,7 +126,7 @@ void SequenceDB::set(int index, Sequence newSeq) { data[index] = newSeq; } catch(exception& e) { - errorOut(e, "SequenceDB", "set"); + m->errorOut(e, "SequenceDB", "set"); exit(1); } } @@ -144,7 +144,7 @@ void SequenceDB::resize(int newSize) { data.resize(newSize); } catch(exception& e) { - errorOut(e, "SequenceDB", "resize"); + m->errorOut(e, "SequenceDB", "resize"); exit(1); } } @@ -156,7 +156,7 @@ void SequenceDB::clear() { data.clear(); } catch(exception& e) { - errorOut(e, "SequenceDB", "clear"); + m->errorOut(e, "SequenceDB", "clear"); exit(1); } } @@ -176,7 +176,7 @@ void SequenceDB::print(ostream& out) { } } catch(exception& e) { - errorOut(e, "SequenceDB", "print"); + m->errorOut(e, "SequenceDB", "print"); exit(1); } } @@ -188,7 +188,7 @@ void SequenceDB::push_back(Sequence newSequence) { data.push_back(newSequence); } catch(exception& e) { - errorOut(e, "SequenceDB", "push_back"); + m->errorOut(e, "SequenceDB", "push_back"); exit(1); } } diff --git a/sequencedb.h b/sequencedb.h index 8c7e649..3672549 100644 --- a/sequencedb.h +++ b/sequencedb.h @@ -42,6 +42,7 @@ private: vector data; string readName(ifstream&); string readSequence(ifstream&); + MothurOut* m; }; diff --git a/setdircommand.cpp b/setdircommand.cpp index 5a2c002..407e57b 100644 --- a/setdircommand.cpp +++ b/setdircommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -SetDirectoryCommand::SetDirectoryCommand(string option){ +SetDirectoryCommand::SetDirectoryCommand(string option) { try { abort = false; @@ -39,12 +39,12 @@ SetDirectoryCommand::SetDirectoryCommand(string option){ if (input == "not found") { input = ""; } if ((input == "") && (output == "")) { - mothurOut("You must provide either an input or output for the set.outdir command."); mothurOutEndLine(); abort = true; + m->mothurOut("You must provide either an input or output for the set.outdir command."); m->mothurOutEndLine(); abort = true; } } } catch(exception& e) { - errorOut(e, "SetDirectoryCommand", "SetDirectoryCommand"); + m->errorOut(e, "SetDirectoryCommand", "SetDirectoryCommand"); exit(1); } } @@ -52,17 +52,17 @@ SetDirectoryCommand::SetDirectoryCommand(string option){ void SetDirectoryCommand::help(){ try { - 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"); - mothurOut("The set.dir command can also be used to specify the directory where your input files are located, the directory must exist.\n"); - mothurOut("The set.dir command parameter is output and is required.\n"); - mothurOut("To return the output to the same directory as the input files you may enter: output=clear.\n"); - mothurOut("To return the input to the same directory as the mothur.exe you may enter: input=clear.\n"); - mothurOut("The set.dir command should be in the following format: set.dir(output=yourOutputDirectory, input=yourInputDirectory).\n"); - mothurOut("Example set.outdir(output=/Users/lab/desktop/outputs, input=/Users/lab/desktop/inputs).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. output), '=' and parameters (i.e.yourOutputDirectory).\n\n"); + 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 parameter is output and 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 same directory as the mothur.exe you may enter: input=clear.\n"); + m->mothurOut("The set.dir command should be in the following format: set.dir(output=yourOutputDirectory, input=yourInputDirectory).\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) { - errorOut(e, "SetDirectoryCommand", "help"); + m->errorOut(e, "SetDirectoryCommand", "help"); exit(1); } } @@ -97,11 +97,11 @@ int SetDirectoryCommand::execute(){ ofstream out; out.open(outTemp.c_str(), ios::trunc); if(!out) { - mothurOut(output + " directory does not exist or is not writable."); mothurOutEndLine(); + m->mothurOut(output + " directory does not exist or is not writable."); m->mothurOutEndLine(); }else{ out.close(); remove(outTemp.c_str()); - mothurOut("Changing output directory to " + output); mothurOutEndLine(); + m->mothurOut("Changing output directory to " + output); m->mothurOutEndLine(); commandFactory->setOutputDirectory(output); } } @@ -123,11 +123,11 @@ int SetDirectoryCommand::execute(){ ofstream in; in.open(inTemp.c_str(), ios::trunc); if(!in) { - mothurOut(input + " directory does not exist or is not writable."); mothurOutEndLine(); + m->mothurOut(input + " directory does not exist or is not writable."); m->mothurOutEndLine(); }else{ in.close(); remove(inTemp.c_str()); - mothurOut("Changing input directory to " + input); mothurOutEndLine(); + m->mothurOut("Changing input directory to " + input); m->mothurOutEndLine(); commandFactory->setInputDirectory(input); } } @@ -135,7 +135,7 @@ int SetDirectoryCommand::execute(){ return 0; } catch(exception& e) { - errorOut(e, "SetDirectoryCommand", "SetDirectoryCommand"); + m->errorOut(e, "SetDirectoryCommand", "SetDirectoryCommand"); exit(1); } } diff --git a/shannon.cpp b/shannon.cpp index 1807375..b38d7fc 100644 --- a/shannon.cpp +++ b/shannon.cpp @@ -52,7 +52,7 @@ EstOutput Shannon::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "Shannon", "getValues"); + m->errorOut(e, "Shannon", "getValues"); exit(1); } } diff --git a/sharedace.cpp b/sharedace.cpp index 61a7c74..24fe5ef 100644 --- a/sharedace.cpp +++ b/sharedace.cpp @@ -100,7 +100,7 @@ EstOutput SharedAce::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "SharedAce", "getValues"); + m->errorOut(e, "SharedAce", "getValues"); exit(1); } } diff --git a/sharedanderbergs.cpp b/sharedanderbergs.cpp index d55a016..38eec63 100644 --- a/sharedanderbergs.cpp +++ b/sharedanderbergs.cpp @@ -40,7 +40,7 @@ EstOutput Anderberg::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "Anderberg", "getValues"); + m->errorOut(e, "Anderberg", "getValues"); exit(1); } } diff --git a/sharedbraycurtis.cpp b/sharedbraycurtis.cpp index 299939d..e8512d4 100644 --- a/sharedbraycurtis.cpp +++ b/sharedbraycurtis.cpp @@ -44,7 +44,7 @@ EstOutput BrayCurtis::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "BrayCurtis", "getValues"); + m->errorOut(e, "BrayCurtis", "getValues"); exit(1); } } diff --git a/sharedchao1.cpp b/sharedchao1.cpp index c19f032..d8cf60b 100644 --- a/sharedchao1.cpp +++ b/sharedchao1.cpp @@ -90,7 +90,7 @@ EstOutput SharedChao1::getValues(vector shared){ return data; } catch(exception& e) { - errorOut(e, "SharedChao1", "getValues"); + m->errorOut(e, "SharedChao1", "getValues"); exit(1); } } @@ -138,8 +138,8 @@ void SharedChao1::initialTree(int n) { setCoef(f2root, 0); } catch(exception& e) { - if ((toString(e.what()) == "vector::_M_fill_insert") || (toString(e.what()) == "St9bad_alloc")) { mothurOut("You are using " + toString(n) + " groups which creates 2^" + toString(n+1) + " nodes. Try reducing the number of groups you selected. "); mothurOutEndLine(); exit(1); } - errorOut(e, "SharedChao1", "initialTree"); + if ((toString(e.what()) == "vector::_M_fill_insert") || (toString(e.what()) == "St9bad_alloc")) { m->mothurOut("You are using " + toString(n) + " groups which creates 2^" + toString(n+1) + " nodes. Try reducing the number of groups you selected. "); m->mothurOutEndLine(); exit(1); } + m->errorOut(e, "SharedChao1", "initialTree"); exit(1); } } @@ -152,7 +152,7 @@ void SharedChao1::updateTree(vector bin) { updateBranchf2(f2root, bin, 0); } catch(exception& e) { - errorOut(e, "SharedChao1", "updateTree"); + m->errorOut(e, "SharedChao1", "updateTree"); exit(1); } } @@ -174,7 +174,7 @@ void SharedChao1::updateBranchf1(IntNode* node, vector bin, int index) { } } catch(exception& e) { - errorOut(e, "SharedChao1", "updateBranchf1"); + m->errorOut(e, "SharedChao1", "updateBranchf1"); exit(1); } } @@ -196,7 +196,7 @@ void SharedChao1::updateBranchf2(IntNode* node, vector bin, int index) { } } catch(exception& e) { - errorOut(e, "SharedChao1", "updateBranchf2"); + m->errorOut(e, "SharedChao1", "updateBranchf2"); exit(1); } } @@ -213,7 +213,7 @@ void SharedChao1::setCoef(IntNode* node, int coef) { } } catch(exception& e) { - errorOut(e, "SharedChao1", "setCoef"); + m->errorOut(e, "SharedChao1", "setCoef"); exit(1); } } @@ -222,10 +222,10 @@ void SharedChao1::setCoef(IntNode* node, int coef) { //for debugging purposes void SharedChao1::printTree() { - mothurOut("F1 leaves"); mothurOutEndLine(); + m->mothurOut("F1 leaves"); m->mothurOutEndLine(); printBranch(f1root); - mothurOut("F2 leaves"); mothurOutEndLine(); + m->mothurOut("F2 leaves"); m->mothurOutEndLine(); printBranch(f2root); @@ -239,13 +239,13 @@ void SharedChao1::printBranch(IntNode* node) { printBranch(node->left); printBranch(node->right); }else { //you are a leaf - mothurOut(toString(node->lvalue)); mothurOutEndLine(); - mothurOut(toString(node->rvalue)); mothurOutEndLine(); + m->mothurOut(toString(node->lvalue)); m->mothurOutEndLine(); + m->mothurOut(toString(node->rvalue)); m->mothurOutEndLine(); } } catch(exception& e) { - errorOut(e, "SharedChao1", "printBranch"); + m->errorOut(e, "SharedChao1", "printBranch"); exit(1); } } diff --git a/sharedcommand.cpp b/sharedcommand.cpp index 4cc0ea7..f03152b 100644 --- a/sharedcommand.cpp +++ b/sharedcommand.cpp @@ -53,7 +53,7 @@ SharedCommand::SharedCommand(string o) : outputDir(o) { } catch(exception& e) { - errorOut(e, "SharedCommand", "SharedCommand"); + m->errorOut(e, "SharedCommand", "SharedCommand"); exit(1); } } @@ -77,7 +77,7 @@ int SharedCommand::execute(){ vector lookup; 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 - mothurOut("Your group file contains " + toString(groupMap->getNumSeqs()) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); mothurOutEndLine(); + m->mothurOut("Your group file contains " + toString(groupMap->getNumSeqs()) + " sequences and list file contains " + toString(SharedList->getNumSeqs()) + " sequences. Please correct."); m->mothurOutEndLine(); out.close(); remove(filename.c_str()); //remove blank shared file you made @@ -128,7 +128,7 @@ int SharedCommand::execute(){ if (pickedGroups) { //check for otus with no seqs in them eliminateZeroOTUS(lookup); } - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -147,7 +147,7 @@ int SharedCommand::execute(){ if (pickedGroups) { //check for otus with no seqs in them eliminateZeroOTUS(lookup); } - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -184,7 +184,7 @@ int SharedCommand::execute(){ if (pickedGroups) { //check for otus with no seqs in them eliminateZeroOTUS(lookup); } - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); printSharedData(lookup); //prints info to the .shared file for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -210,7 +210,7 @@ int SharedCommand::execute(){ return 0; } catch(exception& e) { - errorOut(e, "SharedCommand", "execute"); + m->errorOut(e, "SharedCommand", "execute"); exit(1); } } @@ -232,7 +232,7 @@ void SharedCommand::printSharedData(vector thislookup) { } catch(exception& e) { - errorOut(e, "SharedCommand", "printSharedData"); + m->errorOut(e, "SharedCommand", "printSharedData"); exit(1); } } @@ -272,7 +272,7 @@ void SharedCommand::eliminateZeroOTUS(vector& thislookup) { } catch(exception& e) { - errorOut(e, "SharedCommand", "eliminateZeroOTUS"); + m->errorOut(e, "SharedCommand", "eliminateZeroOTUS"); exit(1); } } @@ -285,7 +285,7 @@ void SharedCommand::createMisMatchFile() { //you have sequences in your list file that are not in your group file if (SharedList->getNumSeqs() > groupMap->getNumSeqs()) { outputMisMatchName += "missing.group"; - mothurOut("For a list of names that are in your list file and not in your group file, please refer to " + outputMisMatchName + "."); mothurOutEndLine(); + m->mothurOut("For a list of names that are in your list file and not in your group file, please refer to " + outputMisMatchName + "."); m->mothurOutEndLine(); openOutputFile(outputMisMatchName, outMisMatch); @@ -305,7 +305,7 @@ void SharedCommand::createMisMatchFile() { if(group == "not found") { outMisMatch << name << endl; } itList = listNames.find(name); - if (itList != listNames.end()) { mothurOut(name + " is in your list file more than once. Sequence names must be unique. please correct."); mothurOutEndLine(); } + if (itList != listNames.end()) { m->mothurOut(name + " is in your list file more than once. Sequence names must be unique. please correct."); m->mothurOutEndLine(); } else { listNames[name] = name; } } @@ -314,7 +314,7 @@ void SharedCommand::createMisMatchFile() { if(group == "not found") { outMisMatch << names << endl; } itList = listNames.find(names); - if (itList != listNames.end()) { mothurOut(names + " is in your list file more than once. Sequence names must be unique. please correct."); mothurOutEndLine(); } + if (itList != listNames.end()) { m->mothurOut(names + " is in your list file more than once. Sequence names must be unique. please correct."); m->mothurOutEndLine(); } else { listNames[names] = names; } } @@ -325,7 +325,7 @@ void SharedCommand::createMisMatchFile() { }else {//you have sequences in your group file that are not in you list file outputMisMatchName += "missing.name"; - mothurOut("For a list of names that are in your group file and not in your list file, please refer to " + outputMisMatchName + "."); mothurOutEndLine(); + m->mothurOut("For a list of names that are in your group file and not in your list file, please refer to " + outputMisMatchName + "."); m->mothurOutEndLine(); map namesInList; map::iterator itList; @@ -340,14 +340,14 @@ void SharedCommand::createMisMatchFile() { names = names.substr(names.find_first_of(',')+1, names.length()); itList = namesInList.find(name); - if (itList != namesInList.end()) { mothurOut(name + " is in your list file more than once. Sequence names must be unique. please correct."); mothurOutEndLine(); } + if (itList != namesInList.end()) { m->mothurOut(name + " is in your list file more than once. Sequence names must be unique. please correct."); m->mothurOutEndLine(); } namesInList[name] = name; } itList = namesInList.find(names); - if (itList != namesInList.end()) { mothurOut(names + " is in your list file more than once. Sequence names must be unique. please correct."); mothurOutEndLine(); } + if (itList != namesInList.end()) { m->mothurOut(names + " is in your list file more than once. Sequence names must be unique. please correct."); m->mothurOutEndLine(); } //get last name namesInList[names] = names; @@ -375,7 +375,7 @@ void SharedCommand::createMisMatchFile() { } catch(exception& e) { - errorOut(e, "SharedCommand", "createMisMatchFile"); + m->errorOut(e, "SharedCommand", "createMisMatchFile"); exit(1); } } @@ -399,7 +399,7 @@ bool SharedCommand::isValidGroup(string groupname, vector groups) { return false; } catch(exception& e) { - errorOut(e, "SharedCommand", "isValidGroup"); + m->errorOut(e, "SharedCommand", "isValidGroup"); exit(1); } } diff --git a/sharedjabund.cpp b/sharedjabund.cpp index d07076a..79c9f52 100644 --- a/sharedjabund.cpp +++ b/sharedjabund.cpp @@ -27,7 +27,7 @@ EstOutput JAbund::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "JAbund", "getValues"); + m->errorOut(e, "JAbund", "getValues"); exit(1); } } diff --git a/sharedjackknife.cpp b/sharedjackknife.cpp index 012d206..26ad126 100644 --- a/sharedjackknife.cpp +++ b/sharedjackknife.cpp @@ -136,7 +136,7 @@ EstOutput SharedJackknife::getValues(vector vectorShared){ } catch(exception& e) { - errorOut(e, "SharedJackknife", "getValues"); + m->errorOut(e, "SharedJackknife", "getValues"); exit(1); } } diff --git a/sharedjclass.cpp b/sharedjclass.cpp index 051f05e..d44f22f 100644 --- a/sharedjclass.cpp +++ b/sharedjclass.cpp @@ -41,7 +41,7 @@ EstOutput Jclass::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "Jclass", "getValues"); + m->errorOut(e, "Jclass", "getValues"); exit(1); } } diff --git a/sharedjest.cpp b/sharedjest.cpp index 0396f47..9c53448 100644 --- a/sharedjest.cpp +++ b/sharedjest.cpp @@ -52,7 +52,7 @@ EstOutput Jest::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "Jest", "getValues"); + m->errorOut(e, "Jest", "getValues"); exit(1); } } diff --git a/sharedkstest.cpp b/sharedkstest.cpp index 567b345..d914788 100644 --- a/sharedkstest.cpp +++ b/sharedkstest.cpp @@ -56,7 +56,7 @@ EstOutput KSTest::getValues(vector shared){ return data; } catch(exception& e) { - errorOut(e, "KSTest", "getValues"); + m->errorOut(e, "KSTest", "getValues"); exit(1); } } diff --git a/sharedkulczynski.cpp b/sharedkulczynski.cpp index cd09063..2b4f723 100644 --- a/sharedkulczynski.cpp +++ b/sharedkulczynski.cpp @@ -40,7 +40,7 @@ EstOutput Kulczynski::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "Kulczynski", "getValues"); + m->errorOut(e, "Kulczynski", "getValues"); exit(1); } } diff --git a/sharedkulczynskicody.cpp b/sharedkulczynskicody.cpp index dbb3c45..a2385d4 100644 --- a/sharedkulczynskicody.cpp +++ b/sharedkulczynskicody.cpp @@ -40,7 +40,7 @@ EstOutput KulczynskiCody::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "KulczynskiCody", "getValues"); + m->errorOut(e, "KulczynskiCody", "getValues"); exit(1); } } diff --git a/sharedlennon.cpp b/sharedlennon.cpp index 514f2b9..a68da6b 100644 --- a/sharedlennon.cpp +++ b/sharedlennon.cpp @@ -46,7 +46,7 @@ EstOutput Lennon::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "Lennon", "getValues"); + m->errorOut(e, "Lennon", "getValues"); exit(1); } } diff --git a/sharedlistvector.cpp b/sharedlistvector.cpp index 4303cfd..cc3cd8d 100644 --- a/sharedlistvector.cpp +++ b/sharedlistvector.cpp @@ -44,7 +44,7 @@ SharedListVector::SharedListVector(ifstream& f) : DataVector(), maxRank(0), numB } catch(exception& e) { - errorOut(e, "SharedListVector", "SharedListVector"); + m->errorOut(e, "SharedListVector", "SharedListVector"); exit(1); } } @@ -63,7 +63,7 @@ void SharedListVector::set(int binNumber, string seqNames){ numSeqs += (nNames_new - nNames_old); } catch(exception& e) { - errorOut(e, "SharedListVector", "set"); + m->errorOut(e, "SharedListVector", "set"); exit(1); } } @@ -88,7 +88,7 @@ void SharedListVector::push_back(string seqNames){ numSeqs += nNames; } catch(exception& e) { - errorOut(e, "SharedListVector", "push_back"); + m->errorOut(e, "SharedListVector", "push_back"); exit(1); } } @@ -128,7 +128,7 @@ void SharedListVector::print(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "SharedListVector", "print"); + m->errorOut(e, "SharedListVector", "print"); exit(1); } } @@ -159,7 +159,7 @@ RAbundVector SharedListVector::getRAbundVector(){ return rav; } catch(exception& e) { - errorOut(e, "SharedListVector", "getRAbundVector"); + m->errorOut(e, "SharedListVector", "getRAbundVector"); exit(1); } } @@ -180,7 +180,7 @@ SAbundVector SharedListVector::getSAbundVector(){ return sav; } catch(exception& e) { - errorOut(e, "SharedListVector", "getSAbundVector"); + m->errorOut(e, "SharedListVector", "getSAbundVector"); exit(1); } } @@ -201,13 +201,13 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){ names = names.substr(names.find_first_of(',')+1, names.length()); groupName = groupmap->getGroup(name); - if(groupName == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + if(groupName == "not found") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } order->push_back(i, binSize, groupName); //i represents what bin you are in } //get last name groupName = groupmap->getGroup(names); - if(groupName == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + if(groupName == "not found") { m->mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } order->push_back(i, binSize, groupName); } @@ -217,7 +217,7 @@ SharedOrderVector* SharedListVector::getSharedOrderVector(){ return order; } catch(exception& e) { - errorOut(e, "SharedListVector", "getSharedOrderVector"); + m->errorOut(e, "SharedListVector", "getSharedOrderVector"); exit(1); } } @@ -233,7 +233,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { name = names.substr(0,names.find_first_of(',')); names = names.substr(names.find_first_of(',')+1, names.length()); group = groupmap->getGroup(name); - if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + if(group == "not found") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } if (group == groupName) { //this name is in the group you want the vector for. rav.set(i, rav.getAbundance(i) + 1, group); //i represents what bin you are in } @@ -241,7 +241,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { //get last name groupName = groupmap->getGroup(names); - if(groupName == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + if(groupName == "not found") { m->mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } if (group == groupName) { //this name is in the group you want the vector for. rav.set(i, rav.getAbundance(i) + 1, group); //i represents what bin you are in } @@ -254,7 +254,7 @@ SharedRAbundVector SharedListVector::getSharedRAbundVector(string groupName) { } catch(exception& e) { - errorOut(e, "SharedListVector", "getSharedRAbundVector"); + m->errorOut(e, "SharedListVector", "getSharedRAbundVector"); exit(1); } } @@ -287,13 +287,13 @@ vector SharedListVector::getSharedRAbundVector() { name = names.substr(0,names.find_first_of(',')); names = names.substr(names.find_first_of(',')+1, names.length()); group = groupmap->getGroup(name); - if(group == "not found") { mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + if(group == "not found") { m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in } //get last name group = groupmap->getGroup(names); - if(group == "not found") { mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); } + if(group == "not found") { m->mothurOut("Error: Sequence '" + names + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); } finder[group]->set(i, finder[group]->getAbundance(i) + 1, group); //i represents what bin you are in } @@ -301,7 +301,7 @@ vector SharedListVector::getSharedRAbundVector() { return lookup; } catch(exception& e) { - errorOut(e, "SharedListVector", "getSharedRAbundVector"); + m->errorOut(e, "SharedListVector", "getSharedRAbundVector"); exit(1); } } @@ -318,7 +318,7 @@ SharedSAbundVector SharedListVector::getSharedSAbundVector(string groupName) { return sav; } catch(exception& e) { - errorOut(e, "SharedListVector", "getSharedSAbundVector"); + m->errorOut(e, "SharedListVector", "getSharedSAbundVector"); exit(1); } } @@ -359,7 +359,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ } else{ if(orderMap->count(seqName) == 0){ - mothurOut(seqName + " not found, check *.names file\n"); + m->mothurOut(seqName + " not found, check *.names file\n"); exit(1); } @@ -369,7 +369,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ } if(orderMap->count(seqName) == 0){ - mothurOut(seqName + " not found, check *.names file\n"); + m->mothurOut(seqName + " not found, check *.names file\n"); exit(1); } ov.set((*orderMap)[seqName], i); @@ -382,7 +382,7 @@ OrderVector SharedListVector::getOrderVector(map* orderMap = NULL){ } } catch(exception& e) { - errorOut(e, "SharedListVector", "getOrderVector"); + m->errorOut(e, "SharedListVector", "getOrderVector"); exit(1); } } diff --git a/sharedmarczewski.cpp b/sharedmarczewski.cpp index e4b80be..57de5f5 100644 --- a/sharedmarczewski.cpp +++ b/sharedmarczewski.cpp @@ -38,7 +38,7 @@ EstOutput SharedMarczewski::getValues(vector vectorShared){ return data; } catch(exception& e) { - errorOut(e, "SharedMarczewski", "getValues"); + m->errorOut(e, "SharedMarczewski", "getValues"); exit(1); } } diff --git a/sharedmorisitahorn.cpp b/sharedmorisitahorn.cpp index d5cdeec..3439747 100644 --- a/sharedmorisitahorn.cpp +++ b/sharedmorisitahorn.cpp @@ -48,7 +48,7 @@ EstOutput MorHorn::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "MorHorn", "getValues"); + m->errorOut(e, "MorHorn", "getValues"); exit(1); } } diff --git a/sharedochiai.cpp b/sharedochiai.cpp index 1d0828e..a1991c9 100644 --- a/sharedochiai.cpp +++ b/sharedochiai.cpp @@ -40,7 +40,7 @@ EstOutput Ochiai::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "Ochiai", "getValues"); + m->errorOut(e, "Ochiai", "getValues"); exit(1); } } diff --git a/sharedordervector.cpp b/sharedordervector.cpp index e1ede6d..2df67b8 100644 --- a/sharedordervector.cpp +++ b/sharedordervector.cpp @@ -96,7 +96,7 @@ SharedOrderVector::SharedOrderVector(ifstream& f) : DataVector() { //reads in a } catch(exception& e) { - errorOut(e, "SharedOrderVector", "SharedOrderVector"); + m->errorOut(e, "SharedOrderVector", "SharedOrderVector"); exit(1); } } @@ -166,7 +166,7 @@ void SharedOrderVector::print(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "SharedOrderVector", "print"); + m->errorOut(e, "SharedOrderVector", "print"); exit(1); } } @@ -175,7 +175,7 @@ void SharedOrderVector::print(ostream& output){ /***********************************************************************/ void SharedOrderVector::resize(int){ - mothurOut("resize() did nothing in class SharedOrderVector"); + m->mothurOut("resize() did nothing in class SharedOrderVector"); } /***********************************************************************/ @@ -218,7 +218,7 @@ RAbundVector SharedOrderVector::getRAbundVector(){ return rav; } catch(exception& e) { - errorOut(e, "SharedOrderVector", "getRAbundVector"); + m->errorOut(e, "SharedOrderVector", "getRAbundVector"); exit(1); } } @@ -238,7 +238,7 @@ OrderVector SharedOrderVector::getOrderVector(map* nameMap = NULL) { return ov; } catch(exception& e) { - errorOut(e, "SharedOrderVector", "getOrderVector"); + m->errorOut(e, "SharedOrderVector", "getOrderVector"); exit(1); } } @@ -268,7 +268,7 @@ SharedRAbundVector SharedOrderVector::getSharedRAbundVector(string group) { return sharedRav; } catch(exception& e) { - errorOut(e, "SharedOrderVector", "getSharedRAbundVector"); + m->errorOut(e, "SharedOrderVector", "getSharedRAbundVector"); exit(1); } } @@ -285,7 +285,7 @@ vector SharedOrderVector::getSharedRAbundVector() { return lookup; } catch(exception& e) { - errorOut(e, "SharedOrderVector", "getSharedRAbundVector"); + m->errorOut(e, "SharedOrderVector", "getSharedRAbundVector"); exit(1); } } @@ -298,7 +298,7 @@ SharedSAbundVector SharedOrderVector::getSharedSAbundVector(string group) { } catch(exception& e) { - errorOut(e, "SharedOrderVector", "getSharedSAbundVector"); + m->errorOut(e, "SharedOrderVector", "getSharedSAbundVector"); exit(1); } } @@ -333,7 +333,7 @@ void SharedOrderVector::updateStats(){ } catch(exception& e) { - errorOut(e, "SharedOrderVector", "updateStats"); + m->errorOut(e, "SharedOrderVector", "updateStats"); exit(1); } } diff --git a/sharedrabundvector.cpp b/sharedrabundvector.cpp index 25f9dd3..114de90 100644 --- a/sharedrabundvector.cpp +++ b/sharedrabundvector.cpp @@ -51,7 +51,7 @@ SharedRAbundVector::SharedRAbundVector(string id, vector rav) : Data } } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "SharedRAbundVector"); + m->errorOut(e, "SharedRAbundVector", "SharedRAbundVector"); exit(1); } } @@ -140,7 +140,7 @@ SharedRAbundVector::SharedRAbundVector(ifstream& f) : DataVector(), maxRank(0), } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "SharedRAbundVector"); + m->errorOut(e, "SharedRAbundVector", "SharedRAbundVector"); exit(1); } } @@ -158,7 +158,7 @@ void SharedRAbundVector::set(int binNumber, int newBinSize, string groupname){ numSeqs += (newBinSize - oldBinSize); } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "set"); + m->errorOut(e, "SharedRAbundVector", "set"); exit(1); } } @@ -219,7 +219,7 @@ void SharedRAbundVector::push_back(int binSize, string groupName){ numSeqs += binSize; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "push_back"); + m->errorOut(e, "SharedRAbundVector", "push_back"); exit(1); } } @@ -243,7 +243,7 @@ void SharedRAbundVector::insert(int binSize, int otu, string groupName){ numSeqs += binSize; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "insert"); + m->errorOut(e, "SharedRAbundVector", "insert"); exit(1); } } @@ -267,7 +267,7 @@ void SharedRAbundVector::push_front(int binSize, int otu, string groupName){ numSeqs += binSize; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "push_front"); + m->errorOut(e, "SharedRAbundVector", "push_front"); exit(1); } } @@ -313,7 +313,7 @@ void SharedRAbundVector::print(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "print"); + m->errorOut(e, "SharedRAbundVector", "print"); exit(1); } } @@ -374,7 +374,7 @@ vector SharedRAbundVector::getSharedRAbundVectors(){ return lookup; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "getSharedRAbundVectors"); + m->errorOut(e, "SharedRAbundVector", "getSharedRAbundVectors"); exit(1); } } @@ -394,7 +394,7 @@ RAbundVector SharedRAbundVector::getRAbundVector() { return rav; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "getRAbundVector"); + m->errorOut(e, "SharedRAbundVector", "getRAbundVector"); exit(1); } } @@ -409,7 +409,7 @@ RAbundVector SharedRAbundVector::getRAbundVector2() { return rav; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "getRAbundVector2"); + m->errorOut(e, "SharedRAbundVector", "getRAbundVector2"); exit(1); } } @@ -431,7 +431,7 @@ SharedSAbundVector SharedRAbundVector::getSharedSAbundVector(){ return sav; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "getSharedSAbundVector"); + m->errorOut(e, "SharedRAbundVector", "getSharedSAbundVector"); exit(1); } } @@ -450,7 +450,7 @@ SAbundVector SharedRAbundVector::getSAbundVector() { return sav; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "getSAbundVector"); + m->errorOut(e, "SharedRAbundVector", "getSAbundVector"); exit(1); } } @@ -474,7 +474,7 @@ SharedOrderVector SharedRAbundVector::getSharedOrderVector() { return ov; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "getSharedOrderVector"); + m->errorOut(e, "SharedRAbundVector", "getSharedOrderVector"); exit(1); } } @@ -495,7 +495,7 @@ OrderVector SharedRAbundVector::getOrderVector(map* nameMap = NULL) return ov; } catch(exception& e) { - errorOut(e, "SharedRAbundVector", "getOrderVector"); + m->errorOut(e, "SharedRAbundVector", "getOrderVector"); exit(1); } } diff --git a/sharedsabundvector.cpp b/sharedsabundvector.cpp index a7dfd66..4aea589 100644 --- a/sharedsabundvector.cpp +++ b/sharedsabundvector.cpp @@ -45,7 +45,7 @@ void SharedSAbundVector::set(int bin, int abundance, string groupName){ if(bin > maxRank) { maxRank = bin; } } catch(exception& e) { - errorOut(e, "SharedSAbundVector", "set"); + m->errorOut(e, "SharedSAbundVector", "set"); exit(1); } } @@ -79,7 +79,7 @@ void SharedSAbundVector::push_back(int abundance, int bin, string groupName){ numSeqs += (maxRank * abundance); } catch(exception& e) { - errorOut(e, "SharedSAbundVector", "push_back"); + m->errorOut(e, "SharedSAbundVector", "push_back"); exit(1); } } @@ -107,7 +107,7 @@ void SharedSAbundVector::print(ostream& output){ output << endl; } catch(exception& e) { - errorOut(e, "SharedSAbundVector", "print"); + m->errorOut(e, "SharedSAbundVector", "print"); exit(1); } } @@ -154,7 +154,7 @@ RAbundVector SharedSAbundVector::getRAbundVector(){ return rav; } catch(exception& e) { - errorOut(e, "SharedSAbundVector", "getRAbundVector"); + m->errorOut(e, "SharedSAbundVector", "getRAbundVector"); exit(1); } } @@ -170,7 +170,7 @@ SAbundVector SharedSAbundVector::getSAbundVector(){ } catch(exception& e) { - errorOut(e, "SharedSAbundVector", "getSAbundVector"); + m->errorOut(e, "SharedSAbundVector", "getSAbundVector"); exit(1); } } @@ -204,7 +204,7 @@ SharedRAbundVector SharedSAbundVector::getSharedRAbundVector(){ return rav; } catch(exception& e) { - errorOut(e, "SharedSAbundVector", "getSharedRAbundVector"); + m->errorOut(e, "SharedSAbundVector", "getSharedRAbundVector"); exit(1); } } @@ -230,7 +230,7 @@ SharedOrderVector SharedSAbundVector::getSharedOrderVector() { return ov; } catch(exception& e) { - errorOut(e, "SharedSAbundVector", "getSharedOrderVector"); + m->errorOut(e, "SharedSAbundVector", "getSharedOrderVector"); exit(1); } } @@ -257,7 +257,7 @@ OrderVector SharedSAbundVector::getOrderVector(map* hold = NULL){ return ov; } catch(exception& e) { - errorOut(e, "SharedSAbundVector", "getOrderVector"); + m->errorOut(e, "SharedSAbundVector", "getOrderVector"); exit(1); } } diff --git a/sharedsobs.cpp b/sharedsobs.cpp index b65a878..c8ecba7 100644 --- a/sharedsobs.cpp +++ b/sharedsobs.cpp @@ -29,7 +29,7 @@ EstOutput SharedSobs::getValues(vector shared){ return data; } catch(exception& e) { - errorOut(e, "SharedSobs", "getValues"); + m->errorOut(e, "SharedSobs", "getValues"); exit(1); } } diff --git a/sharedsobscollectsummary.cpp b/sharedsobscollectsummary.cpp index 0096303..c64c825 100644 --- a/sharedsobscollectsummary.cpp +++ b/sharedsobscollectsummary.cpp @@ -34,7 +34,7 @@ EstOutput SharedSobsCS::getValues(vector shared){ return data; } catch(exception& e) { - errorOut(e, "SharedSobsCS", "getValues"); + m->errorOut(e, "SharedSobsCS", "getValues"); exit(1); } } diff --git a/sharedsorabund.cpp b/sharedsorabund.cpp index 7b472a7..90b825a 100644 --- a/sharedsorabund.cpp +++ b/sharedsorabund.cpp @@ -27,7 +27,7 @@ EstOutput SorAbund::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "SorAbund", "getValues"); + m->errorOut(e, "SorAbund", "getValues"); exit(1); } } diff --git a/sharedsorclass.cpp b/sharedsorclass.cpp index 3bb2219..8f60650 100644 --- a/sharedsorclass.cpp +++ b/sharedsorclass.cpp @@ -41,7 +41,7 @@ EstOutput SorClass::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "SorClass", "getValues"); + m->errorOut(e, "SorClass", "getValues"); exit(1); } } diff --git a/sharedsorest.cpp b/sharedsorest.cpp index 680c4ad..d3ae59e 100644 --- a/sharedsorest.cpp +++ b/sharedsorest.cpp @@ -51,7 +51,7 @@ EstOutput SorEst::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "SorEst", "getValues"); + m->errorOut(e, "SorEst", "getValues"); exit(1); } } diff --git a/sharedthetan.cpp b/sharedthetan.cpp index 6396d1d..d118be9 100644 --- a/sharedthetan.cpp +++ b/sharedthetan.cpp @@ -51,7 +51,7 @@ EstOutput ThetaN::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "ThetaN", "getValues"); + m->errorOut(e, "ThetaN", "getValues"); exit(1); } } diff --git a/sharedthetayc.cpp b/sharedthetayc.cpp index abb30e5..45dce49 100644 --- a/sharedthetayc.cpp +++ b/sharedthetayc.cpp @@ -48,7 +48,7 @@ EstOutput ThetaYC::getValues(vector shared) { return data; } catch(exception& e) { - errorOut(e, "ThetaYC", "getValues"); + m->errorOut(e, "ThetaYC", "getValues"); exit(1); } } diff --git a/sharedutilities.cpp b/sharedutilities.cpp index 7d85c4c..4339a25 100644 --- a/sharedutilities.cpp +++ b/sharedutilities.cpp @@ -49,7 +49,7 @@ void SharedUtil::getSharedVectors(vector Groups, vectorerrorOut(e, "SharedUtil", "getSharedVectors"); exit(1); } } @@ -93,7 +93,7 @@ void SharedUtil::getSharedVectorswithReplacement(vector Groups, vectorerrorOut(e, "SharedUtil", "getSharedVectorswithReplacement"); exit(1); } } @@ -107,7 +107,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups //check that groups are valid for (int i = 0; i < userGroups.size(); i++) { if (isValidGroup(userGroups[i], allGroups) != true) { - mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); mothurOutEndLine(); + m->mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine(); // erase the invalid group from userGroups userGroups.erase(userGroups.begin()+i); i--; @@ -116,7 +116,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups //if the user only entered invalid groups if (userGroups.size() == 0) { - mothurOut("You provided no valid groups. I will run the command using all the groups in your groupfile."); mothurOutEndLine(); + m->mothurOut("You provided no valid groups. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine(); for (int i = 0; i < allGroups.size(); i++) { userGroups.push_back(allGroups[i]); } @@ -136,7 +136,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups } catch(exception& e) { - errorOut(e, "SharedUtil", "setGroups"); + m->errorOut(e, "SharedUtil", "setGroups"); exit(1); } } @@ -149,7 +149,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups //check that groups are valid for (int i = 0; i < userGroups.size(); i++) { if (isValidGroup(userGroups[i], allGroups) != true) { - mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); mothurOutEndLine(); + m->mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine(); // erase the invalid group from userGroups userGroups.erase(userGroups.begin()+i); i--; @@ -171,7 +171,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups if ((mode == "collect") || (mode == "rarefact") || (mode == "summary") || (mode == "treegroup")) { //if the user only entered invalid groups if ((userGroups.size() == 0) || (userGroups.size() == 1)) { - 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."); mothurOutEndLine(); + 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(); for (int i = 0; i < allGroups.size(); i++) { userGroups.push_back(allGroups[i]); } @@ -180,7 +180,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups } catch(exception& e) { - errorOut(e, "SharedUtil", "setGroups"); + m->errorOut(e, "SharedUtil", "setGroups"); exit(1); } } @@ -199,7 +199,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups //check that groups are valid for (int i = 0; i < userGroups.size(); i++) { if (isValidGroup(userGroups[i], allGroups) != true) { - mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); mothurOutEndLine(); + m->mothurOut(userGroups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine(); // erase the invalid group from globaldata->Groups userGroups.erase(userGroups.begin()+i); i--; @@ -236,9 +236,9 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups userGroups.push_back(allGroups[i]); } } - 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."); mothurOutEndLine(); + 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 if (userGroups.size() == 1) { - 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."); mothurOutEndLine(); + 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(); userGroups.clear(); for (int i=0; i < allGroups.size(); i++) { if (allGroups[i] != "xxx") { @@ -251,7 +251,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups }else if ((mode == "unweighted") || (mode == "parsimony")) { //if the user only entered invalid groups if ((userGroups.size() == 0) && (numGroups == 0)) { - mothurOut("When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile."); mothurOutEndLine(); + m->mothurOut("When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine(); for (int i = 0; i < allGroups.size(); i++) { if (allGroups[i] != "xxx") { userGroups.push_back(allGroups[i]); @@ -263,7 +263,7 @@ void SharedUtil::setGroups(vector& userGroups, vector& allGroups } } catch(exception& e) { - errorOut(e, "SharedUtil", "setGroups"); + m->errorOut(e, "SharedUtil", "setGroups"); exit(1); } } @@ -281,7 +281,7 @@ void SharedUtil::getCombos(vector& groupComb, vector userGroups, } } catch(exception& e) { - errorOut(e, "SharedUtil", "getCombos"); + m->errorOut(e, "SharedUtil", "getCombos"); exit(1); } } @@ -295,7 +295,7 @@ bool SharedUtil::isValidGroup(string groupname, vector groups) { return false; } catch(exception& e) { - errorOut(e, "SharedUtil", "isValidGroup"); + m->errorOut(e, "SharedUtil", "isValidGroup"); exit(1); } } @@ -309,7 +309,7 @@ void SharedUtil::updateGroupIndex(vector& userGroups, map& } } catch(exception& e) { - errorOut(e, "SharedUtil", "updateGroupIndex"); + m->errorOut(e, "SharedUtil", "updateGroupIndex"); exit(1); } } diff --git a/sharedutilities.h b/sharedutilities.h index f6b95e3..df7e8d3 100644 --- a/sharedutilities.h +++ b/sharedutilities.h @@ -10,6 +10,7 @@ */ #include "mothur.h" +#include "mothurout.h" class SharedRAbundVector; class SharedOrderVector; @@ -18,7 +19,7 @@ class SharedOrderVector; class SharedUtil { public: - SharedUtil() {}; + SharedUtil() { m = MothurOut::getInstance(); } ~SharedUtil() {}; void getSharedVectors(vector, vector&, SharedOrderVector*); @@ -31,7 +32,7 @@ class SharedUtil { bool isValidGroup(string, vector); private: - + MothurOut* m; }; diff --git a/shen.cpp b/shen.cpp index 0d515eb..dac12bd 100644 --- a/shen.cpp +++ b/shen.cpp @@ -26,14 +26,14 @@ EstOutput Shen::getValues(SAbundVector* rank){ double f0 = ace[0]-rank->getNumBins(); - data[0] = f0 * (1 - pow(1 - f1/n/f0, m)); + data[0] = f0 * (1 - pow(1 - f1/n/f0, f)); delete calc; return data; } catch(exception& e) { - errorOut(e, "Shen", "getValues"); + m->errorOut(e, "Shen", "getValues"); exit(1); } } diff --git a/shen.h b/shen.h index fa8b700..1016e4c 100644 --- a/shen.h +++ b/shen.h @@ -20,11 +20,11 @@ class Shen : public Calculator { public: - Shen(int size, int n) : m(size), abund(n), Calculator("shen", 1, false) {}; + Shen(int size, int n) : f(size), abund(n), Calculator("shen", 1, false) {}; EstOutput getValues(SAbundVector*); EstOutput getValues(vector) {return data;}; private: - int m; + int f; int abund; }; diff --git a/simpson.cpp b/simpson.cpp index 8e176cf..fa5b435 100644 --- a/simpson.cpp +++ b/simpson.cpp @@ -58,7 +58,7 @@ EstOutput Simpson::getValues(SAbundVector* rank){ return data; } catch(exception& e) { - errorOut(e, "Simpson", "getValues"); + m->errorOut(e, "Simpson", "getValues"); exit(1); } } diff --git a/singlelinkage.cpp b/singlelinkage.cpp index 1762615..fe5adca 100644 --- a/singlelinkage.cpp +++ b/singlelinkage.cpp @@ -80,7 +80,7 @@ void SingleLinkage::update(){ removeCell(rowCells[rowInd], -1 , -1); } catch(exception& e) { - errorOut(e, "SingleLinkage", "update"); + m->errorOut(e, "SingleLinkage", "update"); exit(1); } } @@ -97,7 +97,7 @@ bool SingleLinkage::updateDistance(MatData& colCell, MatData& rowCell) { return(changed); } catch(exception& e) { - errorOut(e, "SingleLinkage", "updateDistance"); + m->errorOut(e, "SingleLinkage", "updateDistance"); exit(1); } } diff --git a/slayer.cpp b/slayer.cpp index 66db22b..2d079cd 100644 --- a/slayer.cpp +++ b/slayer.cpp @@ -11,7 +11,7 @@ /***********************************************************************/ Slayer::Slayer(int win, int increment, int parentThreshold, float div, int i, int snp) : - windowSize(win), windowStep(increment), parentFragmentThreshold(parentThreshold), divRThreshold(div), iters(i), percentSNPSample(snp){} + windowSize(win), windowStep(increment), parentFragmentThreshold(parentThreshold), divRThreshold(div), iters(i), percentSNPSample(snp){ m = MothurOut::getInstance(); } /***********************************************************************/ string Slayer::getResults(Sequence* query, vector refSeqs) { try { @@ -98,7 +98,7 @@ string Slayer::getResults(Sequence* query, vector refSeqs) { } } catch(exception& e) { - errorOut(e, "Slayer", "getResults"); + m->errorOut(e, "Slayer", "getResults"); exit(1); } } @@ -130,7 +130,7 @@ vector Slayer::runBellerophon(Sequence* q, Sequence* pA, Sequence* //check window size if (length < (2*windowSize+windowStep)) { - mothurOut("Your window size is too large for " + q->getName() + ". I will make the window size " + toString(length/4) + " which is 1/4 the filtered length."); mothurOutEndLine(); + m->mothurOut("Your window size is too large for " + q->getName() + ". I will make the window size " + toString(length/4) + " which is 1/4 the filtered length."); m->mothurOutEndLine(); windowSize = length / 4; } @@ -208,7 +208,7 @@ vector Slayer::runBellerophon(Sequence* q, Sequence* pA, Sequence* } catch(exception& e) { - errorOut(e, "Slayer", "runBellerophon"); + m->errorOut(e, "Slayer", "runBellerophon"); exit(1); } } @@ -257,7 +257,7 @@ vector Slayer::getSNPS(string parentA, string query, string parentB, int l } catch(exception& e) { - errorOut(e, "Slayer", "getSNPS"); + m->errorOut(e, "Slayer", "getSNPS"); exit(1); } } @@ -342,7 +342,7 @@ void Slayer::bootstrapSNPS(vector left, vector right, float& BSA, fl } catch(exception& e) { - errorOut(e, "Slayer", "bootstrapSNPS"); + m->errorOut(e, "Slayer", "bootstrapSNPS"); exit(1); } } @@ -363,7 +363,7 @@ float Slayer::snpQA(vector data) { return percentID; } catch(exception& e) { - errorOut(e, "Slayer", "snpQA"); + m->errorOut(e, "Slayer", "snpQA"); exit(1); } } @@ -385,7 +385,7 @@ float Slayer::snpQB(vector data) { } catch(exception& e) { - errorOut(e, "Slayer", "snpQB"); + m->errorOut(e, "Slayer", "snpQB"); exit(1); } } @@ -406,7 +406,7 @@ float Slayer::snpAB(vector data) { } catch(exception& e) { - errorOut(e, "Slayer", "snpAB"); + m->errorOut(e, "Slayer", "snpAB"); exit(1); } } @@ -428,7 +428,7 @@ float Slayer::computePercentID(string queryFrag, string parent, int left, int ri return percentID; } catch(exception& e) { - errorOut(e, "Slayer", "computePercentID"); + m->errorOut(e, "Slayer", "computePercentID"); exit(1); } } @@ -494,7 +494,7 @@ map Slayer::verticalFilter(vector seqs) { return maskMap; } catch(exception& e) { - errorOut(e, "Slayer", "verticalFilter"); + m->errorOut(e, "Slayer", "verticalFilter"); exit(1); } } diff --git a/slayer.h b/slayer.h index 099cb20..d746b47 100644 --- a/slayer.h +++ b/slayer.h @@ -87,6 +87,7 @@ class Slayer { float snpQA(vector); float snpQB(vector); float snpAB(vector); + MothurOut* m; }; diff --git a/slibshuff.cpp b/slibshuff.cpp index 1f2d3df..e1ffb0e 100644 --- a/slibshuff.cpp +++ b/slibshuff.cpp @@ -44,7 +44,7 @@ vector > SLibshuff::evaluateAll(){ return dCXYValues; } catch(exception& e) { - errorOut(e, "SLibshuff", "evaluateAll"); + m->errorOut(e, "SLibshuff", "evaluateAll"); exit(1); } } @@ -97,7 +97,7 @@ double SLibshuff::sCalculate(int x, int y){ return sum; } catch(exception& e) { - errorOut(e, "SLibshuff", "sCalculate"); + m->errorOut(e, "SLibshuff", "sCalculate"); exit(1); } } diff --git a/solow.cpp b/solow.cpp index d29b9c9..33f3afb 100644 --- a/solow.cpp +++ b/solow.cpp @@ -21,12 +21,12 @@ EstOutput Solow::getValues(SAbundVector* rank){ double f1 = (double)rank->get(1); double f2 = (double)rank->get(2); - data[0] = f1*f1/2/f2 * (1 - pow(1 - 2*f2/n/f1, m)); + data[0] = f1*f1/2/f2 * (1 - pow(1 - 2*f2/n/f1, f)); return data; } catch(exception& e) { - errorOut(e, "Solow", "getValues"); + m->errorOut(e, "Solow", "getValues"); exit(1); } } diff --git a/solow.h b/solow.h index 7501609..0850141 100644 --- a/solow.h +++ b/solow.h @@ -20,11 +20,11 @@ class Solow : public Calculator { public: - Solow(int size) : m(size), Calculator("solow", 1, false) {}; + Solow(int size) : f(size), Calculator("solow", 1, false) {}; EstOutput getValues(SAbundVector*); EstOutput getValues(vector) {return data;}; private: - int m; + int f; }; diff --git a/sparsematrix.cpp b/sparsematrix.cpp index 7477bd9..bd54433 100644 --- a/sparsematrix.cpp +++ b/sparsematrix.cpp @@ -5,7 +5,7 @@ /***********************************************************************/ -SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){} +SparseMatrix::SparseMatrix() : numNodes(0), minsIndex(0), smallDist(1e6){ m = MothurOut::getInstance(); } /***********************************************************************/ @@ -34,7 +34,7 @@ MatData SparseMatrix::rmCell(MatData data){ // clustering and the clustering algorithm updates smallDist } catch(exception& e) { - errorOut(e, "SparseMatrix", "rmCell"); + m->errorOut(e, "SparseMatrix", "rmCell"); exit(1); } } @@ -50,7 +50,7 @@ void SparseMatrix::addCell(PCell value){ } } catch(exception& e) { - errorOut(e, "SparseMatrix", "addCell"); + m->errorOut(e, "SparseMatrix", "addCell"); exit(1); } } @@ -66,7 +66,7 @@ void SparseMatrix::clear(){ smallDist = 1e6; } catch(exception& e) { - errorOut(e, "SparseMatrix", "clear"); + m->errorOut(e, "SparseMatrix", "clear"); exit(1); } } @@ -97,7 +97,7 @@ void SparseMatrix::print(){ } } catch(exception& e) { - errorOut(e, "SparseMatrix", "print"); + m->errorOut(e, "SparseMatrix", "print"); exit(1); } } @@ -108,15 +108,15 @@ void SparseMatrix::print(ListVector* list){ try { int index = 0; - mothurOutEndLine(); mothurOut("Index\tRow\tColumn\tDistance"); mothurOutEndLine(); + m->mothurOutEndLine(); m->mothurOut("Index\tRow\tColumn\tDistance"); m->mothurOutEndLine(); for(MatData currentCell=matrix.begin();currentCell!=matrix.end();currentCell++){ - mothurOut(toString(index) + "\t" + toString(list->get(currentCell->row)) + "\t" + toString(list->get(currentCell->column)) + "\t" + toString(currentCell->dist)); mothurOutEndLine(); + m->mothurOut(toString(index) + "\t" + toString(list->get(currentCell->row)) + "\t" + toString(list->get(currentCell->column)) + "\t" + toString(currentCell->dist)); m->mothurOutEndLine(); index++; } } catch(exception& e) { - errorOut(e, "SparseMatrix", "print"); + m->errorOut(e, "SparseMatrix", "print"); exit(1); } } @@ -168,7 +168,7 @@ PCell* SparseMatrix::getSmallestCell(){ return smallCell; } catch(exception& e) { - errorOut(e, "SparseMatrix", "getSmallestCell"); + m->errorOut(e, "SparseMatrix", "getSmallestCell"); exit(1); } } diff --git a/sparsematrix.hpp b/sparsematrix.hpp index 8eeda7f..e42fdbb 100644 --- a/sparsematrix.hpp +++ b/sparsematrix.hpp @@ -2,6 +2,7 @@ #define SPARSEMATRIX_H #include "mothur.h" +#include "mothurout.h" class ListVector; @@ -47,6 +48,7 @@ private: vector mins; float smallDist; int minsIndex; + MothurOut* m; }; /***********************************************************************/ diff --git a/suffixdb.cpp b/suffixdb.cpp index 39a9b54..2aa8f3f 100644 --- a/suffixdb.cpp +++ b/suffixdb.cpp @@ -55,7 +55,7 @@ vector SuffixDB::findClosestSequences(Sequence* candidateSeq, int num){ return topMatches; } catch(exception& e) { - errorOut(e, "SuffixDB", "findClosestSequences"); + m->errorOut(e, "SuffixDB", "findClosestSequences"); exit(1); } } @@ -67,7 +67,7 @@ void SuffixDB::addSequence(Sequence seq) { count++; } catch(exception& e) { - errorOut(e, "SuffixDB", "addSequence"); + m->errorOut(e, "SuffixDB", "addSequence"); exit(1); } } diff --git a/suffixnodes.cpp b/suffixnodes.cpp index 1e5d705..130b2be 100644 --- a/suffixnodes.cpp +++ b/suffixnodes.cpp @@ -35,7 +35,7 @@ SuffixNode::SuffixNode(int parent, int start, int end) : parentNode(parent), // we store the parent node as an int startCharPosition(start), // the suffix tree class will hold the sequence that the startCharPosition and endCharPosition(end) // endCharPosition indices correspond to - { /* do nothing */ } + { /* do nothing */ m = MothurOut::getInstance(); } void SuffixNode::setChildren(char, int) { /* do nothing */ } // there's no children in a leaf @@ -57,14 +57,14 @@ SuffixLeaf::SuffixLeaf(int parent, int start, int end) : SuffixNode(parent, star void SuffixLeaf::print(string sequence, int nodeNumber){ - mothurOut(toString(this) + "\t" + toString(parentNode) + "\t" + toString(nodeNumber) + "\t" + + m->mothurOut(toString(this) + "\t" + toString(parentNode) + "\t" + toString(nodeNumber) + "\t" + toString(-1) + "\t" + toString(startCharPosition) + "\t" + toString(endCharPosition) + "\t"); - mothurOut("/"); + m->mothurOut("/"); for(int i=startCharPosition;i<=endCharPosition;i++){ - mothurOut(toString(deCodeSequence(sequence[i]))); + m->mothurOut(toString(deCodeSequence(sequence[i]))); } - mothurOut("/"); mothurOutEndLine(); + m->mothurOut("/"); m->mothurOutEndLine(); } //******************************************************************************************************************** @@ -74,14 +74,14 @@ SuffixBranch::SuffixBranch(int parent, int start, int end) : SuffixNode(parent, } void SuffixBranch::print(string sequence, int nodeNumber){ // this method is different that than - mothurOut(toString(this) + "\t" + toString(parentNode) + "\t" + toString(nodeNumber) + "\t" + // of a leaf because it prints out a + m->mothurOut(toString(this) + "\t" + toString(parentNode) + "\t" + toString(nodeNumber) + "\t" + // of a leaf because it prints out a toString(suffixNode) + "\t" + toString(startCharPosition) + "\t" + toString(endCharPosition) + "\t"); // value for the suffix node - mothurOut("/"); + m->mothurOut("/"); for(int i=startCharPosition;i<=endCharPosition;i++){ - mothurOut(toString(deCodeSequence(sequence[i]))); + m->mothurOut(toString(deCodeSequence(sequence[i]))); } - mothurOut("/"); mothurOutEndLine(); + m->mothurOut("/"); m->mothurOutEndLine(); } // we can access the children by subtracting '0' from the the char value from the string, the difference is an int diff --git a/suffixnodes.hpp b/suffixnodes.hpp index 63918fa..6a22c4d 100644 --- a/suffixnodes.hpp +++ b/suffixnodes.hpp @@ -17,6 +17,7 @@ */ #include "mothur.h" +#include "mothurout.h" //******************************************************************************************************************** @@ -42,6 +43,7 @@ protected: int parentNode; int startCharPosition; int endCharPosition; + MothurOut* m; }; //******************************************************************************************************************** diff --git a/suffixtree.cpp b/suffixtree.cpp index 2842b36..9cd8351 100644 --- a/suffixtree.cpp +++ b/suffixtree.cpp @@ -35,7 +35,7 @@ inline bool compareParents(SuffixNode* left, SuffixNode* right){// this is neces //******************************************************************************************************************** -SuffixTree::SuffixTree(){} +SuffixTree::SuffixTree(){ m = MothurOut::getInstance(); } //******************************************************************************************************************** @@ -75,7 +75,7 @@ string SuffixTree::getSeqName() { void SuffixTree::print(){ vector hold = nodeVector; sort(hold.begin(), hold.end(), compareParents); - mothurOut("Address\t\tParent\tNode\tSuffix\tStartC\tEndC\tSuffix"); mothurOutEndLine(); + m->mothurOut("Address\t\tParent\tNode\tSuffix\tStartC\tEndC\tSuffix"); m->mothurOutEndLine(); for(int i=1;i<=nodeCounter;i++){ hold[i]->print(sequence, i); } diff --git a/suffixtree.hpp b/suffixtree.hpp index ab262ba..805b9b0 100644 --- a/suffixtree.hpp +++ b/suffixtree.hpp @@ -60,6 +60,7 @@ private: int nodeCounter; string seqName; string sequence; + MothurOut* m; }; diff --git a/summarycommand.cpp b/summarycommand.cpp index 0322824..12382a4 100644 --- a/summarycommand.cpp +++ b/summarycommand.cpp @@ -31,7 +31,7 @@ //********************************************************************************************************************** -SummaryCommand::SummaryCommand(string option){ +SummaryCommand::SummaryCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -58,7 +58,7 @@ SummaryCommand::SummaryCommand(string option){ } //make sure the user has already run the read.otu command - if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund, rabund or shared file before you can use the summary.single command."); mothurOutEndLine(); abort = true; } + 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 output directory command factory will send this info to us in the output parameter outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ @@ -98,7 +98,7 @@ SummaryCommand::SummaryCommand(string option){ } } catch(exception& e) { - errorOut(e, "SummaryCommand", "SummaryCommand"); + m->errorOut(e, "SummaryCommand", "SummaryCommand"); exit(1); } } @@ -106,19 +106,19 @@ SummaryCommand::SummaryCommand(string option){ void SummaryCommand::help(){ try { - mothurOut("The summary.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n"); - 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"); - mothurOut("The summary.single command parameters are label, calc, abund. No parameters are required.\n"); - mothurOut("The summary.single command should be in the following format: \n"); - mothurOut("summary.single(label=yourLabel, calc=yourEstimators).\n"); - mothurOut("Example summary.single(label=unique-.01-.03, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson).\n"); + 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. 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); - mothurOut("The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson\n"); - mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n"); + m->mothurOut("The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson\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) { - errorOut(e, "SummaryCommand", "help"); + m->errorOut(e, "SummaryCommand", "help"); exit(1); } } @@ -134,6 +134,8 @@ int SummaryCommand::execute(){ if (abort == true) { return 0; } + vector outputNames; + if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); } else { inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); } @@ -141,9 +143,10 @@ int SummaryCommand::execute(){ string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])) + "summary"; globaldata->inputFileName = inputFileNames[p]; + outputNames.push_back(fileNameRoot); if (inputFileNames.size() > 1) { - mothurOutEndLine(); mothurOut("Processing group " + groups[p]); mothurOutEndLine(); mothurOutEndLine(); + m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine(); } sumCalculators.clear(); @@ -230,7 +233,7 @@ int SummaryCommand::execute(){ if(allLines == 1 || labels.count(sabund->getLabel()) == 1){ - mothurOut(sabund->getLabel()); mothurOutEndLine(); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); @@ -249,7 +252,7 @@ int SummaryCommand::execute(){ delete sabund; sabund = input->getSAbundVector(lastLabel); - mothurOut(sabund->getLabel()); mothurOutEndLine(); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); @@ -275,12 +278,12 @@ int SummaryCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -289,7 +292,7 @@ int SummaryCommand::execute(){ if (sabund != NULL) { delete sabund; } sabund = input->getSAbundVector(lastLabel); - mothurOut(sabund->getLabel()); mothurOutEndLine(); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); outputFileHandle << sabund->getLabel(); for(int i=0;i data = sumCalculators[i]->getValues(sabund); @@ -308,10 +311,15 @@ int SummaryCommand::execute(){ globaldata->sabund = NULL; } + 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; } catch(exception& e) { - errorOut(e, "SummaryCommand", "execute"); + m->errorOut(e, "SummaryCommand", "execute"); exit(1); } } @@ -370,7 +378,7 @@ vector SummaryCommand::parseSharedFile(string filename) { return filenames; } catch(exception& e) { - errorOut(e, "SummaryCommand", "parseSharedFile"); + m->errorOut(e, "SummaryCommand", "parseSharedFile"); exit(1); } } diff --git a/summarysharedcommand.cpp b/summarysharedcommand.cpp index 081f5ef..b6b4f52 100644 --- a/summarysharedcommand.cpp +++ b/summarysharedcommand.cpp @@ -35,7 +35,7 @@ //********************************************************************************************************************** -SummarySharedCommand::SummarySharedCommand(string option){ +SummarySharedCommand::SummarySharedCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -63,7 +63,7 @@ SummarySharedCommand::SummarySharedCommand(string option){ //make sure the user has already run the read.otu command if (globaldata->getSharedFile() == "") { - mothurOut("You must read a list and a group, or a shared before you can use the summary.shared command."); mothurOutEndLine(); abort = true; + 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; } //if the user changes the output directory command factory will send this info to us in the output parameter @@ -159,12 +159,14 @@ SummarySharedCommand::SummarySharedCommand(string option){ outputFileName = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "shared.summary"; openOutputFile(outputFileName, outputFileHandle); + outputNames.push_back(outputFileName); + mult = false; } } } catch(exception& e) { - errorOut(e, "SummarySharedCommand", "SummarySharedCommand"); + m->errorOut(e, "SummarySharedCommand", "SummarySharedCommand"); exit(1); } } @@ -173,22 +175,22 @@ SummarySharedCommand::SummarySharedCommand(string option){ void SummarySharedCommand::help(){ try { - mothurOut("The summary.shared command can only be executed after a successful read.otu command.\n"); - mothurOut("The summary.shared command parameters are label, calc and all. No parameters are required.\n"); - mothurOut("The summary.shared command should be in the following format: \n"); - mothurOut("summary.shared(label=yourLabel, calc=yourEstimators, groups=yourGroups).\n"); - mothurOut("Example summary.shared(label=unique-.01-.03, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan).\n"); + 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 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); - mothurOut("The default value for calc is sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan\n"); - mothurOut("The default value for groups is all the groups in your groupfile.\n"); - mothurOut("The label parameter is used to analyze specific labels in your input.\n"); - 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"); - mothurOut("If you use sharedchao and run into memory issues, set all to false. \n"); - 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"); - mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabel).\n\n"); + 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 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) { - errorOut(e, "SummarySharedCommand", "help"); + m->errorOut(e, "SummarySharedCommand", "help"); exit(1); } } @@ -208,7 +210,7 @@ int SummarySharedCommand::execute(){ try { if (abort == true) { return 0; } - + //if the users entered no valid calculators don't execute command if (sumCalculators.size() == 0) { return 0; } //check if any calcs can do multiples @@ -239,6 +241,7 @@ int SummarySharedCommand::execute(){ if (mult == true) { outAllFileName = ((getRootName(globaldata->inputFileName)) + "sharedmultiple.summary"); openOutputFile(outAllFileName, outAll); + outputNames.push_back(outAllFileName); outAll << "label" <<'\t' << "comparison" << '\t'; for(int i=0;imothurOut("I cannot run the command without at least 2 valid groups."); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } //close files and clean up @@ -262,6 +265,7 @@ int SummarySharedCommand::execute(){ mult = false; outAll.close(); remove(outAllFileName.c_str()); + outputNames.pop_back(); } //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. @@ -272,7 +276,7 @@ int SummarySharedCommand::execute(){ while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); process(lookup); processedLabels.insert(lookup[0]->getLabel()); @@ -285,7 +289,7 @@ int SummarySharedCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); process(lookup); processedLabels.insert(lookup[0]->getLabel()); @@ -307,12 +311,12 @@ int SummarySharedCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -321,7 +325,7 @@ int SummarySharedCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); process(lookup); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } @@ -337,11 +341,16 @@ int SummarySharedCommand::execute(){ for(int i=0;iginput = NULL; + + 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; } catch(exception& e) { - errorOut(e, "SummarySharedCommand", "execute"); + m->errorOut(e, "SummarySharedCommand", "execute"); exit(1); } } @@ -403,7 +412,7 @@ void SummarySharedCommand::process(vector thisLookup) { } catch(exception& e) { - errorOut(e, "SummarySharedCommand", "process"); + m->errorOut(e, "SummarySharedCommand", "process"); exit(1); } } diff --git a/summarysharedcommand.h b/summarysharedcommand.h index 351b135..8f37eeb 100644 --- a/summarysharedcommand.h +++ b/summarysharedcommand.h @@ -37,7 +37,7 @@ private: bool abort, allLines, mult, all; set labels; //holds labels to be used string label, calc, groups; - vector Estimators, Groups; + vector Estimators, Groups, outputNames; vector lookup; string outputFileName, format, outAllFileName, outputDir; ofstream outputFileHandle, outAll; diff --git a/systemcommand.cpp b/systemcommand.cpp index 489a2f1..708724a 100644 --- a/systemcommand.cpp +++ b/systemcommand.cpp @@ -11,7 +11,7 @@ //********************************************************************************************************************** -SystemCommand::SystemCommand(string option){ +SystemCommand::SystemCommand(string option) { try { abort = false; @@ -19,7 +19,7 @@ SystemCommand::SystemCommand(string option){ if(option == "help") { help(); abort = true; } else { - if (option == "") { mothurOut("You must enter a command to run."); mothurOutEndLine(); abort = true; } + if (option == "") { m->mothurOut("You must enter a command to run."); m->mothurOutEndLine(); abort = true; } else { //check for outputdir and inputdir parameters int commaPos = option.find_first_of(','); @@ -35,7 +35,7 @@ SystemCommand::SystemCommand(string option){ } catch(exception& e) { - errorOut(e, "SystemCommand", "SystemCommand"); + m->errorOut(e, "SystemCommand", "SystemCommand"); exit(1); } } @@ -43,13 +43,13 @@ SystemCommand::SystemCommand(string option){ void SystemCommand::help(){ try { - mothurOut("The system command allows you to execute a system command from within mothur.\n"); - mothurOut("The system has no parameters.\n"); - mothurOut("The system command should be in the following format: system(yourCommand).\n"); - mothurOut("Example system(clear).\n"); + 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"); } catch(exception& e) { - errorOut(e, "SystemCommand", "help"); + m->errorOut(e, "SystemCommand", "help"); exit(1); } } @@ -67,7 +67,7 @@ int SystemCommand::execute(){ } catch(exception& e) { - errorOut(e, "SystemCommand", "execute"); + m->errorOut(e, "SystemCommand", "execute"); exit(1); } } diff --git a/taxonomyequalizer.cpp b/taxonomyequalizer.cpp index c84c439..f3ccfe4 100644 --- a/taxonomyequalizer.cpp +++ b/taxonomyequalizer.cpp @@ -12,6 +12,7 @@ /**************************************************************************************************/ TaxEqualizer::TaxEqualizer(string tfile, int c) : cutoff(c) { try { + m = MothurOut::getInstance(); containsConfidence = false; ifstream inTax; @@ -23,8 +24,8 @@ TaxEqualizer::TaxEqualizer(string tfile, int c) : cutoff(c) { if ((cutoff != -1) && (cutoff < highestLevel)) { highestLevel = cutoff; }else if (cutoff > highestLevel) { - mothurOut("The highest level taxonomy you have is " + toString(highestLevel) + " and your cutoff is " + toString(cutoff) + ". I will set the cutoff to " + toString(highestLevel)); - mothurOutEndLine(); + m->mothurOut("The highest level taxonomy you have is " + toString(highestLevel) + " and your cutoff is " + toString(cutoff) + ". I will set the cutoff to " + toString(highestLevel)); + m->mothurOutEndLine(); } inTax.close(); @@ -56,7 +57,7 @@ TaxEqualizer::TaxEqualizer(string tfile, int c) : cutoff(c) { } catch(exception& e) { - errorOut(e, "TaxEqualizer", "TaxEqualizer"); + m->errorOut(e, "TaxEqualizer", "TaxEqualizer"); exit(1); } } @@ -95,7 +96,7 @@ int TaxEqualizer::getHighestLevel(ifstream& in) { } catch(exception& e) { - errorOut(e, "TaxEqualizer", "getHighestLevel"); + m->errorOut(e, "TaxEqualizer", "getHighestLevel"); exit(1); } } @@ -118,7 +119,7 @@ void TaxEqualizer::extendTaxonomy(string name, string& tax, int desiredLevel) { } } catch(exception& e) { - errorOut(e, "TaxEqualizer", "extendTaxonomy"); + m->errorOut(e, "TaxEqualizer", "extendTaxonomy"); exit(1); } } @@ -137,7 +138,7 @@ void TaxEqualizer::truncateTaxonomy(string name, string& tax, int desiredLevel) tax += ";"; } catch(exception& e) { - errorOut(e, "TaxEqualizer", "truncateTaxonomy"); + m->errorOut(e, "TaxEqualizer", "truncateTaxonomy"); exit(1); } } @@ -161,7 +162,7 @@ void TaxEqualizer::removeConfidences(string& tax) { tax = newTax; } catch(exception& e) { - errorOut(e, "TaxEqualizer", "removeConfidences"); + m->errorOut(e, "TaxEqualizer", "removeConfidences"); exit(1); } } diff --git a/taxonomyequalizer.h b/taxonomyequalizer.h index 9f38b2f..e060c9e 100644 --- a/taxonomyequalizer.h +++ b/taxonomyequalizer.h @@ -12,6 +12,7 @@ */ #include "mothur.h" +#include "mothurout.h" //reads in taxonomy file and makes all the taxonomies the same length //by appending the last taxon to a given taxonomy as many times as needed to @@ -39,7 +40,7 @@ private: void extendTaxonomy(string, string&, int); //name, taxonomy, desired level void truncateTaxonomy(string, string&, int); //name, taxonomy, desired level void removeConfidences(string&); //removes the confidence limits on the taxon - + MothurOut* m; }; diff --git a/tree.cpp b/tree.cpp index 731eb64..eca53d5 100644 --- a/tree.cpp +++ b/tree.cpp @@ -14,6 +14,7 @@ Tree::Tree() { try { globaldata = GlobalData::getInstance(); + m = MothurOut::getInstance(); if (globaldata->runParse == true) { parseTreeFile(); globaldata->runParse = false; } //for(int i = 0; i < globaldata->Treenames.size(); i++) { cout << i << '\t' << globaldata->Treenames[i] << endl; } @@ -44,7 +45,7 @@ Tree::Tree() { } } catch(exception& e) { - errorOut(e, "Tree", "Tree"); + m->errorOut(e, "Tree", "Tree"); exit(1); } } @@ -73,7 +74,7 @@ void Tree::addNamesToCounts() { map::iterator itNames = globaldata->names.find(name); - if (itNames == globaldata->names.end()) { mothurOut(name + " is not in your name file, please correct."); mothurOutEndLine(); exit(1); } + if (itNames == globaldata->names.end()) { m->mothurOut(name + " is not in your name file, please correct."); m->mothurOutEndLine(); exit(1); } else { vector dupNames; splitAtComma(globaldata->names[name], dupNames); @@ -134,7 +135,7 @@ void Tree::addNamesToCounts() { } catch(exception& e) { - errorOut(e, "Tree", "addNamesToCounts"); + m->errorOut(e, "Tree", "addNamesToCounts"); exit(1); } } @@ -148,7 +149,7 @@ int Tree::getIndex(string searchName) { } catch(exception& e) { - errorOut(e, "Tree", "getIndex"); + m->errorOut(e, "Tree", "getIndex"); exit(1); } } @@ -160,7 +161,7 @@ void Tree::setIndex(string searchName, int index) { globaldata->gTreemap->setIndex(searchName, index); } catch(exception& e) { - errorOut(e, "Tree", "setIndex"); + m->errorOut(e, "Tree", "setIndex"); exit(1); } } @@ -178,7 +179,7 @@ void Tree::assembleTree() { } } catch(exception& e) { - errorOut(e, "Tree", "assembleTree"); + m->errorOut(e, "Tree", "assembleTree"); exit(1); } } @@ -216,7 +217,7 @@ void Tree::getCopy(Tree* copy) { } catch(exception& e) { - errorOut(e, "Tree", "getCopy"); + m->errorOut(e, "Tree", "getCopy"); exit(1); } } @@ -269,7 +270,7 @@ map Tree::mergeGroups(int i) { return parsimony; } catch(exception& e) { - errorOut(e, "Tree", "mergeGroups"); + m->errorOut(e, "Tree", "mergeGroups"); exit(1); } } @@ -335,7 +336,7 @@ map Tree::mergeUserGroups(int i, vector g) { return parsimony; } catch(exception& e) { - errorOut(e, "Tree", "mergeUserGroups"); + m->errorOut(e, "Tree", "mergeUserGroups"); exit(1); } } @@ -358,7 +359,7 @@ map Tree::mergeGcounts(int position) { return sum; } catch(exception& e) { - errorOut(e, "Tree", "mergeGcounts"); + m->errorOut(e, "Tree", "mergeGcounts"); exit(1); } } @@ -400,7 +401,7 @@ void Tree::randomLabels(vector g) { } } catch(exception& e) { - errorOut(e, "Tree", "randomLabels"); + m->errorOut(e, "Tree", "randomLabels"); exit(1); } } @@ -430,7 +431,7 @@ void Tree::randomLabels(string groupA, string groupB) { } } catch(exception& e) { - errorOut(e, "Tree", "randomLabels"); + m->errorOut(e, "Tree", "randomLabels"); exit(1); } } @@ -446,7 +447,7 @@ void Tree::randomBlengths() { } } catch(exception& e) { - errorOut(e, "Tree", "randomBlengths"); + m->errorOut(e, "Tree", "randomBlengths"); exit(1); } } @@ -503,7 +504,7 @@ void Tree::randomTopology() { } } catch(exception& e) { - errorOut(e, "Tree", "randomTopology"); + m->errorOut(e, "Tree", "randomTopology"); exit(1); } } @@ -515,7 +516,7 @@ void Tree::print(ostream& out) { out << ";" << endl; } catch(exception& e) { - errorOut(e, "Tree", "print"); + m->errorOut(e, "Tree", "print"); exit(1); } } @@ -527,7 +528,7 @@ void Tree::printForBoot(ostream& out) { out << ";" << endl; } catch(exception& e) { - errorOut(e, "Tree", "printForBoot"); + m->errorOut(e, "Tree", "printForBoot"); exit(1); } } @@ -549,7 +550,7 @@ void Tree::createNewickFile(string f) { out.close(); } catch(exception& e) { - errorOut(e, "Tree", "createNewickFile"); + m->errorOut(e, "Tree", "createNewickFile"); exit(1); } } @@ -568,7 +569,7 @@ int Tree::findRoot() { return -1; } catch(exception& e) { - errorOut(e, "Tree", "findRoot"); + m->errorOut(e, "Tree", "findRoot"); exit(1); } } @@ -614,7 +615,7 @@ void Tree::printBranch(int node, ostream& out, string mode) { } catch(exception& e) { - errorOut(e, "Tree", "printBranch"); + m->errorOut(e, "Tree", "printBranch"); exit(1); } } @@ -710,7 +711,7 @@ void Tree::parseTreeFile() { filehandle.close(); } catch(exception& e) { - errorOut(e, "Tree", "parseTreeFile"); + m->errorOut(e, "Tree", "parseTreeFile"); exit(1); } } @@ -774,7 +775,7 @@ int Tree::readTreeString(ifstream& filehandle) { return 0; } catch(exception& e) { - errorOut(e, "Tree", "readTreeString"); + m->errorOut(e, "Tree", "readTreeString"); exit(1); } } diff --git a/tree.h b/tree.h index 37028be..04d9fb1 100644 --- a/tree.h +++ b/tree.h @@ -62,6 +62,7 @@ private: //not included in the tree. //only takes names from the first tree in the tree file and assumes that all trees use the same names. int readTreeString(ifstream&); + MothurOut* m; }; diff --git a/treecalculator.h b/treecalculator.h index 797c457..86cb527 100644 --- a/treecalculator.h +++ b/treecalculator.h @@ -12,6 +12,7 @@ #include "mothur.h" #include "tree.h" +#include "mothurout.h" /* The tree calculator class is the parent class for tree calculators in mothur. */ @@ -22,7 +23,7 @@ typedef vector EstOutput; class TreeCalculator { public: - TreeCalculator(){}; + TreeCalculator(){ m = MothurOut::getInstance(); } TreeCalculator(string n) : name(n) {}; virtual ~TreeCalculator(){}; virtual EstOutput getValues(Tree*) = 0; @@ -33,6 +34,7 @@ public: protected: EstOutput data; string name; + MothurOut* m; }; diff --git a/treegroupscommand.cpp b/treegroupscommand.cpp index e8f68e7..6ce5ee9 100644 --- a/treegroupscommand.cpp +++ b/treegroupscommand.cpp @@ -22,7 +22,7 @@ //********************************************************************************************************************** -TreeGroupCommand::TreeGroupCommand(string option){ +TreeGroupCommand::TreeGroupCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; @@ -99,11 +99,11 @@ TreeGroupCommand::TreeGroupCommand(string option){ else { globaldata->setNameFile(namefile); } //error checking on files - if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == ""))) { mothurOut("You must run the read.otu command or provide a distance file before running the tree.shared command."); mothurOutEndLine(); abort = true; } - else if ((phylipfile != "") && (columnfile != "")) { mothurOut("When running the tree.shared command with a distance file you may not use both the column and the phylip parameters."); mothurOutEndLine(); abort = true; } + 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; } + 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 == "") { mothurOut("You need to provide a namefile if you are going to use the column format."); mothurOutEndLine(); abort = true; } + if (namefile == "") { 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 @@ -187,7 +187,7 @@ TreeGroupCommand::TreeGroupCommand(string option){ } catch(exception& e) { - errorOut(e, "TreeGroupCommand", "TreeGroupCommand"); + m->errorOut(e, "TreeGroupCommand", "TreeGroupCommand"); exit(1); } } @@ -196,25 +196,25 @@ TreeGroupCommand::TreeGroupCommand(string option){ void TreeGroupCommand::help(){ try { - mothurOut("The tree.shared command creates a .tre to represent the similiarity between groups or sequences.\n"); - mothurOut("The tree.shared command can only be executed after a successful read.otu command or by providing a distance file.\n"); - mothurOut("The tree.shared command parameters are groups, calc, phylip, column, name, cutoff, precision and label.\n"); - mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included used.\n"); - 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"); - 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"); - 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"); - mothurOut("The tree.shared command should be in the following format: tree.shared(groups=yourGroups, calc=yourCalcs, label=yourLabels).\n"); - mothurOut("Example tree.shared(groups=A-B-C, calc=jabund-sorabund).\n"); - mothurOut("The default value for groups is all the groups in your groupfile.\n"); - mothurOut("The default value for calc is jclass-thetayc.\n"); - mothurOut("The tree.shared command outputs a .tre file for each calculator you specify at each distance you choose.\n"); + 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); - mothurOut("Or the tree.shared command can be in the following format: tree.shared(phylip=yourPhylipFile).\n"); - mothurOut("Example tree.shared(phylip=abrecovery.dist).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); + 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) { - errorOut(e, "TreeGroupCommand", "help"); + m->errorOut(e, "TreeGroupCommand", "help"); exit(1); } } @@ -242,7 +242,7 @@ int TreeGroupCommand::execute(){ if (format == "sharedfile") { //if the users entered no valid calculators don't execute command - if (treeCalculators.size() == 0) { mothurOut("You have given no valid calculators."); mothurOutEndLine(); return 0; } + if (treeCalculators.size() == 0) { m->mothurOut("You have given no valid calculators."); m->mothurOutEndLine(); return 0; } //you have groups read = new ReadOTUFile(globaldata->inputFileName); @@ -252,7 +252,7 @@ int TreeGroupCommand::execute(){ lookup = input->getSharedRAbundVectors(); lastLabel = lookup[0]->getLabel(); - if (lookup.size() < 2) { mothurOut("You have not provided enough valid groups. I cannot run the command."); mothurOutEndLine(); return 0; } + 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; @@ -300,18 +300,24 @@ int TreeGroupCommand::execute(){ //create a new filename outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + "tre"; + outputNames.push_back(outputFile); createTree(); - mothurOut("Tree complete. "); mothurOutEndLine(); + m->mothurOut("Tree complete. "); m->mothurOutEndLine(); } //reset groups parameter globaldata->Groups.clear(); + + 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; } catch(exception& e) { - errorOut(e, "TreeGroupCommand", "execute"); + m->errorOut(e, "TreeGroupCommand", "execute"); exit(1); } } @@ -388,7 +394,7 @@ void TreeGroupCommand::createTree(){ } catch(exception& e) { - errorOut(e, "TreeGroupCommand", "createTree"); + m->errorOut(e, "TreeGroupCommand", "createTree"); exit(1); } } @@ -412,7 +418,7 @@ void TreeGroupCommand::printSims(ostream& out) { } catch(exception& e) { - errorOut(e, "TreeGroupCommand", "printSims"); + m->errorOut(e, "TreeGroupCommand", "printSims"); exit(1); } } @@ -445,7 +451,7 @@ void TreeGroupCommand::makeSimsDist() { } catch(exception& e) { - errorOut(e, "TreeGroupCommand", "makeSimsDist"); + m->errorOut(e, "TreeGroupCommand", "makeSimsDist"); exit(1); } } @@ -472,7 +478,7 @@ void TreeGroupCommand::makeSimsShared() { while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); process(lookup); processedLabels.insert(lookup[0]->getLabel()); @@ -485,7 +491,7 @@ void TreeGroupCommand::makeSimsShared() { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); process(lookup); processedLabels.insert(lookup[0]->getLabel()); @@ -506,12 +512,12 @@ void TreeGroupCommand::makeSimsShared() { set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -520,7 +526,7 @@ void TreeGroupCommand::makeSimsShared() { for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); process(lookup); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } @@ -528,7 +534,7 @@ void TreeGroupCommand::makeSimsShared() { for(int i = 0 ; i < treeCalculators.size(); i++) { delete treeCalculators[i]; } } catch(exception& e) { - errorOut(e, "TreeGroupCommand", "makeSimsShared"); + m->errorOut(e, "TreeGroupCommand", "makeSimsShared"); exit(1); } } @@ -557,6 +563,7 @@ void TreeGroupCommand::process(vector thisLookup) { //create a new filename outputFile = outputDir + getRootName(getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre"; + outputNames.push_back(outputFile); for (int k = 0; k < thisLookup.size(); k++) { for (int l = k; l < thisLookup.size(); l++) { @@ -581,7 +588,7 @@ void TreeGroupCommand::process(vector thisLookup) { } catch(exception& e) { - errorOut(e, "TreeGroupCommand", "process"); + m->errorOut(e, "TreeGroupCommand", "process"); exit(1); } } diff --git a/treegroupscommand.h b/treegroupscommand.h index e23dc77..899716c 100644 --- a/treegroupscommand.h +++ b/treegroupscommand.h @@ -68,7 +68,7 @@ private: bool abort, allLines; set labels; //holds labels to be used string phylipfile, columnfile, namefile, calc, groups, label, outputDir; - vector Estimators, Groups; //holds estimators to be used + vector Estimators, Groups, outputNames; //holds estimators to be used //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. void process(vector); diff --git a/treemap.cpp b/treemap.cpp index cd046f9..bb62448 100644 --- a/treemap.cpp +++ b/treemap.cpp @@ -135,7 +135,7 @@ bool TreeMap::isValidGroup(string groupname) { return false; } catch(exception& e) { - errorOut(e, "TreeMap", "isValidGroup"); + m->errorOut(e, "TreeMap", "isValidGroup"); exit(1); } } @@ -149,7 +149,7 @@ void TreeMap::print(ostream& output){ } } catch(exception& e) { - errorOut(e, "TreeMap", "print"); + m->errorOut(e, "TreeMap", "print"); exit(1); } } @@ -173,7 +173,7 @@ void TreeMap::makeSim(GroupMap* groupmap) { } catch(exception& e) { - errorOut(e, "TreeMap", "makeSim"); + m->errorOut(e, "TreeMap", "makeSim"); exit(1); } } @@ -199,7 +199,7 @@ void TreeMap::makeSim(ListVector* list) { } catch(exception& e) { - errorOut(e, "TreeMap", "makeSim"); + m->errorOut(e, "TreeMap", "makeSim"); exit(1); } } diff --git a/treemap.h b/treemap.h index 0824ebf..bda6926 100644 --- a/treemap.h +++ b/treemap.h @@ -25,7 +25,7 @@ class ListVector; class TreeMap { public: - TreeMap() {}; + TreeMap() { m = MothurOut::getInstance(); } TreeMap(string); ~TreeMap(); void readMap(); @@ -51,6 +51,7 @@ private: map::iterator it; map::iterator it2; void setNamesOfGroups(string); + MothurOut* m; }; diff --git a/treenode.cpp b/treenode.cpp index 648707a..c00ade0 100644 --- a/treenode.cpp +++ b/treenode.cpp @@ -12,6 +12,7 @@ /****************************************************************/ Node::Node() { + m = MothurOut::getInstance(); //initialize node name = ""; branchLength = -1; @@ -60,30 +61,30 @@ int Node::getIndex() { return vectorIndex; } //to be used by printTree in the Tree class to print the leaf info void Node::printNode() { try{ - mothurOut(toString(parent) + " " + toString(lchild) + " " + toString(rchild) + " "); + m->mothurOut(toString(parent) + " " + toString(lchild) + " " + toString(rchild) + " "); - for (int i = 0; i < group.size(); i++) { mothurOut( group[i] + " "); } + for (int i = 0; i < group.size(); i++) { m->mothurOut( group[i] + " "); } //there is a branch length if (branchLength != -1) { - mothurOut(" " + toString(branchLength)); + m->mothurOut(" " + toString(branchLength)); } - mothurOut(" |"); + m->mothurOut(" |"); map::iterator it; for(it=pGroups.begin();it!=pGroups.end();it++){ - mothurOut(" " + it->first + ":" + toString(it->second)); + m->mothurOut(" " + it->first + ":" + toString(it->second)); } - mothurOut(" |"); + m->mothurOut(" |"); for(it=pcount.begin();it!=pcount.end();it++){ - mothurOut(" " + it->first + ":" + toString(it->second)); + m->mothurOut(" " + it->first + ":" + toString(it->second)); } - mothurOutEndLine(); + m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "Node", "printNode"); + m->errorOut(e, "Node", "printNode"); exit(1); } } diff --git a/treenode.h b/treenode.h index c25806b..029cee9 100644 --- a/treenode.h +++ b/treenode.h @@ -11,6 +11,7 @@ */ #include "mothur.h" +#include "mothurout.h" /* This class represents a node on a tree. */ @@ -58,6 +59,7 @@ class Node { int lchild; int rchild; int vectorIndex; + MothurOut* m; }; #endif diff --git a/trimseqscommand.cpp b/trimseqscommand.cpp index 70b1b4a..1b5c7cf 100644 --- a/trimseqscommand.cpp +++ b/trimseqscommand.cpp @@ -11,7 +11,7 @@ //*************************************************************************************************************** -TrimSeqsCommand::TrimSeqsCommand(string option){ +TrimSeqsCommand::TrimSeqsCommand(string option) { try { abort = false; @@ -70,7 +70,7 @@ TrimSeqsCommand::TrimSeqsCommand(string option){ //check for required parameters fastaFile = validParameter.validFile(parameters, "fasta", true); - if (fastaFile == "not found") { mothurOut("fasta is a required parameter for the screen.seqs command."); mothurOutEndLine(); abort = true; } + if (fastaFile == "not found") { m->mothurOut("fasta is a required parameter for the screen.seqs command."); 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 @@ -121,22 +121,22 @@ TrimSeqsCommand::TrimSeqsCommand(string option){ allFiles = isTrue(temp); if(allFiles && oligoFile == ""){ - mothurOut("You selected allfiles, but didn't enter an oligos file. Ignoring the allfiles request."); mothurOutEndLine(); + m->mothurOut("You selected allfiles, but didn't enter an oligos file. Ignoring the allfiles request."); m->mothurOutEndLine(); } if((qAverage != 0 && qThreshold != 0) && qFileName == ""){ - mothurOut("You didn't provide a quality file name, quality criteria will be ignored."); mothurOutEndLine(); + m->mothurOut("You didn't provide a quality file name, quality criteria will be ignored."); m->mothurOutEndLine(); qAverage=0; qThreshold=0; } if(!flip && oligoFile=="" && !maxLength && !minLength && (maxAmbig==-1) && !maxHomoP && qFileName == ""){ - mothurOut("You didn't set any options... quiting command."); mothurOutEndLine(); + m->mothurOut("You didn't set any options... quiting command."); m->mothurOutEndLine(); abort = true; } } } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "TrimSeqsCommand"); + m->errorOut(e, "TrimSeqsCommand", "TrimSeqsCommand"); exit(1); } } @@ -144,30 +144,30 @@ TrimSeqsCommand::TrimSeqsCommand(string option){ void TrimSeqsCommand::help(){ try { - mothurOut("The trim.seqs command reads a fastaFile and creates .....\n"); - mothurOut("The trim.seqs command parameters are fasta, flip, oligos, maxambig, maxhomop, minlength, maxlength, qfile, qthreshold, qaverage, qtrim and allfiles.\n"); - mothurOut("The fasta parameter is required.\n"); - mothurOut("The flip parameter .... The default is 0.\n"); - mothurOut("The oligos parameter .... The default is "".\n"); - mothurOut("The maxambig parameter .... The default is -1.\n"); - mothurOut("The maxhomop parameter .... The default is 0.\n"); - mothurOut("The minlength parameter .... The default is 0.\n"); - mothurOut("The maxlength parameter .... The default is 0.\n"); - mothurOut("The qfile parameter .....\n"); - mothurOut("The qthreshold parameter .... The default is 0.\n"); - mothurOut("The qaverage parameter .... The default is 0.\n"); - mothurOut("The allfiles parameter .... The default is F.\n"); - mothurOut("The qtrim parameter .... The default is F.\n"); - mothurOut("The trim.seqs command should be in the following format: \n"); - mothurOut("trim.seqs(fasta=yourFastaFile, flip=yourFlip, oligos=yourOligos, maxambig=yourMaxambig, \n"); - mothurOut("maxhomop=yourMaxhomop, minlength=youMinlength, maxlength=yourMaxlength) \n"); - mothurOut("Example trim.seqs(fasta=abrecovery.fasta, flip=..., oligos=..., maxambig=..., maxhomop=..., minlength=..., maxlength=...).\n"); - mothurOut("Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n"); - mothurOut("For more details please check out the wiki http://www.mothur.org/wiki/Trim.seqs .\n\n"); + m->mothurOut("The trim.seqs command reads a fastaFile and creates .....\n"); + m->mothurOut("The trim.seqs command parameters are fasta, flip, oligos, maxambig, maxhomop, minlength, maxlength, qfile, qthreshold, qaverage, qtrim and allfiles.\n"); + m->mothurOut("The fasta parameter is required.\n"); + m->mothurOut("The flip parameter .... The default is 0.\n"); + m->mothurOut("The oligos parameter .... The default is "".\n"); + m->mothurOut("The maxambig parameter .... The default is -1.\n"); + m->mothurOut("The maxhomop parameter .... The default is 0.\n"); + m->mothurOut("The minlength parameter .... The default is 0.\n"); + m->mothurOut("The maxlength parameter .... The default is 0.\n"); + m->mothurOut("The qfile parameter .....\n"); + m->mothurOut("The qthreshold parameter .... The default is 0.\n"); + m->mothurOut("The qaverage parameter .... The default is 0.\n"); + m->mothurOut("The allfiles parameter .... The default is F.\n"); + m->mothurOut("The qtrim parameter .... The default is F.\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) { - errorOut(e, "TrimSeqsCommand", "help"); + m->errorOut(e, "TrimSeqsCommand", "help"); exit(1); } } @@ -184,6 +184,8 @@ int TrimSeqsCommand::execute(){ if (abort == true) { return 0; } + vector outputNames; + numFPrimers = 0; //this needs to be initialized numRPrimers = 0; @@ -193,18 +195,21 @@ int TrimSeqsCommand::execute(){ ofstream outFASTA; string trimSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "trim.fasta"; openOutputFile(trimSeqFile, outFASTA); + outputNames.push_back(trimSeqFile); ofstream outGroups; vector fastaFileNames; if(oligoFile != ""){ string groupFile = outputDir + getRootName(getSimpleName(fastaFile)) + "groups"; openOutputFile(groupFile, outGroups); + outputNames.push_back(groupFile); getOligos(fastaFileNames); } ofstream scrapFASTA; string scrapSeqFile = outputDir + getRootName(getSimpleName(fastaFile)) + "scrap.fasta"; openOutputFile(scrapSeqFile, scrapFASTA); + outputNames.push_back(scrapSeqFile); ifstream qFile; if(qFileName != "") { openInputFile(qFileName, qFile); } @@ -293,6 +298,7 @@ int TrimSeqsCommand::execute(){ openInputFile(getRootName(fastaFile) + groupVector[i] + ".fasta", inFASTA); ofstream outGroups; openOutputFile(outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[i] + ".groups", outGroups); + outputNames.push_back(outputDir + getRootName(getSimpleName(fastaFile)) + groupVector[i] + ".groups"); while(!inFASTA.eof()){ if(inFASTA.get() == '>'){ @@ -304,11 +310,16 @@ int TrimSeqsCommand::execute(){ outGroups.close(); inFASTA.close(); } + + 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; } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "execute"); + m->errorOut(e, "TrimSeqsCommand", "execute"); exit(1); } } @@ -366,7 +377,7 @@ void TrimSeqsCommand::getOligos(vector& outFASTAVec){ } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "getOligos"); + m->errorOut(e, "TrimSeqsCommand", "getOligos"); exit(1); } @@ -397,7 +408,7 @@ bool TrimSeqsCommand::stripBarcode(Sequence& seq, int& group){ } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "stripBarcode"); + m->errorOut(e, "TrimSeqsCommand", "stripBarcode"); exit(1); } @@ -429,7 +440,7 @@ bool TrimSeqsCommand::stripForward(Sequence& seq){ } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "stripForward"); + m->errorOut(e, "TrimSeqsCommand", "stripForward"); exit(1); } } @@ -459,7 +470,7 @@ bool TrimSeqsCommand::stripReverse(Sequence& seq){ } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "stripReverse"); + m->errorOut(e, "TrimSeqsCommand", "stripReverse"); exit(1); } } @@ -480,7 +491,7 @@ bool TrimSeqsCommand::cullLength(Sequence& seq){ } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "cullLength"); + m->errorOut(e, "TrimSeqsCommand", "cullLength"); exit(1); } @@ -499,7 +510,7 @@ bool TrimSeqsCommand::cullHomoP(Sequence& seq){ return success; } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "cullHomoP"); + m->errorOut(e, "TrimSeqsCommand", "cullHomoP"); exit(1); } @@ -518,7 +529,7 @@ bool TrimSeqsCommand::cullAmbigs(Sequence& seq){ return success; } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "cullAmbigs"); + m->errorOut(e, "TrimSeqsCommand", "cullAmbigs"); exit(1); } @@ -557,7 +568,7 @@ bool TrimSeqsCommand::compareDNASeq(string oligo, string seq){ return success; } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "compareDNASeq"); + m->errorOut(e, "TrimSeqsCommand", "compareDNASeq"); exit(1); } @@ -572,7 +583,7 @@ bool TrimSeqsCommand::stripQualThreshold(Sequence& seq, ifstream& qFile){ string name; qFile >> name; - if (name.length() != 0) { if(name.substr(1) != seq.getName()) { mothurOut("sequence name mismatch btwn fasta and qual file"); mothurOutEndLine(); } } + if (name.length() != 0) { if(name.substr(1) != seq.getName()) { m->mothurOut("sequence name mismatch btwn fasta and qual file"); m->mothurOutEndLine(); } } while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13){ break; } } int score; @@ -595,7 +606,7 @@ bool TrimSeqsCommand::stripQualThreshold(Sequence& seq, ifstream& qFile){ return 1; } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "stripQualThreshold"); + m->errorOut(e, "TrimSeqsCommand", "stripQualThreshold"); exit(1); } } @@ -610,7 +621,7 @@ bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){ string name; qFile >> name; - if (name[0] == '>') { if(name.substr(1) != seq.getName()) { mothurOut("sequence name mismatch btwn fasta: " + seq.getName() + " and qual file: " + name); mothurOutEndLine(); } } + if (name[0] == '>') { if(name.substr(1) != seq.getName()) { m->mothurOut("sequence name mismatch btwn fasta: " + seq.getName() + " and qual file: " + name); m->mothurOutEndLine(); } } while (!qFile.eof()) { char c = qFile.get(); if (c == 10 || c == 13){ break; } } @@ -629,7 +640,7 @@ bool TrimSeqsCommand::cullQualAverage(Sequence& seq, ifstream& qFile){ return success; } catch(exception& e) { - errorOut(e, "TrimSeqsCommand", "cullQualAverage"); + m->errorOut(e, "TrimSeqsCommand", "cullQualAverage"); exit(1); } } diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 957a4aa..01f6f98 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -10,12 +10,12 @@ #include "unifracunweightedcommand.h" /***********************************************************/ -UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { +UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; Groups.clear(); - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -35,7 +35,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { } if (globaldata->gTree.size() == 0) {//no trees were read - mothurOut("You must execute the read.tree command, before you may execute the unifrac.unweighted command."); mothurOutEndLine(); abort = true; } + 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"){ @@ -74,6 +74,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { T = globaldata->gTree; tmap = globaldata->gTreemap; sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".uwsummary"; + outputNames.push_back(sumFile); openOutputFile(sumFile, outSum); util = new SharedUtil(); @@ -90,7 +91,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { } catch(exception& e) { - errorOut(e, "UnifracUnweightedCommand", "UnifracUnweightedCommand"); + m->errorOut(e, "UnifracUnweightedCommand", "UnifracUnweightedCommand"); exit(1); } } @@ -99,20 +100,20 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) { void UnifracUnweightedCommand::help(){ try { - mothurOut("The unifrac.unweighted command can only be executed after a successful read.tree command.\n"); - mothurOut("The unifrac.unweighted command parameters are groups, iters, distance and random. No parameters are required.\n"); - 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"); - 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"); - mothurOut("The distance parameter allows you to create a distance file from the results. The default is false.\n"); - mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is true, meaning compare your trees with randomly generated trees.\n"); - mothurOut("The unifrac.unweighted command should be in the following format: unifrac.unweighted(groups=yourGroups, iters=yourIters).\n"); - mothurOut("Example unifrac.unweighted(groups=A-B-C, iters=500).\n"); - mothurOut("The default value for groups is all the groups in your groupfile, and iters is 1000.\n"); - mothurOut("The unifrac.unweighted command output two files: .unweighted and .uwsummary their descriptions are in the manual.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); + 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 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.\n"); + m->mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is true, meaning compare your trees with randomly generated trees.\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) { - errorOut(e, "UnifracUnweightedCommand", "help"); + m->errorOut(e, "UnifracUnweightedCommand", "help"); exit(1); } } @@ -129,13 +130,16 @@ int UnifracUnweightedCommand::execute() { //create new tree with same num nodes and leaves as users outSum << "Tree#" << '\t' << "Groups" << '\t' << "UWScore" <<'\t' << "UWSig" << endl; - mothurOut("Tree#\tGroups\tUWScore\tUWSig"); mothurOutEndLine(); + m->mothurOut("Tree#\tGroups\tUWScore\tUWSig"); m->mothurOutEndLine(); //get pscores for users trees for (int i = 0; i < T.size(); i++) { counter = 0; - if (random) { output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted", itersString); } + if (random) { + output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted", itersString); + outputNames.push_back(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted"); + } //get unweighted for users tree rscoreFreq.resize(numComp); @@ -205,11 +209,16 @@ int UnifracUnweightedCommand::execute() { globaldata->Groups.clear(); outSum.close(); + 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; } catch(exception& e) { - errorOut(e, "UnifracUnweightedCommand", "execute"); + m->errorOut(e, "UnifracUnweightedCommand", "execute"); exit(1); } } @@ -234,7 +243,7 @@ void UnifracUnweightedCommand::printUnweightedFile() { } } catch(exception& e) { - errorOut(e, "UnifracUnweightedCommand", "printUnweightedFile"); + m->errorOut(e, "UnifracUnweightedCommand", "printUnweightedFile"); exit(1); } } @@ -250,28 +259,28 @@ void UnifracUnweightedCommand::printUWSummaryFile(int i) { for(int a = 0; a < numComp; a++) { outSum << i+1 << '\t'; - mothurOut(toString(i+1) + "\t"); + m->mothurOut(toString(i+1) + "\t"); if (random) { if (UWScoreSig[a][0] > (1/(float)iters)) { outSum << setprecision(6) << groupComb[a] << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << UWScoreSig[a][0] << endl; cout << setprecision(6) << groupComb[a] << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << UWScoreSig[a][0] << endl; - mothurOutJustToLog(groupComb[a] + "\t" + toString(utreeScores[a][0]) + "\t" + toString(UWScoreSig[a][0])); mothurOutEndLine(); + m->mothurOutJustToLog(groupComb[a] + "\t" + toString(utreeScores[a][0]) + "\t" + toString(UWScoreSig[a][0])); m->mothurOutEndLine(); }else { outSum << setprecision(6) << groupComb[a] << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; cout << setprecision(6) << groupComb[a] << '\t' << utreeScores[a][0] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; - mothurOutJustToLog(groupComb[a] + "\t" + toString(utreeScores[a][0]) + "\t<" + toString((1/float(iters)))); mothurOutEndLine(); + m->mothurOutJustToLog(groupComb[a] + "\t" + toString(utreeScores[a][0]) + "\t<" + toString((1/float(iters)))); m->mothurOutEndLine(); } }else{ outSum << setprecision(6) << groupComb[a] << '\t' << utreeScores[a][0] << '\t' << "0.00" << endl; cout << setprecision(6) << groupComb[a] << '\t' << utreeScores[a][0] << '\t' << "0.00" << endl; - mothurOutJustToLog(groupComb[a] + "\t" + toString(utreeScores[a][0]) + "\t0.00"); mothurOutEndLine(); + m->mothurOutJustToLog(groupComb[a] + "\t" + toString(utreeScores[a][0]) + "\t0.00"); m->mothurOutEndLine(); } } } catch(exception& e) { - errorOut(e, "UnifracUnweightedCommand", "printUWSummaryFile"); + m->errorOut(e, "UnifracUnweightedCommand", "printUWSummaryFile"); exit(1); } } @@ -279,6 +288,8 @@ void UnifracUnweightedCommand::printUWSummaryFile(int i) { void UnifracUnweightedCommand::createPhylipFile(int i) { try { string phylipFileName = outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".unweighted.dist"; + outputNames.push_back(phylipFileName); + ofstream out; openOutputFile(phylipFileName, out); @@ -317,7 +328,7 @@ void UnifracUnweightedCommand::createPhylipFile(int i) { out.close(); } catch(exception& e) { - errorOut(e, "UnifracUnweightedCommand", "createPhylipFile"); + m->errorOut(e, "UnifracUnweightedCommand", "createPhylipFile"); exit(1); } } diff --git a/unifracunweightedcommand.h b/unifracunweightedcommand.h index c98abc4..c6fc46a 100644 --- a/unifracunweightedcommand.h +++ b/unifracunweightedcommand.h @@ -47,7 +47,7 @@ class UnifracUnweightedCommand : public Command { bool abort, phylip, random; string groups, itersString, outputDir; - vector Groups; //holds groups to be used + vector Groups, outputNames; //holds groups to be used ofstream outSum, out; ifstream inFile; diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index a9f9570..3c6c037 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -15,7 +15,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { globaldata = GlobalData::getInstance(); abort = false; Groups.clear(); - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -35,7 +35,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { } if (globaldata->gTree.size() == 0) {//no trees were read - mothurOut("You must execute the read.tree command, before you may execute the unifrac.weighted command."); mothurOutEndLine(); abort = true; } + 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"){ @@ -69,6 +69,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { tmap = globaldata->gTreemap; sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".wsummary"; openOutputFile(sumFile, outSum); + outputNames.push_back(sumFile); util = new SharedUtil(); string s; //to make work with setgroups @@ -83,7 +84,7 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { } catch(exception& e) { - errorOut(e, "UnifracWeightedCommand", "UnifracWeightedCommand"); + m->errorOut(e, "UnifracWeightedCommand", "UnifracWeightedCommand"); exit(1); } } @@ -91,20 +92,20 @@ UnifracWeightedCommand::UnifracWeightedCommand(string option) { void UnifracWeightedCommand::help(){ try { - mothurOut("The unifrac.weighted command can only be executed after a successful read.tree command.\n"); - mothurOut("The unifrac.weighted command parameters are groups, iters, distance and random. No parameters are required.\n"); - 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"); - 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"); - mothurOut("The distance parameter allows you to create a distance file from the results. The default is false.\n"); - mothurOut("The random parameter allows you to shut off the comparison to random trees. The default is true, meaning compare your trees with randomly generated trees.\n"); - mothurOut("The unifrac.weighted command should be in the following format: unifrac.weighted(groups=yourGroups, iters=yourIters).\n"); - mothurOut("Example unifrac.weighted(groups=A-B-C, iters=500).\n"); - mothurOut("The default value for groups is all the groups in your groupfile, and iters is 1000.\n"); - mothurOut("The unifrac.weighted command output two files: .weighted and .wsummary their descriptions are in the manual.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); + 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 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 true, meaning compare your trees with randomly generated trees.\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) { - errorOut(e, "UnifracWeightedCommand", "help"); + m->errorOut(e, "UnifracWeightedCommand", "help"); exit(1); } } @@ -131,7 +132,10 @@ int UnifracWeightedCommand::execute() { 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 + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted", itersString); } + if (random) { + output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted", itersString); + outputNames.push_back(outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted"); + } userData = weighted->getValues(T[i]); //userData[0] = weightedscore @@ -179,7 +183,7 @@ int UnifracWeightedCommand::execute() { //so if you have 1000 random trees the index returned is 100 //then there are 900 trees with a score greater then you. //giving you a signifigance of 0.900 - int index = findIndex(userData[f], f); if (index == -1) { mothurOut("error in UnifracWeightedCommand"); mothurOutEndLine(); exit(1); } //error code + int index = findIndex(userData[f], f); if (index == -1) { m->mothurOut("error in UnifracWeightedCommand"); m->mothurOutEndLine(); exit(1); } //error code //the signifigance is the number of trees with the users score or higher WScoreSig.push_back((iters-index)/(float)iters); @@ -210,11 +214,16 @@ int UnifracWeightedCommand::execute() { delete randT; + 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; } catch(exception& e) { - errorOut(e, "UnifracWeightedCommand", "execute"); + m->errorOut(e, "UnifracWeightedCommand", "execute"); exit(1); } } @@ -237,7 +246,7 @@ void UnifracWeightedCommand::printWeightedFile() { } } catch(exception& e) { - errorOut(e, "UnifracWeightedCommand", "printWeightedFile"); + m->errorOut(e, "UnifracWeightedCommand", "printWeightedFile"); exit(1); } } @@ -248,7 +257,7 @@ void UnifracWeightedCommand::printWSummaryFile() { try { //column headers outSum << "Tree#" << '\t' << "Groups" << '\t' << "WScore" << '\t' << "WSig" << endl; - mothurOut("Tree#\tGroups\tWScore\tWSig"); mothurOutEndLine(); + m->mothurOut("Tree#\tGroups\tWScore\tWSig"); m->mothurOutEndLine(); //format output outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint); @@ -261,16 +270,16 @@ void UnifracWeightedCommand::printWSummaryFile() { if (WScoreSig[count] > (1/(float)iters)) { outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << WScoreSig[count] << endl; cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << WScoreSig[count] << endl; - mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t" + toString(WScoreSig[count])); mothurOutEndLine(); + m->mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t" + toString(WScoreSig[count])); m->mothurOutEndLine(); }else{ outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(itersString.length()) << "<" << (1/float(iters)) << endl; - mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t<" + toString((1/float(iters)))); mothurOutEndLine(); + m->mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t<" + toString((1/float(iters)))); m->mothurOutEndLine(); } }else{ outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << "0.00" << endl; cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << "0.00" << endl; - mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t0.00"); mothurOutEndLine(); + m->mothurOutJustToLog(toString(i+1) +"\t" + groupComb[j] +"\t" + toString(utreeScores[count]) +"\t0.00"); m->mothurOutEndLine(); } count++; } @@ -278,7 +287,7 @@ void UnifracWeightedCommand::printWSummaryFile() { outSum.close(); } catch(exception& e) { - errorOut(e, "UnifracWeightedCommand", "printWSummaryFile"); + m->errorOut(e, "UnifracWeightedCommand", "printWSummaryFile"); exit(1); } } @@ -290,6 +299,7 @@ void UnifracWeightedCommand::createPhylipFile() { for (int i = 0; i < T.size(); i++) { string phylipFileName = outputDir + getSimpleName(globaldata->getTreeFile()) + toString(i+1) + ".weighted.dist"; + outputNames.push_back(phylipFileName); ofstream out; openOutputFile(phylipFileName, out); @@ -328,7 +338,7 @@ void UnifracWeightedCommand::createPhylipFile() { } } catch(exception& e) { - errorOut(e, "UnifracWeightedCommand", "createPhylipFile"); + m->errorOut(e, "UnifracWeightedCommand", "createPhylipFile"); exit(1); } } @@ -341,7 +351,7 @@ int UnifracWeightedCommand::findIndex(float score, int index) { return rScores[index].size(); } catch(exception& e) { - errorOut(e, "UnifracWeightedCommand", "findIndex"); + m->errorOut(e, "UnifracWeightedCommand", "findIndex"); exit(1); } } @@ -386,7 +396,7 @@ void UnifracWeightedCommand::calculateFreqsCumuls() { } catch(exception& e) { - errorOut(e, "UnifracWeightedCommand", "calculateFreqsCums"); + m->errorOut(e, "UnifracWeightedCommand", "calculateFreqsCums"); exit(1); } } diff --git a/unifracweightedcommand.h b/unifracweightedcommand.h index c36152d..77dd10d 100644 --- a/unifracweightedcommand.h +++ b/unifracweightedcommand.h @@ -23,7 +23,7 @@ class GlobalData; class UnifracWeightedCommand : public Command { public: - UnifracWeightedCommand(string); + UnifracWeightedCommand(string); ~UnifracWeightedCommand() { if (abort == false) { delete weighted; delete util; } } int execute(); void help(); @@ -51,7 +51,7 @@ class UnifracWeightedCommand : public Command { bool abort, phylip, random; string groups, itersString; - vector Groups; //holds groups to be used + vector Groups, outputNames; //holds groups to be used ofstream outSum; diff --git a/unweighted.cpp b/unweighted.cpp index e6ed0eb..5bf6ee3 100644 --- a/unweighted.cpp +++ b/unweighted.cpp @@ -132,7 +132,7 @@ EstOutput Unweighted::getValues(Tree* t) { } catch(exception& e) { - errorOut(e, "Unweighted", "getValues"); + m->errorOut(e, "Unweighted", "getValues"); exit(1); } } @@ -277,7 +277,7 @@ EstOutput Unweighted::getValues(Tree* t, string groupA, string groupB) { } catch(exception& e) { - errorOut(e, "Unweighted", "getValues"); + m->errorOut(e, "Unweighted", "getValues"); exit(1); } } diff --git a/uvest.cpp b/uvest.cpp index afc6022..8aa1666 100644 --- a/uvest.cpp +++ b/uvest.cpp @@ -80,7 +80,7 @@ EstOutput UVEst::getUVest(vector shared) { return results; } catch(exception& e) { - errorOut(e, "UVEst", "getUVest"); + m->errorOut(e, "UVEst", "getUVest"); exit(1); } } diff --git a/uvest.h b/uvest.h index 86b96fd..384e80c 100644 --- a/uvest.h +++ b/uvest.h @@ -21,7 +21,10 @@ typedef vector EstOutput; /***********************************************************************/ class UVEst { public: - EstOutput getUVest(vector); + UVEst() { m = MothurOut::getInstance(); } + EstOutput getUVest(vector); + private: + MothurOut* m; }; /***********************************************************************/ diff --git a/validcalculator.cpp b/validcalculator.cpp index 504eb71..0ade873 100644 --- a/validcalculator.cpp +++ b/validcalculator.cpp @@ -12,6 +12,8 @@ /********************************************************************/ ValidCalculators::ValidCalculators() { try { + m = MothurOut::getInstance(); + initialSingle(); initialShared(); initialRarefaction(); @@ -27,7 +29,7 @@ ValidCalculators::ValidCalculators() { initialHeat(); } catch(exception& e) { - errorOut(e, "ValidCalculator", "ValidCalculator"); + m->errorOut(e, "ValidCalculator", "ValidCalculator"); exit(1); } } @@ -46,11 +48,11 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) { if ((single.find(calculator)) != (single.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the collect.single command and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the collect.single command and will be disregarded. Valid estimators are "); for (it = single.begin(); it != single.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } //are you looking for a calculator for a shared parameter }else if (parameter == "shared") { @@ -58,11 +60,11 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) { if ((shared.find(calculator)) != (shared.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the collect.shared command and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the collect.shared command and will be disregarded. Valid estimators are "); for (it = shared.begin(); it != shared.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } //are you looking for a calculator for a rarefaction parameter }else if (parameter == "rarefaction") { @@ -70,11 +72,11 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) { if ((rarefaction.find(calculator)) != (rarefaction.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the rarefaction.single command and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the rarefaction.single command and will be disregarded. Valid estimators are "); for (it = rarefaction.begin(); it != rarefaction.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } //are you looking for a calculator for a summary parameter }else if (parameter == "summary") { @@ -82,11 +84,11 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) { if ((summary.find(calculator)) != (summary.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the summary.shared command and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the summary.shared command and will be disregarded. Valid estimators are "); for (it = summary.begin(); it != summary.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } //are you looking for a calculator for a sharedsummary parameter }else if (parameter == "sharedsummary") { @@ -94,106 +96,106 @@ bool ValidCalculators::isValidCalculator(string parameter, string calculator) { if ((sharedsummary.find(calculator)) != (sharedsummary.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the summary.shared command and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the summary.shared command and will be disregarded. Valid estimators are "); for (it = sharedsummary.begin(); it != sharedsummary.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } }else if (parameter == "sharedrarefaction") { //is it valid if ((sharedrarefaction.find(calculator)) != (sharedrarefaction.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the rarefaction.shared command and will be disregarded. Valid estimator is "); + m->mothurOut(calculator + " is not a valid estimator for the rarefaction.shared command and will be disregarded. Valid estimator is "); for (it = sharedrarefaction.begin(); it != sharedrarefaction.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } }else if (parameter == "vennsingle") { //is it valid if ((vennsingle.find(calculator)) != (vennsingle.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the venn command in single mode and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the venn command in single mode and will be disregarded. Valid estimators are "); for (it = vennsingle.begin(); it != vennsingle.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } }else if (parameter == "vennshared") { //is it valid if ((vennshared.find(calculator)) != (vennshared.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the venn command in shared mode and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the venn command in shared mode and will be disregarded. Valid estimators are "); for (it = vennshared.begin(); it != vennshared.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } }else if (parameter == "treegroup") { //is it valid if ((treegroup.find(calculator)) != (treegroup.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the tree.shared command and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the tree.shared command and will be disregarded. Valid estimators are "); for (it = treegroup.begin(); it != treegroup.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } }else if (parameter == "matrix") { //is it valid if ((matrix.find(calculator)) != (matrix.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the matrix.output command and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the matrix.output command and will be disregarded. Valid estimators are "); for (it = matrix.begin(); it != matrix.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } }else if (parameter == "heat") { //is it valid if ((heat.find(calculator)) != (heat.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the heatmap.sim command and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the heatmap.sim command and will be disregarded. Valid estimators are "); for (it = heat.begin(); it != heat.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } }else if (parameter == "boot") { //is it valid if ((boot.find(calculator)) != (boot.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the bootstrap.shared command and will be disregarded. Valid estimators are "); + m->mothurOut(calculator + " is not a valid estimator for the bootstrap.shared command and will be disregarded. Valid estimators are "); for (it = boot.begin(); it != boot.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } }else if (parameter == "distance") { //is it valid if ((distance.find(calculator)) != (distance.end())) { return true; }else { - mothurOut(calculator + " is not a valid estimator for the distance command and will be disregarded. Valid calculators are "); + m->mothurOut(calculator + " is not a valid estimator for the distance command and will be disregarded. Valid calculators are "); for (it = distance.begin(); it != distance.end(); it++) { - mothurOut(it->first + ", "); + m->mothurOut(it->first + ", "); } - mothurOutEndLine(); + m->mothurOutEndLine(); return false; } //not a valid parameter }else { return false; } } catch(exception& e) { - errorOut(e, "ValidCalculator", "isValidCalculator"); + m->errorOut(e, "ValidCalculator", "isValidCalculator"); exit(1); } } @@ -224,7 +226,7 @@ void ValidCalculators::initialSingle() { single["default"] = "default"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialSingle"); + m->errorOut(e, "ValidCalculator", "initialSingle"); exit(1); } } @@ -256,7 +258,7 @@ void ValidCalculators::initialShared() { shared["default"] = "default"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialShared"); + m->errorOut(e, "ValidCalculator", "initialShared"); exit(1); } } @@ -277,7 +279,7 @@ void ValidCalculators::initialRarefaction() { rarefaction["default"] = "default"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialRarefaction"); + m->errorOut(e, "ValidCalculator", "initialRarefaction"); exit(1); } } @@ -309,7 +311,7 @@ void ValidCalculators::initialSummary() { summary["default"] = "default"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialSummary"); + m->errorOut(e, "ValidCalculator", "initialSummary"); exit(1); } } @@ -341,7 +343,7 @@ void ValidCalculators::initialSharedSummary() { sharedsummary["default"] = "default"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialSharedSummary"); + m->errorOut(e, "ValidCalculator", "initialSharedSummary"); exit(1); } } @@ -356,7 +358,7 @@ void ValidCalculators::initialSharedRarefact() { sharedrarefaction["default"] = "default"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialSharedRarefact"); + m->errorOut(e, "ValidCalculator", "initialSharedRarefact"); exit(1); } } @@ -372,7 +374,7 @@ void ValidCalculators::initialVennSingle() { vennsingle["default"] = "default"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialVennSingle"); + m->errorOut(e, "ValidCalculator", "initialVennSingle"); exit(1); } } @@ -386,7 +388,7 @@ void ValidCalculators::initialVennShared() { vennshared["default"] = "default"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialVennShared"); + m->errorOut(e, "ValidCalculator", "initialVennShared"); exit(1); } } @@ -406,7 +408,7 @@ void ValidCalculators::initialTreeGroups() { treegroup["braycurtis"] = "braycurtis"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialTreeGroups"); + m->errorOut(e, "ValidCalculator", "initialTreeGroups"); exit(1); } } @@ -425,7 +427,7 @@ void ValidCalculators::initialHeat() { heat["braycurtis"] = "braycurtis"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialHeat"); + m->errorOut(e, "ValidCalculator", "initialHeat"); exit(1); } } @@ -445,7 +447,7 @@ void ValidCalculators::initialMatrix() { matrix["braycurtis"] = "braycurtis"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialMatrix"); + m->errorOut(e, "ValidCalculator", "initialMatrix"); exit(1); } } @@ -465,7 +467,7 @@ void ValidCalculators::initialBoot() { boot["braycurtis"] = "braycurtis"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialBoot"); + m->errorOut(e, "ValidCalculator", "initialBoot"); exit(1); } } @@ -477,7 +479,7 @@ void ValidCalculators::initialDistance() { distance["onegap"] = "onegap"; } catch(exception& e) { - errorOut(e, "ValidCalculator", "initialDistance"); + m->errorOut(e, "ValidCalculator", "initialDistance"); exit(1); } } @@ -548,7 +550,7 @@ void ValidCalculators::printCalc(string parameter, ostream& out) { out << endl; } catch(exception& e) { - errorOut(e, "ValidCalculator", "printCalc"); + m->errorOut(e, "ValidCalculator", "printCalc"); exit(1); } } diff --git a/validcalculator.h b/validcalculator.h index 320f982..bf8819f 100644 --- a/validcalculator.h +++ b/validcalculator.h @@ -11,6 +11,7 @@ */ #include "mothur.h" +#include "mothurout.h" //This class contains a list of all valid calculators in Mothur. //It has a function which will tell you if your calculator is valid for the given parameter. @@ -53,6 +54,8 @@ class ValidCalculators { void initialBoot(); void initialDistance(); void initialHeat(); + + MothurOut* m; }; #endif diff --git a/validparameter.cpp b/validparameter.cpp index a978f0f..0c32a3e 100644 --- a/validparameter.cpp +++ b/validparameter.cpp @@ -13,10 +13,11 @@ ValidParameters::ValidParameters() { try { + m = MothurOut::getInstance(); initParameterRanges(); } catch(exception& e) { - errorOut(e, "ValidParameters", "ValidParameters"); + m->errorOut(e, "ValidParameters", "ValidParameters"); exit(1); } } @@ -38,11 +39,11 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, } } if(!valid) { - mothurOut(parameter + " is not a valid parameter."); mothurOutEndLine(); - mothurOut("The valid parameters are: "); + m->mothurOut(parameter + " is not a valid parameter."); m->mothurOutEndLine(); + m->mothurOut("The valid parameters are: "); for(int i = 0; i < numParams-1; i++) - mothurOut(cParams.at(i) + ", "); - mothurOut("and " + cParams.at(numParams-1) + ".\n"); + m->mothurOut(cParams.at(i) + ", "); + m->mothurOut("and " + cParams.at(numParams-1) + ".\n"); return false; } @@ -73,7 +74,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, double logNum = log10((double)pVal); double diff = (double)((int)logNum - logNum); if(diff != 0) { - mothurOut("The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n"); + m->mothurOut("The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n"); return false; } } @@ -99,7 +100,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, else if(range.at(4).compare("only") == 0) c = 1; else { - mothurOut("The range can only be 'between' or 'only' the bounding numbers.\n"); + m->mothurOut("The range can only be 'between' or 'only' the bounding numbers.\n"); return false; } @@ -108,7 +109,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, else if(range.at(0).compare(">=") == 0 || range[3].compare("=>") == 0) d = 1; else { - mothurOut("The parameter value can only be '>', '>=', or '=>' the lower bounding number.\n"); + m->mothurOut("The parameter value can only be '>', '>=', or '=>' the lower bounding number.\n"); return false; } @@ -117,7 +118,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, else if(range.at(2).compare("<=") == 0 || range[4].compare("=<") == 0) e = 1; else { - mothurOut("The parameter value can only be '<', '<=', or '=<' the upper bounding number.\n"); + m->mothurOut("The parameter value can only be '<', '<=', or '=<' the upper bounding number.\n"); return false; } @@ -161,25 +162,25 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, if(!valid) { - mothurOut("The '" + parameter + "' parameter needs to be "); + m->mothurOut("The '" + parameter + "' parameter needs to be "); if(c == 1) - mothurOut("either '" + toString(a) + "' or '" + toString(b) + "'.\n"); + m->mothurOut("either '" + toString(a) + "' or '" + toString(b) + "'.\n"); else { if(a != piSentinel) { - mothurOut(">"); + m->mothurOut(">"); if(d != 0) - mothurOut("="); - mothurOut(" '" + toString(a) + "'"); + m->mothurOut("="); + m->mothurOut(" '" + toString(a) + "'"); } if(b == piSentinel) - mothurOut( "'.\n"); + m->mothurOut( "'.\n"); else if(a != piSentinel) - mothurOut(" and "); + m->mothurOut(" and "); if(b != piSentinel) { - mothurOut("<"); + m->mothurOut("<"); if(e != 0) - mothurOut("="); - mothurOut(" '" + toString(b) + "'.\n"); + m->mothurOut("="); + m->mothurOut(" '" + toString(b) + "'.\n"); } } return false; @@ -188,7 +189,7 @@ bool ValidParameters::isValidParameter(string parameter, vector cParams, return true; } catch(exception& e) { - errorOut(e, "ValidParameters", "isValidParameters"); + m->errorOut(e, "ValidParameters", "isValidParameters"); exit(1); } } @@ -218,7 +219,7 @@ string ValidParameters::validFile(map container, string paramete } catch(exception& e) { - errorOut(e, "ValidParameters", "validFile"); + m->errorOut(e, "ValidParameters", "validFile"); exit(1); } } @@ -263,7 +264,7 @@ void ValidParameters::initParameterRanges() { parameterRanges["size"] = addParameters(sizeArray, rangeSize); } catch(exception& e) { - errorOut(e, "ValidParameters", "initParameterRanges"); + m->errorOut(e, "ValidParameters", "initParameterRanges"); exit(1); } } @@ -277,7 +278,7 @@ vector ValidParameters::addParameters(string parameters[], int size) { return pVector; } catch(exception& e) { - errorOut(e, "ValidParameters", "addParameters"); + m->errorOut(e, "ValidParameters", "addParameters"); exit(1); } } diff --git a/validparameter.h b/validparameter.h index 5007948..9aeafa2 100644 --- a/validparameter.h +++ b/validparameter.h @@ -11,6 +11,7 @@ */ #include "mothur.h" +#include "mothurout.h" //This class contains a list of all valid parameters in Mothur. //It has a function which will tell you if your parameter is valid. @@ -31,6 +32,7 @@ class ValidParameters { private: map::iterator it; map > parameterRanges; + MothurOut* m; }; diff --git a/venn.cpp b/venn.cpp index 986c68d..43129f5 100644 --- a/venn.cpp +++ b/venn.cpp @@ -19,19 +19,23 @@ Venn::Venn(string o) : outputDir(o) { try { globaldata = GlobalData::getInstance(); + m = MothurOut::getInstance(); } catch(exception& e) { - errorOut(e, "Venn", "Venn"); + m->errorOut(e, "Venn", "Venn"); exit(1); } } //********************************************************************************************************************** -void Venn::getPic(SAbundVector* sabund, vector vCalcs) { +vector Venn::getPic(SAbundVector* sabund, vector vCalcs) { try { - + + vector outputNames; + for(int i=0;iinputFileName) + ".venn." + sabund->getLabel() + vCalcs[i]->getName() + ".svg"; + outputNames.push_back(filenamesvg); openOutputFile(filenamesvg, outsvg); vector data = vCalcs[i]->getValues(sabund); @@ -53,17 +57,20 @@ void Venn::getPic(SAbundVector* sabund, vector vCalcs) { outsvg << "\n\n"; outsvg.close(); } + + return outputNames; } catch(exception& e) { - errorOut(e, "Venn", "getPic"); + m->errorOut(e, "Venn", "getPic"); exit(1); } } //********************************************************************************************************************** -void Venn::getPic(vector lookup, vector vCalcs) { +vector Venn::getPic(vector lookup, vector vCalcs) { try { vector subset; + vector outputNames; /******************* 1 Group **************************/ if (lookup.size() == 1) { @@ -74,6 +81,7 @@ void Venn::getPic(vector lookup, vector vCalcs //make a file for each calculator for(int i=0;iinputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg"; + outputNames.push_back(filenamesvg); openOutputFile(filenamesvg, outsvg); //in essence you want to run it like a single @@ -123,6 +131,7 @@ void Venn::getPic(vector lookup, vector vCalcs //make a file for each calculator for(int i=0;iinputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg"; + outputNames.push_back(filenamesvg); openOutputFile(filenamesvg, outsvg); //get estimates for sharedAB @@ -190,8 +199,8 @@ void Venn::getPic(vector lookup, vector vCalcs //make a file for each calculator for(int i=0;iinputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg"; + outputNames.push_back(filenamesvg); openOutputFile(filenamesvg, outsvg); if (vCalcs[i]->getName() == "sharedace") { @@ -444,9 +453,10 @@ void Venn::getPic(vector lookup, vector vCalcs //make a file for each calculator for(int i=0;igetName() != "sharedsobs") && (vCalcs[i]->getName() != "sharedchao")) { mothurOut(vCalcs[i]->getName() + " is not a valid calculator with four groups. It will be disregarded. "); mothurOutEndLine(); } + 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 + getSimpleName(globaldata->inputFileName) + lookup[0]->getLabel() + ".venn." + vCalcs[i]->getName() + ".svg"; + outputNames.push_back(filenamesvg); openOutputFile(filenamesvg, outsvg); @@ -625,9 +635,11 @@ void Venn::getPic(vector lookup, vector vCalcs } } + return outputNames; + } catch(exception& e) { - errorOut(e, "Venn", "getPic"); + m->errorOut(e, "Venn", "getPic"); exit(1); } } diff --git a/venn.h b/venn.h index cf6a5ee..d3a3f05 100644 --- a/venn.h +++ b/venn.h @@ -23,14 +23,15 @@ public: Venn(string); ~Venn(){}; - void getPic(SAbundVector*, vector); - void getPic(vector, vector); + vector getPic(SAbundVector*, vector); + vector getPic(vector, vector); private: GlobalData* globaldata; Calculator* singleCalc; string groupComb, outputDir; ofstream outsvg; + MothurOut* m; }; /***********************************************************************/ diff --git a/venncommand.cpp b/venncommand.cpp index 437f044..57228ad 100644 --- a/venncommand.cpp +++ b/venncommand.cpp @@ -19,13 +19,13 @@ //********************************************************************************************************************** -VennCommand::VennCommand(string option){ +VennCommand::VennCommand(string option) { try { globaldata = GlobalData::getInstance(); abort = false; allLines = 1; labels.clear(); - + //allow user to run help if(option == "help") { help(); abort = true; } @@ -46,7 +46,7 @@ VennCommand::VennCommand(string option){ //make sure the user has already run the read.otu command if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) { - mothurOut("You must read a list, or a list and a group, or a shared before you can use the venn command."); mothurOutEndLine(); abort = true; + 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 output directory command factory will send this info to us in the output parameter @@ -136,7 +136,7 @@ VennCommand::VennCommand(string option){ } catch(exception& e) { - errorOut(e, "VennCommand", "VennCommand"); + m->errorOut(e, "VennCommand", "VennCommand"); exit(1); } } @@ -145,21 +145,21 @@ VennCommand::VennCommand(string option){ void VennCommand::help(){ try { - mothurOut("The venn command can only be executed after a successful read.otu command.\n"); - mothurOut("The venn command parameters are groups, calc, abund and label. No parameters are required.\n"); - 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"); - 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"); - mothurOut("The venn command should be in the following format: venn(groups=yourGroups, calc=yourCalcs, label=yourLabels, abund=yourAbund).\n"); - mothurOut("Example venn(groups=A-B-C, calc=sharedsobs-sharedchao, abund=20).\n"); - 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"); - 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"); - 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"); - mothurOut("The only estmiator available four 4 groups is sharedsobs.\n"); - mothurOut("The venn command outputs a .svg file for each calculator you specify at each distance you choose.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); + 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 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 only estmiator available four 4 groups is sharedsobs.\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) { - errorOut(e, "VennCommand", "help"); + m->errorOut(e, "VennCommand", "help"); exit(1); } } @@ -185,6 +185,7 @@ int VennCommand::execute(){ if (abort == true) { return 0; } string lastLabel; + vector outputNames; //if the users entered no valid calculators don't execute command if (vennCalculators.size() == 0) { return 0; } @@ -217,15 +218,17 @@ int VennCommand::execute(){ while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) { if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){ - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); if (lookup.size() > 4) { - mothurOut("Error: Too many groups chosen. You may use up to 4 groups with the venn command. I will use the first four groups in your groupfile."); mothurOutEndLine(); + m->mothurOut("Error: Too many groups chosen. You may use up to 4 groups with the venn command. I will use the first four groups in your groupfile."); m->mothurOutEndLine(); for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor } - venn->getPic(lookup, vennCalculators); + + vector outfilenames = venn->getPic(lookup, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } } if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { @@ -234,15 +237,16 @@ int VennCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); if (lookup.size() > 4) { - mothurOut("Error: Too many groups chosen. You may use up to 4 groups with the venn command. I will use the first four groups in your groupfile."); mothurOutEndLine(); + m->mothurOut("Error: Too many groups chosen. You may use up to 4 groups with the venn command. I will use the first four groups in your groupfile."); m->mothurOutEndLine(); for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor } - venn->getPic(lookup, vennCalculators); + vector outfilenames = venn->getPic(lookup, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } //restore real lastlabel to save below lookup[0]->setLabel(saveLabel); @@ -260,12 +264,12 @@ int VennCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -274,15 +278,17 @@ int VennCommand::execute(){ for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } } lookup = input->getSharedRAbundVectors(lastLabel); - mothurOut(lookup[0]->getLabel()); mothurOutEndLine(); + m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); if (lookup.size() > 4) { - mothurOut("Error: Too many groups chosen. You may use up to 4 groups with the venn command. I will use the first four groups in your groupfile."); mothurOutEndLine(); + m->mothurOut("Error: Too many groups chosen. You may use up to 4 groups with the venn command. I will use the first four groups in your groupfile."); m->mothurOutEndLine(); for (int i = lookup.size(); i > 4; i--) { lookup.pop_back(); } //no memmory leak because pop_back calls destructor } - venn->getPic(lookup, vennCalculators); + vector outfilenames = venn->getPic(lookup, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } @@ -296,8 +302,10 @@ int VennCommand::execute(){ if(allLines == 1 || labels.count(sabund->getLabel()) == 1){ - mothurOut(sabund->getLabel()); mothurOutEndLine(); - venn->getPic(sabund, vennCalculators); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); + vector outfilenames = venn->getPic(sabund, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); @@ -309,8 +317,10 @@ int VennCommand::execute(){ delete sabund; sabund = input->getSAbundVector(lastLabel); - mothurOut(sabund->getLabel()); mothurOutEndLine(); - venn->getPic(sabund, vennCalculators); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); + vector outfilenames = venn->getPic(sabund, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + processedLabels.insert(sabund->getLabel()); userLabels.erase(sabund->getLabel()); @@ -329,12 +339,12 @@ int VennCommand::execute(){ set::iterator it; bool needToRun = false; for (it = userLabels.begin(); it != userLabels.end(); it++) { - mothurOut("Your file does not include the label " + *it); + m->mothurOut("Your file does not include the label " + *it); if (processedLabels.count(lastLabel) != 1) { - mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine(); needToRun = true; }else { - mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine(); + m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine(); } } @@ -343,8 +353,10 @@ int VennCommand::execute(){ if (sabund != NULL) { delete sabund; } sabund = input->getSAbundVector(lastLabel); - mothurOut(sabund->getLabel()); mothurOutEndLine(); - venn->getPic(sabund, vennCalculators); + m->mothurOut(sabund->getLabel()); m->mothurOutEndLine(); + vector outfilenames = venn->getPic(sabund, vennCalculators); + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + delete sabund; } @@ -352,10 +364,17 @@ int VennCommand::execute(){ } for (int i = 0; i < vennCalculators.size(); i++) { delete vennCalculators[i]; } + + 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; } catch(exception& e) { - errorOut(e, "VennCommand", "execute"); + m->errorOut(e, "VennCommand", "execute"); exit(1); } } diff --git a/weighted.cpp b/weighted.cpp index 8a31229..9a0d5d2 100644 --- a/weighted.cpp +++ b/weighted.cpp @@ -127,7 +127,7 @@ EstOutput Weighted::getValues(Tree* t) { return data; } catch(exception& e) { - errorOut(e, "Weighted", "getValues"); + m->errorOut(e, "Weighted", "getValues"); exit(1); } } @@ -225,7 +225,7 @@ EstOutput Weighted::getValues(Tree* t, string groupA, string groupB) { return data; } catch(exception& e) { - errorOut(e, "Weighted", "getValues"); + m->errorOut(e, "Weighted", "getValues"); exit(1); } } diff --git a/whittaker.cpp b/whittaker.cpp index 48bc322..8688edd 100644 --- a/whittaker.cpp +++ b/whittaker.cpp @@ -27,7 +27,7 @@ EstOutput Whittaker::getValues(vector shared){ return data; } catch(exception& e) { - errorOut(e, "Whittaker", "getValues"); + m->errorOut(e, "Whittaker", "getValues"); exit(1); } } -- 2.39.2