Search in sources :

Example 26 with NodeRef

use of dr.evolution.tree.NodeRef in project beast-mcmc by beast-dev.

the class SeqGen method simulate.

public Alignment simulate(Tree tree) {
    int[] initialSequence = new int[length];
    drawSequence(initialSequence, freqModel);
    int[] siteCategories = new int[length];
    drawSiteCategories(siteModel, siteCategories);
    double[] rates = new double[siteModel.getCategoryCount()];
    for (int i = 0; i < rates.length; i++) {
        rates[i] = siteModel.getRateForCategory(i) * substitutionRate;
    }
    for (int i = 0; i < tree.getChildCount(tree.getRoot()); i++) {
        NodeRef child = tree.getChild(tree.getRoot(), i);
        evolveSequences(initialSequence, tree, child, substModel, siteCategories, rates);
    }
    Map<State, State[]> damageMap = new HashMap<State, State[]>();
    damageMap.put(Nucleotides.A_STATE, new State[] { Nucleotides.G_STATE });
    damageMap.put(Nucleotides.C_STATE, new State[] { Nucleotides.T_STATE });
    damageMap.put(Nucleotides.G_STATE, new State[] { Nucleotides.A_STATE });
    damageMap.put(Nucleotides.T_STATE, new State[] { Nucleotides.C_STATE });
    Sequence[] sequences = new Sequence[tree.getExternalNodeCount()];
    List<NucleotideState> nucs = jebl.evolution.sequences.Nucleotides.getCanonicalStates();
    for (int i = 0; i < tree.getExternalNodeCount(); i++) {
        NodeRef node = tree.getExternalNode(i);
        int[] seq = (int[]) tree.getNodeTaxon(node).getAttribute("seq");
        State[] states = new State[seq.length];
        for (int j = 0; j < states.length; j++) {
            states[j] = nucs.get(seq[j]);
        }
        if (damageRate > 0) {
            damageSequence(states, damageRate, tree.getNodeHeight(node), damageMap);
        }
        sequences[i] = new BasicSequence(SequenceType.NUCLEOTIDE, Taxon.getTaxon(tree.getNodeTaxon(node).getId()), states);
    }
    BasicAlignment alignment = new BasicAlignment(sequences);
    return alignment;
}
Also used : HashMap(java.util.HashMap) NodeRef(dr.evolution.tree.NodeRef) BasicAlignment(jebl.evolution.alignments.BasicAlignment)

Example 27 with NodeRef

use of dr.evolution.tree.NodeRef in project beast-mcmc by beast-dev.

the class SequenceSimulator method getTransitionProbabilities.

// traverse
void getTransitionProbabilities(Tree tree, NodeRef node, int rateCategory, double[] probs) {
    NodeRef parent = tree.getParent(node);
    final double branchRate = m_branchRateModel.getBranchRate(tree, node);
    // Get the operational time of the branch
    final double branchTime = branchRate * (tree.getNodeHeight(parent) - tree.getNodeHeight(node));
    if (branchTime < 0.0) {
        throw new RuntimeException("Negative branch length: " + branchTime);
    }
    double branchLength = m_siteModel.getRateForCategory(rateCategory) * branchTime;
    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);
}
Also used : NodeRef(dr.evolution.tree.NodeRef) SubstitutionEpochModel(dr.oldevomodel.substmodel.SubstitutionEpochModel)

Example 28 with NodeRef

use of dr.evolution.tree.NodeRef in project beast-mcmc by beast-dev.

the class GaussianProcessSkytrackTreeOperator method collectAllTimes.

private static void collectAllTimes(Tree tree, NodeRef top, NodeRef[] excludeBelow, ArrayList<ComparableDouble> times, ArrayList<Integer> childs) {
    times.add(new ComparableDouble(tree.getNodeHeight(top)));
    childs.add(tree.getChildCount(top));
    for (int i = 0; i < tree.getChildCount(top); i++) {
        NodeRef child = tree.getChild(top, i);
        if (excludeBelow == null) {
            collectAllTimes(tree, child, excludeBelow, times, childs);
        } else {
            // check if this subtree is included in the coalescent density
            boolean include = true;
            for (NodeRef anExcludeBelow : excludeBelow) {
                if (anExcludeBelow.getNumber() == child.getNumber()) {
                    include = false;
                    break;
                }
            }
            if (include)
                collectAllTimes(tree, child, excludeBelow, times, childs);
        }
    }
}
Also used : NodeRef(dr.evolution.tree.NodeRef) ComparableDouble(dr.util.ComparableDouble)

Example 29 with NodeRef

use of dr.evolution.tree.NodeRef in project beast-mcmc by beast-dev.

the class BivariateTraitBranchAttributeProvider method getTrait.

public Double getTrait(Tree tree, NodeRef node) {
    if (tree != traitLikelihood.getTreeModel())
        throw new RuntimeException("Bad bug.");
    NodeRef parent = tree.getParent(node);
    double[] startTrait = traitLikelihood.getTraitForNode(tree, parent, traitName);
    double[] endTrait = traitLikelihood.getTraitForNode(tree, node, traitName);
    double startTime = tree.getNodeHeight(parent);
    double endTime = tree.getNodeHeight(node);
    return branchFunction(startTrait, endTrait, startTime, endTime);
}
Also used : NodeRef(dr.evolution.tree.NodeRef)

Example 30 with NodeRef

use of dr.evolution.tree.NodeRef in project beast-mcmc by beast-dev.

the class ContinuousDiffusionStatistic method onAncestralPathTime.

//the sum of the branchLength for all the descendent nodes for a particular node should be larger than a user-specified value
private static boolean onAncestralPathTime(Tree tree, NodeRef node, double time) {
    double maxDescendentTime = 0;
    Set leafSet = TreeUtils.getExternalNodes(tree, node);
    Set nodeSet = TreeUtils.getExternalNodes(tree, node);
    Iterator iter = leafSet.iterator();
    while (iter.hasNext()) {
        //            System.out.println("found node set");
        NodeRef currentNode = (NodeRef) iter.next();
        while (tree.getNodeHeight(node) > tree.getNodeHeight(currentNode)) {
            //                System.out.println("found node height");
            if (!nodeSet.contains(currentNode)) {
                //                    System.out.println("found node");
                nodeSet.add(currentNode);
            }
            currentNode = tree.getParent(currentNode);
        }
    }
    Iterator nodeIter = nodeSet.iterator();
    while (nodeIter.hasNext()) {
        NodeRef testNode = (NodeRef) nodeIter.next();
        maxDescendentTime += tree.getBranchLength(testNode);
    }
    if (maxDescendentTime > time) {
        return true;
    } else {
        return false;
    }
}
Also used : NodeRef(dr.evolution.tree.NodeRef)

Aggregations

NodeRef (dr.evolution.tree.NodeRef)426 ArrayList (java.util.ArrayList)38 LinkedList (java.util.LinkedList)20 Taxon (dr.evolution.util.Taxon)18 Tree (dr.evolution.tree.Tree)14 TreeModel (dr.evomodel.tree.TreeModel)14 Parameter (dr.inference.model.Parameter)14 Clade (dr.evolution.tree.Clade)13 MutableTree (dr.evolution.tree.MutableTree)9 Node (dr.evomodel.arg.ARGModel.Node)9 MultivariateTraitTree (dr.evolution.tree.MultivariateTraitTree)8 BranchMapModel (dr.evomodel.epidemiology.casetocase.BranchMapModel)8 BitSet (java.util.BitSet)8 FixedBitSet (jebl.util.FixedBitSet)8 FlexibleTree (dr.evolution.tree.FlexibleTree)7 AbstractCase (dr.evomodel.epidemiology.casetocase.AbstractCase)7 Matrix (dr.math.matrixAlgebra.Matrix)6 CompoundParameter (dr.inference.model.CompoundParameter)5 TimeScale (dr.evolution.util.TimeScale)4 MicrosatelliteSamplerTreeModel (dr.evomodel.tree.MicrosatelliteSamplerTreeModel)4