use of beast.evolution.tree.Node in project beast2 by CompEvol.
the class SimulatedAlignment method getTransitionProbabilities.
// traverse
/**
* get transition probability matrix for particular rate category *
*/
void getTransitionProbabilities(Tree tree, Node node, int rateCategory, double[] probs) {
Node parent = node.getParent();
double branchRate = (m_branchRateModel == null ? 1.0 : m_branchRateModel.getRateForBranch(node));
branchRate *= m_siteModel.getRateForCategory(rateCategory, node);
// Get the operational time of the branch
// final double branchTime = branchRate * (parent.getHeight() - node.getHeight());
// if (branchTime < 0.0) {
// throw new RuntimeException("Negative branch length: " + branchTime);
// }
// double branchLength = m_siteModel.getRateForCategory(rateCategory) * branchTime;
// // TODO Hack until SiteRateModel issue is resolved
// if (m_siteModel.getSubstitutionModel() instanceof SubstitutionEpochModel) {
// ((SubstitutionEpochModel)m_siteModel.getSubstitutionModel()).getTransitionProbabilities(tree.getNodeHeight(node),
// tree.getNodeHeight(parent),branchLength, probs);
// return;
// }
// m_siteModel.getSubstitutionModel().getTransitionProbabilities(branchLength, probs);
m_siteModel.getSubstitutionModel().getTransitionProbabilities(node, parent.getHeight(), node.getHeight(), branchRate, probs);
}
use of beast.evolution.tree.Node in project beast2 by CompEvol.
the class SimulatedAlignment method simulate.
// intArray2Sequence
/**
* perform the actual sequence generation
*
* @return alignment containing randomly generated sequences for the nodes in the
* leaves of the tree
*/
public void simulate() {
Node root = m_tree.getRoot();
double[] categoryProbs = m_siteModel.getCategoryProportions(root);
int[] category = new int[m_sequenceLength];
for (int i = 0; i < m_sequenceLength; i++) {
category[i] = Randomizer.randomChoicePDF(categoryProbs);
}
double[] frequencies = m_siteModel.getSubstitutionModel().getFrequencies();
int[] seq = new int[m_sequenceLength];
for (int i = 0; i < m_sequenceLength; i++) {
seq[i] = Randomizer.randomChoicePDF(frequencies);
}
// alignment.setDataType(m_siteModel.getFrequencyModel().getDataType());
traverse(root, seq, category);
}
use of beast.evolution.tree.Node in project beast2 by CompEvol.
the class CladeSystem method addClades.
private BitSet addClades(Node node, boolean includeTips) {
BitSet bits = new BitSet();
if (node.isLeaf()) {
int index = getTaxonIndex(node);
bits.set(2 * index);
if (includeTips) {
addClade(bits);
}
} else {
for (int i = 0; i < node.getChildCount(); i++) {
Node node1 = node.getChild(i);
bits.or(addClades(node1, includeTips));
}
for (int i = 1; i < bits.length(); i = i + 2) {
bits.set(i, false);
}
if (node.isFake()) {
int index = getTaxonIndex(node.getDirectAncestorChild());
bits.set(2 * index + 1);
}
addClade(bits);
}
return bits;
}
use of beast.evolution.tree.Node in project beast2 by CompEvol.
the class CladeSystem method getTreeCladeCodes.
int getTreeCladeCodes(Node node, BitSet[] codes) {
final int inode = node.getNr();
codes[inode].clear();
if (node.isLeaf()) {
// getTaxonIndex(node);
int index = getTaxonIndex(node);
codes[inode].set(index);
} else {
for (int i = 0; i < node.getChildCount(); i++) {
final Node child = node.getChild(i);
final int childIndex = getTreeCladeCodes(child, codes);
codes[inode].or(codes[childIndex]);
}
}
return inode;
}
use of beast.evolution.tree.Node in project beast2 by CompEvol.
the class CladeSystem method collectAttributes.
private BitSet collectAttributes(Node node, Set<String> attributeNames) {
BitSet bits = new BitSet();
if (node.isLeaf()) {
int index = getTaxonIndex(node);
if (index < 0) {
throw new IllegalArgumentException("Taxon, " + node.getID() + ", not found in target tree");
}
bits.set(2 * index);
} else {
for (int i = 0; i < node.getChildCount(); i++) {
Node node1 = node.getChild(i);
bits.or(collectAttributes(node1, attributeNames));
}
for (int i = 1; i < bits.length(); i = i + 2) {
bits.set(i, false);
}
if (node.isFake()) {
int index = getTaxonIndex(node.getDirectAncestorChild());
bits.set(2 * index + 1);
}
}
collectAttributesForClade(bits, node, attributeNames);
return bits;
}
Aggregations