X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=knn.cpp;h=1835c48f802b861f29a6a6c2360a47788d13bc46;hb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6;hp=beee4aff06b91ff23c55fbc7253c0616b6a7f995;hpb=4a2d841cb97fb02351022efe9d7068b1dc212bf9;p=mothur.git diff --git a/knn.cpp b/knn.cpp index beee4af..1835c48 100644 --- 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; + m->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 closest = database->findClosestSequences(seq, num); - + + if (search == "distance") { ofstream outDistance; m->openOutputFileAppend(outDistName, outDistance); outDistance << seq->getName() << '\t' << database->getName(closest[0]) << '\t' << database->getSearchScore() << endl; outDistance.close(); } + if (m->control_pressed) { return tax; } vector closestNames;