]> git.donarmstrong.com Git - mothur.git/commitdiff
added debug flag to mothurOut. added debug parameter to set.dir. added debug code...
authorJohn Westcott <johnwestcott@laptop.(none)>
Wed, 9 May 2012 15:31:46 +0000 (11:31 -0400)
committerJohn Westcott <johnwestcott@laptop.(none)>
Wed, 9 May 2012 15:31:46 +0000 (11:31 -0400)
14 files changed:
Mothur.xcodeproj/project.pbxproj
aligncommand.h
catchallcommand.cpp
chimerabellerophoncommand.cpp
commandfactory.cpp
getcoremicrobiomcommand.cpp [new file with mode: 0644]
getcoremicrobiomcommand.h [new file with mode: 0644]
getseqscommand.cpp
getseqscommand.h
mothurout.h
newcommandtemplate.cpp [new file with mode: 0644]
newcommandtemplate.h [new file with mode: 0644]
setdircommand.cpp
setdircommand.h

index 6e156df32f8d604dacdc37e9d350b6a6645f8a14..4553219568d78e02ea441d05a475b063419a95b8 100644 (file)
@@ -7,6 +7,8 @@
        objects = {
 
 /* Begin PBXBuildFile section */
+               219C1DE01552C4BD004209F9 /* newcommandtemplate.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 219C1DDF1552C4BD004209F9 /* newcommandtemplate.cpp */; };
+               219C1DE41559BCCF004209F9 /* getcoremicrobiomcommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 219C1DE31559BCCD004209F9 /* getcoremicrobiomcommand.cpp */; };
                7E6BE10A12F710D8007ADDBE /* refchimeratest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7E6BE10912F710D8007ADDBE /* refchimeratest.cpp */; };
                8DD76FB00486AB0100D96B5E /* mothur.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6A0FF2C0290799A04C91782 /* mothur.1 */; };
                A70332B712D3A13400761E33 /* makefile in Sources */ = {isa = PBXBuildFile; fileRef = A70332B512D3A13400761E33 /* makefile */; };
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
+               219C1DDF1552C4BD004209F9 /* newcommandtemplate.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = newcommandtemplate.cpp; sourceTree = "<group>"; };
+               219C1DE11552C508004209F9 /* newcommandtemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = newcommandtemplate.h; sourceTree = "<group>"; };
+               219C1DE31559BCCD004209F9 /* getcoremicrobiomcommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = getcoremicrobiomcommand.cpp; sourceTree = "<group>"; };
+               219C1DE51559BCF2004209F9 /* getcoremicrobiomcommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = getcoremicrobiomcommand.h; sourceTree = "<group>"; };
                7E6BE10812F710D8007ADDBE /* refchimeratest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = refchimeratest.h; sourceTree = "<group>"; };
                7E6BE10912F710D8007ADDBE /* refchimeratest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = refchimeratest.cpp; sourceTree = "<group>"; };
                7E78911B135F3E8600E725D2 /* eachgapdistignorens.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = eachgapdistignorens.h; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                A7E9B6AE12D37EC400DA6239 /* command.hpp */,
+                               219C1DE11552C508004209F9 /* newcommandtemplate.h */,
+                               219C1DDF1552C4BD004209F9 /* newcommandtemplate.cpp */,
                                A7E9B65212D37EC300DA6239 /* aligncommand.h */,
                                A7E9B65112D37EC300DA6239 /* aligncommand.cpp */,
                                A7A61F2B130062E000E05B6B /* amovacommand.h */,
                                A7E9B6E312D37EC400DA6239 /* filterseqscommand.cpp */,
                                A778FE69134CA6CA00C0BA33 /* getcommandinfocommand.h */,
                                A778FE6A134CA6CA00C0BA33 /* getcommandinfocommand.cpp */,
+                               219C1DE51559BCF2004209F9 /* getcoremicrobiomcommand.h */,
+                               219C1DE31559BCCD004209F9 /* getcoremicrobiomcommand.cpp */,
                                A7FE7C3E1330EA1000F7B327 /* getcurrentcommand.h */,
                                A7FE7C3F1330EA1000F7B327 /* getcurrentcommand.cpp */,
                                A7E9B6F312D37EC400DA6239 /* getgroupcommand.h */,
                                A7876A26152A017C00A0AE86 /* subsample.cpp in Sources */,
                                A7D755DA1535F679009BF21A /* treereader.cpp in Sources */,
                                A724D2B7153C8628000A826F /* makebiomcommand.cpp in Sources */,
+                               219C1DE01552C4BD004209F9 /* newcommandtemplate.cpp in Sources */,
+                               219C1DE41559BCCF004209F9 /* getcoremicrobiomcommand.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                        isa = XCBuildConfiguration;
                        buildSettings = {
                                ALWAYS_SEARCH_USER_PATHS = NO;
+                               CONFIGURATION_TEMP_DIR = /Users/johnwestcott/desktop/debug;
                                COPY_PHASE_STRIP = NO;
+                               DEPLOYMENT_LOCATION = YES;
                                GCC_DYNAMIC_NO_PIC = NO;
                                GCC_MODEL_TUNING = G5;
                                GCC_OPTIMIZATION_LEVEL = 0;
-                               INSTALL_PATH = /usr/local/bin;
+                               INSTALL_PATH = /Users/johnwestcott/desktop/debug;
+                               OBJROOT = /Users/johnwestcott/desktop/debug;
                                PRODUCT_NAME = Mothur;
                                SDKROOT = macosx10.6;
+                               SYMROOT = /Users/johnwestcott/desktop/debug;
                        };
                        name = Debug;
                };
                        isa = XCBuildConfiguration;
                        buildSettings = {
                                ALWAYS_SEARCH_USER_PATHS = NO;
+                               CONFIGURATION_TEMP_DIR = /Users/johnwestcott/desktop/debug;
                                DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
                                DEPLOYMENT_LOCATION = YES;
                                GCC_MODEL_TUNING = G5;
                                GCC_WARN_UNUSED_VALUE = YES;
-                               INSTALL_PATH = ./;
+                               INSTALL_PATH = /Users/johnwestcott/desktop/debug;
+                               OBJROOT = /Users/johnwestcott/desktop/debug;
                                PRODUCT_NAME = Mothur;
+                               SYMROOT = /Users/johnwestcott/desktop/debug;
                        };
                        name = Release;
                };
index 5da7a1f7e112b39aebe42c6d5428f010212d383d..86bb4d7a4377904f0ca3c2712204d5932fdb46f6 100644 (file)
@@ -10,7 +10,6 @@
  *
  */
 
-#include "mothur.h"
 #include "command.hpp"
 #include "database.hpp"
 #include "alignment.hpp"
index bf866cbedca07b7ee8b732eec683c64520ee2017..cc99e6d992cb182f7495e412b674298a643981f6 100644 (file)
@@ -174,19 +174,32 @@ int CatchAllCommand::execute() {
                path = path.substr(0, (path.find_last_of("othur")-5));
                path = m->getFullPathName(path);
                
+        if (m->debug) { m->mothurOut("[DEBUG]: mothur's path = " + path + "\n"); }
+        
                savedOutputDir = outputDir;
-               string catchAllCommandExe = ""; 
+               string catchAllCommandExe = "";
+        string catchAllTest = "";
                #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                        catchAllCommandExe += "mono " + path + "CatchAllcmdL.exe ";
                        if (outputDir == "") { outputDir = "./"; } //force full pathname to be created for catchall, this is necessary because if catchall is in the path it will look for input file whereever the exe is and not the cwd.
+            catchAllTest = path + "CatchAllcmdL.exe";
                #else
                        catchAllCommandExe += "\"" + path + "CatchAllcmdW.exe\"" + " ";
                        if (outputDir == "") { outputDir = ".\\"; } //force full pathname to be created for catchall, this is necessary because if catchall is in the path it will look for input file whereever the exe is and not the cwd.
+            catchAllTest = path + "CatchAllcmdW.exe";
                #endif
                
+        //test to make sure formatdb exists
+               ifstream in;
+               catchAllTest = m->getFullPathName(catchAllTest);
+               int ableToOpen = m->openInputFile(catchAllTest, in, "no error"); in.close();
+               if(ableToOpen == 1) {   m->mothurOut("[ERROR]: " + catchAllTest + " file does not exist. mothur requires the catchall executable to run the catchall command."); m->mothurOutEndLine(); m->control_pressed = true; return 0;  }
+        
                //prepare full output directory
                outputDir = m->getFullPathName(outputDir);
                
+        if (m->debug) { m->mothurOut("[DEBUG]: catchall location = " + catchAllCommandExe + ".\n [DEBUG]: outputDir = " + outputDir + ".\n"); }
+        
                vector<string> inputFileNames;
                if (sharedfile != "") { inputFileNames = parseSharedFile(sharedfile);   }
                else {  inputFileNames.push_back(sabundfile);  }                
@@ -196,8 +209,8 @@ int CatchAllCommand::execute() {
                                m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
                        }
                        
-                       InputData* input = new InputData(inputFileNames[p], "sabund");
-                       SAbundVector* sabund = input->getSAbundVector();
+                       InputData input(inputFileNames[p], "sabund");
+                       SAbundVector* sabund = input.getSAbundVector();
                        string lastLabel = sabund->getLabel();
                                                        
                        set<string> processedLabels;
@@ -206,10 +219,14 @@ int CatchAllCommand::execute() {
                        string summaryfilename = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p])) + "catchall.summary";
                        summaryfilename = m->getFullPathName(summaryfilename);
                        
+            if (m->debug) { m->mothurOut("[DEBUG]: Input File = " + inputFileNames[p] + ".\n [DEBUG]: inputdata address = " + toString(&input) + ".\n [DEBUG]: sabund address = " + toString(&sabund) + ".\n"); } 
+            
                        ofstream out;
                        m->openOutputFile(summaryfilename, out);        
                        
                        out << "label\tmodel\testimate\tlci\tuci" << endl;
+            
+            if (m->debug) { string open = "no"; if (out.is_open()) { open = "yes"; } m->mothurOut("[DEBUG]: output stream is open = " + open + ".\n"); }
                        
                        //for each label the user selected
                        while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
@@ -232,11 +249,16 @@ int CatchAllCommand::execute() {
                                                        //wrap entire string in ""
                                                        catchAllCommand = "\"" + catchAllCommand + "\"";
                                                #endif
-                                       
+                        
+                        if (m->debug) {  m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
+                    
                                                //run catchall
                                                system(catchAllCommand.c_str());
-                                       
-                                               m->mothurRemove(filename);
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
+                    
+                        if (!m->debug) { m->mothurRemove(filename); }
+
                                        
                                                filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
                                                if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
@@ -245,10 +267,14 @@ int CatchAllCommand::execute() {
                                                outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv");
                                                outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv");
                                                outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");
-                                       
+                        
+                        if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
+                    
                                                createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
                                                                                        
-                                               if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);   }  delete input;  delete sabund;  return 0; }
+                                               if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);   }  delete sabund;  return 0; }
 
                                                processedLabels.insert(sabund->getLabel());
                                                userLabels.erase(sabund->getLabel());
@@ -258,7 +284,7 @@ int CatchAllCommand::execute() {
                                                string saveLabel = sabund->getLabel();
                                                
                                                delete sabund;          
-                                               sabund = (input->getSAbundVector(lastLabel));
+                                               sabund = (input.getSAbundVector(lastLabel));
                                                
                                                m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
                                                
@@ -276,11 +302,16 @@ int CatchAllCommand::execute() {
                                                        catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
                                                        catchAllCommand = "\"" + catchAllCommand + "\"";
                                                #endif
-
+                        
+                        if (m->debug) {  m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
+                    
                                                //run catchall
                                                system(catchAllCommand.c_str());
-                                       
-                                               m->mothurRemove(filename);
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
+                    
+                        if (!m->debug) { m->mothurRemove(filename); }
+
                                        
                                                filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
                                                if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
@@ -289,10 +320,15 @@ int CatchAllCommand::execute() {
                                                outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv");
                                                outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv");
                                                outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");
-                                       
+                        
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
+                    
                                                createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
+                    
+                        if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
                                        
-                                               if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);   }  delete input;  delete sabund;  return 0; }
+                                               if (m->control_pressed) { out.close(); for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);   }   delete sabund;  return 0; }
 
                                                processedLabels.insert(sabund->getLabel());
                                                userLabels.erase(sabund->getLabel());
@@ -305,7 +341,7 @@ int CatchAllCommand::execute() {
                                lastLabel = sabund->getLabel(); 
                                
                                delete sabund;          
-                               sabund = (input->getSAbundVector());
+                               sabund = (input.getSAbundVector());
                        }
                        
                        //output error messages about any remaining user labels
@@ -324,7 +360,7 @@ int CatchAllCommand::execute() {
                        //run last label if you need to
                        if (needToRun == true)  {
                                if (sabund != NULL) {   delete sabund;  }
-                               sabund = (input->getSAbundVector(lastLabel));
+                               sabund = (input.getSAbundVector(lastLabel));
                                
                                m->mothurOut(sabund->getLabel());  m->mothurOutEndLine();
                                
@@ -341,11 +377,15 @@ int CatchAllCommand::execute() {
                                        catchAllCommand += catchAllCommandExe + "\"" + filename + "\" \""  + outputPath + "\" 1";
                                        catchAllCommand = "\"" + catchAllCommand + "\"";
                                #endif
+                
+                if (m->debug) {  m->mothurOut("[DEBUG]: catchall command = " + catchAllCommand + ". About to call system.\n"); }
                                
                                //run catchall
                                system(catchAllCommand.c_str());
+                
+                if (m->debug) { m->mothurOut("[DEBUG]: back from system call. Keeping file: " + filename + ".\n"); }
                                
-                               m->mothurRemove(filename);
+                               if (!m->debug) { m->mothurRemove(filename); }
                                
                                filename = m->getRootName(filename); filename = filename.substr(0, filename.length()-1); //rip off extra .
                                if (savedOutputDir == "") { filename = m->getSimpleName(filename); }
@@ -354,14 +394,16 @@ int CatchAllCommand::execute() {
                                outputNames.push_back(filename + "_BestModelsAnalysis.csv"); outputTypes["csv"].push_back(filename + "_BestModelsAnalysis.csv");
                                outputNames.push_back(filename + "_BestModelsFits.csv"); outputTypes["csv"].push_back(filename + "_BestModelsFits.csv");
                                outputNames.push_back(filename + "_BubblePlot.csv"); outputTypes["csv"].push_back(filename + "_BubblePlot.csv");        
-                               
+                               if (m->debug) { m->mothurOut("[DEBUG]: About to create summary file for: " + filename + ".\n[DEBUG]: sabund label = " + sabund->getLabel() + ".\n"); }
+                
                                createSummaryFile(filename + "_BestModelsAnalysis.csv", sabund->getLabel(), out);
+                
+                if (m->debug) { m->mothurOut("[DEBUG]: Done creating summary file.\n"); }
                                
                                delete sabund;
                        }
                        
                        out.close();
-                       delete input; 
                        
                        if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {m->mothurRemove(outputNames[i]);        } return 0; }
                                
@@ -402,14 +444,19 @@ string CatchAllCommand::process(SAbundVector* sabund, string file1) {
                ofstream out;
                m->openOutputFile(filename, out);
                
+        if (m->debug) { m->mothurOut("[DEBUG]: Creating " + filename + " file for catchall, shown below.\n\n"); }
+        
                for (int i = 1; i <= sabund->getMaxRank(); i++) {
                        int temp = sabund->get(i);
                        
                        if (temp != 0) {
                                out << i << "," << temp << endl;
+                if (m->debug) { m->mothurOut(toString(i) + "," + toString(temp) + "\n"); }
                        }
                }
                out.close();
+        
+        if (m->debug) { m->mothurOut("[DEBUG]: Done creating " + filename + " file for catchall, shown above.\n\n"); }
                
                return filename;
        
@@ -572,8 +619,8 @@ vector<string> CatchAllCommand::parseSharedFile(string filename) {
                vector<string> filenames;
                
                //read first line
-               InputData* input = new InputData(filename, "sharedfile");
-               vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
+               InputData input(filename, "sharedfile");
+               vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
                
                string sharedFileRoot = outputDir + m->getRootName(m->getSimpleName(filename));
                
@@ -595,11 +642,9 @@ vector<string> CatchAllCommand::parseSharedFile(string filename) {
                        }
                        
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
-                       lookup = input->getSharedRAbundVectors();
+                       lookup = input.getSharedRAbundVectors();
                }
                
-               delete input;
-               
                return filenames;
        }
        catch(exception& e) {
index 1fc87db562bf2994465ee3b9e043f4a961c4e844..c519f91ede4bafbf1802dc813d2679be4a792c17 100644 (file)
@@ -15,7 +15,7 @@ vector<string> ChimeraBellerophonCommand::setParameters(){
        try {
                CommandParameter pfasta("fasta", "InputTypes", "", "", "none","none","none",false,true); parameters.push_back(pfasta);
                CommandParameter pfilter("filter", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pfilter);
-               CommandParameter pcorrection("filter", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pcorrection);
+               CommandParameter pcorrection("correction", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pcorrection);
                CommandParameter pwindow("window", "Number", "", "0", "", "", "",false,false); parameters.push_back(pwindow);
                CommandParameter pincrement("increment", "Number", "", "25", "", "", "",false,false); parameters.push_back(pincrement);
                CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
index 527f7bfe4fddf6ecf1ddce45ab7c93a161f52ad1..c334b095abbc65a5bd9e40cc6f2160f6c37d3e2e 100644 (file)
 #include "pcrseqscommand.h"
 #include "createdatabasecommand.h"
 #include "makebiomcommand.h"
+#include "getcoremicrobiomcommand.h"
 
 /*******************************************************/
 
@@ -283,6 +284,7 @@ CommandFactory::CommandFactory(){
     commands["pcr.seqs"]            = "pcr.seqs";
     commands["create.database"]     = "create.database";
     commands["make.biom"]           = "make.biom";
+    commands["get.coremicrobiom"]   = "get.coremircrobiom";
        commands["quit"]                                = "MPIEnabled"; 
 
 }
@@ -493,6 +495,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString){
         else if(commandName == "pcr.seqs")              {      command = new PcrSeqsCommand(optionString);                 }
         else if(commandName == "create.database")       {      command = new CreateDatabaseCommand(optionString);          }
         else if(commandName == "make.biom")             {      command = new MakeBiomCommand(optionString);                }
+        else if(commandName == "get.coremicrobiom")     {      command = new GetCoreMicroBiomCommand(optionString);                }
                else                                                                                    {       command = new NoCommand(optionString);                                          }
 
                return command;
@@ -644,6 +647,7 @@ Command* CommandFactory::getCommand(string commandName, string optionString, str
         else if(commandName == "pcr.seqs")              {      pipecommand = new PcrSeqsCommand(optionString);                 }
         else if(commandName == "create.database")       {      pipecommand = new CreateDatabaseCommand(optionString);          }
         else if(commandName == "make.biom")             {      pipecommand = new MakeBiomCommand(optionString);                }
+        else if(commandName == "get.coremicrobiom")     {      pipecommand = new GetCoreMicroBiomCommand(optionString);                }
                else                                                                                    {       pipecommand = new NoCommand(optionString);                                              }
 
                return pipecommand;
@@ -781,6 +785,7 @@ Command* CommandFactory::getCommand(string commandName){
         else if(commandName == "pcr.seqs")              {      shellcommand = new PcrSeqsCommand();                }
         else if(commandName == "create.database")       {      shellcommand = new CreateDatabaseCommand();         }
         else if(commandName == "make.biom")             {      shellcommand = new MakeBiomCommand();               }
+        else if(commandName == "get.coremicrobiom")     {      shellcommand = new GetCoreMicroBiomCommand();       }
                else                                                                                    {       shellcommand = new NoCommand();                                         }
 
                return shellcommand;
diff --git a/getcoremicrobiomcommand.cpp b/getcoremicrobiomcommand.cpp
new file mode 100644 (file)
index 0000000..253e836
--- /dev/null
@@ -0,0 +1,329 @@
+//
+//  getcoremicrobiomcommand.cpp
+//  Mothur
+//
+//  Created by John Westcott on 5/8/12.
+//  Copyright (c) 2012 Schloss Lab. All rights reserved.
+//
+
+#include "getcoremicrobiomcommand.h"
+
+
+//**********************************************************************************************************************
+vector<string> GetCoreMicroBiomCommand::setParameters(){       
+       try {
+        CommandParameter pshared("shared", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(pshared);
+               CommandParameter prelabund("relabund", "InputTypes", "", "", "SharedRel", "SharedRel", "none",false,false); parameters.push_back(prelabund);
+        CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
+               CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
+               
+        //every command must have inputdir and outputdir.  This allows mothur users to redirect input and output files.
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               
+               vector<string> myArray;
+               for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetCoreMicroBiomCommand", "setParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+string GetCoreMicroBiomCommand::getHelpString(){       
+       try {
+               string helpString = "";
+               helpString += "The new command allows you to ....\n";
+               helpString += "The new command parameters are: ....\n";
+               helpString += "The whatever parameter is used to ....\n";
+               helpString += "The new command should be in the following format: \n";
+               helpString += "new(...)\n";
+               return helpString;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetCoreMicroBiomCommand", "getHelpString");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+GetCoreMicroBiomCommand::GetCoreMicroBiomCommand(){    
+       try {
+               abort = true; calledHelp = true;
+               setParameters();
+        vector<string> tempOutNames;
+               outputTypes["coremicrobiom"] = tempOutNames; 
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetCoreMicroBiomCommand", "GetCoreMicroBiomCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+GetCoreMicroBiomCommand::GetCoreMicroBiomCommand(string option)  {
+       try {
+               abort = false; calledHelp = false;   allLines = 1;
+               
+               //allow user to run help
+               if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
+               
+               else {
+                       //valid paramters for this command
+                       vector<string> myArray = setParameters();
+                       
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       map<string,string>::iterator it;
+                       //check to make sure all parameters are valid for command
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+                       
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                
+                               string path;
+                               it = parameters.find("relabund");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["relabund"] = inputDir + it->second;         }
+                               }
+                
+                it = parameters.find("shared");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["shared"] = inputDir + it->second;           }
+                               }
+            }
+           
+        
+                       //check for parameters
+            sharedfile = validParameter.validFile(parameters, "shared", true);
+                       if (sharedfile == "not open") { abort = true; }
+                       else if (sharedfile == "not found") { sharedfile = ""; }
+                       else { inputFileName = sharedfile; format = "sharedfile"; m->setSharedFile(sharedfile); }
+                       
+                       relabundfile = validParameter.validFile(parameters, "relabund", true);
+                       if (relabundfile == "not open") { abort = true; }
+                       else if (relabundfile == "not found") { relabundfile = ""; }
+                       else { inputFileName = relabundfile; format = "relabund"; m->setRelAbundFile(relabundfile); }
+            
+            if ((relabundfile == "") && (sharedfile == "")) { 
+                               //is there are current file available for either of these?
+                               //give priority to shared, then relabund
+                               sharedfile = m->getSharedFile(); 
+                               if (sharedfile != "") {  inputFileName = sharedfile; format="sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
+                               else { 
+                                       relabundfile = m->getRelAbundFile(); 
+                                       if (relabundfile != "") {  inputFileName = relabundfile; format="relabund"; m->mothurOut("Using " + relabundfile + " as input file for the relabund parameter."); m->mothurOutEndLine(); }
+                                       else { 
+                                               m->mothurOut("No valid current files. You must provide a shared or relabund."); m->mothurOutEndLine(); 
+                                               abort = true;
+                                       }
+                               }
+                       }
+            
+            //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = m->hasPath(inputFileName); //if user entered a file with a path then preserve it    
+                       }
+            
+            string groups = validParameter.validFile(parameters, "groups", false);                     
+                       if (groups == "not found") { groups = ""; }
+                       else { m->splitAtDash(groups, Groups); }
+                       m->setGroups(Groups);
+            
+            string label = validParameter.validFile(parameters, "label", false);                       
+                       if (label == "not found") { label = ""; }
+                       else { 
+                               if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
+                               else { allLines = 1;  }
+                       }
+               }
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GetCoreMicroBiomCommand", "GetCoreMicroBiomCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+int GetCoreMicroBiomCommand::execute(){
+       try {
+               
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+        
+        InputData input(inputFileName, format);
+        vector<SharedRAbundFloatVector*> lookup = input.getSharedRAbundFloatVectors();
+        string lastLabel = lookup[0]->getLabel();
+        
+        //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+        set<string> processedLabels;
+        set<string> userLabels = labels;
+        
+        //as long as you are not at the end of the file or done wih the lines you want
+        while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+            
+            if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
+            
+            if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                     
+                
+                m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+                
+                createTable(lookup);
+                
+                processedLabels.insert(lookup[0]->getLabel());
+                userLabels.erase(lookup[0]->getLabel());
+            }
+            
+            if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+                string saveLabel = lookup[0]->getLabel();
+                
+                for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  
+                lookup = input.getSharedRAbundFloatVectors(lastLabel);
+                m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+                
+                createTable(lookup);
+                
+                processedLabels.insert(lookup[0]->getLabel());
+                userLabels.erase(lookup[0]->getLabel());
+                
+                //restore real lastlabel to save below
+                lookup[0]->setLabel(saveLabel);
+            }
+            
+            lastLabel = lookup[0]->getLabel();
+            //prevent memory leak
+            for (int i = 0; i < lookup.size(); i++) {  delete lookup[i]; lookup[i] = NULL; }
+            
+            if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); }  return 0; }
+            
+            //get next line to process
+            lookup = input.getSharedRAbundFloatVectors();                              
+        }
+        
+        if (m->control_pressed) {  for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); }  return 0; }
+        
+        //output error messages about any remaining user labels
+        set<string>::iterator it;
+        bool needToRun = false;
+        for (it = userLabels.begin(); it != userLabels.end(); it++) {  
+            m->mothurOut("Your file does not include the label " + *it); 
+            if (processedLabels.count(lastLabel) != 1) {
+                m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
+                needToRun = true;
+            }else {
+                m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
+            }
+        }
+        
+        //run last label if you need to
+        if (needToRun == true)  {
+            for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }  
+            lookup = input.getSharedRAbundFloatVectors(lastLabel);
+            
+            m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+            
+            createTable(lookup);
+            
+            for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
+        }
+        
+        if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); }  return 0; }
+        
+        //output files created by command
+               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) {
+               m->errorOut(e, "GetCoreMicroBiomCommand", "execute");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+int GetCoreMicroBiomCommand::createTable(vector<SharedRAbundFloatVector*>& lookup){
+       try {
+        
+        string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputFileName)) + lookup[0]->getLabel() + ".core.microbiom";
+        outputNames.push_back(outputFileName);  outputTypes["coremicrobiom"].push_back(outputFileName);
+               ofstream out;
+               m->openOutputFile(outputFileName, out);
+        
+        int numSamples = lookup.size();
+        int numOtus = lookup[0]->getNumBins();
+        
+        //table is 100 by numsamples
+        //question we are answering is: what fraction of OTUs in a study have a relative abundance at or above %X
+        //in at least %Y samples. x goes from 0 to 100, y from 1 to numSamples
+        vector< vector<double> > table; table.resize(101);
+        for (int i = 0; i < table.size(); i++) { table[i].resize(numSamples, 0.0); }
+        
+        for (int i = 0; i < numOtus; i++) {
+            
+            if (m->control_pressed) { break; }
+            
+            //count number of samples in this otu with a relabund >= spot in count
+            vector<int> counts; counts.resize(101, 0);
+            
+            for (int j = 0; j < lookup.size(); j++) {
+                double relabund = lookup[j]->getAbundance(i);
+                int wholeRelabund = (int) (floor(relabund*100));
+                cout << i << '\t' << j << '\t' << relabund << '\t' << wholeRelabund << endl;
+                for (int k = 0; k < wholeRelabund; k++) { counts[k]++; }
+            }
+            
+            //add this otus info to table
+            for (int j = 0; j < table.size(); j++) {
+                for (int k = 0; k < counts[j]; k++) { table[j][k]++; }
+            }
+            
+        }
+               
+        //format output
+               out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint);
+        out << "NumSamples\t";
+        
+        //convert table counts to percents
+        for (int i = 0; i < table.size(); i++) {
+            out << "Relabund-" << i << '\t';
+            if (m->control_pressed) { break; }
+            for (int j = 0; j < table[i].size(); j++) {  table[i][j] /= (double) numOtus; }
+        }
+        out << endl;
+        
+        for (int i = 0; i < numSamples; i++) {
+            if (m->control_pressed) { break; }
+            out << i+1 << '\t';
+            for (int j = 0; j < table.size(); j++) {  out << table[j][i] << '\t'; }
+            out << endl;
+        }
+
+        out.close();
+        
+        return 0;
+    }
+       catch(exception& e) {
+               m->errorOut(e, "GetCoreMicroBiomCommand", "createTable");
+               exit(1);
+       }
+}
+
+//**********************************************************************************************************************
+
+
diff --git a/getcoremicrobiomcommand.h b/getcoremicrobiomcommand.h
new file mode 100644 (file)
index 0000000..01e3302
--- /dev/null
@@ -0,0 +1,54 @@
+#ifndef Mothur_getcoremicrobiomcommand_h
+#define Mothur_getcoremicrobiomcommand_h
+
+
+//
+//  getcoremicrobiomcommand.h
+//  Mothur
+//
+//  Created by John Westcott on 5/8/12.
+//  Copyright (c) 2012 Schloss Lab. All rights reserved.
+//
+
+
+#include "command.hpp"
+#include "inputdata.h"
+
+/**************************************************************************************************/
+
+class GetCoreMicroBiomCommand : public Command {
+public:
+    GetCoreMicroBiomCommand(string);
+    GetCoreMicroBiomCommand();
+    ~GetCoreMicroBiomCommand(){}
+    
+    vector<string> setParameters();
+    string getCommandName()                    { return "get.coremicrobiom";                   }
+    string getCommandCategory()                { return "OTU-Based Approaches";                } 
+    //commmand category choices: Sequence Processing, OTU-Based Approaches, Hypothesis Testing, Phylotype Analysis, General, Clustering and Hidden
+    string getHelpString();    
+    string getCitation() { return "http://www.mothur.org/wiki/get.coremicrobio"; }
+    string getDescription()            { return "description"; }
+    
+    int execute(); 
+    void help() { m->mothurOut(getHelpString()); }     
+    
+private:
+    string relabundfile, sharedfile, inputFileName, format;
+    bool allLines;
+    vector<string> Groups;
+    set<string> labels;
+    bool abort;
+    string outputDir;
+    vector<string> outputNames;
+    
+    int createTable(vector<SharedRAbundFloatVector*>&);
+
+};
+
+/**************************************************************************************************/
+
+
+
+
+#endif
index 9bf188db3d25fa4ac16b82973a2802c3b1e6ad75..84fe0acab9abc0ec603df10896be1c0fe1e7f47c 100644 (file)
@@ -283,6 +283,8 @@ int GetSeqsCommand::execute(){
                if (taxfile != "")                      {               readTax();                      }
                if (qualfile != "")                     {               readQual();                     }
                if (accnosfile2 != "")          {               compareAccnos();        }
+        
+        if (m->debug) { runSanityCheck(); }
                
                if (m->control_pressed) { outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {   m->mothurRemove(outputNames[i]);  } return 0; }
                
@@ -352,6 +354,8 @@ int GetSeqsCommand::readFasta(){
                
                bool wroteSomething = false;
                int selectedCount = 0;
+        
+        if (m->debug) { set<string> temp; sanity["fasta"] = temp; }
                
                while(!in.eof()){
                
@@ -367,6 +371,8 @@ int GetSeqsCommand::readFasta(){
                                        
                                        currSeq.printSequence(out);
                                        selectedCount++;
+                    
+                    if (m->debug) { sanity["fasta"].insert(name); }
                                }
                        }
                        m->gobble(in);
@@ -405,6 +411,7 @@ int GetSeqsCommand::readQual(){
                bool wroteSomething = false;
                int selectedCount = 0;
                
+        if (m->debug) { set<string> temp; sanity["qual"] = temp; }
                
                while(!in.eof()){       
                        string saveName = "";
@@ -436,6 +443,7 @@ int GetSeqsCommand::readQual(){
                                                
                                out << name << endl << scores;
                                selectedCount++;
+                if (m->debug) { sanity["qual"].insert(name); }
                        }
                        
                        m->gobble(in);
@@ -472,6 +480,8 @@ int GetSeqsCommand::readList(){
                
                bool wroteSomething = false;
                int selectedCount = 0;
+        
+        if (m->debug) { set<string> temp; sanity["list"] = temp; }
                
                while(!in.eof()){
                        
@@ -498,11 +508,11 @@ int GetSeqsCommand::readList(){
                                        binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
                                        
                                        //if that name is in the .accnos file, add it
-                                       if (names.count(name) != 0) {  newNames += name + ",";  selectedCount++; }
+                                       if (names.count(name) != 0) {  newNames += name + ",";  selectedCount++; if (m->debug) { sanity["list"].insert(name); } }
                                }
                        
                                //get last name
-                               if (names.count(binnames) != 0) {  newNames += binnames + ",";  selectedCount++; }
+                               if (names.count(binnames) != 0) {  newNames += binnames + ",";  selectedCount++;  if (m->debug) { sanity["list"].insert(binnames); } }
 
                                //if there are names in this bin add to new list
                                if (newNames != "") { 
@@ -551,6 +561,9 @@ int GetSeqsCommand::readName(){
                
                bool wroteSomething = false;
                int selectedCount = 0;
+        
+        if (m->debug) { set<string> temp; sanity["name"] = temp; }
+        if (m->debug) { set<string> temp; sanity["dupname"] = temp; }
                
                while(!in.eof()){
                
@@ -569,14 +582,16 @@ int GetSeqsCommand::readName(){
                        for (int i = 0; i < parsedNames.size(); i++) {
                                if (names.count(parsedNames[i]) != 0) {
                                        validSecond.push_back(parsedNames[i]);
+                    if (m->debug) { sanity["dupname"].insert(parsedNames[i]); }
                                }
                        }
 
                        if ((dups) && (validSecond.size() != 0)) { //dups = true and we want to add someone, then add everyone
-                               for (int i = 0; i < parsedNames.size(); i++) {  names.insert(parsedNames[i]);  }
+                               for (int i = 0; i < parsedNames.size(); i++) {  names.insert(parsedNames[i]); if (m->debug) { sanity["dupname"].insert(parsedNames[i]); } }
                                out << firstCol << '\t' << hold << endl;
                                wroteSomething = true;
                                selectedCount += parsedNames.size();
+                if (m->debug) { sanity["name"].insert(firstCol); }
                        }else {
                                selectedCount += validSecond.size();
                                
@@ -590,6 +605,8 @@ int GetSeqsCommand::readName(){
                                        //you know you have at least one valid second since first column is valid
                                        for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
                                        out << validSecond[validSecond.size()-1] << endl;
+                    
+                    if (m->debug) { sanity["name"].insert(firstCol); }
                                        
                                
                                //make first name in set you come to first column and then add the remaining names to second column
@@ -604,6 +621,8 @@ int GetSeqsCommand::readName(){
                                                //you know you have at least one valid second since first column is valid
                                                for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
                                                out << validSecond[validSecond.size()-1] << endl;
+                        
+                        if (m->debug) { sanity["name"].insert(validSecond[0]); }
                                        }
                                }
                        }
@@ -642,6 +661,8 @@ int GetSeqsCommand::readGroup(){
                
                bool wroteSomething = false;
                int selectedCount = 0;
+        
+        if (m->debug) { set<string> temp; sanity["group"] = temp; }
                
                while(!in.eof()){
 
@@ -657,6 +678,8 @@ int GetSeqsCommand::readGroup(){
                                
                                out << name << '\t' << group << endl;
                                selectedCount++;
+                
+                if (m->debug) {  sanity["group"].insert(name); }
                        }
                                        
                        m->gobble(in);
@@ -693,6 +716,8 @@ int GetSeqsCommand::readTax(){
                
                bool wroteSomething = false;
                int selectedCount = 0;
+        
+        if (m->debug) { set<string> temp; sanity["tax"] = temp; }
                
                while(!in.eof()){
 
@@ -707,6 +732,8 @@ int GetSeqsCommand::readTax(){
                                
                                out << name << '\t' << tax << endl;
                                selectedCount++;
+                
+                if (m->debug) { sanity["tax"].insert(name); }
                        }
                                        
                        m->gobble(in);
@@ -826,6 +853,99 @@ int GetSeqsCommand::readAccnos(){
        }
 }
 //**********************************************************************************************************************
+//just looking at common mistakes. 
+int GetSeqsCommand::runSanityCheck(){
+       try {
+        string thisOutputDir = outputDir;
+        if (outputDir == "") {  thisOutputDir += m->hasPath(fastafile);  }
+        string filename = outputDir + "get.seqs.debug.report";
+        
+        ofstream out;
+               m->openOutputFile(filename, out); 
+
+       
+        //compare fasta, name, qual and taxonomy if given to make sure they contain the same seqs
+        if (fastafile != "") {
+            if (namefile != "") { //compare with fasta
+                if (sanity["fasta"] != sanity["name"]) { //create mismatch file
+                    createMisMatchFile(out, fastafile, namefile, sanity["fasta"], sanity["name"]);
+                }
+            }
+            if (qualfile != "") {
+                if (sanity["fasta"] != sanity["qual"]) { //create mismatch file
+                    createMisMatchFile(out, fastafile, qualfile, sanity["fasta"], sanity["qual"]);
+                }
+            }
+            if (taxfile != "") {
+                if (sanity["fasta"] != sanity["tax"]) { //create mismatch file
+                    createMisMatchFile(out, fastafile, taxfile, sanity["fasta"], sanity["tax"]);
+                }
+            }
+        }
+        
+        //compare dupnames, groups and list if given to make sure they match
+        if (namefile != "") {
+            if (groupfile != "") {
+                if (sanity["dupname"] != sanity["group"]) { //create mismatch file
+                    createMisMatchFile(out, namefile, groupfile, sanity["dupname"], sanity["group"]);
+                } 
+            }
+            if (listfile != "") {
+                if (sanity["dupname"] != sanity["list"]) { //create mismatch file
+                    createMisMatchFile(out, namefile, listfile, sanity["dupname"], sanity["list"]);
+                } 
+            }
+        }else{
+
+            if ((groupfile != "") && (fastafile != "")) {
+                if (sanity["fasta"] != sanity["group"]) { //create mismatch file
+                    createMisMatchFile(out, fastafile, groupfile, sanity["fasta"], sanity["group"]);
+                } 
+            }
+        }
+        
+        out.close();
+        
+        if (m->isBlank(filename)) { m->mothurRemove(filename); }
+        else { m->mothurOut("\n[DEBUG]: " + filename + " contains the file mismatches.\n");outputNames.push_back(filename); outputTypes["debug"].push_back(filename); }
+        
+        return 0;
+    }
+       catch(exception& e) {
+               m->errorOut(e, "GetSeqsCommand", "runSanityCheck");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+//just looking at common mistakes. 
+int GetSeqsCommand::createMisMatchFile(ofstream& out, string filename1, string filename2, set<string> set1, set<string> set2){
+       try {
+        out << "****************************************" << endl << endl;
+        out << "Names unique to " << filename1 << ":\n";
+        
+        //remove names in set1 that are also in set2
+        for (set<string>::iterator it = set1.begin(); it != set1.end();) {
+            string name = *it;
+            
+            if (set2.count(name) == 0)  { out << name << endl;  } //name unique to set1
+            else                        { set2.erase(name);     } //you are in both so erase 
+            set1.erase(it++);
+        }
+        
+        out << "\nNames unique to " << filename2 << ":\n";
+        //output results
+        for (set<string>::iterator it = set2.begin(); it != set2.end(); it++) {  out << *it << endl;  }
+        
+        out << "****************************************" << endl << endl;
+        
+        return 0;
+    }
+       catch(exception& e) {
+               m->errorOut(e, "GetSeqsCommand", "runSanityCheck");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 
 int GetSeqsCommand::compareAccnos(){
        try {
index 4561d28614c62686c42e29a9747b84d853537fd0..0f606ffb59ac884b46ac97d861aa3542786d1793 100644 (file)
@@ -36,6 +36,9 @@ class GetSeqsCommand : public Command {
                vector<string> outputNames;
                string accnosfile, accnosfile2, fastafile, namefile, groupfile, alignfile, listfile, taxfile, qualfile, outputDir;
                bool abort, dups;
+    
+        //for debug
+        map<string, set<string> > sanity; //maps file type to names chosen for file. something like "fasta" -> vector<string>. If running in debug mode this is filled and we check to make sure all the files have the same names. If they don't we output the differences for the user.
                
                int readFasta();
                int readName();
@@ -46,6 +49,9 @@ class GetSeqsCommand : public Command {
                int readTax();
                int readQual();
                int compareAccnos();
+        int runSanityCheck();
+        int createMisMatchFile(ofstream&, string, string, set<string>, set<string>);
+
                
 };
 
index 9ce698be4e1963e6af9abee67673ded3e1743fde..db1a4f1ca4e6c4207a652d05ac20b24157dfa46d 100644 (file)
@@ -140,7 +140,7 @@ class MothurOut {
                int getRandomIndex(int); //highest
 
                int control_pressed;
-               bool executing, runParse, jumble, gui, mothurCalling;
+               bool executing, runParse, jumble, gui, mothurCalling, debug;
                
                //current files - if you add a new type you must edit optionParser->getParameters, get.current command and mothurOut->printCurrentFiles/clearCurrentFiles.
                string getPhylipFile()          { return phylipfile;            }
@@ -225,6 +225,7 @@ class MothurOut {
                        printedHeaders = false;
                        commandInputsConvertError = false;
             mothurCalling = false;
+            debug = false;
                        sharedHeaderMode = "";
                }
                ~MothurOut();
diff --git a/newcommandtemplate.cpp b/newcommandtemplate.cpp
new file mode 100644 (file)
index 0000000..9299206
--- /dev/null
@@ -0,0 +1,427 @@
+//
+//  newcommandtemplate.cpp
+//  Mothur
+//
+//  Created by Sarah Westcott on 5/3/12.
+//  Copyright (c) 2012 Schloss Lab. All rights reserved.
+//
+
+
+#include "newcommandtemplate.h"
+
+//**********************************************************************************************************************
+vector<string> NewCommand::setParameters(){    
+       try {
+               //eaxamples of each type of parameter. more info on the types of parameters can be found in commandparameter.h
+               CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
+        
+        //files that have dependancies
+        CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip);
+               CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname);
+               CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn);              
+        //files that do not have dependancies - fasta is set to not be required whereas shared is set to be required
+               CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pfasta);
+        CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared);            
+
+        
+        CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
+               CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
+               
+        //choose more than one multiple options
+        CommandParameter pcalc("calc", "Multiple", "jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-morisitahorn-braycurtis", "jest-thetayc", "", "", "",true,false); parameters.push_back(pcalc);
+        //choose only one multiple options
+        CommandParameter pdistance("distance", "Multiple", "column-lt-square", "column", "", "", "",false,false); parameters.push_back(pdistance);
+        
+        CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptiming);
+        
+        //every command must have inputdir and outputdir.  This allows mothur users to redirect input and output files.
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               
+               vector<string> myArray;
+               for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NewCommand", "setParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+string NewCommand::getHelpString(){    
+       try {
+               string helpString = "";
+               helpString += "The new command allows you to ....\n";
+               helpString += "The new command parameters are: ....\n";
+               helpString += "The whatever parameter is used to ....\n";
+               helpString += "The new command should be in the following format: \n";
+               helpString += "new(...)\n";
+               return helpString;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NewCommand", "getHelpString");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+NewCommand::NewCommand(){      
+       try {
+               abort = true; calledHelp = true;
+               setParameters();
+        vector<string> tempOutNames;
+               outputTypes["fileType1"] = tempOutNames; //filetypes should be things like: shared, fasta, accnos...
+               outputTypes["fileType2"] = tempOutNames;
+               outputTypes["FileType2"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NewCommand", "NewCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+NewCommand::NewCommand(string option)  {
+       try {
+////////////////////////////////////////////////////////
+/////////////////// start leave alone block ////////////
+////////////////////////////////////////////////////////
+               abort = false; calledHelp = false;   
+               
+               //allow user to run help
+               if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
+               
+               else {
+                       //valid paramters for this command
+                       vector<string> myArray = setParameters();
+                       
+                       OptionParser parser(option);
+                       map<string,string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       map<string,string>::iterator it;
+                       //check to make sure all parameters are valid for command
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+                       
+                       
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                
+///////////////////////////////////////////////////////////////
+//////////////// stop leave alone block ///////////////////////
+///////////////////////////////////////////////////////////////
+                
+//edit file types below to include only the types you added as parameters
+                
+                               string path;
+                               it = parameters.find("phylip");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("column");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["column"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("fasta");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
+                               }
+                                                               
+                               it = parameters.find("name");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["name"] = inputDir + it->second;             }
+                               }
+                
+                it = parameters.find("shared");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = m->hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["shared"] = inputDir + it->second;           }
+                               }
+            }
+///////////////////////////////////////////////////////////////////////////////
+/////////// example of getting filenames and checking dependancies ////////////
+// the validParameter class will make sure file exists, fill with correct    //
+// and name is current is given ///////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+            
+            
+            ///variables for examples below that you will most likely want to put in the header for 
+            //use by the other class functions.
+            string phylipfile, columnfile, namefile, fastafile, sharedfile, method;
+            int processors;
+            bool useTiming, allLines;
+            vector<string> Estimators, Groups;
+            set<string> labels;
+            //if allLines is used it should be initialized to 1 above.
+            
+            
+                       //check for parameters
+            phylipfile = validParameter.validFile(parameters, "phylip", true);
+                       if (phylipfile == "not open") { phylipfile = ""; abort = true; }
+                       else if (phylipfile == "not found") { phylipfile = ""; }        
+                       else {  m->setPhylipFile(phylipfile); }
+                       
+                       columnfile = validParameter.validFile(parameters, "column", true);
+                       if (columnfile == "not open") { columnfile = ""; abort = true; }        
+                       else if (columnfile == "not found") { columnfile = ""; }
+                       else {   m->setColumnFile(columnfile);  }
+                       
+                       namefile = validParameter.validFile(parameters, "name", true);
+                       if (namefile == "not open") { abort = true; }   
+                       else if (namefile == "not found") { namefile = ""; }
+                       else { m->setNameFile(namefile); }
+            
+            //get fastafile - it is not required
+            fastafile = validParameter.validFile(parameters, "fasta", true);
+                       if (fastafile == "not open") { fastafile = ""; abort=true;  }
+                       else if (fastafile == "not found") {  fastafile = "";  }
+                       if (fastafile != "") { m->setFastaFile(fastafile); }
+
+                       
+                       if ((phylipfile == "") && (columnfile == "")) { 
+                               //is there are current file available for either of these?
+                               //give priority to column, then phylip
+                               columnfile = m->getColumnFile(); 
+                               if (columnfile != "") {   m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); }
+                               else { 
+                                       phylipfile = m->getPhylipFile(); 
+                                       if (phylipfile != "") {  m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); }
+                                       else { 
+                                               m->mothurOut("No valid current files. You must provide a phylip or column file before you can use the cluster command."); m->mothurOutEndLine(); 
+                                               abort = true;
+                                       }
+                               }
+                       }
+                       else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When executing a cluster command you must enter ONLY ONE of the following: phylip or column."); m->mothurOutEndLine(); abort = true; }
+                       
+                       if (columnfile != "") {
+                               if (namefile == "") { 
+                                       namefile = m->getNameFile(); 
+                                       if (namefile != "") {  m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); }
+                                       else { 
+                                               m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); 
+                                               abort = true; 
+                                       }       
+                               }
+                       }
+            
+            //get shared file, it is required
+                       sharedfile = validParameter.validFile(parameters, "shared", true);
+                       if (sharedfile == "not open") { sharedfile = ""; abort = true; }        
+                       else if (sharedfile == "not found") { 
+                               //if there is a current shared file, use it
+                               sharedfile = m->getSharedFile(); 
+                               if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
+                               else {  m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; }
+                       }else { m->setSharedFile(sharedfile); }
+            
+            //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = m->hasPath(sharedfile); //if user entered a file with a path then preserve it       
+                       }
+
+                       
+//////////////////////////////////////////////////////////////////////
+////////// example of getting other types of parameters //////////////
+//////////////////////////////////////////////////////////////////////
+            
+                       //use only one Mutliple type
+                       method = validParameter.validFile(parameters, "method", false);
+                       if (method == "not found") { method = "average"; }
+                       
+                       if ((method == "furthest") || (method == "nearest") || (method == "average") || (method == "weighted")) { }
+                       else { m->mothurOut("Not a valid clustering method.  Valid clustering algorithms are furthest, nearest, average, and weighted."); m->mothurOutEndLine(); abort = true; }
+            
+            //use more than one multiple type. do not check to make sure the entry is valid.
+            string calc = validParameter.validFile(parameters, "calc", false);                 
+                       if (calc == "not found") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
+                       else { 
+                if (calc == "default")  {  calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
+                       }
+                       m->splitAtDash(calc, Estimators);
+            
+            //Boolean type - m->isTrue looks for t, true, f or false and is case insensitive
+                       string timing = validParameter.validFile(parameters, "timing", false);
+                       if (timing == "not found") { timing = "F"; }
+            useTiming = m->isTrue(timing);
+                       
+            //Number type - mothurConvert makes sure the convert can happen to avoid a crash.
+            string temp = validParameter.validFile(parameters, "processors", false);   if (temp == "not found"){       temp = m->getProcessors();      }
+                       m->setProcessors(temp);
+                       m->mothurConvert(temp, processors);
+            
+            //Groups must be checked later to make sure they are valid. SharedUtilities has functions of check the validity, just make to so m->setGroups() after the checks.  If you are using these with a shared file no need to check the SharedRAbundVector class will call SharedUtilites for you, kinda nice, huh?
+            string groups = validParameter.validFile(parameters, "groups", false);                     
+                       if (groups == "not found") { groups = ""; }
+                       else { m->splitAtDash(groups, Groups); }
+                       m->setGroups(Groups);
+            
+            //Commonly used to process list, rabund, sabund, shared and relabund files.  Look at "smart distancing" examples below in the execute function.
+            string label = validParameter.validFile(parameters, "label", false);                       
+                       if (label == "not found") { label = ""; }
+                       else { 
+                               if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
+                               else { allLines = 1;  }
+                       }
+            
+            //if your command has a namefile as an option, you may want ot check to see if there is a current namefile
+            //saved by mothur that is associated with the other files you are using as inputs.  
+            //You can do so by adding the files associated with the namefile to the files vector and then asking parser to check.  
+            //This saves our users headaches over file mismatches because they forgot to include the namefile, :)
+            if (namefile == "") {
+                               vector<string> files; files.push_back(fastafile);
+                               parser.getNameFile(files);
+                       }
+                       
+               }
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NewCommand", "NewCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+int NewCommand::execute(){
+       try {
+               
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+        
+        // reading and processing a shared file code example
+        // Note: As long as you set groups and labels as shown in the constructor, you can use this code without modification other than adding your function call which is passed the lookup vector.
+        // The classes used below will handle the checking of groups to make sure they are valid and returning only the groups you selected.  The while loop implements mothur "smart distancing" so as long as you filled label as shown above in the constructor the code below will handle bad labels or labels not included in the sharedfile.
+         
+         //Reads sharefile, binLabels are stored in m->currentBinLabels, lookup will be filled with groups in m->getGroups() or all groups in file if m->getGroups is empty. If groups are selected, some bins maybe eliminated if they only contained seqs from groups not included. No need to worry about the details of this, SharedRAbundVector takes care of it.  Just make sure to use m->currentBinLabels if you are outputting OTU labels so that if otus are eliminated you still have the correct names.
+        
+        /*
+         InputData input(sharedfile, "sharedfile");
+         vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
+         string lastLabel = lookup[0]->getLabel();
+         
+         //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+         set<string> processedLabels;
+         set<string> userLabels = labels;
+         
+                  
+         //as long as you are not at the end of the file or done wih the lines you want
+         while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+         
+         if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  return 0; }
+         
+         if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                        
+         
+         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+         
+         ///////////////////////////////////////////////////////////////////////////////////
+         //// Call your function to process specific distance in sharedfile, ie lookup /////
+         ///////////////////////////////////////////////////////////////////////////////////
+         
+         processedLabels.insert(lookup[0]->getLabel());
+         userLabels.erase(lookup[0]->getLabel());
+         }
+         
+         if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+         string saveLabel = lookup[0]->getLabel();
+         
+         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  
+         lookup = input.getSharedRAbundVectors(lastLabel);
+         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+         
+         ///////////////////////////////////////////////////////////////////////////////////
+         //// Call your function to process specific distance in sharedfile, ie lookup /////
+         ///////////////////////////////////////////////////////////////////////////////////
+
+         
+         processedLabels.insert(lookup[0]->getLabel());
+         userLabels.erase(lookup[0]->getLabel());
+         
+         //restore real lastlabel to save below
+         lookup[0]->setLabel(saveLabel);
+         }
+         
+         lastLabel = lookup[0]->getLabel();
+         //prevent memory leak
+         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i]; lookup[i] = NULL; }
+         
+         if (m->control_pressed) { return 0; }
+         
+         //get next line to process
+         lookup = input.getSharedRAbundVectors();                              
+         }
+         
+         if (m->control_pressed) {  return 0; }
+         
+         //output error messages about any remaining user labels
+         set<string>::iterator it;
+         bool needToRun = false;
+         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
+         m->mothurOut("Your file does not include the label " + *it); 
+         if (processedLabels.count(lastLabel) != 1) {
+         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
+         needToRun = true;
+         }else {
+         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
+         }
+         }
+         
+         //run last label if you need to
+         if (needToRun == true)  {
+         for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }  
+         lookup = input.getSharedRAbundVectors(lastLabel);
+         
+         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
+         
+         ///////////////////////////////////////////////////////////////////////////////////
+         //// Call your function to process specific distance in sharedfile, ie lookup /////
+         ///////////////////////////////////////////////////////////////////////////////////
+
+         
+         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
+         }
+         */
+        
+        
+        
+        //if you make a new file or a type that mothur keeps track of the current version, you can update it with something like the following.
+               string currentFasta = "";
+               itTypes = outputTypes.find("fasta");
+               if (itTypes != outputTypes.end()) {
+                       if ((itTypes->second).size() != 0) { currentFasta = (itTypes->second)[0]; m->setFastaFile(currentFasta); }
+               }
+               
+        //output files created by command
+               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) {
+               m->errorOut(e, "NewCommand", "NewCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+
diff --git a/newcommandtemplate.h b/newcommandtemplate.h
new file mode 100644 (file)
index 0000000..5fd36b1
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef Mothur_newcommandtemplate_h
+#define Mothur_newcommandtemplate_h
+
+//
+//  newcommandtemplate.h
+//  Mothur
+//
+//  Created by westcott on 5/3/12.
+//  Copyright (c) 2012 Schloss Lab. All rights reserved.
+//
+
+
+//*********Be sure to change ifdef and define to a unique name.**************//
+
+/* This class is designed to provide a template for creating new commands. 
+ It includes code snippets to make creating the command classes virtually pure
+ functions easier. It includes sample parameter declaration and parameter checking,
+ as well as reference to other classes you may find helpful.
+ It also includes the code needed to read a sharedfile. It is a work in progress so 
+ please add things you may find helpful to yourself or other developers trying to 
+ add commands to mothur.
+*/
+
+#include "command.hpp"
+
+/**************************************************************************************************/
+
+class NewCommand : public Command {
+public:
+    NewCommand(string);
+    NewCommand();
+    ~NewCommand(){}
+    
+    vector<string> setParameters();
+    string getCommandName()                    { return "newCommandNameToBeSeenByUser";                        }
+    string getCommandCategory()                { return "commandCategory";             } 
+    //commmand category choices: Sequence Processing, OTU-Based Approaches, Hypothesis Testing, Phylotype Analysis, General, Clustering and Hidden
+    string getHelpString();    
+    string getCitation() { return "http://www.mothur.org/wiki/newCommandNameToBeSeenByUser"; }
+    string getDescription()            { return "brief description"; }
+    
+    int execute(); 
+    void help() { m->mothurOut(getHelpString()); }     
+    
+private:
+    bool abort;
+    string outputDir;
+    vector<string> outputNames;
+};
+
+/**************************************************************************************************/
+
+
+
+
+#endif
index 55b752dba4f40e76f11a46d2608e75d43c0de506..b0d12b87bc49f4d3b6e9cae63558ba622b199701 100644 (file)
@@ -12,7 +12,8 @@
 //**********************************************************************************************************************
 vector<string> SetDirectoryCommand::setParameters(){   
        try {
-               CommandParameter ptempdefault("tempdefault", "String", "", "", "", "", "",false,false); parameters.push_back(ptempdefault);     
+               CommandParameter ptempdefault("tempdefault", "String", "", "", "", "", "",false,false); parameters.push_back(ptempdefault);
+        CommandParameter pdebug("debug", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pdebug);
                CommandParameter pinput("input", "String", "", "", "", "", "",false,false); parameters.push_back(pinput);
                CommandParameter poutput("output", "String", "", "", "", "", "",false,false); parameters.push_back(poutput);
                CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
@@ -34,7 +35,9 @@ string SetDirectoryCommand::getHelpString(){
                helpString += "The set.dir command can be used to direct the output files generated by mothur to a specific place, the directory must exist.\n";
                helpString += "The set.dir command can also be used to specify the directory where your input files are located, the directory must exist.\n";
                helpString += "The set.dir command can also be used to override or set the default location mothur will look for files if it is unable to find them, the directory must exist.\n";
-               helpString += "The set.dir command parameters are input, output and tempdefault and one is required.\n";
+        helpString += "The set.dir command can also be used to run mothur in debug mode.\n";
+               helpString += "The set.dir command parameters are input, output, tempdefault and debug and one is required.\n";
+        helpString += "To run mothur in debug mode set debug=true. Default debug=false.\n";
                helpString += "To return the output to the same directory as the input files you may enter: output=clear.\n";
                helpString += "To return the input to the current working directory you may enter: input=clear.\n";
                helpString += "To set the output to the directory where mothur.exe is located you may enter: output=default.\n";
@@ -81,10 +84,18 @@ SetDirectoryCommand::SetDirectoryCommand(string option)  {
                        
                        tempdefault = validParameter.validFile(parameters, "tempdefault", false);                       
                        if (tempdefault == "not found") {  tempdefault = "";  }
+            
+            bool debug = false;
+            bool nodebug = false;
+            debugOnly = false;
+            string temp = validParameter.validFile(parameters, "debug", false);                        
+                       if (temp == "not found") {  debug = false;  nodebug=true; }
+            else {  debug = m->isTrue(temp); }
+            m->debug = debug;
                                
-                       if ((input == "") && (output == "") && (tempdefault == "")) {   
-                               m->mothurOut("You must provide either an input, output or tempdefault for the set.outdir command."); m->mothurOutEndLine(); abort = true;
-                       }
+                       if ((input == "") && (output == "") && (tempdefault == "") && nodebug) {        
+                               m->mothurOut("You must provide either an input, output, tempdefault or debug for the set.outdir command."); m->mothurOutEndLine(); abort = true;
+                       }else if((input == "") && (output == "") && (tempdefault == "")) { debugOnly = true; }
                }
        }
        catch(exception& e) {
@@ -99,6 +110,8 @@ int SetDirectoryCommand::execute(){
                
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
+        if (debugOnly) { return 0; }
+        
                commandFactory = CommandFactory::getInstance();
                
                m->mothurOut("Mothur's directories:"); m->mothurOutEndLine();
index b3b00c46c65b65f1c7f243221ceb4e814a37dbc5..9afc4ea6579d68019dfe04c56aab7119b78d656a 100644 (file)
@@ -35,7 +35,7 @@ public:
 private:
        CommandFactory* commandFactory;
        string output, input, tempdefault;
-       bool abort;
+       bool abort, debugOnly;
        vector<string> outputNames;