use of dr.evolution.tree.Clade in project beast-mcmc by beast-dev.
the class ConditionalCladeFrequency method getChanceForNodeHeights.
public double getChanceForNodeHeights(TreeModel tree, Likelihood likelihood) {
double prob = 0.0;
NodeRef node = tree.getRoot();
Clade currentClade = getClade(tree, node);
int childcount = tree.getChildCount(node);
for (int i = 0; i < childcount; i++) {
NodeRef child = tree.getChild(node, i);
if (!tree.isExternal(child)) {
// prob += getChanceForNodeheights(tree, child, currentClade,
// likelihood, prior);
}
}
return prob;
}
use of dr.evolution.tree.Clade in project beast-mcmc by beast-dev.
the class ConditionalCladeFrequency method addTree.
/**
* increments the number of occurrences for all conditional clades
*
* @param tree - the tree to be added
*/
public void addTree(Tree tree) {
samples++;
List<Clade> clades = new ArrayList<Clade>();
List<Clade> parentClades = new ArrayList<Clade>();
// get clades contained in the tree
getClades(tree, tree.getRoot(), parentClades, clades);
// add the clade containing all taxa as well so that it get counted
clades.add(parentClades.get(parentClades.size() - 1));
parentClades.add(clades.get(clades.size() - 1));
int size = clades.size();
// tree probability
for (int i = 0; i < size; i++) {
Clade c = clades.get(i);
// get the bits of the clade
Clade parent = parentClades.get(i);
HashMap<BitSet, Clade> coFreqs;
// increment the clade occurrences
if (cladeProbabilities.containsKey(c.getBits())) {
Clade tmp = cladeProbabilities.get(c.getBits());
// tmp.addSample();
tmp.addHeight(c.getHeight());
// add the amount to the current occurences
// frequency += cladeProbabilities.get(c);
} else {
// just to set the first value of the height value list
// c.addSample();
c.addHeight(c.getHeight());
cladeProbabilities.put(c.getBits(), c);
}
// increment the conditional clade occurrences
if (!parent.equals(c)) {
if (cladeCoProbabilities.containsKey(parent.getBits())) {
coFreqs = cladeCoProbabilities.get(parent.getBits());
} else {
// if it's the first time we observe the parent then we need
// a new list for its conditional clades
coFreqs = new HashMap<BitSet, Clade>();
cladeCoProbabilities.put(parent.getBits(), coFreqs);
}
// clade
if (coFreqs.containsKey(c.getBits())) {
Clade tmp = coFreqs.get(c.getBits());
tmp.addHeight(c.getHeight());
// coFrequency += coFreqs.get(c.getBits());
} else {
// TODO check this code, especially if the cloning is needed
// and not just the clade could be added
Clade tmp = new Clade((BitSet) c.getBits().clone(), c.getHeight());
tmp.addHeight(c.getHeight());
coFreqs.put(c.getBits(), tmp);
}
}
}
}
use of dr.evolution.tree.Clade in project beast-mcmc by beast-dev.
the class AbstractCladeImportanceDistribution method getClades.
/**
* Creates a list with all clades of the tree
*
* @param taxonMap - the lookup map for the taxon representing an index
* @param tree - the tree from which the clades are extracted
* @param node - the starting node. All clades below starting at this branch
* are added
*/
protected Clade getClades(Tree tree, NodeRef node, List<Clade> parentClades, List<Clade> childClade, HashMap<String, Integer> taxonMap) {
// create a new bit set for this clade
BitSet bits = new BitSet();
Clade c = null;
// check if the node is external
if (tree.isExternal(node)) {
// if so, the only taxon in the clade is I
// int index = node.getNumber();
String taxon = tree.getTaxon(node.getNumber()).getId();
int index = taxonMap.get(taxon);
bits.set(index);
c = new Clade(bits, tree.getNodeHeight(node));
} else {
// otherwise, call all children and add its taxon together to one
// clade
NodeRef childNode = tree.getChild(node, 0);
// add just my first child to the list
// the second child is complementary to the first
Clade leftChild = getClades(tree, childNode, parentClades, childClade, taxonMap);
bits.or(leftChild.getBits());
childNode = tree.getChild(node, 1);
// add just my first child to the list
// the second child is complementary to the first
Clade rightChild = getClades(tree, childNode, parentClades, childClade, taxonMap);
bits.or(rightChild.getBits());
c = new Clade(bits, tree.getNodeHeight(node));
if (leftChild.getSize() >= 2) {
parentClades.add(c);
childClade.add(leftChild);
}
if (rightChild.getSize() >= 2) {
parentClades.add(c);
childClade.add(rightChild);
}
}
return c;
}
use of dr.evolution.tree.Clade in project beast-mcmc by beast-dev.
the class AbstractCladeImportanceDistribution method getClades.
/**
* Creates a list with all clades of the tree
*
* @param tree - the tree from which the clades are extracted
* @param node - the starting node. All clades below starting at this branch
* are added
* @param clades - the list in which the clades are stored
* @param bits - a bit set to which the current bits of the clades are added
*/
public void getClades(Tree tree, NodeRef node, List<Clade> clades, BitSet bits) {
// create a new bit set for this clade
BitSet bits2 = new BitSet();
// check if the node is external
if (tree.isExternal(node)) {
// if so, the only taxon in the clade is I
int index = node.getNumber();
bits2.set(index);
} else {
// clade
for (int i = 0; i < tree.getChildCount(node); i++) {
NodeRef child = tree.getChild(node, i);
getClades(tree, child, clades, bits2);
}
// add my bit set to the list
clades.add(new Clade(bits2, tree.getNodeHeight(node)));
}
// this is needed for adding all children clades together
if (bits != null) {
bits.or(bits2);
}
}
use of dr.evolution.tree.Clade in project beast-mcmc by beast-dev.
the class AbstractCladeImportanceDistribution method getClades.
/**
* Creates a list with all clades of the tree
*
* @param tree - the tree from which the clades are extracted
* @param node - the starting node. All clades below starting at this branch
* are added
*/
protected Clade getClades(Tree tree, NodeRef node, List<Clade> parentClades, List<Clade> childClade) {
// create a new bit set for this clade
BitSet bits = new BitSet();
Clade c = null;
// check if the node is external
if (tree.isExternal(node)) {
// if so, the only taxon in the clade is I
int index = node.getNumber();
bits.set(index);
c = new Clade(bits, tree.getNodeHeight(node));
} else {
// otherwise, call all children and add its taxon together to one
// clade
NodeRef childNode = tree.getChild(node, 0);
// add just my first child to the list
// the second child is complementary to the first
Clade leftChild = getClades(tree, childNode, parentClades, childClade);
bits.or(leftChild.getBits());
childNode = tree.getChild(node, 1);
// add just my first child to the list
// the second child is complementary to the first
Clade rightChild = getClades(tree, childNode, parentClades, childClade);
bits.or(rightChild.getBits());
c = new Clade(bits, tree.getNodeHeight(node));
if (leftChild.getSize() >= 2) {
parentClades.add(c);
childClade.add(leftChild);
}
if (rightChild.getSize() >= 2) {
parentClades.add(c);
childClade.add(rightChild);
}
}
return c;
}
Aggregations