#include "readphylip.h"
#include "readcolumn.h"
#include "readmatrix.hpp"
+#include "clusterdoturcommand.h"
//**********************************************************************************************************************
vector<string> ClusterCommand::setParameters(){
CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn);
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", "furthest", "", "", "",false,false); parameters.push_back(pmethod);
+ CommandParameter pmethod("method", "Multiple", "furthest-nearest-average-weighted", "average", "", "", "",false,false); parameters.push_back(pmethod);
CommandParameter pshowabund("showabund", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pshowabund);
CommandParameter ptiming("timing", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ptiming);
CommandParameter psim("sim", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psim);
- CommandParameter phard("hard", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(phard);
+ CommandParameter phard("hard", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(phard);
CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
helpString += "The cluster command parameter options are phylip, column, name, method, cuttoff, hard, precision, sim, showabund and timing. Phylip or column and name are required, unless you have a valid current file.\n";
helpString += "The cluster command should be in the following format: \n";
helpString += "cluster(method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n";
- helpString += "The acceptable cluster methods are furthest, nearest, average and weighted. If no method is provided then furthest is assumed.\n\n";
+ helpString += "The acceptable cluster methods are furthest, nearest, average and weighted. If no method is provided then average is assumed.\n";
return helpString;
}
catch(exception& e) {
}
}
//**********************************************************************************************************************
+string ClusterCommand::getOutputFileNameTag(string type, string inputName=""){
+ try {
+ string outputFileName = "";
+ map<string, vector<string> >::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, "ClusterCommand", "getOutputFileNameTag");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
ClusterCommand::ClusterCommand(){
try {
abort = true; calledHelp = true;
//allow user to run help
if(option == "help") { help(); abort = true; calledHelp = true; }
+ else if(option == "citation") { citation(); abort = true; calledHelp = true;}
else {
vector<string> myArray = setParameters();
phylipfile = validParameter.validFile(parameters, "phylip", true);
if (phylipfile == "not open") { phylipfile = ""; abort = true; }
else if (phylipfile == "not found") { phylipfile = ""; }
- else { distfile = phylipfile; format = "phylip"; }
+ else { distfile = phylipfile; format = "phylip"; m->setPhylipFile(phylipfile); }
columnfile = validParameter.validFile(parameters, "column", true);
if (columnfile == "not open") { columnfile = ""; abort = true; }
else if (columnfile == "not found") { columnfile = ""; }
- else { distfile = columnfile; format = "column"; }
+ else { distfile = columnfile; format = "column"; m->setColumnFile(columnfile); }
namefile = validParameter.validFile(parameters, "name", true);
if (namefile == "not open") { abort = true; }
else if (namefile == "not found") { namefile = ""; }
+ else { m->setNameFile(namefile); }
if ((phylipfile == "") && (columnfile == "")) {
//is there are current file available for either of these?
//give priority to column, then phylip
columnfile = m->getColumnFile();
- if (columnfile != "") { m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); }
+ if (columnfile != "") { distfile = columnfile; format = "column"; m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); }
else {
phylipfile = m->getPhylipFile();
- if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); }
+ if (phylipfile != "") { distfile = phylipfile; format = "phylip"; m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); }
else {
m->mothurOut("No valid current files. You must provide a phylip or column file before you can use the cluster command."); m->mothurOutEndLine();
abort = true;
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 = "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"; }
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);
- if (method == "not found") { method = "furthest"; }
+ if (method == "not found") { method = "average"; }
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; }
timing = validParameter.validFile(parameters, "timing", false);
if (timing == "not found") { timing = "F"; }
- }
+ }
}
catch(exception& e) {
m->errorOut(e, "ClusterCommand", "ClusterCommand");
if (abort == true) { if (calledHelp) { return 0; } return 2; }
+ //phylip file given and cutoff not given - use cluster.classic because it uses less memory and is faster
+ if ((format == "phylip") && (cutoff > 10.0)) {
+ m->mothurOutEndLine(); m->mothurOut("You are using a phylip file and no cutoff. I will run cluster.classic to save memory and time."); m->mothurOutEndLine();
+
+ //run unique.seqs for deconvolute results
+ string inputString = "phylip=" + distfile;
+ if (namefile != "") { inputString += ", name=" + namefile; }
+ inputString += ", precision=" + toString(precision);
+ inputString += ", method=" + method;
+ if (hard) { inputString += ", hard=T"; }
+ else { inputString += ", hard=F"; }
+ if (sim) { inputString += ", sim=T"; }
+ else { inputString += ", sim=F"; }
+
+
+ m->mothurOutEndLine();
+ m->mothurOut("/------------------------------------------------------------/"); m->mothurOutEndLine();
+ m->mothurOut("Running command: cluster.classic(" + inputString + ")"); m->mothurOutEndLine();
+
+ Command* clusterClassicCommand = new ClusterDoturCommand(inputString);
+ clusterClassicCommand->execute();
+ delete clusterClassicCommand;
+
+ m->mothurOut("/------------------------------------------------------------/"); m->mothurOutEndLine();
+
+ return 0;
+ }
+
ReadMatrix* read;
if (format == "column") { read = new ReadColumnMatrix(columnfile, sim); } //sim indicates whether its a similarity matrix
else if (format == "phylip") { read = new ReadPhylipMatrix(phylipfile, sim); }
if (m->control_pressed) { //clean up
delete list; delete matrix; delete rabund;
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;
}
if (outputDir == "") { outputDir += m->hasPath(distfile); }
fileroot = outputDir + m->getRootName(m->getSimpleName(distfile));
- m->openOutputFile(fileroot+ tag + ".sabund", sabundFile);
- m->openOutputFile(fileroot+ tag + ".rabund", rabundFile);
- m->openOutputFile(fileroot+ tag + ".list", listFile);
+ 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(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");
+ 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);
time_t estart = time(NULL);
if (m->control_pressed) { //clean up
delete list; delete matrix; delete rabund; 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;
}
cout.flush();
print_start = false;
}
-
+
if(previousDist <= 0.0000){
printData("unique");
}