X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=nmdscommand.cpp;h=a90ed2965888928f4a90049fe04fe888d773c450;hp=8fa0145ea7e97081000ee99337309861a0f8c7a9;hb=a8e2df1b96a57f5f29576b08361b86a96a8eff4f;hpb=ca9ac1d80c62f57270b0dcd49410ebe08a8aecd6 diff --git a/nmdscommand.cpp b/nmdscommand.cpp index 8fa0145..a90ed29 100644 --- a/nmdscommand.cpp +++ b/nmdscommand.cpp @@ -13,15 +13,15 @@ //********************************************************************************************************************** vector NMDSCommand::setParameters(){ try { - CommandParameter paxes("axes", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paxes); - CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); - CommandParameter pmaxdim("maxdim", "Number", "", "2", "", "", "",false,false); parameters.push_back(pmaxdim); - CommandParameter pmindim("mindim", "Number", "", "2", "", "", "",false,false); parameters.push_back(pmindim); - CommandParameter piters("iters", "Number", "", "10", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pmaxiters("maxiters", "Number", "", "500", "", "", "",false,false); parameters.push_back(pmaxiters); - CommandParameter pepsilon("epsilon", "Number", "", "0.000000000001", "", "", "",false,false); parameters.push_back(pepsilon); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter paxes("axes", "InputTypes", "", "", "none", "none", "none","",false,false,true); parameters.push_back(paxes); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none","nmds-stress",false,true,true); parameters.push_back(pphylip); + CommandParameter pmaxdim("maxdim", "Number", "", "2", "", "", "","",false,false); parameters.push_back(pmaxdim); + CommandParameter pmindim("mindim", "Number", "", "2", "", "", "","",false,false); parameters.push_back(pmindim); + CommandParameter piters("iters", "Number", "", "10", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pmaxiters("maxiters", "Number", "", "500", "", "", "","",false,false); parameters.push_back(pmaxiters); + CommandParameter pepsilon("epsilon", "Number", "", "0.000000000001", "", "", "","",false,false); parameters.push_back(pepsilon); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); vector myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -46,7 +46,7 @@ string NMDSCommand::getHelpString(){ helpString += "The iters parameter allows you to select the number of random configuration to try. Default=10\n"; helpString += "The epsilon parameter allows you to select set an acceptable stopping point. Default=1e-12.\n"; helpString += "Example nmds(phylip=yourDistanceFile).\n"; - helpString += "Note: No spaces between parameter labels (i.e. phylip), '=' and parameters (i.e.yourDistanceFile).\n\n"; + helpString += "Note: No spaces between parameter labels (i.e. phylip), '=' and parameters (i.e.yourDistanceFile).\n"; return helpString; } catch(exception& e) { @@ -54,6 +54,24 @@ string NMDSCommand::getHelpString(){ exit(1); } } +//********************************************************************************************************************** +string NMDSCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "nmds") { pattern = "[filename],nmds.axes"; } + else if (type == "stress") { pattern = "[filename],nmds.stress"; } + else if (type == "iters") { pattern = "[filename],nmds.iters"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "NMDSCommand", "getOutputPattern"); + exit(1); + } +} + //********************************************************************************************************************** NMDSCommand::NMDSCommand(){ try { @@ -77,6 +95,7 @@ NMDSCommand::NMDSCommand(string option) { //allow user to run help if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { vector myArray = setParameters(); @@ -127,7 +146,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; } @@ -140,22 +159,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; } } } @@ -185,8 +204,10 @@ 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"; + map variables; + variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(phylipfile)); + string outputFileName = getOutputFileName("iters",variables); + string stressFileName = getOutputFileName("stress",variables); outputNames.push_back(outputFileName); outputTypes["iters"].push_back(outputFileName); outputNames.push_back(stressFileName); outputTypes["stress"].push_back(stressFileName); @@ -216,21 +237,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'; @@ -248,14 +269,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 = getOutputFileName("nmds",variables); outputNames.push_back(BestFileName); outputTypes["nmds"].push_back(BestFileName); m->mothurOut("\nNumber of dimensions:\t" + toString(bestDim) + "\n"); @@ -275,7 +296,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();