]> git.donarmstrong.com Git - mothur.git/blobdiff - distancedb.cpp
added template=self capability to chimers.slayer, worked on corr.axes and added accno...
[mothur.git] / distancedb.cpp
index 25641eb0dacdf63d812cd1bf2a828a7cdfd5f8d2..ca6ffe8ba61217ac0b66b353e8f33461f4916e52 100644 (file)
@@ -21,7 +21,7 @@ DistanceDB::DistanceDB() {
                distCalculator = new eachGapDist();
        }
        catch(exception& e) {
-               errorOut(e, "DistanceDB", "DistanceDB");
+               m->errorOut(e, "DistanceDB", "DistanceDB");
                exit(1);
        }       
 }
@@ -29,14 +29,14 @@ DistanceDB::DistanceDB() {
 void DistanceDB::addSequence(Sequence seq) {
        try {
                //are the template sequences aligned
-               if (!isAligned(seq.getAligned())) { templateAligned = false; mothurOut(seq.getName() + " is not aligned. Sequences must be aligned to use the distance method."); 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(); }
                                
                data.push_back(seq);
        }
        catch(exception& e) {
-               errorOut(e, "DistanceDB", "addSequence");
+               m->errorOut(e, "DistanceDB", "addSequence");
                exit(1);
        }       
 }
@@ -49,7 +49,9 @@ vector<int> DistanceDB::findClosestSequences(Sequence* query, int numWanted){
                string sequence = query->getAligned();
                vector<seqDist> dists;
                
-               if (numWanted > data.size()) { mothurOut("numwanted is larger than the number of template sequences, using 10."); mothurOutEndLine(); numWanted = 10; }
+               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 (sequence.length() != templateSeqsLength) { templateSameLength = false; }
                
@@ -66,20 +68,23 @@ vector<int> DistanceDB::findClosestSequences(Sequence* query, int numWanted){
                        
                        sort(dists.begin(), dists.end(), compareSequenceDistance);  //sorts by distance lowest to highest
                        
+                       //save distance of best match
+                       searchScore = dists[0].dist;
+                       
                        //fill topmatches with numwanted closest sequences indexes
                        for (int i = 0; i < numWanted; i++) {
                                topMatches.push_back(dists[i].seq2);
                        }
                
                }else{
-                       mothurOut("cannot find closest matches using distance method for " + query->getName() + " without aligned template sequences of the same length."); 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);
                }
                
                return topMatches;
        }
        catch(exception& e) {
-               errorOut(e, "DistanceDB", "findClosestSequence");
+               m->errorOut(e, "DistanceDB", "findClosestSequence");
                exit(1);
        }       
 }
@@ -98,7 +103,7 @@ bool DistanceDB::isAligned(string seq){
                return aligned;
        }
        catch(exception& e) {
-               errorOut(e, "DistanceDB", "isAligned");
+               m->errorOut(e, "DistanceDB", "isAligned");
                exit(1);
        }       
 }