]> git.donarmstrong.com Git - mothur.git/blobdiff - clustercommand.cpp
changed the daughterLevels in classifiers summary file to reflect the classifications...
[mothur.git] / clustercommand.cpp
index 5d9c7bccfbb250267553997fa3d6b16d7aa560b7..30c45e167ad6a398b23727293577f92362f5d6c7 100644 (file)
@@ -22,7 +22,7 @@ ClusterCommand::ClusterCommand(string option)  {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"cutoff","precision","method","showabund","timing","outputdir","inputdir"};
+                       string Array[] =  {"cutoff","precision","method","showabund","timing","hard","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -56,10 +56,13 @@ ClusterCommand::ClusterCommand(string option)  {
                        length = temp.length();
                        convert(temp, precision); 
                        
+                       temp = validParameter.validFile(parameters, "hard", false);                     if (temp == "not found") { temp = "F"; }
+                       hard = isTrue(temp);
+                       
                        temp = validParameter.validFile(parameters, "cutoff", false);
                        if (temp == "not found") { temp = "10"; }
                        convert(temp, cutoff); 
-                       cutoff += (5 / (precision * 10.0));
+                       cutoff += (5 / (precision * 10.0));  
                        
                        method = validParameter.validFile(parameters, "method", false);
                        if (method == "not found") { method = "furthest"; }
@@ -114,7 +117,7 @@ ClusterCommand::ClusterCommand(string option)  {
 void ClusterCommand::help(){
        try {
                m->mothurOut("The cluster command can only be executed after a successful read.dist command.\n");
-               m->mothurOut("The cluster command parameter options are method, cuttoff, precision, showabund and timing. No parameters are required.\n");
+               m->mothurOut("The cluster command parameter options are method, cuttoff, hard, precision, showabund and timing. No parameters are required.\n");
                m->mothurOut("The cluster command should be in the following format: \n");
                m->mothurOut("cluster(method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n");
                m->mothurOut("The acceptable cluster methods are furthest, nearest and average.  If no method is provided then furthest is assumed.\n\n");      
@@ -154,6 +157,17 @@ int ClusterCommand::execute(){
                double saveCutoff = cutoff;
                
                while (matrix->getSmallDist() < cutoff && matrix->getNNodes() > 0){
+               
+                       if (m->control_pressed) { //clean up
+                               delete globaldata->gSparseMatrix;  globaldata->gSparseMatrix = NULL;
+                               delete globaldata->gListVector;  globaldata->gListVector = NULL;
+                               if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); }
+                               else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); }
+                               sabundFile.close();rabundFile.close();listFile.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }
+                               return 0;
+                       }
+               
                        if (print_start && isTrue(timing)) {
                                m->mothurOut("Clustering (" + tag + ") dist " + toString(matrix->getSmallDist()) + "/" 
                                        + toString(roundDist(matrix->getSmallDist(), precision)) 
@@ -165,8 +179,14 @@ int ClusterCommand::execute(){
                        loops++;
 
                        cluster->update(cutoff);
+       
                        float dist = matrix->getSmallDist();
-                       float rndDist = roundDist(dist, precision);
+                       float rndDist;
+                       if (hard) {
+                               rndDist = ceilDist(dist, precision); 
+                       }else{
+                               rndDist = roundDist(dist, precision); 
+                       }
 
                        if(previousDist <= 0.0000 && dist != previousDist){
                                printData("unique");
@@ -198,7 +218,7 @@ int ClusterCommand::execute(){
                //delete globaldata's copy of the sparsematrix and listvector to free up memory
                delete globaldata->gSparseMatrix;  globaldata->gSparseMatrix = NULL;
                delete globaldata->gListVector;  globaldata->gListVector = NULL;
-               
+       
                //saves .list file so you can do the collect, rarefaction and summary commands without doing a read.list
                if (globaldata->getFormat() == "phylip") { globaldata->setPhylipFile(""); }
                else if (globaldata->getFormat() == "column") { globaldata->setColumnFile(""); }
@@ -210,7 +230,7 @@ int ClusterCommand::execute(){
                sabundFile.close();
                rabundFile.close();
                listFile.close();
-               
+       
                if (saveCutoff != cutoff) { m->mothurOut("changed cutoff to " + toString(cutoff)); m->mothurOutEndLine();  }
                
                m->mothurOutEndLine();