X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bayesian.cpp;h=af1fa27f2202de76086e562c775229f4f241e387;hb=30f2d98fffb579b870c8969ddcc1dfc61ccbb70a;hp=3a2d3e0156468f1114dd0ebb2d47fe87fe577789;hpb=7b3c9ca940891c1b20b3b7ec13e05d7e7b316b63;p=mothur.git diff --git a/bayesian.cpp b/bayesian.cpp index 3a2d3e0..af1fa27 100644 --- a/bayesian.cpp +++ b/bayesian.cpp @@ -11,8 +11,8 @@ #include "kmer.hpp" /**************************************************************************************************/ -Bayesian::Bayesian(string tfile, string tempFile, string method, int ksize, int cutoff) : -Classify(tfile, tempFile, method, ksize, 0, 0, 0, 0), kmerSize(ksize), confidenceThreshold(cutoff) { +Bayesian::Bayesian(string tfile, string tempFile, string method, int ksize, int cutoff, int i) : +Classify(tfile, tempFile, method, ksize, 0.0, 0.0, 0.0, 0.0), kmerSize(ksize), confidenceThreshold(cutoff), iters(i) { try { numKmers = database->getMaxKmer() + 1; @@ -43,10 +43,10 @@ Classify(tfile, tempFile, method, ksize, 0, 0, 0, 0), kmerSize(ksize), confidenc int start = time(NULL); if(probFileTest && probFileTest2){ - mothurOut("Reading template probabilities... "); cout.flush(); + m->mothurOut("Reading template probabilities... "); cout.flush(); readProbFile(probFileTest, probFileTest2); }else{ - mothurOut("Calculating template probabilities... "); cout.flush(); + m->mothurOut("Calculating template probabilities... "); cout.flush(); ofstream out; openOutputFile(probFileName, out); @@ -56,6 +56,7 @@ Classify(tfile, tempFile, method, ksize, 0, 0, 0, 0), kmerSize(ksize), confidenc //for each word for (int i = 0; i < numKmers; i++) { + if (m->control_pressed) { break; } out << i << '\t'; @@ -88,18 +89,18 @@ Classify(tfile, tempFile, method, ksize, 0, 0, 0, 0), kmerSize(ksize), confidenc } - mothurOut("DONE."); mothurOutEndLine(); - mothurOut("It took " + toString(time(NULL) - start) + " seconds get probabilities. "); mothurOutEndLine(); + m->mothurOut("DONE."); m->mothurOutEndLine(); + m->mothurOut("It took " + toString(time(NULL) - start) + " seconds get probabilities. "); m->mothurOutEndLine(); } catch(exception& e) { - errorOut(e, "Bayesian", "getTaxonomy"); + m->errorOut(e, "Bayesian", "Bayesian"); exit(1); } } /**************************************************************************************************/ string Bayesian::getTaxonomy(Sequence* seq) { try { - string tax; + string tax = ""; Kmer kmer(kmerSize); //get words contained in query @@ -114,15 +115,17 @@ string Bayesian::getTaxonomy(Sequence* seq) { } int index = getMostProbableTaxonomy(queryKmers); + + if (m->control_pressed) { return tax; } //bootstrap - to set confidenceScore int numToSelect = queryKmers.size() / 8; tax = bootstrapResults(queryKmers, index, numToSelect); - + return tax; } catch(exception& e) { - errorOut(e, "Bayesian", "getTaxonomy"); + m->errorOut(e, "Bayesian", "getTaxonomy"); exit(1); } } @@ -142,7 +145,9 @@ string Bayesian::bootstrapResults(vector kmers, int tax, int numToSelect) { map::iterator itBoot2; map::iterator itConvert; - for (int i = 0; i < 100; i++) { + for (int i = 0; i < iters; i++) { + if (m->control_pressed) { return "control"; } + vector temp; for (int j = 0; j < numToSelect; j++) { @@ -185,7 +190,7 @@ string Bayesian::bootstrapResults(vector kmers, int tax, int numToSelect) { } if (confidence >= confidenceThreshold) { - confidenceTax = seqTax.name + "(" + toString(confidence) + ");" + confidenceTax; + confidenceTax = seqTax.name + "(" + toString(((confidence/(float)iters) * 100)) + ");" + confidenceTax; simpleTax = seqTax.name + ";" + simpleTax; } @@ -196,7 +201,7 @@ string Bayesian::bootstrapResults(vector kmers, int tax, int numToSelect) { } catch(exception& e) { - errorOut(e, "Bayesian", "bootstrapResults"); + m->errorOut(e, "Bayesian", "bootstrapResults"); exit(1); } } @@ -225,7 +230,7 @@ int Bayesian::getMostProbableTaxonomy(vector queryKmer) { return indexofGenus; } catch(exception& e) { - errorOut(e, "Bayesian", "getMostProbableTaxonomy"); + m->errorOut(e, "Bayesian", "getMostProbableTaxonomy"); exit(1); } } @@ -252,7 +257,7 @@ map Bayesian::parseTaxMap(string newTax) { } catch(exception& e) { - errorOut(e, "Bayesian", "parseTax"); + m->errorOut(e, "Bayesian", "parseTax"); exit(1); } } @@ -291,7 +296,7 @@ void Bayesian::readProbFile(ifstream& in, ifstream& inNum) { in.close(); } catch(exception& e) { - errorOut(e, "Bayesian", "readProbFile"); + m->errorOut(e, "Bayesian", "readProbFile"); exit(1); } }