+}
+/**************************************************************************/
+int FullMatrix::readSquareMatrix(ifstream& filehandle) {
+ try {
+
+ Progress* reading;
+ reading = new Progress("Reading matrix: ", numSeqs * numSeqs);
+
+ int count = 0;
+
+ string group, name;
+
+ for(int i=1;i<numSeqs;i++){
+ filehandle >> name;
+
+ group = groupmap->getGroup(name);
+ index[i].seqName = name;
+ index[i].groupName = group;
+
+ 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];
+ if (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) {
+ m->errorOut(e, "FullMatrix", "readSquareMatrix");
+ exit(1);
+ }
+}
+/**************************************************************************/
+int FullMatrix::readLTMatrix(ifstream& filehandle) {
+ try {
+
+ Progress* reading;
+ reading = new Progress("Reading matrix: ", numSeqs * (numSeqs - 1) / 2);
+
+ int count = 0;
+ float distance;
+
+ string group, name;
+
+ for(int i=1;i<numSeqs;i++){
+ filehandle >> name;
+
+ group = groupmap->getGroup(name);
+ index[i].seqName = name;
+ index[i].groupName = group;
+
+ 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;
+ if (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) {
+ m->errorOut(e, "FullMatrix", "readLTMatrix");
+ exit(1);
+ }
+}
+
+/**************************************************************************/
+
+void FullMatrix::sortGroups(int low, int high){
+ try{
+
+ if (low < high) {
+ int i = low+1;
+ int j = high;
+ int pivot = (low+high) / 2;
+
+ swapRows(low, pivot); //puts pivot in final spot
+
+ /* compare value */
+ //what group does this row belong to
+ string key = index[low].groupName;
+
+ /* partition */
+ while(i <= j) {
+ /* find member above ... */
+ while((i <= high) && (index[i].groupName <= key)) { i++; }
+
+ /* find element below ... */
+ while((j >= low) && (index[j].groupName > key)) { j--; }
+
+ if(i < j) {
+ swapRows(i, j);
+ }
+ }
+
+ swapRows(low, j);
+
+ /* recurse */
+ sortGroups(low, j-1);
+ sortGroups(j+1, high);
+ }
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "FullMatrix", "sortGroups");