]> git.donarmstrong.com Git - mothur.git/blobdiff - hcluster.cpp
changes while testing
[mothur.git] / hcluster.cpp
index 8a596f3163c06dd55129cdc8de0f5779a5d6cb4d..f8f48095b2ec55a8dce91d55881271f2f1837218 100644 (file)
@@ -10,7 +10,6 @@
 #include "hcluster.h"
 #include "rabundvector.hpp"
 #include "listvector.hpp"
-#include "sparsematrix.hpp"
 
 /***********************************************************************/
 HCluster::HCluster(RAbundVector* rav, ListVector* lv, string ms, string d, NameAssignment* n, float c) :  rabund(rav), list(lv), method(ms), distfile(d), nameMap(n), cutoff(c) {
@@ -259,7 +258,7 @@ void HCluster::updateArrayandLinkTable() {
        }
 }
 /***********************************************************************/
-bool HCluster::update(int row, int col, float distance){
+double HCluster::update(int row, int col, float distance){
        try {
                bool cluster = false;
                smallRow = row;
@@ -296,7 +295,7 @@ bool HCluster::update(int row, int col, float distance){
                        }
                }
                
-               return cluster;
+               return cutoff;
                //printInfo();
        }
        catch(exception& e) {
@@ -430,7 +429,6 @@ vector<seqDist> HCluster::getSeqsFNNN(){
        }
 }
 //**********************************************************************************************************************
-//don't need cutoff since processFile removes all distance above cutoff and changes names to indexes
 vector<seqDist> HCluster::getSeqsAN(){
        try {
                int firstName, secondName;
@@ -552,7 +550,7 @@ int HCluster::combineFile() {
                           
                           in >> first >> second >> dist; m->gobble(in);
                           
-                          if (m->control_pressed) { in.close(); out.close(); remove(tempDistFile.c_str()); return 0; }
+                          if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(tempDistFile); return 0; }
                           
                           //while there are still values in mergedMin that are smaller than the distance read from file
                           while (count < mergedMin.size())  {
@@ -572,7 +570,9 @@ int HCluster::combineFile() {
                                                        smallRowColValues[0][mergedMin[count].seq1] = mergedMin[count].dist;
                                                }else { //if no, write to temp file
                                                        //outputString += toString(mergedMin[count].seq1) + '\t' + toString(mergedMin[count].seq2) + '\t' + toString(mergedMin[count].dist) + '\n';
-                                                       out << mergedMin[count].seq1 << '\t' << mergedMin[count].seq2 << '\t' << mergedMin[count].dist << endl;
+                                                       //if (mergedMin[count].dist < cutoff) { 
+                                                               out << mergedMin[count].seq1 << '\t' << mergedMin[count].seq2 << '\t' << mergedMin[count].dist << endl;
+                                                       //}
                                                }
                                                count++;
                                        }else{   break; }
@@ -592,7 +592,9 @@ int HCluster::combineFile() {
                           
                           }else { //if no, write to temp file
                                        //outputString += toString(first) + '\t' + toString(second) + '\t' + toString(dist) + '\n';
-                                       out << first << '\t' << second << '\t' << dist << endl;
+                                  //if (dist < cutoff) {
+                                          out << first << '\t' << second << '\t' << dist << endl;
+                                  //}
                           }
                        }
                        
@@ -617,7 +619,9 @@ int HCluster::combineFile() {
                                smallRowColValues[0][mergedMin[count].seq1] = mergedMin[count].dist;
                                
                        }else { //if no, write to temp file
-                               out << mergedMin[count].seq1 << '\t' << mergedMin[count].seq2 << '\t' << mergedMin[count].dist << endl;
+                               //if (mergedMin[count].dist < cutoff) {
+                                       out << mergedMin[count].seq1 << '\t' << mergedMin[count].seq2 << '\t' << mergedMin[count].dist << endl;
+                               //}
                        }
                        count++;
                }
@@ -625,7 +629,7 @@ int HCluster::combineFile() {
                mergedMin.clear();
                        
                //rename tempfile to distfile
-               remove(distfile.c_str());
+               m->mothurRemove(distfile);
                rename(tempDistFile.c_str(), distfile.c_str());
 //cout << "remove = "<< renameOK << " rename = " << ok << endl;        
 
@@ -650,9 +654,17 @@ int HCluster::combineFile() {
                                
                                seqDist temp(clusterArray[smallRow].parent, itMerge->first, average);
                                mergedMin.push_back(temp);
+                       }else {  
+                               //can't find value so update cutoff
+                               if (cutoff > itMerge->second) { cutoff = itMerge->second; }
                        }
                }
-
+               
+               //update cutoff
+               for(itMerge = smallRowColValues[1].begin(); itMerge != smallRowColValues[1].end(); itMerge++) { 
+                       if (cutoff > itMerge->second) { cutoff = itMerge->second; }
+               }
+               
                //sort merged values
                sort(mergedMin.begin(), mergedMin.end(), compareSequenceDistance);      
                
@@ -739,7 +751,7 @@ seqDist HCluster::getNextDist(char* buffer, int& index, int size){
                exit(1);
        }
 }
-/***********************************************************************/
+***********************************************************************/
 int HCluster::processFile() {
        try {
                string firstName, secondName;
@@ -754,7 +766,7 @@ int HCluster::processFile() {
        
                //get entry
                while (!in.eof()) {
-                       if (m->control_pressed) { in.close(); out.close(); remove(outTemp.c_str()); return 0; }
+                       if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outTemp); return 0; }
                        
                        in >> firstName >> secondName >> distance;    m->gobble(in);            
                        
@@ -774,7 +786,7 @@ int HCluster::processFile() {
                in.close();
                out.close();
                
-               remove(distfile.c_str());
+               m->mothurRemove(distfile);
                rename(outTemp.c_str(), distfile.c_str());
                
                return 0;