+//**********************************************************************************************************************
+int HeatMapSimCommand::runCommandDist() {
+ try {
+
+ vector< vector<double> > matrix;
+ vector<string> names;
+ ifstream in;
+
+ //read distance file and create distance vector and names vector
+ if (format == "phylip") {
+ //read phylip file
+ openInputFile(phylipfile, in);
+
+ string name;
+ int numSeqs;
+ in >> numSeqs >> name;
+
+ //save name
+ names.push_back(name);
+
+ //resize the matrix and fill with zeros
+ matrix.resize(numSeqs);
+ for(int i = 0; i < numSeqs; i++) {
+ matrix[i].resize(numSeqs, 0.0);
+ }
+
+ //determine if matrix is square or lower triangle
+ //if it is square read the distances for the first sequence
+ char d;
+ bool square;
+ while((d=in.get()) != EOF){
+
+ //is d a number meaning its square
+ if(isalnum(d)){
+ square = true;
+ in.putback(d);
+
+ for(int i=0;i<numSeqs;i++){
+ in >> matrix[0][i];
+ }
+ break;
+ }
+
+ //is d a line return meaning its lower triangle
+ if(d == '\n'){
+ square = false;
+ break;
+ }
+ }
+
+ //read rest of matrix
+ if (square == true) {
+ for(int i=1;i<numSeqs;i++){
+ in >> name;
+ names.push_back(name);
+
+ if (m->control_pressed) { return 0; }
+
+ for(int j=0;j<numSeqs;j++) { in >> matrix[i][j]; }
+ gobble(in);
+ }
+ }else {
+ double dist;
+ for(int i=1;i<numSeqs;i++){
+ in >> name;
+ names.push_back(name);
+
+ if (m->control_pressed) { return 0; }
+
+ for(int j=0;j<i;j++){
+ in >> dist;
+ matrix[i][j] = dist; matrix[j][i] = dist;
+ }
+ gobble(in);
+ }
+ }
+ in.close();
+ }else {
+ //read names file
+ NameAssignment* nameMap = new NameAssignment(namefile);
+ nameMap->readMap();
+
+ //put names in order in vector
+ for (int i = 0; i < nameMap->size(); i++) {
+ names.push_back(nameMap->get(i));
+ }
+
+ //resize matrix
+ matrix.resize(nameMap->size());
+ for (int i = 0; i < nameMap->size(); i++) {
+ matrix[i].resize(nameMap->size(), 0.0);
+ }
+
+ //read column file
+ string first, second;
+ double dist;
+ openInputFile(columnfile, in);
+
+ while (!in.eof()) {
+ in >> first >> second >> dist; gobble(in);
+
+ if (m->control_pressed) { return 0; }
+
+ map<string, int>::iterator itA = nameMap->find(first);
+ map<string, int>::iterator itB = nameMap->find(second);
+
+ if(itA == nameMap->end()){ cerr << "AAError: Sequence '" << first << "' was not found in the names file, please correct\n"; exit(1); }
+ if(itB == nameMap->end()){ cerr << "ABError: Sequence '" << second << "' was not found in the names file, please correct\n"; exit(1); }
+
+ //save distance
+ matrix[itA->second][itB->second] = dist;
+ matrix[itB->second][itA->second] = dist;
+ }
+ in.close();
+
+ delete nameMap;
+ }
+