X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=clustercommand.cpp;h=6df5faad98cd9a0cd1a78644794cecc3eef0df7d;hb=7ae40733a270f73ec8a331540cc7f28fd60b24fc;hp=9ed67e04433edecd93262c1824732edbb3cd186c;hpb=dabb32850eae34e26b066a7da55716ad685786a3;p=mothur.git diff --git a/clustercommand.cpp b/clustercommand.cpp index 9ed67e0..6df5faa 100644 --- a/clustercommand.cpp +++ b/clustercommand.cpp @@ -57,18 +57,18 @@ ClusterCommand::ClusterCommand(string option) { convert(temp, precision); temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "F"; } - hard = isTrue(temp); + hard = m->isTrue(temp); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "10"; } convert(temp, cutoff); - if (!hard) { cutoff += (5 / (precision * 10.0)); } + cutoff += (5 / (precision * 10.0)); method = validParameter.validFile(parameters, "method", false); if (method == "not found") { method = "furthest"; } - if ((method == "furthest") || (method == "nearest") || (method == "average")) { } - else { m->mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average."); m->mothurOutEndLine(); abort = true; } + if ((method == "furthest") || (method == "nearest") || (method == "average") || (method == "weighted")) { } + else { m->mothurOut("Not a valid clustering method. Valid clustering algorithms are furthest, nearest, average, and weighted."); m->mothurOutEndLine(); abort = true; } showabund = validParameter.validFile(parameters, "showabund", false); if (showabund == "not found") { showabund = "T"; } @@ -91,14 +91,15 @@ ClusterCommand::ClusterCommand(string option) { if (method == "furthest") { cluster = new CompleteLinkage(rabund, list, matrix, cutoff, method); } else if(method == "nearest"){ cluster = new SingleLinkage(rabund, list, matrix, cutoff, method); } else if(method == "average"){ cluster = new AverageLinkage(rabund, list, matrix, cutoff, method); } + else if(method == "weighted"){ cluster = new WeightedLinkage(rabund, list, matrix, cutoff, method); } tag = cluster->getTag(); - if (outputDir == "") { outputDir += hasPath(globaldata->inputFileName); } - fileroot = outputDir + getRootName(getSimpleName(globaldata->inputFileName)); + if (outputDir == "") { outputDir += m->hasPath(globaldata->inputFileName); } + fileroot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)); - openOutputFile(fileroot+ tag + ".sabund", sabundFile); - openOutputFile(fileroot+ tag + ".rabund", rabundFile); - openOutputFile(fileroot+ tag + ".list", listFile); + m->openOutputFile(fileroot+ tag + ".sabund", sabundFile); + m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); + m->openOutputFile(fileroot+ tag + ".list", listFile); outputNames.push_back(fileroot+ tag + ".sabund"); outputNames.push_back(fileroot+ tag + ".rabund"); @@ -168,9 +169,9 @@ int ClusterCommand::execute(){ return 0; } - if (print_start && isTrue(timing)) { + if (print_start && m->isTrue(timing)) { m->mothurOut("Clustering (" + tag + ") dist " + toString(matrix->getSmallDist()) + "/" - + toString(roundDist(matrix->getSmallDist(), precision)) + + toString(m->roundDist(matrix->getSmallDist(), precision)) + "\t(precision: " + toString(precision) + ", Nodes: " + toString(matrix->getNNodes()) + ")"); cout.flush(); print_start = false; @@ -181,7 +182,12 @@ int ClusterCommand::execute(){ cluster->update(cutoff); float dist = matrix->getSmallDist(); - float rndDist = roundDist(dist, precision); + float rndDist; + if (hard) { + rndDist = m->ceilDist(dist, precision); + }else{ + rndDist = m->roundDist(dist, precision); + } if(previousDist <= 0.0000 && dist != previousDist){ printData("unique"); @@ -196,7 +202,7 @@ int ClusterCommand::execute(){ oldList = *list; } - if (print_start && isTrue(timing)) { + if (print_start && m->isTrue(timing)) { m->mothurOut("Clustering (" + tag + ") for distance " + toString(previousDist) + "/" + toString(rndPreviousDist) + "\t(precision: " + toString(precision) + ", Nodes: " + toString(matrix->getNNodes()) + ")"); cout.flush(); @@ -226,7 +232,12 @@ int ClusterCommand::execute(){ rabundFile.close(); listFile.close(); - if (saveCutoff != cutoff) { m->mothurOut("changed cutoff to " + toString(cutoff)); m->mothurOutEndLine(); } + if (saveCutoff != cutoff) { + if (hard) { saveCutoff = m->ceilDist(saveCutoff, precision); } + else { saveCutoff = m->roundDist(saveCutoff, precision); } + + m->mothurOut("changed cutoff to " + toString(cutoff)); m->mothurOutEndLine(); + } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine(); @@ -234,7 +245,7 @@ int ClusterCommand::execute(){ m->mothurOutEndLine(); - //if (isTrue(timing)) { + //if (m->isTrue(timing)) { m->mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster"); m->mothurOutEndLine(); //} @@ -251,7 +262,7 @@ int ClusterCommand::execute(){ void ClusterCommand::printData(string label){ try { - if (isTrue(timing)) { + if (m->isTrue(timing)) { m->mothurOut("\tTime: " + toString(time(NULL) - start) + "\tsecs for " + toString(oldRAbund.getNumBins()) + "\tclusters. Updates: " + toString(loops)); m->mothurOutEndLine(); } @@ -260,7 +271,7 @@ void ClusterCommand::printData(string label){ start = time(NULL); oldRAbund.setLabel(label); - if (isTrue(showabund)) { + if (m->isTrue(showabund)) { oldRAbund.getSAbundVector().print(cout); } oldRAbund.print(rabundFile);