本文整理汇总了Java中dr.evolution.tree.MutableTree类的典型用法代码示例。如果您正苦于以下问题:Java MutableTree类的具体用法?Java MutableTree怎么用?Java MutableTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MutableTree类属于dr.evolution.tree包,在下文中一共展示了MutableTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fillInternalGaps
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
private Object fillInternalGaps(Tree tree, NodeRef node) {
if (!tree.isExternal(node)) {
Object left = fillInternalGaps(tree, tree.getChild(node, 0));
Object right = fillInternalGaps(tree, tree.getChild(node, 1));
if (tree.getNodeAttribute(node, POP) == null) {
if (left == null && right == null) {
throw new RuntimeException("left and right are both null for node " + node.getNumber());
}
if (left == null) left = right;
if (right == null) right = left;
if (left.equals(right)) {
((MutableTree) tree).setNodeAttribute(node, POP, left);
//System.out.println("Setting pop to " + left + " in node " + node.getNumber());
} else {
throw new RuntimeException(left + "!=" + right + " in children of node " + node.getNumber());
}
}
}
return tree.getNodeAttribute(node, POP);
}
示例2: fillExternalGaps
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
private void fillExternalGaps(Tree tree) {
for (int i = 0; i < tree.getExternalNodeCount(); i++) {
NodeRef node = tree.getExternalNode(i);
if (tree.getNodeAttribute(node, POP) == null) {
((MutableTree) tree).setNodeAttribute(node, POP,
tree.getNodeAttribute(tree.getParent(node), POP));
}
}
}
示例3: adjustInternalHeights
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
private static void adjustInternalHeights(MutableTree tree, NodeRef node) {
if (!tree.isExternal(node)) {
// pre-order recursion
for (int i = 0; i < tree.getChildCount(node); i++) {
adjustInternalHeights(tree, tree.getChild(node, i));
}
}
NodeRef parent = tree.getParent(node);
if (parent != null) {
if (tree.getNodeHeight(parent) < tree.getNodeHeight(node)) {
tree.setNodeHeight(parent, tree.getNodeHeight(node));
}
}
}
示例4: rescaleTree
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
private void rescaleTree(Tree tree, double scale) {
if (tree instanceof MutableTree) {
MutableTree mutableTree = (MutableTree) tree;
for (int i = 0; i < tree.getNodeCount(); i++) {
NodeRef node = tree.getNode(i);
if (node != tree.getRoot()) {
double length = tree.getBranchLength(node);
mutableTree.setBranchLength(node, length * scale);
}
}
} else {
throw new IllegalArgumentException("Tree not mutable");
}
}
示例5: setTree
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
/**
* Set the tree.
*/
public void setTree(Tree tree) {
this.tree = tree;
if (tree != null) {
if (tree instanceof MutableTree) {
((MutableTree)tree).addMutableTreeListener(this);
}
if (tree instanceof MutableTaxonList) {
((MutableTaxonList)tree).addMutableTaxonListListener(this);
}
}
repaint();
}
示例6: makeCompatible
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
public void makeCompatible(double rootHeight) {
for( GeneTreeInfo t : getGeneTrees() ) {
MutableTree tree = t.tree;
for (int i = 0; i < tree.getExternalNodeCount(); i++) {
final NodeRef node = tree.getExternalNode(i);
final NodeRef p = tree.getParent(node);
tree.setNodeHeight(p, rootHeight + tree.getNodeHeight(p));
}
MutableTree.Utils.correctHeightsForTips(tree);
// (todo) ugly re-init - can I do something better?
t.wasChanged();
t.getCoalInfo();
t.wasBacked = false;
//t.wasChanged();
}
}
示例7: doOperation
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
public double doOperation() {
if( tree.getInternalNodeCount() < 2 ) {
throw new RuntimeException("no node found");
}
tree.beginTreeEdit();
switch( nodesToMove ) {
case 2: move2(); break;
case 3: move3(); break;
}
tree.endTreeEdit();
// AR not sure whether this check is needed...
try {
tree.checkTreeIsValid();
} catch( MutableTree.InvalidTreeException ite ) {
throw new RuntimeException(ite.toString());
}
return 0;
}
示例8: parseXMLObject
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
MutableTree model = (MutableTree) xo.getChild(MutableTree.class);
final CompoundParameter allTraits = (CompoundParameter) xo.getChild(CompoundParameter.class);
String taxonString = (String) xo.getAttribute(TreeModelParser.TAXON);
final int leafIndex = model.getTaxonIndex(taxonString);
if (leafIndex == -1) {
throw new XMLParseException("Unable to find taxon '" + taxonString + "' in trees.");
}
final Parameter leafTrait = allTraits.getParameter(leafIndex);
boolean setBounds = xo.getAttribute(SET_BOUNDS, true);
if (setBounds) {
Parameter.DefaultBounds bound = new Parameter.DefaultBounds(Double.MAX_VALUE, -Double.MAX_VALUE,
leafTrait.getDimension());
leafTrait.addBounds(bound);
}
return leafTrait;
}
示例9: addNewClades
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
private BitSet addNewClades(final MutableTree tree, final NodeRef node) {
final BitSet bitSet = new BitSet(tree.getTaxonCount());
if (tree.isExternal(node)) {
bitSet.set(hostTaxonList.getTaxonIndex(tree.getNodeTaxon(node).getId()));
} else {
for (int i = 0; i < tree.getChildCount(node); ++i) {
bitSet.or(addNewClades(tree, tree.getChild(node, i)));
}
}
if (!clades.containsKey(bitSet))
clades.put(bitSet, clades.size());
final int id = clades.get(bitSet);
ids[(Integer) tree.getNodeAttribute(node, NODE_REF)] = id;
tree.setNodeAttribute(node, NODE_REF, id);
return bitSet;
}
示例10: annotateModeAttribute
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
private void annotateModeAttribute(MutableTree tree, NodeRef node, String label, HashMap<Object, Integer> values) {
Object mode = null;
int maxCount = 0;
int totalCount = 0;
int countInMode = 1;
for (Object key : values.keySet()) {
int thisCount = values.get(key);
if (thisCount == maxCount) {
// I hope this is the intention
mode = mode.toString().concat("+" + key);
countInMode++;
} else if (thisCount > maxCount) {
mode = key;
maxCount = thisCount;
countInMode = 1;
}
totalCount += thisCount;
}
double freq = (double) maxCount / (double) totalCount * countInMode;
tree.setNodeAttribute(node, label, mode);
tree.setNodeAttribute(node, label + ".prob", freq);
}
示例11: annotateFrequencyAttribute
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
private void annotateFrequencyAttribute(MutableTree tree, NodeRef node, String label, HashMap<Object, Integer> values) {
double totalCount = 0;
Set keySet = values.keySet();
int length = keySet.size();
String[] name = new String[length];
Double[] freq = new Double[length];
int index = 0;
for (Object key : values.keySet()) {
name[index] = key.toString();
freq[index] = new Double(values.get(key));
totalCount += freq[index];
index++;
}
for (int i = 0; i < length; i++)
freq[i] /= totalCount;
tree.setNodeAttribute(node, label + ".set", name);
tree.setNodeAttribute(node, label + ".set.prob", freq);
}
示例12: annotateHPDAttribute
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
private void annotateHPDAttribute(MutableTree tree, NodeRef node, String label, double hpd, double[] values) {
int[] indices = new int[values.length];
HeapSort.sort(values, indices);
double minRange = Double.MAX_VALUE;
int hpdIndex = 0;
int diff = (int) Math.round(hpd * (double) values.length);
for (int i = 0; i <= (values.length - diff); i++) {
double minValue = values[indices[i]];
double maxValue = values[indices[i + diff - 1]];
double range = Math.abs(maxValue - minValue);
if (range < minRange) {
minRange = range;
hpdIndex = i;
}
}
double lower = values[indices[hpdIndex]];
double upper = values[indices[hpdIndex + diff - 1]];
tree.setNodeAttribute(node, label, new Object[]{lower, upper});
}
示例13: doOperation
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
public double doOperation() throws OperatorFailedException {
if( tree.getInternalNodeCount() < 2 ) {
throw new OperatorFailedException("no node found");
}
tree.beginTreeEdit();
switch( nodesToMove ) {
case 2: move2(); break;
case 3: move3(); break;
}
tree.endTreeEdit();
// AR not sure whether this check is needed...
try {
tree.checkTreeIsValid();
} catch( MutableTree.InvalidTreeException ite ) {
throw new OperatorFailedException(ite.toString());
}
return 0;
}
示例14: simulate
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
/**
* simulates a trait ona tree.
* @param clone if true, use copy of the tree, otherwise use given tree
* @return the simulated tree.
*/
public Tree simulate(Tree tree, double value, boolean clone) {
Tree binaryTree = null;
if (clone) {
binaryTree = new FlexibleTree(tree);
((FlexibleTree)binaryTree).resolveTree();
} else {
binaryTree = tree;
}
simulate((MutableTree)binaryTree, binaryTree.getRoot(), value);
return binaryTree;
}
示例15: getSyntaxRules
import dr.evolution.tree.MutableTree; //导入依赖的package包/类
@Override
public XMLSyntaxRule[] getSyntaxRules() {
return new XMLSyntaxRule[]{
AttributeRule.newStringRule(TreeModelParser.TAXON),
AttributeRule.newBooleanRule(SET_BOUNDS, true),
new ElementRule(MutableTree.class),
new ElementRule(CompoundParameter.class),
};
}