X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=consensuscommand.cpp;h=9880b8dbf01f72abe4a2a50d9630a2d09d3fd6d0;hb=4f9a6e14a608172f8a97f0297a3b8e6ea267c518;hp=dc278017c906dcfeb9f7967bc99f767df7007011;hpb=74844a60d80c6dd06e3fb02ee9b928424f9019b0;p=mothur.git diff --git a/consensuscommand.cpp b/consensuscommand.cpp index dc27801..9880b8d 100644 --- a/consensuscommand.cpp +++ b/consensuscommand.cpp @@ -9,12 +9,64 @@ #include "consensuscommand.h" +//********************************************************************************************************************** +vector ConcensusCommand::getValidParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ConcensusCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ConcensusCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ConcensusCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ConcensusCommand::getRequiredFiles(){ + try { + string AlignArray[] = {"tree","group"}; + vector 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 tempOutNames; + outputTypes["tree"] = tempOutNames; + outputTypes["nodepairs"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "ConcensusCommand", "ConcensusCommand"); + exit(1); + } +} //********************************************************************************************************************** ConcensusCommand::ConcensusCommand(string fileroot) { try { globaldata = GlobalData::getInstance(); - abort = false; + abort = false; calledHelp = false; + + //initialize outputTypes + vector tempOutNames; + outputTypes["tree"] = tempOutNames; + outputTypes["nodepairs"] = tempOutNames; filename = fileroot; @@ -55,18 +107,20 @@ ConcensusCommand::~ConcensusCommand(){} 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(); @@ -82,8 +136,12 @@ int ConcensusCommand::execute(){ 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; } @@ -91,8 +149,13 @@ int ConcensusCommand::execute(){ //output sets included out2 << endl << "Sets included in the consensus tree:" << endl << endl; + if (m->control_pressed) { delete consensusTree; return 0; } + vector 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(); @@ -118,6 +181,9 @@ int ConcensusCommand::execute(){ //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(), "."); @@ -136,10 +202,10 @@ int ConcensusCommand::execute(){ 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(); @@ -159,6 +225,8 @@ int ConcensusCommand::buildConcensusTree(vector nodeSet) { vector leftChildSet; vector 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 @@ -186,7 +254,7 @@ int ConcensusCommand::buildConcensusTree(vector nodeSet) { } //********************************************************************************************************************** -void ConcensusCommand::getSets() { +int ConcensusCommand::getSets() { try { vector temp; treeSet.clear(); @@ -196,6 +264,9 @@ void ConcensusCommand::getSets() { //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++) { @@ -219,6 +290,8 @@ void ConcensusCommand::getSets() { //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(); @@ -239,16 +312,18 @@ void ConcensusCommand::getSets() { //set initial rating on pairs to sightings + subgroup sightings while (nodePairsCopy.size() != 0) { + if (m->control_pressed) { return 1; } - vector small = getSmallest(nodePairsCopy); + vector 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) { m->errorOut(e, "ConcensusCommand", "getSets");