X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=hclustercommand.cpp;h=cf35cd9d6fa4c2a8fe1349b63399eb60007a4217;hb=c7e8c2d15bd7cedcfdf18675cb0ea1a0dcd0e3c0;hp=d98f5c69926f795cb75510853184197676647ab9;hpb=7bf9a81bba76538ecaf351ae208de3da4bf1b6dd;p=mothur.git diff --git a/hclustercommand.cpp b/hclustercommand.cpp index d98f5c6..cf35cd9 100644 --- a/hclustercommand.cpp +++ b/hclustercommand.cpp @@ -52,6 +52,28 @@ string HClusterCommand::getHelpString(){ } } //********************************************************************************************************************** +string HClusterCommand::getOutputFileNameTag(string type, string inputName=""){ + try { + string outputFileName = ""; + map >::iterator it; + + //is this a type this command creates + it = outputTypes.find(type); + if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } + else { + if (type == "list") { outputFileName = "list"; } + else if (type == "rabund") { outputFileName = "rabund"; } + else if (type == "sabund") { outputFileName = "sabund"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } + } + return outputFileName; + } + catch(exception& e) { + m->errorOut(e, "HClusterCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** HClusterCommand::HClusterCommand(){ try { abort = true; calledHelp = true; @@ -182,14 +204,14 @@ HClusterCommand::HClusterCommand(string option) { if (temp == "not found") { temp = "100"; } //saves precision legnth for formatting below length = temp.length(); - convert(temp, precision); + m->mothurConvert(temp, precision); temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "T"; } hard = m->isTrue(temp); temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "10"; } - convert(temp, cutoff); + m->mothurConvert(temp, cutoff); cutoff += (5 / (precision * 10.0)); method = validParameter.validFile(parameters, "method", false); @@ -219,13 +241,17 @@ HClusterCommand::HClusterCommand(string option) { else if (method == "weighted") { tag = "wn"; } else { tag = "an"; } - m->openOutputFile(fileroot+ tag + ".sabund", sabundFile); - m->openOutputFile(fileroot+ tag + ".rabund", rabundFile); - m->openOutputFile(fileroot+ tag + ".list", listFile); - - outputNames.push_back(fileroot+ tag + ".sabund"); outputTypes["sabund"].push_back(fileroot+ tag + ".sabund"); - outputNames.push_back(fileroot+ tag + ".rabund"); outputTypes["rabund"].push_back(fileroot+ tag + ".rabund"); - outputNames.push_back(fileroot+ tag + ".list"); outputTypes["list"].push_back(fileroot+ tag + ".list"); + string sabundFileName = fileroot+ tag + "." + getOutputFileNameTag("sabund"); + string rabundFileName = fileroot+ tag + "." + getOutputFileNameTag("rabund"); + string listFileName = fileroot+ tag + "." + getOutputFileNameTag("list"); + + m->openOutputFile(sabundFileName, sabundFile); + m->openOutputFile(rabundFileName, rabundFile); + m->openOutputFile(listFileName, listFile); + + outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName); + outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName); + outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName); } } } @@ -260,7 +286,7 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -276,7 +302,7 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -306,35 +332,41 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } + float saveCutoff = cutoff; while (seqs.size() != 0){ seqs = cluster->getSeqs(); + //to account for cutoff change in average neighbor + if (seqs.size() != 0) { + if (seqs[0].dist > cutoff) { break; } + } + if (m->control_pressed) { delete cluster; sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } for (int i = 0; i < seqs.size(); i++) { //-1 means skip me if (seqs[i].seq1 != seqs[i].seq2) { - cluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist); + cutoff = cluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist); if (m->control_pressed) { delete cluster; sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -367,7 +399,7 @@ int HClusterCommand::execute(){ sabundFile.close(); rabundFile.close(); listFile.close(); - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -384,10 +416,18 @@ int HClusterCommand::execute(){ delete cluster; if (m->control_pressed) { - for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); + for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } + + 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(); + } + //set list file as new current listfile string current = ""; itTypes = outputTypes.find("list");