]> git.donarmstrong.com Git - mothur.git/blobdiff - hclustercommand.cpp
1.12.0
[mothur.git] / hclustercommand.cpp
index e6875b6af18d71bb0f78341f2a04bfc2c002886d..b4d601751630af81741d64ab605c95d5650838a5 100644 (file)
@@ -21,7 +21,7 @@ HClusterCommand::HClusterCommand(string option)  {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"cutoff","precision","method","phylip","column","name","sorted","showabund","timing","outputdir","inputdir"};
+                       string Array[] =  {"cutoff","hard","precision","method","phylip","column","name","sorted","showabund","timing","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -104,10 +104,13 @@ HClusterCommand::HClusterCommand(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"; }
@@ -160,7 +163,7 @@ void HClusterCommand::help(){
                m->mothurOut("The name parameter allows you to enter your name file and is required if your distance file is in column format. \n");
                m->mothurOut("The hcluster command should be in the following format: \n");
                m->mothurOut("hcluster(column=youDistanceFile, name=yourNameFile, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n");
-               m->mothurOut("The acceptable hcluster methods are furthest and nearest, but we hope to add average in the future.\n\n");        
+               m->mothurOut("The acceptable hcluster methods are furthest, nearest and average.\n\n"); 
        }
        catch(exception& e) {
                m->errorOut(e, "HClusterCommand", "help");
@@ -189,9 +192,19 @@ int HClusterCommand::execute(){
                time_t estart = time(NULL);
                
                if (!sorted) {
-                       read = new ReadCluster(distfile, cutoff);       
+                       read = new ReadCluster(distfile, cutoff, outputDir, true);      
                        read->setFormat(format);
                        read->read(globaldata->nameMap);
+                       
+                       if (m->control_pressed) {  
+                               delete read; 
+                               sabundFile.close();
+                               rabundFile.close();
+                               listFile.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0;  
+                       }
+                       
                        distfile = read->getOutputFile();
                
                        list = read->getListVector();
@@ -199,7 +212,15 @@ int HClusterCommand::execute(){
                }else {
                        list = new ListVector(globaldata->nameMap->getListVector());
                }
-       
+               
+               if (m->control_pressed) {  
+                       sabundFile.close();
+                       rabundFile.close();
+                       listFile.close();
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                       return 0;  
+               }
+
                m->mothurOut("It took " + toString(time(NULL) - estart) + " seconds to sort. "); m->mothurOutEndLine();
                estart = time(NULL);
        
@@ -221,16 +242,51 @@ int HClusterCommand::execute(){
                cluster = new HCluster(rabund, list, method, distfile, globaldata->nameMap, cutoff);
                vector<seqDist> seqs; seqs.resize(1); // to start loop
                
+               if (m->control_pressed) {  
+                               delete cluster;
+                               sabundFile.close();
+                               rabundFile.close();
+                               listFile.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0;  
+               }
+
+               
                while (seqs.size() != 0){
                
                        seqs = cluster->getSeqs();
-                               
-                       for (int i = 0; i < seqs.size(); i++) {  //-1 means skip me
+                       
+                       if (m->control_pressed) {  
+                               delete cluster;
+                               sabundFile.close();
+                               rabundFile.close();
+                               listFile.close();
+                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                               return 0;  
+                       }
 
+                       for (int i = 0; i < seqs.size(); i++) {  //-1 means skip me
+                               
                                if (seqs[i].seq1 != seqs[i].seq2) {
                                        cluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist);
                                        
-                                       float rndDist = roundDist(seqs[i].dist, precision);
+                                       if (m->control_pressed) {  
+                                               delete cluster;
+                                               sabundFile.close();
+                                               rabundFile.close();
+                                               listFile.close();
+                                               for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                                               return 0;  
+                                       }
+
+                       
+                                       float rndDist;
+                                       if (hard) {
+                                               rndDist = ceilDist(seqs[i].dist, precision); 
+                                       }else{
+                                               rndDist = roundDist(seqs[i].dist, precision); 
+                                       }
+
                                        
                                        if((previousDist <= 0.0000) && (seqs[i].dist != previousDist)){
                                                printData("unique");
@@ -247,6 +303,15 @@ int HClusterCommand::execute(){
                        }
                }
 
+               if (m->control_pressed) {  
+                       delete cluster;
+                       sabundFile.close();
+                       rabundFile.close();
+                       listFile.close();
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                       return 0;  
+               }
+                                       
                if(previousDist <= 0.0000){
                        printData("unique");
                }
@@ -270,6 +335,12 @@ int HClusterCommand::execute(){
                listFile.close();
                delete cluster;
                
+               if (m->control_pressed) {  
+                       for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());  }
+                       return 0;  
+               }
+
+               
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }