]> git.donarmstrong.com Git - mothur.git/blobdiff - knn.cpp
added weightedlinkage.cpp
[mothur.git] / knn.cpp
diff --git a/knn.cpp b/knn.cpp
index c11626a082ac9003785fd937e87b922e3bf8025a..beee4aff06b91ff23c55fbc7253c0616b6a7f995 100644 (file)
--- a/knn.cpp
+++ b/knn.cpp
 
 /**************************************************************************************************/
 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)  {}
+: Classify(), num(n)  {
+       try {
+               //create search database and names vector
+               generateDatabaseAndNames(tfile, tempFile, method, kmerSize, gapOpen, gapExtend, match, misMatch);
+       }
+       catch(exception& e) {
+               m->errorOut(e, "Knn", "Knn");
+               exit(1);
+       }
+}
+/**************************************************************************************************/
+Knn::~Knn() {
+       try {
+                delete phyloTree; 
+                if (database != NULL) {  delete database; }
+       }
+       catch(exception& e) {
+               m->errorOut(e, "Knn", "~Knn");
+               exit(1);
+       }
+}
 /**************************************************************************************************/
 string Knn::getTaxonomy(Sequence* seq) {
        try {
                string tax;
                
                //use database to find closest seq
-
                vector<int> closest = database->findClosestSequences(seq, num);
+               
+               if (m->control_pressed) { return tax; }
 
                vector<string> closestNames;
                for (int i = 0; i < closest.size(); i++) {
@@ -59,6 +80,7 @@ string Knn::findCommonTaxonomy(vector<string> closest)  {
                int smallest = 100;
                
                for (int i = 0; i < closest.size(); i++) {
+                       if (m->control_pressed) { return "control"; }
                
                        string tax = taxonomy[closest[i]];  //we know its there since we checked in getTaxonomy
                
@@ -73,6 +95,7 @@ string Knn::findCommonTaxonomy(vector<string> closest)  {
                //start at the highest level all the closest seqs have
                string common = "";
                for (int i = (smallest-1); i >= 0; i--) {
+                       if (m->control_pressed) { return "control"; }
 
                        string thistax = taxons[0][i];
                        int num = 0;