X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=nmdscommand.cpp;h=900f50bd43ffb2aaee98f279023e684bb8d7c00d;hb=6ede3bf5c0a9eedb23f24577a97da81ab3e1f7df;hp=4567dbba1e7b0b16e88f496307ef3cb7ff3a8650;hpb=e150b0b0664caec517485ee6d69dcdade6dcae77;p=mothur.git diff --git a/nmdscommand.cpp b/nmdscommand.cpp index 4567dbb..900f50b 100644 --- a/nmdscommand.cpp +++ b/nmdscommand.cpp @@ -55,6 +55,28 @@ string NMDSCommand::getHelpString(){ } } //********************************************************************************************************************** +string NMDSCommand::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 == "nmds") { outputFileName = "nmds.axes"; } + else if (type == "stress") { outputFileName = "nmds.stress"; } + else if (type == "iters") { outputFileName = "nmds.iters"; } + 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, "NMDSCommand", "getOutputFileNameTag"); + exit(1); + } +} +//********************************************************************************************************************** NMDSCommand::NMDSCommand(){ try { abort = true; calledHelp = true; @@ -128,7 +150,7 @@ NMDSCommand::NMDSCommand(string option) { phylipfile = m->getPhylipFile(); if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } else { m->mothurOut("You have no current phylip file and the phylip parameter is required."); m->mothurOutEndLine(); abort = true; } - } + }else { m->setPhylipFile(phylipfile); } axesfile = validParameter.validFile(parameters, "axes", true); if (axesfile == "not open") { axesfile = ""; abort = true; } @@ -141,22 +163,22 @@ NMDSCommand::NMDSCommand(string option) { } string temp = validParameter.validFile(parameters, "mindim", false); if (temp == "not found") { temp = "2"; } - convert(temp, mindim); + m->mothurConvert(temp, mindim); temp = validParameter.validFile(parameters, "maxiters", false); if (temp == "not found") { temp = "500"; } - convert(temp, maxIters); + m->mothurConvert(temp, maxIters); temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "10"; } - convert(temp, iters); + m->mothurConvert(temp, iters); temp = validParameter.validFile(parameters, "maxdim", false); if (temp == "not found") { temp = "2"; } - convert(temp, maxdim); + m->mothurConvert(temp, maxdim); temp = validParameter.validFile(parameters, "epsilon", false); if (temp == "not found") { temp = "0.000000000001"; } - convert(temp, epsilon); + m->mothurConvert(temp, epsilon); if (mindim < 1) { m->mothurOut("mindim must be at least 1."); m->mothurOutEndLine(); abort = true; } - if (maxdim < mindim) { m->mothurOut("maxdim must be greater than mindim."); m->mothurOutEndLine(); abort = true; } + if (maxdim < mindim) { maxdim = mindim; } } } @@ -186,8 +208,8 @@ int NMDSCommand::execute(){ vector< vector > axes; if (axesfile != "") { axes = readAxes(names); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "nmds.iters"; - string stressFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "nmds.stress"; + string outputFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("iters"); + string stressFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("stress"); outputNames.push_back(outputFileName); outputTypes["iters"].push_back(outputFileName); outputNames.push_back(stressFileName); outputTypes["stress"].push_back(stressFileName); @@ -217,21 +239,21 @@ int NMDSCommand::execute(){ vector< vector > thisConfig; if (axesfile == "") { thisConfig = generateStartingConfiguration(names.size(), i); } else { thisConfig = getConfiguration(axes, i); } - if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { remove(outputNames[k].c_str()); } return 0; } + if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { m->mothurRemove(outputNames[k]); } return 0; } //calc nmds for this dimension double stress; vector< vector > endConfig = nmdsCalc(matrix, thisConfig, stress); - if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { remove(outputNames[k].c_str()); } return 0; } + if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { m->mothurRemove(outputNames[k]); } return 0; } //calc euclid distances for new config vector< vector > newEuclid = linearCalc.calculateEuclidianDistance(endConfig); - if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { remove(outputNames[k].c_str()); } return 0; } + if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { m->mothurRemove(outputNames[k]); } return 0; } //calc correlation between original distances and euclidean distances from this config double rsquared = linearCalc.calcPearson(newEuclid, matrix); rsquared *= rsquared; - if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { remove(outputNames[k].c_str()); } return 0; } + if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { m->mothurRemove(outputNames[k]); } return 0; } //output results out << "Config" << (j+1) << '\t'; @@ -249,14 +271,14 @@ int NMDSCommand::execute(){ bestConfig = endConfig; } - if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { remove(outputNames[k].c_str()); } return 0; } + if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) { m->mothurRemove(outputNames[k]); } return 0; } } } out.close(); out2.close(); //output best config - string BestFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + "nmds.axes"; + string BestFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("nmds"); outputNames.push_back(BestFileName); outputTypes["nmds"].push_back(BestFileName); m->mothurOut("\nNumber of dimensions:\t" + toString(bestDim) + "\n"); @@ -276,7 +298,7 @@ int NMDSCommand::execute(){ outBest.close(); - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; } + if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; } m->mothurOutEndLine(); m->mothurOut("Output File Names: "); m->mothurOutEndLine();