+//**********************************************************************************************************************
+int GetOTURepCommand::readDist() {
+ try {
+
+ if (!large) {
+ //read distance files
+ if (format == "column") { readMatrix = new ReadColumnMatrix(distFile); }
+ else if (format == "phylip") { readMatrix = new ReadPhylipMatrix(distFile); }
+ else { m->mothurOut("File format error."); m->mothurOutEndLine(); return 0; }
+
+ readMatrix->setCutoff(cutoff);
+
+ NameAssignment* nameMap = NULL;
+ if(namefile != ""){
+ nameMap = new NameAssignment(namefile);
+ nameMap->readMap();
+ readMatrix->read(nameMap);
+ }else if (countfile != "") {
+ readMatrix->read(&ct);
+ }else {
+ readMatrix->read(nameMap);
+ }
+
+ if (m->control_pressed) { delete readMatrix; return 0; }
+
+ list = readMatrix->getListVector();
+ SparseDistanceMatrix* matrix = readMatrix->getDMatrix();
+
+ // Create a data structure to quickly access the distance information.
+ // It consists of a vector of distance maps, where each map contains
+ // all distances of a certain sequence. Vector and maps are accessed
+ // via the index of a sequence in the distance matrix
+ seqVec = vector<SeqMap>(list->size());
+ for (int i = 0; i < matrix->seqVec.size(); i++) {
+ for (int j = 0; j < matrix->seqVec[i].size(); j++) {
+ if (m->control_pressed) { delete readMatrix; return 0; }
+ //already added everyone else in row
+ if (i < matrix->seqVec[i][j].index) { seqVec[i][matrix->seqVec[i][j].index] = matrix->seqVec[i][j].dist; }
+ }
+ }
+ //add dummy map for unweighted calc
+ SeqMap dummy;
+ seqVec.push_back(dummy);
+
+ delete matrix;
+ delete readMatrix;
+ delete nameMap;
+
+ if (m->control_pressed) { return 0; }
+ }else {
+ //process file and set up indexes
+ if (format == "column") { formatMatrix = new FormatColumnMatrix(distFile); }
+ else if (format == "phylip") { formatMatrix = new FormatPhylipMatrix(distFile); }
+ else { m->mothurOut("File format error."); m->mothurOutEndLine(); return 0; }
+
+ formatMatrix->setCutoff(cutoff);
+
+ NameAssignment* nameMap = NULL;
+ if(namefile != ""){
+ nameMap = new NameAssignment(namefile);
+ nameMap->readMap();
+ formatMatrix->read(nameMap);
+ }else if (countfile != "") {
+ formatMatrix->read(&ct);
+ }else {
+ formatMatrix->read(nameMap);
+ }
+
+ if (m->control_pressed) { delete formatMatrix; return 0; }
+
+ list = formatMatrix->getListVector();
+ distFile = formatMatrix->getFormattedFileName();
+
+ //positions in file where the distances for each sequence begin
+ //rowPositions[1] = position in file where distance related to sequence 1 start.
+ rowPositions = formatMatrix->getRowPositions();
+ rowPositions.push_back(-1); //dummy row for unweighted calc
+
+ delete formatMatrix;
+ delete nameMap;
+
+ //openfile for getMap to use
+ m->openInputFile(distFile, inRow);
+
+ if (m->control_pressed) { inRow.close(); m->mothurRemove(distFile); return 0; }
+ }
+
+
+ //list bin 0 = first name read in distance matrix, list bin 1 = second name read in distance matrix
+ if (list != NULL) {
+ vector<string> names;
+ string binnames;
+ //map names to rows in sparsematrix
+ for (int i = 0; i < list->size(); i++) {
+ names.clear();
+ binnames = list->get(i);
+
+ m->splitAtComma(binnames, names);
+
+ for (int j = 0; j < names.size(); j++) {
+ nameToIndex[names[j]] = i;
+ }
+ }
+ } else { m->mothurOut("error, no listvector."); m->mothurOutEndLine(); }