]> git.donarmstrong.com Git - mothur.git/blobdiff - fullmatrix.cpp
changes to filter.seqs
[mothur.git] / fullmatrix.cpp
index 5612041528a00e9e0e441422662c6d3738bcb07c..72866491648e1fb02f681c1ca5842fdbba8e58a2 100644 (file)
@@ -13,6 +13,7 @@
 //This constructor reads a distance matrix file and stores the data in the matrix.
 FullMatrix::FullMatrix(ifstream& filehandle) {
        try{
+               m = MothurOut::getInstance();
                globaldata = GlobalData::getInstance();
                groupmap = globaldata->gGroupmap;
                
@@ -25,7 +26,7 @@ FullMatrix::FullMatrix(ifstream& filehandle) {
                        matrix[i].resize(numSeqs, 0.0);
                }
                group = groupmap->getGroup(name);
-               if(group == "not found") {      mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); }
+               if(group == "not found") {      m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); }
                index.resize(numSeqs);
                index[0].seqName = name;
                index[0].groupName = group;
@@ -55,19 +56,21 @@ FullMatrix::FullMatrix(ifstream& filehandle) {
                }
                
                //read rest of matrix
-               if (square == true) { readSquareMatrix(filehandle); }
-               else { readLTMatrix(filehandle); }
+               if (square == true) {  readSquareMatrix(filehandle); }
+               else {  readLTMatrix(filehandle); }
                
-               sortGroups(0, numSeqs-1);       
+               filehandle.close();
+               
+               if (!m->control_pressed) { sortGroups(0, numSeqs-1); }  
                                
        }
        catch(exception& e) {
-               errorOut(e, "FullMatrix", "FullMatrix");
+               m->errorOut(e, "FullMatrix", "FullMatrix");
                exit(1);
        }
 }
 /**************************************************************************/
-void FullMatrix::readSquareMatrix(ifstream& filehandle) {
+int FullMatrix::readSquareMatrix(ifstream& filehandle) {
        try {
        
                Progress* reading;
@@ -76,7 +79,7 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) {
                int count = 0;
                
                string group, name;
-               
+       
                for(int i=1;i<numSeqs;i++){
                        filehandle >> name;             
                        
@@ -84,25 +87,32 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) {
                        index[i].seqName = name;
                        index[i].groupName = group;
                        
-                       if(group == "not found") {      mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine(); exit(1); }
+                       if(group == "not found") {      m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine(); exit(1); }
                                
                        for(int j=0;j<numSeqs;j++){
+                               if (m->control_pressed) { delete reading;  return 0; }
+                               
                                filehandle >> matrix[i][j];
                                
                                count++;
                                reading->update(count);
                        }
                }
+               
+               if (m->control_pressed) { delete reading;  return 0; }
+               
                reading->finish();
                delete reading;
+               
+               return 0;
        }
        catch(exception& e) {
-               errorOut(e, "FullMatrix", "readSquareMatrix");
+               m->errorOut(e, "FullMatrix", "readSquareMatrix");
                exit(1);
        }
 } 
 /**************************************************************************/
-void FullMatrix::readLTMatrix(ifstream& filehandle) {
+int FullMatrix::readLTMatrix(ifstream& filehandle) {
        try {
                Progress* reading;
                reading = new Progress("Reading matrix:     ", numSeqs * (numSeqs - 1) / 2);
@@ -119,21 +129,28 @@ void FullMatrix::readLTMatrix(ifstream& filehandle) {
                        index[i].seqName = name;
                        index[i].groupName = group;
        
-                       if(group == "not found") {      mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); mothurOutEndLine();  exit(1); }
+                       if(group == "not found") {      m->mothurOut("Error: Sequence '" + name + "' was not found in the group file, please correct."); m->mothurOutEndLine();  exit(1); }
                                
                        for(int j=0;j<i;j++){
+                               if (m->control_pressed) { delete reading;  return 0; }
+                               
                                filehandle >> distance;
+               
                                matrix[i][j] = distance;  matrix[j][i] = distance;
                                count++;
                                reading->update(count);
                        }
                }
-
+               
+               if (m->control_pressed) { delete reading;  return 0; }
+               
                reading->finish();
                delete reading;
+               
+               return 0;
        }
        catch(exception& e) {
-               errorOut(e, "FullMatrix", "readLTMatrix");
+               m->errorOut(e, "FullMatrix", "readLTMatrix");
                exit(1);
        }
 }
@@ -176,7 +193,7 @@ void FullMatrix::sortGroups(int low, int high){
        
        }
        catch(exception& e) {
-               errorOut(e, "FullMatrix", "sortGroups");
+               m->errorOut(e, "FullMatrix", "sortGroups");
                exit(1);
        }
 }
@@ -214,7 +231,7 @@ void FullMatrix::swapRows(int i, int j) {
                
        }
        catch(exception& e) {
-               errorOut(e, "FullMatrix", "swapRows");
+               m->errorOut(e, "FullMatrix", "swapRows");
                exit(1);
        }
 }
@@ -253,7 +270,7 @@ void FullMatrix::printMatrix(ostream& out) {
                for (int i = 0; i < numSeqs; i++) {  out << i << '\t' <<  index[i].seqName << endl;  }
        }
        catch(exception& e) {
-               errorOut(e, "FullMatrix", "printMatrix");
+               m->errorOut(e, "FullMatrix", "printMatrix");
                exit(1);
        }
 }