+ //merge results
+ map<string, string> seen;
+ map<string, string>::iterator it;
+
+ vector<SeqDist> dists;
+ float lastRight = distsRight[0].dist;
+ float lastLeft = distsLeft[0].dist;
+ //int lasti = 0;
+ for (int i = 0; i < numWanted+1; i++) {
+
+ if (m->control_pressed) { return seqsMatches; }
+
+ //add left if you havent already
+ it = seen.find(thisTemplate[distsLeft[i].index]->getName());
+ if (it == seen.end()) {
+ dists.push_back(distsLeft[i]);
+ seen[thisTemplate[distsLeft[i].index]->getName()] = thisTemplate[distsLeft[i].index]->getName();
+ lastLeft = distsLeft[i].dist;
+// cout << "loop-left\t" << db[distsLeft[i].index]->getName() << '\t' << distsLeft[i].dist << endl;
+ }
+
+ //add right if you havent already
+ it = seen.find(thisTemplate[distsRight[i].index]->getName());
+ if (it == seen.end()) {
+ dists.push_back(distsRight[i]);
+ seen[thisTemplate[distsRight[i].index]->getName()] = thisTemplate[distsRight[i].index]->getName();
+ lastRight = distsRight[i].dist;
+// cout << "loop-right\t" << db[distsRight[i].index]->getName() << '\t' << distsRight[i].dist << endl;
+ }
+
+ }
+
+ //are we still above the minimum similarity cutoff
+ if ((lastLeft >= minSim) || (lastRight >= minSim)) {
+ //add in ties from left
+ int i = numWanted;
+ while (i < distsLeft.size()) {
+ if (distsLeft[i].dist == lastLeft) { dists.push_back(distsLeft[i]); }
+ else { break; }
+ i++;
+ }
+
+ //add in ties from right
+ i = numWanted;
+ while (i < distsRight.size()) {
+ if (distsRight[i].dist == lastRight) { dists.push_back(distsRight[i]); }
+ else { break; }
+ i++;
+ }
+ }
+
+
+
+ //cout << numWanted << endl;
+ for (int i = 0; i < dists.size(); i++) {
+// cout << db[dists[i].index]->getName() << '\t' << dists[i].dist << endl;
+
+ if ((thisTemplate[dists[i].index]->getName() != querySeq->getName()) && (dists[i].dist >= minSim)) {
+ Sequence* temp = new Sequence(thisTemplate[dists[i].index]->getName(), thisTemplate[dists[i].index]->getAligned()); //have to make a copy so you can trim and filter without stepping on eachother.
+
+ seqsMatches.push_back(temp);
+ }
+