]> git.donarmstrong.com Git - mothur.git/blobdiff - knn.cpp
created mothurOut class to handle logfiles
[mothur.git] / knn.cpp
diff --git a/knn.cpp b/knn.cpp
index 6d57fb135f14398fb6b7ab776eb81e84e4728406..c11626a082ac9003785fd937e87b922e3bf8025a 100644 (file)
--- a/knn.cpp
+++ b/knn.cpp
@@ -10,7 +10,7 @@
 #include "knn.h"
 
 /**************************************************************************************************/
-Knn::Knn(string tfile, string tempFile, string method, int kmerSize, int gapOpen, int gapExtend, int match, int misMatch, int n) 
+Knn::Knn(string tfile, string tempFile, string method, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch, int n) 
 : Classify(tfile, tempFile, method, kmerSize, gapOpen, gapExtend, match, misMatch), num(n)  {}
 /**************************************************************************************************/
 string Knn::getTaxonomy(Sequence* seq) {
@@ -18,8 +18,9 @@ string Knn::getTaxonomy(Sequence* seq) {
                string tax;
                
                //use database to find closest seq
+
                vector<int> closest = database->findClosestSequences(seq, num);
-               
+
                vector<string> closestNames;
                for (int i = 0; i < closest.size(); i++) {
                        //find that sequences taxonomy in map
@@ -27,22 +28,23 @@ string Knn::getTaxonomy(Sequence* seq) {
                
                        //is this sequence in the taxonomy file
                        if (it == taxonomy.end()) { //error not in file
-                               mothurOut("Error: sequence " + names[closest[i]] + " is not in the taxonomy file.  It will be eliminated as a match to sequence " + seq->getName() + "."); mothurOutEndLine();
+                               m->mothurOut("Error: sequence " + names[closest[i]] + " is not in the taxonomy file.  It will be eliminated as a match to sequence " + seq->getName() + "."); m->mothurOutEndLine();
                        }else{   closestNames.push_back(it->first);     }
                }
                
                if (closestNames.size() == 0) {
-                       mothurOut("Error: All the matches for sequence " + seq->getName() + " have been eliminated. " + seq->getName() + " will be disregarded."); mothurOutEndLine();
+                       m->mothurOut("Error: All the matches for sequence " + seq->getName() + " have been eliminated. " + seq->getName() + " will be disregarded."); m->mothurOutEndLine();
                        tax = "bad seq";
                }else{
                        tax = findCommonTaxonomy(closestNames);
-                       if (tax == "") { mothurOut("There are no common levels for sequence " + seq->getName() + ". " + seq->getName() + " will be disregarded."); mothurOutEndLine(); tax = "bad seq"; }
+                       if (tax == "") { m->mothurOut("There are no common levels for sequence " + seq->getName() + ". " + seq->getName() + " will be disregarded."); m->mothurOutEndLine(); tax = "bad seq"; }
                }
                
+               simpleTax = tax;
                return tax;     
        }
        catch(exception& e) {
-               errorOut(e, "Knn", "getTaxonomy");
+               m->errorOut(e, "Knn", "getTaxonomy");
                exit(1);
        }
 }
@@ -60,18 +62,7 @@ string Knn::findCommonTaxonomy(vector<string> closest)  {
                
                        string tax = taxonomy[closest[i]];  //we know its there since we checked in getTaxonomy
                
-                       tax = tax.substr(0, tax.length()-1);  //get rid of last ';'
-       
-                       //parse taxonomy
-                       string individual;
-                       while (tax.find_first_of(';') != -1) {
-                               individual = tax.substr(0,tax.find_first_of(';'));
-                               tax = tax.substr(tax.find_first_of(';')+1, tax.length());
-                               taxons[i].push_back(individual);
-                       
-                       }
-                       //get last one
-                       taxons[i].push_back(tax);
+                       taxons[i] = parseTax(tax);
                
                        //figure out who has the shortest taxonomy info. so you can start comparing there
                        if (taxons[i].size() < smallest) {
@@ -101,7 +92,7 @@ string Knn::findCommonTaxonomy(vector<string> closest)  {
                return common;
        }
        catch(exception& e) {
-               errorOut(e, "Knn", "findCommonTaxonomy");
+               m->errorOut(e, "Knn", "findCommonTaxonomy");
                exit(1);
        }
 }