X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=knn.cpp;h=1835c48f802b861f29a6a6c2360a47788d13bc46;hb=cdf9083dc32543cc640e72e9ca3aee0323cbad45;hp=93a7aa33faa6e2e1d9cb43c0505464056cbb1f08;hpb=aa9238c0a9e6e7aa0ed8b8b606b08ad4fd7dcfe3;p=mothur.git diff --git a/knn.cpp b/knn.cpp index 93a7aa3..1835c48 100644 --- a/knn.cpp +++ b/knn.cpp @@ -11,16 +11,51 @@ /**************************************************************************************************/ 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), search(method) { + 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); + } +} +/**************************************************************************************************/ +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; + 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 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;