-
- //map location of name in names1 to location of name in names2
- map<string, int> names1Map;
- map<string, int>::iterator it;
- for (int i = 0; i < names1.size(); i++) { names1Map[names1[i]] = i; }
-
- map<string, int> names2Map;
- bool nameError = false;
- for (int i = 0; i < names2.size(); i++) {
-
- //if you find one name error stop looking
- if (!nameError) {
- it = names1Map.find(names2[i]);
- if (it == names1Map.end()) { nameError = true; }
- }
-
- //are names different
- names2Map[names2[i]] = i;
- }
-
- //initialize space
- matrix2.resize(names2.size());
- for (int i = 0; i < matrix2.size(); i++) { matrix2[i].resize(names2.size(), 0.0); }
-
- //fill matrix2
- //are we comparing apples to apples?
- if (nameError) {
- m->mothurOut("[WARNING]: Names do not match between distance files. Comparing based on order in files."); m->mothurOutEndLine();
-
- for (int i = 0; i < temp.size(); i++) {
- matrix2[temp[i].seq1][temp[i].seq2] = temp[i].dist;
- matrix2[temp[i].seq2][temp[i].seq1] = temp[i].dist;
- }
-
- }else { //no name error just different orders, so reorder
-
- for (int i = 0; i < temp.size(); i++) {
-
- //what's the location of this distance comparison in matrix1
- string matrix2NameI = names2[temp[i].seq1];
- string matrix2NameJ = names2[temp[i].seq2];
- int locationI = names1Map[matrix2NameI];
- int locationJ = names1Map[matrix2NameJ];
-
- matrix2[locationI][locationJ] = temp[i].dist;
- matrix2[locationJ][locationI] = temp[i].dist;
- }
- }
-
- }
-
- //frees up space
- temp.clear();