]> git.donarmstrong.com Git - mothur.git/blobdiff - clustercommand.cpp
Merge remote-tracking branch 'origin/master'
[mothur.git] / clustercommand.cpp
index 059f277db6856e2b8c360dbb03b1929d7fa39de5..8019def31cad9acc54c1308171bf796e949890a1 100644 (file)
@@ -11,6 +11,7 @@
 #include "readphylip.h"
 #include "readcolumn.h"
 #include "readmatrix.hpp"
+#include "clusterdoturcommand.h"
 
 //**********************************************************************************************************************
 vector<string> ClusterCommand::setParameters(){        
@@ -53,6 +54,28 @@ string ClusterCommand::getHelpString(){
        }
 }
 //**********************************************************************************************************************
+string ClusterCommand::getOutputFileNameTag(string type, string inputName=""){ 
+       try {
+        string outputFileName = "";
+               map<string, vector<string> >::iterator it;
+        
+        //is this a type this command creates
+        it = outputTypes.find(type);
+        if (it == outputTypes.end()) {  m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
+        else {
+            if (type == "list") {  outputFileName =  "list"; }
+            else if (type == "rabund") {  outputFileName =  "rabund"; }
+            else if (type == "sabund") {  outputFileName =  "sabund"; }
+            else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;  }
+        }
+        return outputFileName;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "ClusterCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 ClusterCommand::ClusterCommand(){      
        try {
                abort = true; calledHelp = true; 
@@ -182,7 +205,7 @@ ClusterCommand::ClusterCommand(string option)  {
                        if (temp == "not found") { temp = "100"; }
                        //saves precision legnth for formatting below
                        length = temp.length();
-                       convert(temp, precision); 
+                       m->mothurConvert(temp, precision); 
                        
                        temp = validParameter.validFile(parameters, "hard", false);                     if (temp == "not found") { temp = "T"; }
                        hard = m->isTrue(temp);
@@ -192,7 +215,7 @@ ClusterCommand::ClusterCommand(string option)  {
                        
                        temp = validParameter.validFile(parameters, "cutoff", false);
                        if (temp == "not found") { temp = "10"; }
-                       convert(temp, cutoff); 
+                       m->mothurConvert(temp, cutoff); 
                        cutoff += (5 / (precision * 10.0));  
                        
                        method = validParameter.validFile(parameters, "method", false);
@@ -207,7 +230,7 @@ ClusterCommand::ClusterCommand(string option)  {
                        timing = validParameter.validFile(parameters, "timing", false);
                        if (timing == "not found") { timing = "F"; }
                        
-                       }
+               }
        }
        catch(exception& e) {
                m->errorOut(e, "ClusterCommand", "ClusterCommand");
@@ -223,6 +246,34 @@ int ClusterCommand::execute(){
        
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
+               //phylip file given and cutoff not given - use cluster.classic because it uses less memory and is faster
+               if ((format == "phylip") && (cutoff > 10.0)) {
+                       m->mothurOutEndLine(); m->mothurOut("You are using a phylip file and no cutoff.  I will run cluster.classic to save memory and time."); m->mothurOutEndLine();
+                       
+                       //run unique.seqs for deconvolute results
+                       string inputString = "phylip=" + distfile;
+                       if (namefile != "") { inputString += ", name=" + namefile; }
+                       inputString += ", precision=" + toString(precision);
+                       inputString += ", method=" + method;
+                       if (hard)       { inputString += ", hard=T";    }
+                       else            { inputString += ", hard=F";    }
+                       if (sim)        { inputString += ", sim=T";             }
+                       else            { inputString += ", sim=F";             }
+
+                       
+                       m->mothurOutEndLine(); 
+                       m->mothurOut("/------------------------------------------------------------/"); m->mothurOutEndLine(); 
+                       m->mothurOut("Running command: cluster.classic(" + inputString + ")"); m->mothurOutEndLine(); 
+                       
+                       Command* clusterClassicCommand = new ClusterDoturCommand(inputString);
+                       clusterClassicCommand->execute();
+                       delete clusterClassicCommand;
+                       
+                       m->mothurOut("/------------------------------------------------------------/"); m->mothurOutEndLine();  
+
+                       return 0;
+               }
+               
                ReadMatrix* read;
                if (format == "column") { read = new ReadColumnMatrix(columnfile, sim); }       //sim indicates whether its a similarity matrix
                else if (format == "phylip") { read = new ReadPhylipMatrix(phylipfile, sim); }
@@ -258,13 +309,17 @@ int ClusterCommand::execute(){
                if (outputDir == "") { outputDir += m->hasPath(distfile); }
                fileroot = outputDir + m->getRootName(m->getSimpleName(distfile));
                
-               m->openOutputFile(fileroot+ tag + ".sabund",    sabundFile);
-               m->openOutputFile(fileroot+ tag + ".rabund",    rabundFile);
-               m->openOutputFile(fileroot+ tag + ".list",              listFile);
+        string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund");
+        string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund");
+        string listFileName = fileroot+ tag + "." + getOutputFileNameTag("list");
+        
+               m->openOutputFile(sabundFileName,       sabundFile);
+               m->openOutputFile(rabundFileName,       rabundFile);
+               m->openOutputFile(listFileName, listFile);
                
-               outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund");
-               outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund");
-               outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list");
+               outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName);
+               outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName);
+               outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName);
                
                
                time_t estart = time(NULL);
@@ -326,7 +381,7 @@ int ClusterCommand::execute(){
                        cout.flush();
                        print_start = false;
                }
-       
+               
                if(previousDist <= 0.0000){
                        printData("unique");
                }