+
+ if (abort == true) { return 0; }
+
+ time_t start = time(NULL);
+ size_t numDists = 0;
+
+ if (format == "matrix") {
+ ifstream in;
+ openInputFile(distFileName, in);
+ matrix = new FullMatrix(in); //reads the matrix file
+ in.close();
+
+ //if files don't match...
+ if (matrix->getNumSeqs() < groupMap->getNumSeqs()) {
+ mothurOut("Your distance file contains " + toString(matrix->getNumSeqs()) + " sequences, and your group file contains " + toString(groupMap->getNumSeqs()) + " sequences."); mothurOutEndLine();
+ //create new group file
+ string newGroupFile = getRootName(groupfile) + "editted.groups";
+ ofstream outGroups;
+ openOutputFile(newGroupFile, outGroups);
+
+ for (int i = 0; i < matrix->getNumSeqs(); i++) {
+ Names temp = matrix->getRowInfo(i);
+ outGroups << temp.seqName << '\t' << temp.groupName << endl;
+ }
+ outGroups.close();
+
+ mothurOut(newGroupFile + " is a new group file containing only the sequence that are in your distance file. I will read this file instead."); mothurOutEndLine();
+
+ //read new groupfile
+ delete groupMap; groupMap = NULL;
+ groupfile = newGroupFile;
+ globaldata->setGroupFile(groupfile);
+
+ groupMap = new GroupMap(groupfile);
+ groupMap->readMap();
+
+ globaldata->gGroupmap = groupMap;
+ }
+
+ //memory leak prevention
+ if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix; }
+ globaldata->gMatrix = matrix; //save matrix for coverage commands
+ numDists = matrix->getSizes()[1];
+ } else {
+ read->read(nameMap);
+ //to prevent memory leak
+
+ if (globaldata->gListVector != NULL) { delete globaldata->gListVector; }
+ globaldata->gListVector = read->getListVector();
+
+ if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix; }
+ globaldata->gSparseMatrix = read->getMatrix();
+ numDists = globaldata->gSparseMatrix->getNNodes();
+
+ int lines = cutoff / (1.0/precision);
+ vector<float> dist_cutoff(lines+1,0);
+ for (int i = 0; i <= lines;i++) {
+ dist_cutoff[i] = (i + 0.5) / precision;
+ }
+ vector<int> dist_count(lines+1,0);
+ list<PCell>::iterator currentCell;
+ SparseMatrix* smatrix = globaldata->gSparseMatrix;
+ for (currentCell = smatrix->begin(); currentCell != smatrix->end(); currentCell++) {
+ for (int i = 0; i <= lines;i++) {
+ if (currentCell->dist < dist_cutoff[i]) {
+ dist_count[i]++;
+ break;
+ }
+ }
+ }
+
+ // string dist_string = "Dist:";
+ // string count_string = "Count: ";
+ //for (int i = 0; i <= lines;i++) {
+ //dist_string = dist_string.append("\t").append(toString(dist_cutoff[i]));
+ // count_string = count_string.append("\t").append(toString(dist_count[i]));
+ // }
+ //mothurOut(dist_string); mothurOutEndLine(); mothurOut(count_string); mothurOutEndLine();
+ }
+ mothurOut("It took " + toString(time(NULL) - start) + " secs to read "); mothurOutEndLine();