X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=fullmatrix.cpp;h=6151a65202901fa24ec6ff91166017a682483c62;hb=9ca2caadbeac83bb84b3330d9204b1b659d62941;hp=c61109c78ce2cdcca001455a0408be34692c47d1;hpb=9651e8e7172d86707b34af15e95ec60ad4c3c3f9;p=mothur.git diff --git a/fullmatrix.cpp b/fullmatrix.cpp index c61109c..6151a65 100644 --- a/fullmatrix.cpp +++ b/fullmatrix.cpp @@ -27,7 +27,8 @@ FullMatrix::FullMatrix(ifstream& filehandle) { group = groupmap->getGroup(name); if(group == "not found") { cout << "Error: Sequence '" << name << "' was not found in the group file, please correct." << endl; exit(1); } - index[0] = group; + index[0].groupname = group; + index[0].seqName = name; //determine if matrix is square or lower triangle //if it is square read the distances for the first sequence @@ -38,6 +39,7 @@ FullMatrix::FullMatrix(ifstream& filehandle) { if(isalnum(d)){ square = true; filehandle.putback(d); + for(int i=0;i> matrix[0][i]; } @@ -55,14 +57,9 @@ FullMatrix::FullMatrix(ifstream& filehandle) { if (square == true) { readSquareMatrix(filehandle); } else { readLTMatrix(filehandle); } - - - printMatrix(cout); //sort sequences so they are gathered in groups for processing - sortGroups(); - cout << "after sort" << endl; - printMatrix(cout); - + sortGroups(0, numSeqs-1); + } catch(exception& e) { cout << "Standard Error: " << e.what() << " has occurred in the FullMatrix class Function FullMatrix. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; @@ -82,13 +79,15 @@ void FullMatrix::readSquareMatrix(ifstream& filehandle) { int count = 0; float distance; + string group, name; for(int i=1;i> name; group = groupmap->getGroup(name); - index[i] = group; + index[i].groupname = group; + index[i].seqName = name; if(group == "not found") { cout << "Error: Sequence '" << name << "' was not found in the group file, please correct." << endl; exit(1); } @@ -121,13 +120,15 @@ void FullMatrix::readLTMatrix(ifstream& filehandle) { int count = 0; float distance; + string group, name; for(int i=1;i> name; group = groupmap->getGroup(name); - index[i] = group; + index[i].groupname = group; + index[i].seqName = name; if(group == "not found") { cout << "Error: Sequence '" << name << "' was not found in the group file, please correct." << endl; exit(1); } @@ -138,6 +139,7 @@ void FullMatrix::readLTMatrix(ifstream& filehandle) { count++; reading->update(count); } + } reading->finish(); delete reading; @@ -154,82 +156,74 @@ void FullMatrix::readLTMatrix(ifstream& filehandle) { } /**************************************************************************/ -void FullMatrix::sortGroups(){ +void FullMatrix::sortGroups(int low, int high){ try{ - //sort each row by group and when you do, swap rows too. - for (int i = 0; i < numSeqs; i++) { - quicksort(0, numSeqs-1, i); - } - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the FullMatrix class Function sortGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the FullMatrix class function sortGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - -} -/**************************************************************************/ -//this is a version of quicksort taken from http://www.c.happycodings.com/Sorting_Searching/code13.html -/* sort everything inbetween `low' <-> `high' */ -void FullMatrix::quicksort(int low, int high, int row) { - try { + int i = low; int j = high; int y = 0; + string name; /* compare value */ //what group does this row belong to - string z = index[(low + high) / 2]; + string z = index[(low + high) / 2].groupname; /* partition */ do { /* find member above ... */ - while(index[i] < z) i++; + while(index[i].groupname < z) i++; /* find element below ... */ - while(index[j] > z) j--; + while(index[j].groupname > z) j--; if(i <= j) { - /* swap two elements in row*/ - y = matrix[row][i]; - matrix[row][i] = matrix[row][j]; - matrix[row][j] = y; + /* swap rows*/ + for (int h = 0; h < numSeqs; h++) { + y = matrix[i][h]; + matrix[i][h] = matrix[j][h]; + matrix[j][h] = y; + } - /* swap two elements in column*/ - y = matrix[i][row]; - matrix[i][row] = matrix[j][row]; - matrix[j][row] = y; + /* swap columns*/ + for (int b = 0; b < numSeqs; b++) { + y = matrix[b][i]; + matrix[b][i] = matrix[b][j]; + matrix[b][j] = y; + } //swap map elements - z = index[i]; - index[i] = index[j]; - index[j] = z; + z = index[i].groupname; + index[i].groupname = index[j].groupname; + index[j].groupname = z; + + name = index[i].seqName; + index[i].seqName = index[j].seqName; + index[j].seqName = name; + i++; j--; -//cout << "swapping elements " << i << " " << j << endl; -//printMatrix(cout); cout << endl; } } while(i <= j); /* recurse */ if(low < j) - quicksort(low, j, row); + sortGroups(low, j); if(i < high) - quicksort(i, high, row); + sortGroups(i, high); + + } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the FullMatrix class Function quicksort. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "Standard Error: " << e.what() << " has occurred in the FullMatrix class Function sortGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } catch(...) { - cout << "An unknown error has occurred in the FullMatrix class function quicksort. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + cout << "An unknown error has occurred in the FullMatrix class function sortGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; exit(1); } + } /**************************************************************************/ @@ -239,7 +233,7 @@ int FullMatrix::getNumSeqs(){ return numSeqs; } void FullMatrix::printMatrix(ostream& out) { try{ for (int i = 0; i < numSeqs; i++) { - out << "row " << i << " group = " << index[i] << endl; + out << "row " << i << " group = " << index[i].groupname << " name = " << index[i].seqName << endl; for (int j = 0; j < numSeqs; j++) { out << matrix[i][j] << " "; } @@ -256,5 +250,80 @@ void FullMatrix::printMatrix(ostream& out) { } } + /**************************************************************************/ +void FullMatrix::getMinsForRowsVectors(){ + try{ + numGroups = globaldata->gGroupmap->namesOfGroups.size(); + + //sort globaldata->gGroupmap.namesOfGroups so that it will match the matrix + sort(globaldata->gGroupmap->namesOfGroups.begin(), globaldata->gGroupmap->namesOfGroups.end()); + + /*************************************************/ + //find where in matrix each group starts and stops + /*************************************************/ + vector bounds; //bounds[1] = starting row in matrix from group B, bounds[2] = starting row in matrix from group C, bounds[3] = no need to find upper bound of C because its numSeqs. + bounds.resize(numGroups); + + bounds[0] = 0; + bounds[numGroups] = numSeqs-1; + //for each group find bounds of subgroup/comparison + for (int i = 1; i < numGroups; i++) { + getBounds(bounds[i], globaldata->gGroupmap->namesOfGroups[i]); + } + + /************************************************************/ + //fill the minsForRows vectors for each group the user wants + /************************************************************/ + int countx = bounds[1]; //where second group starts + int county = bounds[1]; + + //go through the entire matrix + for (int x = 0; x < numSeqs; x++) { + for (int y = 0; y < numSeqs; y++) { + //if have not changed groups + if ((x < countx) && (y < county)) { + + } + } + } + + + + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the FullMatrix class Function getMinsForRowsVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the FullMatrix class function getMinsForRowsVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +} + +/**************************************************************************/ +void FullMatrix::getBounds(int& higher, string group) { + try{ + bool gotLower = false; + + //for each group find bounds of subgroup/comparison + for (it = index.begin(); it != index.end(); it++) { + if (it->second.groupname == group) { + if (gotLower != true) { gotLower = true; } + }else if ((gotLower == true) && (it->second.groupname != group)) { higher = it->first; break; } + } + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the FullMatrix class Function getBounds. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the FullMatrix class function getBounds. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + +}