//**********************************************************************************************************************
vector<string> ParsimonyCommand::setParameters(){
try {
- CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree);
- CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup);
- CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname);
- CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
- CommandParameter prandom("random", "String", "", "", "", "", "",false,false); parameters.push_back(prandom);
- CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters);
- CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
- CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
- CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+ CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","parsimony-psummary",false,true,true); parameters.push_back(ptree);
+ CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname);
+ CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount);
+ CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup);
+ CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups);
+ CommandParameter prandom("random", "String", "", "", "", "", "","",false,false); parameters.push_back(prandom);
+ CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters);
+ CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors);
+ CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+ CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
vector<string> myArray;
for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
string ParsimonyCommand::getHelpString(){
try {
string helpString = "";
- helpString += "The parsimony command parameters are tree, group, name, random, groups, processors and iters. tree parameter is required unless you have valid current tree file or are using random.\n";
+ helpString += "The parsimony command parameters are tree, group, name, count, random, groups, processors and iters. tree parameter is required unless you have valid current tree file or are using random.\n";
helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 1 valid group.\n";
helpString += "The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n";
helpString += "The parsimony command should be in the following format: parsimony(random=yourOutputFilename, groups=yourGroups, iters=yourIters).\n";
}
}
//**********************************************************************************************************************
-string ParsimonyCommand::getOutputFileNameTag(string type, string inputName=""){
- try {
- string outputFileName = "";
- map<string, vector<string> >::iterator it;
+string ParsimonyCommand::getOutputPattern(string type) {
+ try {
+ string pattern = "";
- //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 == "parsimony") { outputFileName = "parsimony"; }
- else if (type == "psummary") { outputFileName = "psummary"; }
- 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, "ParsimonyCommand", "getOutputFileNameTag");
- exit(1);
- }
+ if (type == "parsimony") { pattern = "[filename],parsimony"; }
+ else if (type == "psummary") { pattern = "[filename],psummary"; }
+ else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
+
+ return pattern;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ParsimonyCommand", "getOutputPattern");
+ exit(1);
+ }
}
-
//**********************************************************************************************************************
ParsimonyCommand::ParsimonyCommand(){
try {
//if the user has not given a path then, add inputdir. else leave path alone.
if (path == "") { parameters["name"] = inputDir + it->second; }
}
+
+ it = parameters.find("count");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = m->hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["count"] = inputDir + it->second; }
+ }
}
outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
if (namefile == "not open") { namefile = ""; abort = true; }
else if (namefile == "not found") { namefile = ""; }
else { m->setNameFile(namefile); }
+
+ countfile = validParameter.validFile(parameters, "count", true);
+ if (countfile == "not open") { countfile = ""; abort = true; }
+ else if (countfile == "not found") { countfile = ""; }
+ else { m->setCountTableFile(countfile); }
+
+ if ((namefile != "") && (countfile != "")) {
+ m->mothurOut("[ERROR]: you may only use one of the following: name or count."); m->mothurOutEndLine(); abort = true;
+ }
+
+ if ((groupfile != "") && (countfile != "")) {
+ m->mothurOut("[ERROR]: you may only use one of the following: group or count."); m->mothurOutEndLine(); abort=true;
+ }
+
}
//if the user changes the output directory command factory will send this info to us in the output parameter
m->setProcessors(temp);
m->mothurConvert(temp, processors);
- if (namefile == "") {
- vector<string> files; files.push_back(treefile);
- parser.getNameFile(files);
- }
+ if (countfile=="") {
+ if (namefile == "") {
+ vector<string> files; files.push_back(treefile);
+ parser.getNameFile(files);
+ }
+ }
}
m->setTreeFile(treefile);
- TreeReader* reader = new TreeReader(treefile, groupfile, namefile);
+ TreeReader* reader;
+ if (countfile == "") { reader = new TreeReader(treefile, groupfile, namefile); }
+ else { reader = new TreeReader(treefile, countfile); }
T = reader->getTrees();
- tmap = T[0]->getTreeMap();
+ ct = T[0]->getCountTable();
delete reader;
if(outputDir == "") { outputDir += m->hasPath(treefile); }
- output = new ColumnFile(outputDir + m->getSimpleName(treefile) + "." + getOutputFileNameTag("parsimony"), itersString);
- outputNames.push_back(outputDir + m->getSimpleName(treefile) + "." + getOutputFileNameTag("parsimony"));
- outputTypes["parsimony"].push_back(outputDir + m->getSimpleName(treefile) + "." + getOutputFileNameTag("parsimony"));
+ map<string, string> variables;
+ variables["[filename]"] = outputDir + m->getSimpleName(treefile) + ".";
+
+ output = new ColumnFile(getOutputFileName("parsimony",variables), itersString);
+ outputNames.push_back(getOutputFileName("parsimony",variables));
+ outputTypes["parsimony"].push_back(getOutputFileName("parsimony",variables));
- sumFile = outputDir + m->getSimpleName(treefile) + "." + getOutputFileNameTag("psummary");
+ sumFile = getOutputFileName("psummary",variables);
m->openOutputFile(sumFile, outSum);
outputNames.push_back(sumFile);
outputTypes["psummary"].push_back(sumFile);
//set users groups to analyze
SharedUtil util;
vector<string> mGroups = m->getGroups();
- vector<string> tGroups = tmap->getNamesOfGroups();
+ vector<string> tGroups = ct->getNamesOfGroups();
util.setGroups(mGroups, tGroups, allGroups, numGroups, "parsimony"); //sets the groups the user wants to analyze
util.getCombos(groupComb, mGroups, numComp);
m->setGroups(mGroups);
if (m->control_pressed) {
delete reading; delete output;
- delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
+ delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; }
if (randomtree == "") { outSum.close(); }
for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
m->clearGroups();
if (m->control_pressed) {
delete reading; delete output;
- delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
+ delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; }
if (randomtree == "") { outSum.close(); }
for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
m->clearGroups();
for (int j = 0; j < iters; j++) {
//create new tree with same num nodes and leaves as users
- randT = new Tree(tmap);
+ randT = new Tree(ct);
//create random relationships between nodes
randT->assembleRandomTree();
delete reading; delete output; delete randT;
if (randomtree == "") { outSum.close(); }
for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
- delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
+ delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; }
m->clearGroups();
return 0;
}
for (int j = 0; j < iters; j++) {
//create new tree with same num nodes and leaves as users
- randT = new Tree(tmap);
+ randT = new Tree(ct);
//create random relationships between nodes
randT->assembleRandomTree();
if (m->control_pressed) {
- delete reading; delete output; delete randT; delete tmap;
+ delete reading; delete output; delete randT; delete ct;
for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;
}
randomData = pars.getValues(randT, processors, outputDir);
if (m->control_pressed) {
- delete reading; delete output; delete randT; delete tmap;
+ delete reading; delete output; delete randT; delete ct;
for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;
}
if (m->control_pressed) {
delete reading; delete output;
- delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
+ delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; }
if (randomtree == "") { outSum.close(); }
for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
return 0;
printParsimonyFile();
if (randomtree == "") { printUSummaryFile(); }
- delete output; delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; }
+ delete output; delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; }
if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;}
try {
//create treemap
- tmap = new TreeMap();
+ ct = new CountTable();
m->mothurOut("Please enter the number of groups you would like to analyze: ");
cin >> numGroups;
count = 1;
numEachGroup.resize(numGroups, 0);
-
+ set<string> nameMap;
+ map<string, string> groupMap;
+ set<string> gps;
+
for (int i = 1; i <= numGroups; i++) {
m->mothurOut("Please enter the number of sequences in group " + toString(i) + ": ");
cin >> num;
m->mothurOutJustToLog(toString(num)); m->mothurOutEndLine();
-
- //set tmaps seqsPerGroup
- tmap->seqsPerGroup[toString(i)] = num;
- tmap->addGroup(toString(i));
+ gps.insert(toString(i));
+
//set tmaps namesOfSeqs
for (int j = 0; j < num; j++) {
- tmap->namesOfSeqs.push_back(toString(count));
- tmap->treemap[toString(count)].groupname = toString(i);
+ groupMap[toString(count)] = toString(i);
+ nameMap.insert(toString(count));
count++;
}
}
-
+ ct->createTable(nameMap, groupMap, gps);
+
//clears buffer so next command doesn't have error
string s;
getline(cin, s);
- m->Treenames = tmap->namesOfSeqs;
-
+ m->Treenames = ct->getNamesOfSeqs();
+ m->runParse = false;
}
catch(exception& e) {
m->errorOut(e, "ParsimonyCommand", "getUserInput");