Permalink
Browse files

Fixes negative values and delta issue opticluster

  • Loading branch information...
1 parent 4199174 commit ef324c8bd74cfe8034df13bbad8f5d651478b6d1 @mothur-westcott mothur-westcott committed Aug 11, 2016
Showing with 25 additions and 15 deletions.
  1. +21 −11 source/commands/clustercommand.cpp
  2. +4 −4 source/opticluster.cpp
@@ -81,6 +81,7 @@ string ClusterCommand::getOutputPattern(string type) {
else if (type == "rabund") { pattern = "[filename],[clustertag],rabund"; }
else if (type == "sabund") { pattern = "[filename],[clustertag],sabund"; }
else if (type == "sensspec") { pattern = "[filename],[clustertag],sensspec"; }
+ else if (type == "steps") { pattern = "[filename],[clustertag],steps"; }
else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
return pattern;
@@ -100,6 +101,7 @@ ClusterCommand::ClusterCommand(){
outputTypes["sensspec"] = tempOutNames;
outputTypes["rabund"] = tempOutNames;
outputTypes["sabund"] = tempOutNames;
+ outputTypes["steps"] = tempOutNames;
}
catch(exception& e) {
m->errorOut(e, "ClusterCommand", "ClusterCommand");
@@ -138,6 +140,7 @@ ClusterCommand::ClusterCommand(string option) {
outputTypes["sensspec"] = tempOutNames;
outputTypes["rabund"] = tempOutNames;
outputTypes["sabund"] = tempOutNames;
+ outputTypes["steps"] = tempOutNames;
//if the user changes the output directory command factory will send this info to us in the output parameter
outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
@@ -862,17 +865,28 @@ int ClusterCommand::runOptiCluster(){
m->openOutputFile(listFileName, listFile);
outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName);
+ map<string, string> variables;
+ variables["[filename]"] = fileroot;
+ variables["[clustertag]"] = tag;
+ string outputName = getOutputFileName("steps", variables);
+ outputNames.push_back(outputName); outputTypes["steps"].push_back(outputName);
+ ofstream outStep;
+ m->openOutputFile(outputName, outStep);
+
int iters = 0;
double listVectorMetric = 0; //worst state
double delta = 1;
cluster.initialize(listVectorMetric, true);
m->mothurOut("\n\niter\tlabel\tcutoff\ttp\ttn\tfp\tfn\tsensitivity\tspecificity\tppv\tnpv\tfdr\taccuracy\tmcc\tf1score\n");
+ outStep << "iter\tlabel\tcutoff\ttp\ttn\tfp\tfn\tsensitivity\tspecificity\tppv\tnpv\tfdr\taccuracy\tmcc\tf1score\n";
vector<double> results = cluster.getStats();
- m->mothurOut("Initial Randomization\t" + toString(cutoff) + "\t" + toString(cutoff) + "\t");
- for (int i = 0; i < results.size(); i++) { m->mothurOut(toString(results[i]) + "\t"); }
+ m->mothurOut("0\t" + toString(cutoff) + "\t" + toString(cutoff) + "\t");
+ outStep << "0\t" + toString(cutoff) + "\t" + toString(cutoff) + "\t";
+ for (int i = 0; i < results.size(); i++) { m->mothurOut(toString(results[i]) + "\t"); outStep << results[i] << "\t"; }
m->mothurOutEndLine();
+ outStep << endl;
while ((delta > stableMetric) && (iters < maxIters)) {
@@ -886,14 +900,11 @@ int ClusterCommand::runOptiCluster(){
results = cluster.getStats();
- bool stop = false;
- for (int i = 0; i < results.size(); i++) { if (results[i] < 0) { stop = true; } }
- if (!stop) {
- m->mothurOut(toString(iters) + "\t" + toString(cutoff) + "\t" + toString(cutoff) + "\t");
- for (int i = 0; i < results.size(); i++) { m->mothurOut(toString(results[i]) + "\t"); }
- m->mothurOutEndLine();
- }else { break; }
-
+ m->mothurOut(toString(iters) + "\t" + toString(cutoff) + "\t" + toString(cutoff) + "\t");
+ outStep << (toString(iters) + "\t" + toString(cutoff) + "\t" + toString(cutoff) + "\t");
+ for (int i = 0; i < results.size(); i++) { m->mothurOut(toString(results[i]) + "\t"); outStep << results[i] << "\t"; }
+ m->mothurOutEndLine();
+ outStep << endl;
}
m->mothurOutEndLine(); m->mothurOutEndLine();
@@ -904,7 +915,6 @@ int ClusterCommand::runOptiCluster(){
else { list->print(listFile); }
listFile.close();
- map<string, string> variables;
variables["[filename]"] = fileroot;
variables["[clustertag]"] = tag;
string sabundFileName = getOutputFileName("sabund", variables);
View
@@ -175,14 +175,14 @@ bool OptiCluster::update(double& listMetric) {
//choose "best" otu - which is highest value or last item in map. - shuffle for ties
random_shuffle(bestMetricsTPValues.begin(), bestMetricsTPValues.end());
int bestBin = bestMetricsTPValues[0][0];
- truePositives = bestMetricsTPValues[0][1];
- trueNegatives = bestMetricsTPValues[0][2];
- falsePositives = bestMetricsTPValues[0][3];
- falseNegatives = bestMetricsTPValues[0][4];
if (bestBin == -1) { bestBin = insertLocation; }
if (bestBin != binNumber) {
+ truePositives = bestMetricsTPValues[0][1];
+ trueNegatives = bestMetricsTPValues[0][2];
+ falsePositives = bestMetricsTPValues[0][3];
+ falseNegatives = bestMetricsTPValues[0][4];
//move seq from i to j
bins[bestBin].push_back(seqNumber); //add seq to bestbin
bins[binNumber].erase(remove(bins[binNumber].begin(), bins[binNumber].end(), seqNumber), bins[binNumber].end()); //remove from old bin i

0 comments on commit ef324c8

Please sign in to comment.