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


Java Node.addChild方法代码示例

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


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

示例1: balanced_halved

import pal.tree.Node; //导入方法依赖的package包/类
private void balanced_halved(int nodes, double height) {
    if (!isPowerOfTwo(nodes))
        throw new RuntimeException("Does not implement balanced tree where number_of_taxa != 2^n");

    Node root = NodeFactory.createNode();

    List<Node> currentTips = Lists.newArrayList(root);

    int totalTips = currentTips.size();
    int depth = 0;

    while (totalTips < nodes) {
        depth++;

        List<Node> newTips = Lists.newArrayList();

        for (Node n : currentTips) {

            double l;
            l = height / Math.pow(2, depth);

            if (depth == 7) l += l;

            Node n1 = NodeFactory.createNode();
            n1.setBranchLength(l);
            newTips.add(n1);

            Node n2 = NodeFactory.createNode();
            n2.setBranchLength(l );
            newTips.add(n2);

            n.addChild(n1);
            n.addChild(n2);

        }

        currentTips.clear();
        currentTips.addAll(newTips);

        totalTips = currentTips.size();
    }


    SimpleTree st = new SimpleTree(root);

    int seqNumber = 1;
    for (Node tip : PhyloUtils.externalNodes(st)) {
        tip.setIdentifier(new Identifier("seq_" + seqNumber++));
    }

    System.out.println(st.toString());
}
 
开发者ID:tamuri,项目名称:swmutsel,代码行数:53,代码来源:TreeCreator.java

示例2: balanced_fixed

import pal.tree.Node; //导入方法依赖的package包/类
private void balanced_fixed(int nodes, double length) {

        if (!isPowerOfTwo(nodes))
            throw new RuntimeException("Does not implement balanced tree where number_of_taxa != 2^n");

        Node root = NodeFactory.createNode();

        List<Node> currentTips = Lists.newArrayList(root);


        int totalTips = currentTips.size();

        while (totalTips < nodes) {
            List<Node> newTips = Lists.newArrayList();

            for (Node n : currentTips) {
                Node n1 = NodeFactory.createNode();
                n1.setBranchLength(length);
                newTips.add(n1);

                Node n2 = NodeFactory.createNode();
                n2.setBranchLength(length);
                newTips.add(n2);

                n.addChild(n1);
                n.addChild(n2);
            }

            currentTips.clear();
            currentTips.addAll(newTips);

            totalTips = currentTips.size();
        }


        SimpleTree st = new SimpleTree(root);

        int seqNumber = 1;
        for (Node tip : PhyloUtils.externalNodes(st)) {
            tip.setIdentifier(new Identifier("seq_" + seqNumber++));
        }

        System.out.println(st.toString());


    }
 
开发者ID:tamuri,项目名称:swmutsel,代码行数:47,代码来源:TreeCreator.java

示例3: unbalanced_fixed

import pal.tree.Node; //导入方法依赖的package包/类
private void unbalanced_fixed(int totalNodes, double stepLength) {

        int nodeNumber = totalNodes;

        Node n1 = NodeFactory.createNode();
        n1.setIdentifier(new Identifier("seq_" + nodeNumber--));
        n1.setBranchLength(stepLength);

        Node n2 = NodeFactory.createNode();
        n2.setIdentifier(new Identifier("seq_" + nodeNumber--));
        n2.setBranchLength(stepLength);

        Node n3 = NodeFactory.createNode();
        n3.addChild(n1);
        n3.addChild(n2);

        Node root = n3;

        for (int i : seq(1, totalNodes - 2)) {

            root.setBranchLength(stepLength);

            Node n4 = NodeFactory.createNode();

            n4.addChild(root);

            root = n4;


            double length = stepLength * (i + 1);
            Node n5 = NodeFactory.createNode();
            n5.setBranchLength(length);
            n5.setIdentifier(new Identifier("seq_" + nodeNumber--));


            n4.addChild(n5);

        }

        SimpleTree st = new SimpleTree(root);
        System.out.println(st.toString());

    }
 
开发者ID:tamuri,项目名称:swmutsel,代码行数:44,代码来源:TreeCreator.java


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