X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=fullmatrix.cpp;h=fe61307552b67bdc4567d00025e1a1401a9e70f3;hb=0486bc2eed084ac387d2f59b6d23d13b2382daf7;hp=5612041528a00e9e0e441422662c6d3738bcb07c;hpb=9354b70bb84f6dd52ff4a1955754bcbf7edeedbf;p=mothur.git diff --git a/fullmatrix.cpp b/fullmatrix.cpp index 5612041..fe61307 100644 --- a/fullmatrix.cpp +++ b/fullmatrix.cpp @@ -13,19 +13,21 @@ //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; string name, group; - filehandle >> numSeqs >> name; + filehandle >> numSeqs >> name; + //make the matrix filled with zeros matrix.resize(numSeqs); for(int i = 0; i < numSeqs; i++) { 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; @@ -43,6 +45,7 @@ FullMatrix::FullMatrix(ifstream& filehandle) { for(int i=0;i> matrix[0][i]; + if (globaldata->sim) { matrix[0][i] = 1.0 - matrix[0][i]; } } break; } @@ -53,21 +56,23 @@ FullMatrix::FullMatrix(ifstream& filehandle) { break; } } - + //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 +81,7 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) { int count = 0; string group, name; - + for(int i=1;i> name; @@ -84,26 +89,35 @@ 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;jcontrol_pressed) { delete reading; return 0; } + filehandle >> matrix[i][j]; + if (globaldata->sim) { matrix[i][j] = 1.0 - 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 +133,30 @@ 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;jcontrol_pressed) { delete reading; return 0; } + filehandle >> distance; + if (globaldata->sim) { distance = 1.0 - 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 +199,7 @@ void FullMatrix::sortGroups(int low, int high){ } catch(exception& e) { - errorOut(e, "FullMatrix", "sortGroups"); + m->errorOut(e, "FullMatrix", "sortGroups"); exit(1); } } @@ -214,7 +237,7 @@ void FullMatrix::swapRows(int i, int j) { } catch(exception& e) { - errorOut(e, "FullMatrix", "swapRows"); + m->errorOut(e, "FullMatrix", "swapRows"); exit(1); } } @@ -253,7 +276,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); } }