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


Java Node.getChildCount方法代码示例

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


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

示例1: drawBranch

import beast.evolution.tree.Node; //导入方法依赖的package包/类
final void drawBranch(Node node, Node childNode, Graphics2D g) {

        if (colorTraitName != null) {
            int childColorIndex = getIntegerTrait(childNode, colorTraitName);

            int parentColorIndex = getIntegerTrait(node, colorTraitName);

            if (childColorIndex == parentColorIndex && node.getChildCount() == 1) {
                System.out.println("Parent and single child have same state!!");
                drawNode(getTransformedNodePoint2D(node), g, NodeDecorator.BLACK_DOT);
            }

            g.setColor(traitColorTable.getColor(childColorIndex));
        }

        Shape shape = branchStyle.getBranchShape(getCanonicalNodePoint2D(childNode), getCanonicalNodePoint2D(node));
        Shape transformed = orientation.getTransform(bounds).createTransformedShape(shape);

        g.draw(transformed);
    }
 
开发者ID:CompEvol,项目名称:beastshell,代码行数:21,代码来源:TreeComponent.java

示例2: getTreeCladeCodes

import beast.evolution.tree.Node; //导入方法依赖的package包/类
int getTreeCladeCodes(Node node, BitSet[] codes) {
    final int inode = node.getNr();
    codes[inode].clear();
    if (node.isLeaf()) {
        int index = getTaxonIndex(node);//getTaxonIndex(node);
        codes[inode].set(index);
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            final Node child = node.getChild(i);
            final int childIndex = getTreeCladeCodes(child, codes);

            codes[inode].or(codes[childIndex]);
        }
    }
    return inode;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:17,代码来源:CladeSystem.java

示例3: binarizeMultifurcation

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * Use zero-length edges to replace multifurcations with a sequence of bifurcations.
 *
 * @param node node representing multifurcation
 */
private void binarizeMultifurcation(Node node) {
     if (node.getChildCount()>2) {
        List<Node> children = new ArrayList<>(node.getChildren());
        Node prevDummy = node;
        for (int i=1; i<children.size()-1; i++) {
            Node child = children.get(i);

            Node dummyNode = newNode();
            dummyNode.setNr(-1);
            dummyNode.setHeight(0);
            prevDummy.addChild(dummyNode);

            node.removeChild(child);
            dummyNode.addChild(child);

            prevDummy = dummyNode;
        }
        node.removeChild(children.get(children.size()-1));
        prevDummy.addChild(children.get(children.size()-1));
    }
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:27,代码来源:TreeParser.java

示例4: removeSingleChildNodes

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * Extract the sampled tree by discarding all the nodes that have -1 number simultaneously suppress single
 * child nodes (nodes with only one child numbered by non-negative number)
 * @param node
 */
public void removeSingleChildNodes(Node node) {
    if (!node.isLeaf()) {
        Node left = node.getLeft();
        Node right = node.getRight();

        removeSingleChildNodes(left);
        removeSingleChildNodes(right);
        for (Node child:node.getChildren()) {
            if (child.getNr() == -1) {
                node.removeChild(child);
            }
        }
        if (node.getChildCount() == 1 && node.getParent() != null) {
            Node parent = node.getParent();
            Node newChild =  node.getLeft();
            parent.removeChild(node);
            parent.addChild(newChild);
            newChild.setParent(parent);
            //node.setParent(null);
        }
    }
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:28,代码来源:SABDSkylineTreeSimulatorArbitraryRateChanges.java

示例5: convertTree

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private void convertTree(Node node) {

        if (!node.isLeaf()) {
            if (node.isFake()) {
                Node directAncestor = node.getDirectAncestorChild();
                node.removeChild(directAncestor);
                node.setNr(directAncestor.getNr());
                node.setID(directAncestor.getID());
                directAncestor.setParent(null);
            }
            for (int i = 0; i < node.getChildCount(); i++) {
                Node childNode = node.getChild(i);
                convertTree(childNode);
            }
        }



    }
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:20,代码来源:ConvertZBTreeToSATree.java

示例6: collectDT

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private void collectDT(Node node, BitSet bits, double[] divergenceTimes) {


        if (node.isLeaf()) {
            bits.set(Integer.parseInt(node.getID().replaceAll("A","")));
        } else {

            BitSet bits2 = new BitSet();
            for (int i = 0; i < node.getChildCount(); i++) {
                Node childNode = node.getChild(i);
                collectDT(childNode, bits2, divergenceTimes);
            }

            for (BitSet cladeBits:cladeList) {
                BitSet cladeBitsClone = (BitSet)cladeBits.clone();
                cladeBitsClone.andNot(bits2);
                if (cladeBitsClone.isEmpty()) {
                    int index = cladeList.indexOf(cladeBits);
                    if (divergenceTimes[index] < 0) {
                        divergenceTimes[index] = node.getHeight();
                    }
                }
            }

            if (bits != null) {
                bits.or(bits2);
            }
        }


    }
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:32,代码来源:DivergenceTimeProcessor.java

示例7: convertToFakeSATree

import beast.evolution.tree.Node; //导入方法依赖的package包/类
public static void convertToFakeSATree(Node node, int[] nextNr) {
    if (!node.isLeaf()) {
        convertToFakeSATree(node.getLeft(), nextNr);
        if (node.getRight() != null) {
            convertToFakeSATree(node.getRight(), nextNr);
        }
    }
    if (node.getChildCount() == 1) {
        Node parent = new Node();
        parent.setHeight(node.getHeight());
        Node child = node.getLeft();
        parent.setLeft(child);
        child.setParent(parent);
        node.removeChild(child);
        parent.setRight(node);
        parent.setNr(nextNr[0]);
        nextNr[0]++;
        if (!node.isRoot()) {
            Node grandparent = node.getParent();

            if (grandparent.getLeft().getNr() == node.getNr()) {
                grandparent.setLeft(parent);
            }  else {
                grandparent.setRight(parent);
            }
            parent.setParent(grandparent);
        }  else {
            node.getTree().setRoot(parent);
        }
        node.setParent(parent);
    }
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:33,代码来源:SampledAncestorTreeComparator.java

示例8: listNodesUnder

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private ArrayList<Integer> listNodesUnder(Node node) {

        ArrayList<Integer> tmp = new ArrayList<Integer>();
        if (node.getChildCount() < 2)
            tmp.add(node.getNr()+1);
        if (node.getLeft() != null)
            tmp.addAll(listNodesUnder(node.getLeft()));
        if (node.getRight() != null)
            tmp.addAll(listNodesUnder(node.getRight()));
        return tmp;
    }
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:12,代码来源:SampledAncestorTreeAnalysis.java

示例9: extractAllDClades

import beast.evolution.tree.Node; //导入方法依赖的package包/类
public ArrayList<String> extractAllDClades(Node node, boolean zeroBranchTrees) {
    ArrayList<String> tmp = new ArrayList<String>();

    if ((!zeroBranchTrees && node.getChildCount() < 2) || (zeroBranchTrees && node.isLeaf()))
        tmp.add(extractDClade(node, zeroBranchTrees));
    if (node.getLeft() != null)
        tmp.addAll(extractAllDClades(node.getLeft(), zeroBranchTrees));
    if (node.getRight() != null)
        tmp.addAll(extractAllDClades(node.getRight(), zeroBranchTrees));

    return tmp;
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:13,代码来源:SampledAncestorTreeAnalysis.java

示例10: removeFossils

import beast.evolution.tree.Node; //导入方法依赖的package包/类
public void removeFossils(Node node, Tree tree, ArrayList<Node> removedNodes) {
    if (node.isLeaf()) {
        if (!extantTaxa.contains(node.getID())) {
            node.getParent().removeChild(node);
            node.setParent(null);
            removedNodes.add(node);
        }
    }  else {
        Node left = node.getLeft();
        Node right = node.getRight();
        removeFossils(left, tree, removedNodes);
        removeFossils(right, tree, removedNodes);


        if (node.isLeaf()) {
            node.getParent().removeChild(node);
            node.setParent(null);
            removedNodes.add(node);
        }
        if (node.getChildCount() == 1) {
            Node child = node.getChild(0);
            if (node.getParent() != null) {
                Node grandParent = node.getParent();
                grandParent.removeChild(node);
                grandParent.addChild(child);
                child.setParent(grandParent);
                node.setParent(null);
            }
            else {
                child.setParent(null);
                tree.setRootOnly(child);
            }
            removedNodes.add(node);
        }

    }
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:38,代码来源:FullToExtantTreeConverter.java

示例11: convertToFakeSATree

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * convert a tree with single child node to ZeroBranchSATree.
 *
 * @param node all the nodes that are under this node and have single child will be
 *             replaced with zero branches
 * @throws Exception
 */

private void convertToFakeSATree(Node node, int[] lastLabel) throws Exception {
    if (!node.isLeaf()) {
        convertToFakeSATree(node.getLeft(), lastLabel);
        if (node.getRight() != null) {
            convertToFakeSATree(node.getRight(), lastLabel);
        }
    }
    if (node.getChildCount() == 1) {
        Node parent = newNode();
        parent.setNr(-1);
        parent.setHeight(node.getHeight());
        Node child = node.getLeft();
        parent.setLeft(child);
        child.setParent(parent);
        node.removeChild(child);
        parent.setRight(node);
        if (!node.isRoot()) {
            Node grandparent = node.getParent();

            if (grandparent.getLeft().equals(node)) {
                grandparent.setLeft(parent);
            }  else {
                grandparent.setRight(parent);
            }
            parent.setParent(grandparent);
        }
        node.setParent(parent);
        if (node.getNr() == -1) {
            node.setNr(lastLabel[0]+1);
            lastLabel[0]++;
        }
    }
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:42,代码来源:ZeroBranchSATreeParser.java

示例12: visitNode

import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public Node visitNode(NewickParser.NodeContext ctx) {
    Node node = newNode();

    for (NewickParser.NodeContext ctxChild : ctx.node()) {
        node.addChild(visit(ctxChild));
    }

    NewickParser.PostContext postCtx = ctx.post();

    // Process metadata

    if (postCtx.nodeMeta != null)
        processMetadata(node, postCtx.nodeMeta, false);

    if (postCtx.lengthMeta != null)
        processMetadata(node, postCtx.lengthMeta, true);

    // Process edge length

    if (postCtx.length != null)
        node.setHeight(Double.parseDouble(postCtx.length.getText()));
    else
        node.setHeight(DEFAULT_LENGTH);

    // Process label

    node.setNr(-1);
    if (postCtx.label() != null) {
        node.setID(postCtx.label().getText());

        if (postCtx.label().number() == null
                || postCtx.label().number().INT() == null)
            integerLeafLabels = false;

        // Treat labels as node numbers in certain situations
        if (!isLabelledNewickInput.get()
                && postCtx.label().number() != null
                && postCtx.label().number().INT() != null) {

            int nodeNr = Integer.parseInt(postCtx.label().getText()) - offsetInput.get();
            if (nodeNr<0)
                throw new TreeParsingException("Node number given " +
                        "is smaller than current offset (" +
                        offsetInput.get() + ").  Perhaps offset is " +
                        "too high?");

            node.setNr(nodeNr);
            numberedNodeCount += 1;
        } else {
            if (node.isLeaf()) {
                node.setNr(getLabelIndex(postCtx.label().getText()));
                numberedNodeCount += 1;
            }
        }
    }

    if (node.getChildCount()==1 && !allowSingleChildInput.get())
        throw new TreeParsingException("Node with single child found.");

    // Use length-zero edges to binarize multifurcations.
    if (binarizeMultifurcationsInput.get())
        binarizeMultifurcation(node);


    return node;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:68,代码来源:TreeParser.java


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