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;
}
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);
}
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);
}
}
}
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);
}
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;
}
}
Aggregations