Search in sources :

Example 21 with Node

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);
}
Also used : Node(beast.evolution.tree.Node)

Example 22 with Node

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);
}
Also used : Node(beast.evolution.tree.Node)

Example 23 with Node

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;
}
Also used : Node(beast.evolution.tree.Node) BitSet(java.util.BitSet)

Example 24 with Node

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;
}
Also used : Node(beast.evolution.tree.Node)

Example 25 with Node

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;
}
Also used : Node(beast.evolution.tree.Node) BitSet(java.util.BitSet)

Aggregations

Node (beast.evolution.tree.Node)140 Conversion (bacter.Conversion)24 MultiTypeNode (beast.evolution.tree.MultiTypeNode)22 Locus (bacter.Locus)17 ArrayList (java.util.ArrayList)15 Tree (beast.evolution.tree.Tree)14 Test (org.junit.Test)9 CalculationNode (beast.core.CalculationNode)8 RealParameter (beast.core.parameter.RealParameter)8 TreeInterface (beast.evolution.tree.TreeInterface)7 ClusterTree (beast.util.ClusterTree)7 ConversionGraph (bacter.ConversionGraph)6 Alignment (beast.evolution.alignment.Alignment)6 TaxonSet (beast.evolution.alignment.TaxonSet)6 SiteModel (beast.evolution.sitemodel.SiteModel)5 BitSet (java.util.BitSet)5 StateNode (beast.core.StateNode)4 JukesCantor (beast.evolution.substitutionmodel.JukesCantor)4 TreeParser (beast.util.TreeParser)3 CFEventList (bacter.CFEventList)2