当前位置: 首页>>代码示例>>Java>>正文


Java TreeParser.getNodesAsArray方法代码示例

本文整理汇总了Java中beast.util.TreeParser.getNodesAsArray方法的典型用法代码示例。如果您正苦于以下问题:Java TreeParser.getNodesAsArray方法的具体用法?Java TreeParser.getNodesAsArray怎么用?Java TreeParser.getNodesAsArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在beast.util.TreeParser的用法示例。


在下文中一共展示了TreeParser.getNodesAsArray方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findNode

import beast.util.TreeParser; //导入方法依赖的package包/类
private Node findNode(final TreeParser tree, final String[] targetArray) {
    final Node[] treeNodes = tree.getNodesAsArray();
    final Set<String> targetSet = new HashSet<>();
    for (int i = 0; i < targetArray.length; i++) {
        targetSet.add(targetArray[i]);
    }

    for (Node node: treeNodes) {
        Set<String> nodeSet = new HashSet<>();

        if (node.isLeaf()) {
            nodeSet.add(node.getID());
        } else {
            final List<Node> leafNodes = node.getAllLeafNodes();
            for (Node leaf: leafNodes) {
                nodeSet.add(leaf.getID());
            }
        }

        if (targetSet.equals(nodeSet)) {
            return node;
        }
    }

    return null;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:27,代码来源:StarbeastClockTest.java

示例2: testTreeScaling

import beast.util.TreeParser; //导入方法依赖的package包/类
@Test
public void testTreeScaling() {
       String newick = "((0:1.0,1:1.0)4:1.0,(2:1.0,3:1.0)5:0.5)6:0.0;";

       TreeParser treeParser = new TreeParser(newick, false, false, false, 0);

       Node [] node = treeParser.getNodesAsArray();
       assertEquals(0.0, node[0].getHeight(), EPSILON);
       assertEquals(0.0, node[1].getHeight(), EPSILON);
       // leaf node, not scaled
       assertEquals(0.5, node[2].getHeight(), EPSILON);
       assertEquals(0.5, node[3].getHeight(), EPSILON);
       // internal nodes, all scaled
       assertEquals(1.0, node[4].getHeight(), EPSILON);
       assertEquals(1.5, node[5].getHeight(), EPSILON);
       assertEquals(2.0, node[6].getHeight(), EPSILON);
       
       treeParser.scale(2.0);
       
       // leaf node
       node = treeParser.getNodesAsArray();
       assertEquals(0.0, node[0].getHeight(), EPSILON);
       assertEquals(0.0, node[1].getHeight(), EPSILON);
       // leaf node, not scaled
       assertEquals(0.5, node[2].getHeight(), EPSILON);
       assertEquals(0.5, node[3].getHeight(), EPSILON);
       // internal nodes, all scaled
       assertEquals(2.0, node[4].getHeight(), EPSILON);
       assertEquals(3.0, node[5].getHeight(), EPSILON);
       assertEquals(4.0, node[6].getHeight(), EPSILON);
	
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:33,代码来源:TreeTest.java

示例3: testTreeScaling

import beast.util.TreeParser; //导入方法依赖的package包/类
@Test
public void testTreeScaling() {
       String newick = "((0:1.0,1:1.0)4:1.0,(2:1.0,3:1.0)5:0.5)6:0.0;";

       TreeParser tree = new TreeParser(newick, false, false, false, 0);

       Node [] node = tree.getNodesAsArray();
       
       ScaleOperator operator = new ScaleOperator();
       operator.initByName("tree", tree, "weight", 1.0);
       operator.proposal();
       
       // leaf node
       node = tree.getNodesAsArray();
       assertEquals(0.0, node[0].getHeight(), EPSILON);
       assertEquals(0.0, node[1].getHeight(), EPSILON);
       // leaf node, not scaled
       assertEquals(0.5, node[2].getHeight(), EPSILON);
       assertEquals(0.5, node[3].getHeight(), EPSILON);
       
       // internal nodes, all scaled
       // first determine scale factor
       double scale = node[4].getHeight() / 1.0;
       assertEquals(1.0 * scale, node[4].getHeight(), EPSILON);
       assertEquals(1.5 * scale, node[5].getHeight(), EPSILON);
       assertEquals(2.0 * scale, node[6].getHeight(), EPSILON);
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:28,代码来源:ScaleOperatorTest.java

示例4: traverse

import beast.util.TreeParser; //导入方法依赖的package包/类
private double traverse(TreeParser newickTree, double[][] geoBioDiversities, String[] traitsLong, String[] traitsShort, int[][] totalNodes, double[] totalLength) {
    if (traitsLong.length < traitsShort.length)
        throw new RuntimeException("Error: Trait 1 length = " + traitsLong.length + " < Trait 2 length = " + traitsShort.length);

    final int taxonCount = newickTree.getLeafNodeCount();
    final Node[] nodes = newickTree.getNodesAsArray();
    final String[] taxaNames = newickTree.getTaxaNames();
    double totalLengthOverTree = 0;

    for (int n = 0; n < taxonCount; n++) {
        assert (nodes[n].isLeaf());

        int matrixId = getIndexFrom(taxaNames[nodes[n].getNr()], traitsLong, traitsShort);

        if (matrixId < 0)
            throw new RuntimeException("Cannot find traits from " + taxaNames[nodes[n].getNr()]);
        if (matrixId >= traitsLong.length * traitsShort.length)
            throw new RuntimeException("Index = " + matrixId + " out of boundary at node " + n);

        if (verbose) {
            System.out.println(n + ", geoBioDiversities[" + matrixId + "][" + matrixId + "] = " +
                    geoBioDiversities[matrixId][matrixId] + " + " + nodes[n].getLength());
        }

        geoBioDiversities[matrixId][matrixId] += nodes[n].getLength();

        totalNodes[0][matrixId] ++;
        totalNodes[1][matrixId] ++;
        totalLength[matrixId] += nodes[n].getLength();
        totalLengthOverTree += nodes[n].getLength();
    }

    for (int n = taxonCount; n < nodes.length - 1; n++) { // exclude nodes[length - 1] which is root
        if (nodes[n].isRoot()) System.out.println(n + " is Root : " + nodes[n].getLength());

        List<Integer> traitsIndex = getAllTraitsIndexFromInternalNode(nodes[n], taxaNames, traitsLong, traitsShort);
        Collections.sort(traitsIndex);

        if (verbose) System.out.println(n + ", traitsIndex = " + traitsIndex);

        if (traitsIndex.size() < 1) {
            throw new RuntimeException("plotsIndex.size() < 1 when n = " + n);
        } else if (traitsIndex.size() == 1) {
            if (verbose) {
                System.out.println(n + ", geoBioDiversities[" + traitsIndex.get(0) + "][" + traitsIndex.get(0) + "] = " +
                        geoBioDiversities[traitsIndex.get(0)][traitsIndex.get(0)] + " + " + nodes[n].getLength());
            }
            geoBioDiversities[traitsIndex.get(0)][traitsIndex.get(0)] += nodes[n].getLength();

            totalNodes[0][traitsIndex.get(0)] ++;
            totalNodes[1][traitsIndex.get(0)] ++;
            totalLength[traitsIndex.get(0)] += nodes[n].getLength();

        } else {
            for (int i = 0; i < traitsIndex.size(); i++) {
                for (int j = i + 1; j < traitsIndex.size(); j++) {
                    if (verbose) {
                        System.out.println(n + ", geoBioDiversities[" + traitsIndex.get(i) + "][" + traitsIndex.get(j) + "] = " +
                                geoBioDiversities[traitsIndex.get(i)][traitsIndex.get(j)] + " + " + nodes[n].getLength());
                    }

                    geoBioDiversities[traitsIndex.get(i)][traitsIndex.get(j)] += nodes[n].getLength();

                }
                totalNodes[1][traitsIndex.get(i)] ++;
                totalLength[traitsIndex.get(i)] += nodes[n].getLength();
            }
        }

        totalLengthOverTree += nodes[n].getLength();
    }
    return totalLengthOverTree;

}
 
开发者ID:CompEvol,项目名称:NZGOT,代码行数:75,代码来源:GeoBioDiversityMatrix.java


注:本文中的beast.util.TreeParser.getNodesAsArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。