X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=clusterdoturcommand.cpp;h=603bd73d680b485fb4df6ef6cf62e935af3f1ff5;hb=791f42d21a85f794529fd4c912dcc27d873c25e8;hp=5bcfe03416f90700a02a4ff3d58ad312f788bb96;hpb=348de0f8b17d84ede77081dcf67bd6ef43496677;p=mothur.git diff --git a/clusterdoturcommand.cpp b/clusterdoturcommand.cpp index 5bcfe03..603bd73 100644 --- a/clusterdoturcommand.cpp +++ b/clusterdoturcommand.cpp @@ -11,51 +11,55 @@ #include "clusterclassic.h" //********************************************************************************************************************** -vector ClusterDoturCommand::getValidParameters(){ +vector ClusterDoturCommand::setParameters(){ try { - string AlignArray[] = {"phylip","name","hard","cutoff","precision","method","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); + CommandParameter pcutoff("cutoff", "Number", "", "10", "", "", "",false,false); parameters.push_back(pcutoff); + CommandParameter pprecision("precision", "Number", "", "100", "", "", "",false,false); parameters.push_back(pprecision); + CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "",false,false); parameters.push_back(pmethod); + CommandParameter phard("hard", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(phard); + CommandParameter psim("sim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psim); + 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); } return myArray; } catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "getValidParameters"); + m->errorOut(e, "ClusterDoturCommand", "setParameters"); exit(1); } } //********************************************************************************************************************** -ClusterDoturCommand::ClusterDoturCommand(){ +string ClusterDoturCommand::getHelpString(){ try { - abort = true; calledHelp = true; - vector tempOutNames; - outputTypes["list"] = tempOutNames; - outputTypes["rabund"] = tempOutNames; - outputTypes["sabund"] = tempOutNames; + string helpString = ""; + helpString += "The cluster.classic command clusters using the algorithm from dotur. \n"; + helpString += "The cluster.classic command parameter options are phylip, name, method, cuttoff, hard, sim, precision. Phylip is required, unless you have a valid current file.\n"; + helpString += "The cluster.classic command should be in the following format: \n"; + helpString += "cluster.classic(phylip=yourDistanceMatrix, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"; + helpString += "The acceptable cluster methods are furthest, nearest, weighted and average. If no method is provided then average is assumed.\n"; + return helpString; } catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "ClusterCommand"); + m->errorOut(e, "ClusterDoturCommand", "getHelpString"); exit(1); } } //********************************************************************************************************************** -vector ClusterDoturCommand::getRequiredParameters(){ - try { - string Array[] = {"phylip"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - return myArray; - } - catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "getRequiredParameters"); - exit(1); - } -} -//********************************************************************************************************************** -vector ClusterDoturCommand::getRequiredFiles(){ +ClusterDoturCommand::ClusterDoturCommand(){ try { - vector myArray; - return myArray; + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["list"] = tempOutNames; + outputTypes["rabund"] = tempOutNames; + outputTypes["sabund"] = tempOutNames; } catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "getRequiredFiles"); + m->errorOut(e, "ClusterDoturCommand", "ClusterCommand"); exit(1); } } @@ -68,11 +72,10 @@ ClusterDoturCommand::ClusterDoturCommand(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 { - //valid paramters for this command - string Array[] = {"phylip","name","cutoff","hard","precision","method","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -122,31 +125,42 @@ ClusterDoturCommand::ClusterDoturCommand(string option) { //check for required parameters phylipfile = validParameter.validFile(parameters, "phylip", true); if (phylipfile == "not open") { abort = true; } - else if (phylipfile == "not found") { phylipfile = ""; m->mothurOut("When executing the cluster.dotur command you must enter a phylip file."); m->mothurOutEndLine(); abort = true; } + else if (phylipfile == "not found") { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a phylip file with the cluster.classic command."); m->mothurOutEndLine(); + abort = true; + } + }else { m->setPhylipFile(phylipfile); } //check for optional parameter and set defaults namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } + else { m->setNameFile(namefile); } string temp; temp = validParameter.validFile(parameters, "precision", false); 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, "cutoff", false); if (temp == "not found") { temp = "10"; } - convert(temp, cutoff); + m->mothurConvert(temp, cutoff); cutoff += (5 / (precision * 10.0)); - temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "F"; } + temp = validParameter.validFile(parameters, "hard", false); if (temp == "not found") { temp = "T"; } hard = m->isTrue(temp); + temp = validParameter.validFile(parameters, "sim", false); if (temp == "not found") { temp = "F"; } + sim = m->isTrue(temp); + method = validParameter.validFile(parameters, "method", false); - if (method == "not found") { method = "furthest"; } + if (method == "not found") { method = "average"; } if ((method == "furthest") || (method == "nearest") || (method == "average") || (method == "weighted")) { if (method == "furthest") { tag = "fn"; } @@ -161,28 +175,6 @@ ClusterDoturCommand::ClusterDoturCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void ClusterDoturCommand::help(){ - try { - m->mothurOut("The cluster.classic command clusters using the algorithm from dotur. \n"); - m->mothurOut("The cluster.classic command parameter options are phylip, name, method, cuttoff, hard, precision. Phylip is required.\n"); - m->mothurOut("The cluster.classic command should be in the following format: \n"); - m->mothurOut("cluster.classic(phylip=yourDistanceMatrix, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"); - m->mothurOut("The acceptable cluster methods are furthest, nearest, weighted and average. If no method is provided then furthest is assumed.\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "ClusterDoturCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -ClusterDoturCommand::~ClusterDoturCommand(){} - //********************************************************************************************************************** int ClusterDoturCommand::execute(){ @@ -198,7 +190,7 @@ int ClusterDoturCommand::execute(){ } //reads phylip file storing data in 2D vector, also fills list and rabund - ClusterClassic* cluster = new ClusterClassic(cutoff, method); + ClusterClassic* cluster = new ClusterClassic(cutoff, method, sim); cluster->readPhylipFile(phylipfile, nameMap); if (m->control_pressed) { delete cluster; delete list; delete rabund; return 0; } @@ -227,7 +219,7 @@ int ClusterDoturCommand::execute(){ int estart = time(NULL); while ((cluster->getSmallDist() < cutoff) && (cluster->getNSeqs() > 1)){ - if (m->control_pressed) { delete cluster; delete list; delete rabund; sabundFile.close();rabundFile.close();listFile.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear(); return 0; } + if (m->control_pressed) { delete cluster; delete list; delete rabund; sabundFile.close();rabundFile.close();listFile.close(); for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } cluster->update(cutoff);