]> git.donarmstrong.com Git - mothur.git/blobdiff - knn.cpp
added versioning info to all shortcut files mothur makes.
[mothur.git] / knn.cpp
diff --git a/knn.cpp b/knn.cpp
index beee4aff06b91ff23c55fbc7253c0616b6a7f995..a8430723fdd653899e9239b22adaa941af113012 100644 (file)
--- a/knn.cpp
+++ b/knn.cpp
@@ -11,7 +11,7 @@
 
 /**************************************************************************************************/
 Knn::Knn(string tfile, string tempFile, string method, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch, int n) 
-: Classify(), num(n)  {
+: Classify(), num(n), search(method) {
        try {
                //create search database and names vector
                generateDatabaseAndNames(tfile, tempFile, method, kmerSize, gapOpen, gapExtend, match, misMatch);
@@ -22,6 +22,20 @@ Knn::Knn(string tfile, string tempFile, string method, int kmerSize, float gapOp
        }
 }
 /**************************************************************************************************/
+void Knn::setDistName(string s) {
+       try {
+               outDistName = s;
+               ofstream outDistance;
+               openOutputFile(outDistName, outDistance);
+               outDistance << "Name\tBestMatch\tDistance" << endl;
+               outDistance.close();
+       }
+       catch(exception& e) {
+               m->errorOut(e, "Knn", "setDistName");
+               exit(1);
+       }
+}
+/**************************************************************************************************/
 Knn::~Knn() {
        try {
                 delete phyloTree; 
@@ -39,7 +53,9 @@ string Knn::getTaxonomy(Sequence* seq) {
                
                //use database to find closest seq
                vector<int> closest = database->findClosestSequences(seq, num);
-               
+       
+               if (search == "distance") { ofstream outDistance; openOutputFileAppend(outDistName, outDistance); outDistance << seq->getName() << '\t' << database->getName(closest[0]) << '\t' << database->getSearchScore() << endl; outDistance.close();  }
+       
                if (m->control_pressed) { return tax; }
 
                vector<string> closestNames;