#include "consensuscommand.h"
+//**********************************************************************************************************************
+vector<string> ConcensusCommand::getValidParameters(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ConcensusCommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> ConcensusCommand::getRequiredParameters(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ConcensusCommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> ConcensusCommand::getRequiredFiles(){
+ try {
+ string AlignArray[] = {"tree","group"};
+ vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ConcensusCommand", "getRequiredFiles");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+ConcensusCommand::ConcensusCommand(){
+ try {
+ abort = true; calledHelp = true;
+ vector<string> tempOutNames;
+ outputTypes["tree"] = tempOutNames;
+ outputTypes["nodepairs"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "ConcensusCommand", "ConcensusCommand");
+ exit(1);
+ }
+}
//**********************************************************************************************************************
-ConcensusCommand::ConcensusCommand(string fileroot){
+ConcensusCommand::ConcensusCommand(string fileroot) {
try {
globaldata = GlobalData::getInstance();
- abort = false;
+ abort = false; calledHelp = false;
+
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["tree"] = tempOutNames;
+ outputTypes["nodepairs"] = tempOutNames;
filename = fileroot;
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "ConcensusCommand");
+ m->errorOut(e, "ConcensusCommand", "ConcensusCommand");
exit(1);
}
}
void ConcensusCommand::help(){
try {
- mothurOut("The consensus command can only be executed after a successful read.tree command.\n");
- mothurOut("The consensus command has no parameters.\n");
- mothurOut("The consensus command should be in the following format: consensus().\n");
- mothurOut("The consensus command output two files: .consensus.tre and .consensuspairs.\n");
- mothurOut("The .consensus.tre file contains the consensus tree of the trees in your input file.\n");
- mothurOut("The branch lengths are the percentage of trees in your input file that had the given pair.\n");
- mothurOut("The .consensuspairs file contains a list of the internal nodes in your tree. For each node, the pair that was used in the consensus tree \n");
- mothurOut("is reported with its percentage, as well as the other pairs that were seen for that node but not used and their percentages.\n\n");
+ m->mothurOut("The consensus command can only be executed after a successful read.tree command.\n");
+ m->mothurOut("The consensus command has no parameters.\n");
+ m->mothurOut("The consensus command should be in the following format: consensus().\n");
+ m->mothurOut("The consensus command output two files: .consensus.tre and .consensuspairs.\n");
+ m->mothurOut("The .consensus.tre file contains the consensus tree of the trees in your input file.\n");
+ m->mothurOut("The branch lengths are the percentage of trees in your input file that had the given pair.\n");
+ m->mothurOut("The .consensuspairs file contains a list of the internal nodes in your tree. For each node, the pair that was used in the consensus tree \n");
+ m->mothurOut("is reported with its percentage, as well as the other pairs that were seen for that node but not used and their percentages.\n\n");
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "help");
+ m->errorOut(e, "ConcensusCommand", "help");
exit(1);
}
}
int ConcensusCommand::execute(){
try {
- if (abort == true) { return 0; }
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
else {
numNodes = t[0]->getNumNodes();
numLeaves = t[0]->getNumLeaves();
}
//get the possible pairings
- getSets();
+ getSets();
+
+ if (m->control_pressed) { return 0; }
//open file for pairing not included in the tree
- notIncluded = filename + ".cons.pairs";
- openOutputFile(notIncluded, out2);
+ notIncluded = filename + ".cons.pairs"; outputNames.push_back(notIncluded); outputTypes["nodepairs"].push_back(notIncluded);
+ m->openOutputFile(notIncluded, out2);
consensusTree = new Tree();
buildConcensusTree(treeSet);
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
consensusTree->assembleTree();
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
//output species in order
out2 << "Species in Order: " << endl << endl;
for (int i = 0; i < treeSet.size(); i++) { out2 << i+1 << ". " << treeSet[i] << endl; }
//output sets included
out2 << endl << "Sets included in the consensus tree:" << endl << endl;
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
vector<string> temp;
for (it2 = nodePairsInTree.begin(); it2 != nodePairsInTree.end(); it2++) {
+
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
//only output pairs not leaves
if (it2->first.size() > 1) {
temp.clear();
//output sets not included
out2 << endl << "Sets NOT included in the consensus tree:" << endl << endl;
for (it2 = nodePairs.begin(); it2 != nodePairs.end(); it2++) {
+
+ if (m->control_pressed) { delete consensusTree; return 0; }
+
temp.clear();
//initialize temp to all "."
temp.resize(treeSet.size(), ".");
out2 << '\t' << it2->second << endl;
}
- outputFile = filename + ".cons.tre";
- openOutputFile(outputFile, out);
+ outputFile = filename + ".cons.tre"; outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile);
+ m->openOutputFile(outputFile, out);
- consensusTree->printForBoot(out);
+ consensusTree->print(out, "boot");
out.close(); out2.close();
delete consensusTree;
+ //set first tree file as new current treefile
+ string currentTree = "";
+ itTypes = outputTypes.find("tree");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { currentTree = (itTypes->second)[0]; m->setTreeFile(currentTree); }
+ }
+
return 0;
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "execute");
+ m->errorOut(e, "ConcensusCommand", "execute");
exit(1);
}
}
vector<string> leftChildSet;
vector<string> rightChildSet;
+ if (m->control_pressed) { return 1; }
+
//if you are at a leaf
if (nodeSet.size() == 1) {
//return the vector index of the leaf you are at
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "buildConcensusTree");
+ m->errorOut(e, "ConcensusCommand", "buildConcensusTree");
exit(1);
}
}
//**********************************************************************************************************************
-void ConcensusCommand::getSets() {
+int ConcensusCommand::getSets() {
try {
vector<string> temp;
treeSet.clear();
//for each non-leaf node get descendant info.
for (int j = numLeaves; j < numNodes; j++) {
+
+ if (m->control_pressed) { return 1; }
+
temp.clear();
//go through pcounts and pull out descendants
for (it = t[i]->tree[j].pcount.begin(); it != t[i]->tree[j].pcount.end(); it++) {
//you want the leaves in there but with insignifigant sightings value so it is added last
//for each leaf node get descendant info.
for (int j = 0; j < numLeaves; j++) {
+
+ if (m->control_pressed) { return 1; }
//only need the first one since leaves have no descendants but themselves
it = t[0]->tree[j].pcount.begin();
//set initial rating on pairs to sightings + subgroup sightings
while (nodePairsCopy.size() != 0) {
+ if (m->control_pressed) { return 1; }
- vector<string> small = getSmallest(nodePairsCopy);
+ vector<string> smallOne = getSmallest(nodePairsCopy);
- int subgrouprate = getSubgroupRating(small);
+ int subgrouprate = getSubgroupRating(smallOne);
- nodePairsInitialRate[small] = nodePairs[small] + subgrouprate;
+ nodePairsInitialRate[smallOne] = nodePairs[smallOne] + subgrouprate;
- nodePairsCopy.erase(small);
+ nodePairsCopy.erase(smallOne);
}
+ return 0;
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "getSets");
+ m->errorOut(e, "ConcensusCommand", "getSets");
exit(1);
}
}
return smallest;
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "getSmallest");
+ m->errorOut(e, "ConcensusCommand", "getSmallest");
exit(1);
}
}
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "getNextAvailableSet");
+ m->errorOut(e, "ConcensusCommand", "getNextAvailableSet");
exit(1);
}
}
return rate;
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "getSubgroupRating");
+ m->errorOut(e, "ConcensusCommand", "getSubgroupRating");
exit(1);
}
}
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "getRestSet");
+ m->errorOut(e, "ConcensusCommand", "getRestSet");
exit(1);
}
}
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "isSubset");
+ m->errorOut(e, "ConcensusCommand", "isSubset");
exit(1);
}
}
}
catch(exception& e) {
- errorOut(e, "ConcensusCommand", "findSpot");
+ m->errorOut(e, "ConcensusCommand", "findSpot");
exit(1);
}
}