]> git.donarmstrong.com Git - mothur.git/blobdiff - distancedb.cpp
changes while testing
[mothur.git] / distancedb.cpp
index b5c22b35bf7a58addcff79651e6841b9506ec8e2..27e278574493c89d0197d99cbe71c0c3dd03d0d9 100644 (file)
 #include "database.hpp"
 #include "sequence.hpp"
 #include "distancedb.hpp"
-#include "eachgapdist.h"
+#include "onegapignore.h"
+
 
 /**************************************************************************************************/
-DistanceDB::DistanceDB() { 
+DistanceDB::DistanceDB() : Database() 
        try {
                templateAligned = true;  
                templateSeqsLength = 0; 
-               distCalculator = new eachGapDist();
+               distCalculator = new oneGapIgnoreTermGapDist();
        }
        catch(exception& e) {
                m->errorOut(e, "DistanceDB", "DistanceDB");
@@ -29,7 +30,11 @@ DistanceDB::DistanceDB() {
 void DistanceDB::addSequence(Sequence seq) {
        try {
                //are the template sequences aligned
-               if (!isAligned(seq.getAligned())) { templateAligned = false; m->mothurOut(seq.getName() + " is not aligned. Sequences must be aligned to use the distance method."); m->mothurOutEndLine(); }
+               if (!isAligned(seq.getAligned())) {
+                       templateAligned = false;
+                       m->mothurOut(seq.getName() + " is not aligned. Sequences must be aligned to use the distance method.");
+                       m->mothurOutEndLine(); 
+               }
                
                if (templateSeqsLength == 0) { templateSeqsLength = seq.getAligned().length(); }
                                
@@ -45,13 +50,18 @@ void DistanceDB::addSequence(Sequence seq) {
 vector<int> DistanceDB::findClosestSequences(Sequence* query, int numWanted){
        try {
                vector<int> topMatches;
+               Scores.clear();
                bool templateSameLength = true;
                string sequence = query->getAligned();
                vector<seqDist> dists; 
                
                searchScore = -1.0;
        
-               if (numWanted > data.size()) { m->mothurOut("numwanted is larger than the number of template sequences, using "+ toString(data.size()) + "."); m->mothurOutEndLine(); numWanted = data.size(); }
+               if (numWanted > data.size()){
+                       m->mothurOut("numwanted is larger than the number of template sequences, using "+ toString(data.size()) + ".");
+                       m->mothurOutEndLine();
+                       numWanted = data.size();
+               }
                
                if (sequence.length() != templateSeqsLength) { templateSameLength = false; }
                
@@ -79,6 +89,7 @@ vector<int> DistanceDB::findClosestSequences(Sequence* query, int numWanted){
                                //fill topmatches with numwanted closest sequences indexes
                                for (int i = 0; i < numWanted; i++) {
                                        topMatches.push_back(dists[i].seq2);
+                                       Scores.push_back(dists[i].dist);
                                }
                        }else {
                                int bestIndex = 0;
@@ -93,13 +104,14 @@ vector<int> DistanceDB::findClosestSequences(Sequence* query, int numWanted){
                                                smallDist = dist;
                                        }
                                }
-                               
                                searchScore = smallDist;
                                topMatches.push_back(bestIndex);
+                               Scores.push_back(smallDist);
                        }
                
                }else{
-                       m->mothurOut("cannot find closest matches using distance method for " + query->getName() + " without aligned template sequences of the same length."); m->mothurOutEndLine();
+                       m->mothurOut("cannot find closest matches using distance method for " + query->getName() + " without aligned template sequences of the same length.");
+                       m->mothurOutEndLine();
                        exit(1);
                }