]> git.donarmstrong.com Git - mothur.git/blobdiff - clustercommand.cpp
added name option to read.tree for use in unifrac and parimony commands
[mothur.git] / clustercommand.cpp
index 8208b7efbde6148c4d5c6c0ad0d090335edd6d0c..9d09d2cbe465da6531bbf720f0fd7d89aec08bce 100644 (file)
@@ -21,7 +21,7 @@ ClusterCommand::ClusterCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"cutoff","precision","method","showabund","timing"};
+                       string Array[] =  {"cutoff","precision","method","showabund","timing","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -36,6 +36,9 @@ ClusterCommand::ClusterCommand(string option){
                                }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
+                       
                        //error checking to make sure they read a distance file
                        if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) {
                                mothurOut("Before you use the cluster command, you first need to read in a distance matrix."); mothurOutEndLine();
@@ -81,12 +84,13 @@ ClusterCommand::ClusterCommand(string option){
                                }
                                
                                //create cluster
-                               if (method == "furthest")       {       cluster = new CompleteLinkage(rabund, list, matrix); }
-                               else if(method == "nearest"){   cluster = new SingleLinkage(rabund, list, matrix); }
-                               else if(method == "average"){   cluster = new AverageLinkage(rabund, list, matrix);     }
+                               if (method == "furthest")       {       cluster = new CompleteLinkage(rabund, list, matrix, cutoff); }
+                               else if(method == "nearest"){   cluster = new SingleLinkage(rabund, list, matrix, cutoff); }
+                               else if(method == "average"){   cluster = new AverageLinkage(rabund, list, matrix, cutoff);     }
                                tag = cluster->getTag();
-
-                               fileroot = getRootName(globaldata->inputFileName);
+                               
+                               if (outputDir == "") { outputDir += hasPath(globaldata->inputFileName); }
+                               fileroot = outputDir + getRootName(getSimpleName(globaldata->inputFileName));
                        
                                openOutputFile(fileroot+ tag + ".sabund",       sabundFile);
                                openOutputFile(fileroot+ tag + ".rabund",       rabundFile);
@@ -133,7 +137,7 @@ int ClusterCommand::execute(){
                if (abort == true) {    return 0;       }
                
                time_t estart = time(NULL);
-               int ndist = matrix->getNNodes();
+               //int ndist = matrix->getNNodes();
                float previousDist = 0.00000;
                float rndPreviousDist = 0.00000;
                oldRAbund = *rabund;
@@ -200,9 +204,9 @@ int ClusterCommand::execute(){
                sabundFile.close();
                rabundFile.close();
                listFile.close();
-               if (isTrue(timing)) {
-                       mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster " + toString(ndist) + " distances"); mothurOutEndLine();
-               }
+               //if (isTrue(timing)) {
+                       mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster"); mothurOutEndLine();
+               //}
                return 0;
        }
        catch(exception& e) {