本文整理汇总了Java中dr.evolution.tree.MutableTree.setNodeAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java MutableTree.setNodeAttribute方法的具体用法?Java MutableTree.setNodeAttribute怎么用?Java MutableTree.setNodeAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dr.evolution.tree.MutableTree
的用法示例。
在下文中一共展示了MutableTree.setNodeAttribute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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);
}
示例4: 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});
}
示例5: simulate
import dr.evolution.tree.MutableTree; //导入方法依赖的package包/类
private void simulate(MutableTree tree, NodeRef node, double value) {
tree.setNodeAttribute(node, traitName, new Double(value));
int childCount = tree.getChildCount(node);
double height = tree.getNodeHeight(node);
for (int i = 0; i < childCount; i++) {
NodeRef child = tree.getChild(node, i);
simulate(tree, child, diffusionModel.simulateForward(value, height - tree.getNodeHeight(child)));
}
}
示例6: PreAnnotator
import dr.evolution.tree.MutableTree; //导入方法依赖的package包/类
/**
* @throws IOException
* @throws ImportException
*
*/
public PreAnnotator(final String hostTreesFile, final String symbiontTreesFile, final String hostTreesOutputFile, final String symbiontTreesOutputFile) throws IOException, ImportException {
final FileReader hostFileReader = new FileReader(hostTreesFile);
final FileReader symbiontFileReader = new FileReader(symbiontTreesFile);
final TreeImporter hostTreeImporter = new NexusImporter(hostFileReader);
final TreeImporter symbiontTreeImporter = new NexusImporter(symbiontFileReader);
final PrintStream hostTreesStream = new PrintStream(new FileOutputStream(hostTreesOutputFile));
final PrintStream symbiontTreesStream = new PrintStream(new FileOutputStream(symbiontTreesOutputFile));
final NexusExporter hostNexusExporter = new NexusExporter(hostTreesStream);
final NexusExporter symbiontNexusExporter = new NexusExporter(symbiontTreesStream);
Map<String,Integer> hostNexusHeader = null;
Map<String,Integer> symbiontNexusHeader = null;
int totalTrees = 10000;
final int stepSize = totalTrees / 60;
PrintStream progressStream = System.out;
progressStream.println("Reading trees (bar assumes 10,000 trees)...");
progressStream.println("0 25 50 75 100");
progressStream.println("|--------------|--------------|--------------|--------------|");
totalTrees = 0;
while (hostTreeImporter.hasTree() && symbiontTreeImporter.hasTree()) {
MutableTree hostTree = (MutableTree) hostTreeImporter.importNextTree();
MutableTree symbiontTree = (MutableTree) symbiontTreeImporter.importNextTree();
if (hostTaxonList == null) hostTaxonList = hostTree;
ids = new int[hostTree.getNodeCount()];
addNewClades(hostTree, hostTree.getRoot());
for (int i = 0; i < symbiontTree.getNodeCount(); ++i) {
NodeRef n = symbiontTree.getNode(i);
symbiontTree.setNodeAttribute(n, HOST_NODE_REF, ids[(Integer) symbiontTree.getNodeAttribute(n, HOST_NODE_REF)]);
}
if (hostNexusHeader == null) {
hostNexusHeader = hostNexusExporter.writeNexusHeader(hostTree);
hostTreesStream.println("\t\t;");
symbiontNexusHeader = symbiontNexusExporter.writeNexusHeader(symbiontTree);
symbiontTreesStream.println("\t\t;");
}
hostNexusExporter.writeNexusTree(hostTree, hostTree.getId(), true, hostNexusHeader);
symbiontNexusExporter.writeNexusTree(symbiontTree, symbiontTree.getId(), true, symbiontNexusHeader);
if (totalTrees++ % stepSize == 0) {
progressStream.print("*");
progressStream.flush();
}
}
progressStream.println();
progressStream.println("Read " + totalTrees + " trees.");
hostTreesStream.println("End;");
symbiontTreesStream.println("End;");
progressStream.println("Done.");
hostFileReader.close();
symbiontFileReader.close();
hostTreesStream.close();
symbiontTreesStream.close();
}
示例7: annotateMeanAttribute
import dr.evolution.tree.MutableTree; //导入方法依赖的package包/类
private void annotateMeanAttribute(MutableTree tree, NodeRef node, String label, double[] values) {
double mean = DiscreteStatistics.mean(values);
tree.setNodeAttribute(node, label, mean);
}
示例8: annotateMedianAttribute
import dr.evolution.tree.MutableTree; //导入方法依赖的package包/类
private void annotateMedianAttribute(MutableTree tree, NodeRef node, String label, double[] values) {
double median = DiscreteStatistics.median(values);
tree.setNodeAttribute(node, label, median);
}
示例9: annotateRangeAttribute
import dr.evolution.tree.MutableTree; //导入方法依赖的package包/类
private void annotateRangeAttribute(MutableTree tree, NodeRef node, String label, double[] values) {
double min = DiscreteStatistics.min(values);
double max = DiscreteStatistics.max(values);
tree.setNodeAttribute(node, label, new Object[]{min, max});
}
示例10: annotateRates
import dr.evolution.tree.MutableTree; //导入方法依赖的package包/类
private static void annotateRates(
MutableTree targetTree, NodeRef node, Tree timeTree, Tree mutationTree) {
Set<String> leafSet = Tree.Utils.getDescendantLeaves(targetTree, node);
if (Tree.Utils.isMonophyletic(timeTree, leafSet)) {
NodeRef timeNode = Tree.Utils.getCommonAncestorNode(timeTree, leafSet);
NodeRef mutationNode = Tree.Utils.getCommonAncestorNode(mutationTree, leafSet);
double height = timeTree.getNodeHeight(timeNode);
if (!targetTree.isRoot(node)) {
double time = timeTree.getNodeHeight(timeTree.getParent(timeNode)) - height;
double mutations = mutationTree.getNodeHeight(mutationTree.getParent(mutationNode)) - mutationTree.getNodeHeight(mutationNode);
//double rate = mutations/time;
Number totalMutations = (Number)targetTree.getNodeAttribute(node, "totalMutations");
Number totalTime = (Number)targetTree.getNodeAttribute(node, "totalTime");
if (totalMutations == null) {
targetTree.setNodeAttribute(node, "totalMutations", mutations);
targetTree.setNodeAttribute(node, "totalTime", time);
targetTree.setNodeAttribute(node, "count", 1);
} else {
Integer count = (Integer)targetTree.getNodeAttribute(node, "count");
targetTree.setNodeAttribute(node, "totalMutations", totalMutations.doubleValue() + mutations);
targetTree.setNodeAttribute(node, "totalTime", totalTime.doubleValue() + time);
targetTree.setNodeAttribute(node, "count", count + 1);
}
}
if (!targetTree.isExternal(node)) {
java.util.List<Double> list = (java.util.List<Double>)targetTree.getNodeAttribute(node, "heightList");
if (list == null) {
list = new ArrayList<Double>() ;
targetTree.setNodeAttribute(node, "heightList", list);
}
list.add(height);
}
}
for (int i = 0; i < targetTree.getChildCount(node); i++) {
annotateRates(targetTree, targetTree.getChild(node, i), timeTree, mutationTree);
}
}