void CandidateSet::addCandidateSplits(string treeString) { vector<string> taxaNames = aln->getSeqNames(); MTree tree(treeString, taxaNames, Params::getInstance().is_rooted); SplitGraph allSplits; tree.convertSplits(allSplits); for (SplitGraph::iterator splitIt = allSplits.begin(); splitIt != allSplits.end(); splitIt++) { int value; Split *sp = candSplits.findSplit(*splitIt, value); if (sp != NULL) { sp->setWeight(value + 1); candSplits.setValue(sp, value + 1); } else { sp = new Split(*(*splitIt)); sp->setWeight(1); candSplits.insertSplit(sp, 1); } } candSplits.setNumTree(candSplits.getNumTree() + 1); }
int CandidateSet::computeSplitOccurences(double supportThreshold) { candSplits.clear(); candSplits.setNumTree(size()); /* Store all splits in the best trees in candSplits. * The variable numTree in SpitInMap is the number of trees, from which the splits are converted. */ CandidateSet::iterator treeIt; //vector<string> taxaNames = aln->getSeqNames(); for (treeIt = begin(); treeIt != end(); treeIt++) { MTree tree(treeIt->second.tree, Params::getInstance().is_rooted); SplitGraph splits; tree.convertSplits(splits); SplitGraph::iterator itg; for (itg = splits.begin(); itg != splits.end(); itg++) { int value; Split *sp = candSplits.findSplit(*itg, value); if (sp != NULL) { int newHashWeight = value + 1; double newSupport = (double) newHashWeight / (double) candSplits.getNumTree(); sp->setWeight(newSupport); candSplits.setValue(sp, newHashWeight); } else { sp = new Split(*(*itg)); sp->setWeight(1.0 / (double) candSplits.getNumTree()); candSplits.insertSplit(sp, 1); } } } int newNumStableSplits = countStableSplits(supportThreshold); if (verbose_mode >= VB_MED) { cout << ((double) newNumStableSplits / (aln->getNSeq() - 3)) * 100; cout << " % of the splits are stable (support threshold " << supportThreshold; cout << " from " << candSplits.getNumTree() << " trees)" << endl; } return numStableSplits; }
void CandidateSet::removeCandidateSplits(string treeString) { vector<string> taxaNames = aln->getSeqNames(); MTree tree(treeString, taxaNames, Params::getInstance().is_rooted); SplitGraph allSplits; tree.convertSplits(allSplits); for (SplitGraph::iterator splitIt = allSplits.begin(); splitIt != allSplits.end(); splitIt++) { int value = 0; Split *sp; sp = candSplits.findSplit(*splitIt, value); if (value == 0) { cout << "Cannot find split: "; (*splitIt)->report(cout); exit(1); } else { assert(sp->getWeight() >= 1); if (sp->getWeight() > 1) { sp->setWeight(value - 1); } else { candSplits.eraseSplit(*splitIt); } } } candSplits.setNumTree(candSplits.getNumTree() - 1); }