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


Java Node.isLeaf方法代码示例

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


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

示例1: findNode

import beast.evolution.tree.Node; //导入方法依赖的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: branchLogP

import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public double branchLogP(int speciesTreeNodeNumber, Node speciesTreeNode, double ploidy, double[] branchCoalescentTimes, int branchLineageCount, int branchEventCount) {
    final RealParameter tipPopSizes = tipPopSizesInput.get();
    final RealParameter topPopSizes = topPopSizesInput.get();

    double branchTipPopSize;
    if (speciesTreeNode.isLeaf()) {
        branchTipPopSize = tipPopSizes.getValue(speciesTreeNodeNumber);
    } else {
        final int leftChildTopI = speciesTreeNode.getLeft().getNr();
        final int rightChildTopI = speciesTreeNode.getRight().getNr();
        branchTipPopSize = topPopSizes.getValue(leftChildTopI) + topPopSizes.getValue(rightChildTopI);
    }

    if (speciesTreeNode.isRoot()) {
        return ConstantPopulations.constantLogP(branchTipPopSize, ploidy, branchCoalescentTimes, branchLineageCount, branchEventCount);
    } else {
        final int speciesTopI = speciesTreeNodeNumber;
        final double branchTopPopSize = topPopSizes.getValue(speciesTopI);
        return linearLogP(branchTopPopSize, branchTipPopSize, ploidy, branchCoalescentTimes, branchLineageCount, branchEventCount);
    }
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:23,代码来源:LinearWithConstantRoot.java

示例3: serialize

import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public void serialize(Node speciesTreeNode, StringBuffer buf, DecimalFormat df) {
    final RealParameter tipPopSizes = tipPopSizesInput.get();
    final RealParameter topPopSizes = topPopSizesInput.get();
    final int speciesTreeNodeNumber = speciesTreeNode.getNr();

    double branchTipPopSize;
    if (speciesTreeNode.isLeaf()) {
        branchTipPopSize = tipPopSizes.getValue(speciesTreeNodeNumber);
    } else {
        final int leftChildTopI = speciesTreeNode.getLeft().getNr();
        final int rightChildTopI = speciesTreeNode.getRight().getNr();
        branchTipPopSize = topPopSizes.getValue(leftChildTopI) + topPopSizes.getValue(rightChildTopI);
    }

    final double branchTopPopSize = (speciesTreeNode.isRoot()) ? branchTipPopSize : topPopSizes.getValue(speciesTreeNode.getNr());

    if (df == null) buf.append("dmv={" + branchTopPopSize + "," + branchTipPopSize + "}");
    else buf.append("dmv={" + df.format(branchTopPopSize) + "," + df.format(branchTipPopSize) + "}");
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:21,代码来源:LinearWithConstantRoot.java

示例4: findDescendants

import beast.evolution.tree.Node; //导入方法依赖的package包/类
protected Set<String> findDescendants(Node speciesTreeNode, int speciesTreeNodeNumber) {
    final Multimap<Integer, String> numberTipMap = speciesTreeInput.get().getNumberTipMap();
    final Set<String> descendantNames = new HashSet<>();

    if (speciesTreeNode.isLeaf()) {
        descendantNames.addAll(numberTipMap.get(speciesTreeNodeNumber));
    } else {
        final Node leftChild = speciesTreeNode.getLeft();
        final Node rightChild = speciesTreeNode.getRight();
        final int leftChildNumber = leftChild.getNr();
        final int rightChildNumber = rightChild.getNr();

        descendantNames.addAll(findDescendants(leftChild, leftChildNumber));
        descendantNames.addAll(findDescendants(rightChild, rightChildNumber));
    }

    return descendantNames;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:19,代码来源:CoordinatedOperator.java

示例5: findGraftBranches

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private boolean findGraftBranches(Node geneTreeNode, Set<Node> graftNodes, Set<String> branchDescendants) {
    if (geneTreeNode.isLeaf()) {
        final String descendantName = geneTreeNode.getID();
        return branchDescendants.contains(descendantName);
    }

    final Node leftChild = geneTreeNode.getLeft();
    final Node rightChild = geneTreeNode.getRight();
    final boolean leftOverlaps = findGraftBranches(leftChild, graftNodes, branchDescendants);
    final boolean rightOverlaps = findGraftBranches(rightChild, graftNodes, branchDescendants);

    // subtree defined by a child node overlaps species subtree defined by branch
    if (leftOverlaps || rightOverlaps) {
        if (leftOverlaps) {
            graftNodes.add(leftChild);
        }

        if (rightOverlaps) {
            graftNodes.add(rightChild);
        }

        return true;
    }

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

示例6: recurseLength

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private static double recurseLength(final Node treeNode, final double parentHeight) {
    if (treeNode.isLeaf()) {
        return parentHeight;
    } else {
        double subtreeLength = 0.0;

        final double nodeHeight = treeNode.getHeight();
        subtreeLength += parentHeight - nodeHeight;

        final double leftChildLength = recurseLength(treeNode.getLeft(), nodeHeight);
        final double rightChildLength = recurseLength(treeNode.getRight(), nodeHeight);
        subtreeLength += leftChildLength;
        subtreeLength += rightChildLength;

        return subtreeLength;
    }
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:18,代码来源:TreeStats.java

示例7: recurseBranchRates

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * This is a recursive function that does the work of
 * calculating the unscaled branch rates across the tree
 * taking into account the indicator variables.
 *
 * @param node the node
 * @param rate the rate of the parent node
 */
private void recurseBranchRates(Node node, double parentHeight, double rate, Boolean[] indicators, Double[] branchRates) {
    final int nodeNumber = node.getNr();
    final double nodeHeight = node.getHeight();

    // not the root, and indicator is "on"
    if (nodeNumber < rootNodeNumber && indicators[nodeNumber]) {
        rate = branchRates[nodeNumber];
    }

    double branchLength = parentHeight - nodeHeight;
    strictRatesTotal += branchLength;
    relaxedRatesTotal += branchLength * rate;

    ratesArray[nodeNumber] = rate;

    if (!node.isLeaf()) {
        recurseBranchRates(node.getLeft(), nodeHeight, rate, indicators, branchRates);
        recurseBranchRates(node.getRight(), nodeHeight, rate, indicators, branchRates);
    }
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:29,代码来源:RandomLocalRates.java

示例8: setPartials

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * set leaf partials in likelihood core *
 */
protected void setPartials(Node node, int patternCount) {
    if (node.isLeaf()) {
        //Alignment data = m_data.get();
        int nStates = data.getDataType().getStateCount();
        double[] partials = new double[patternCount * nStates];

        int k = 0;
        int iTaxon = data.getTaxonIndex(node.getID());
        for (int iPattern = 0; iPattern < patternCount; iPattern++) {
            int nState = data.getPattern(iTaxon, iPattern);
            boolean[] stateSet = data.getStateSet(nState);
            for (int iState = 0; iState < nStates; iState++) {
                partials[k++] = (stateSet[iState] ? 1.0 : 0.0);
            }
        }
        //System.out.println(m_likelihoodCore == null);
        m_likelihoodCore.setNodePartials(node.getNr(), partials);

    } else {
        //System.out.println(m_likelihoodCore == null);
        setPartials(node.getLeft(), patternCount);
        setPartials(node.getRight(), patternCount);
    }
}
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:28,代码来源:NewWVTreeLikelihood.java

示例9: 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,代码来源:SABDSimulator.java

示例10: setStates

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * set leaf states in likelihood core *
 */
protected void setStates(Node node, int patternCount) {
    if (node.isLeaf()) {
        Alignment data = dataInput.get();
        int i;
        int[] states = new int[patternCount];
        int taxonIndex = getTaxonIndex(node.getID(), data);
        for (i = 0; i < patternCount; i++) {
            int code = data.getPattern(taxonIndex, i);
            int[] statesForCode = data.getDataType().getStatesForCode(code);
            if (statesForCode.length==1)
                states[i] = statesForCode[0];
            else
                states[i] = code; // Causes ambiguous states to be ignored.
        }
        likelihoodCore.setNodeStates(node.getNr(), states);

    } else {
        setStates(node.getLeft(), patternCount);
        setStates(node.getRight(), patternCount);
    }
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:25,代码来源:TreeLikelihood.java

示例11: lengthToHeight

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/** convert length to height
 *  and set ID of leafs
 */
private double lengthToHeight(Node node, double offSet) {
	if (node.isLeaf()) {
		node.setHeight(-offSet - node.getHeight());
		node.setID(m_sLabels.get(node.getNr()));
		return -node.getHeight();
	} else {
		double posY = offSet + node.getHeight();
		double yMax = 0;
		yMax = Math.max(yMax, lengthToHeight(node.getLeft(), posY));
		if (node.getRight() != null) {
			yMax = Math.max(yMax, lengthToHeight(node.getRight(), posY));
		}
		node.setHeight(-posY);
		return yMax;
	}
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:20,代码来源:TreeSetParser.java

示例12: collectTimes

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * extract coalescent times and tip information into array times from beast.tree.
 *
 * @param tree        the beast.tree
 * @param times       the times of the nodes in the beast.tree
 * @param childCounts the number of children of each node
 */
protected static void collectTimes(Tree tree, double[] times, int[] childCounts) {
    Node[] nodes = tree.getNodesAsArray();
    for (int i = 0; i < nodes.length; i++) {
        Node node = nodes[i];
        times[i] = node.getHeight();
        childCounts[i] = node.isLeaf() ? 0 : 2;
    }
}
 
开发者ID:nicfel,项目名称:Mascot,代码行数:16,代码来源:StructuredTreeIntervals.java

示例13: calcMinHeight

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private double calcMinHeight(Node node) {
	if (node.isLeaf()) {
		return node.getHeight();
	}
	
	double minHeight = 0.0;
	for (Node child: node.getChildren()) {
		minHeight = Math.max(minHeight, calcMinHeight(child));
	}
	
	return minHeight;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:13,代码来源:NodeReheight2.java

示例14: checkConsistency

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private boolean checkConsistency(final Node node, final boolean[] used) {
    if (used[node.getNr()]) {
        // used twice? tha's bad
        return false;
    }
    used[node.getNr()] = true;
    if ( node.isLeaf() ) {
        return true;
    }
    return checkConsistency(node.getLeft(), used) && checkConsistency(node.getRight(), used);
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:12,代码来源:NodeReheight2.java

示例15: collectHeights

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 ** gather height of each node, and the node index associated with the height.*
 **/
private int collectHeights(final Node node, final double[] heights, final int[] reverseOrder, int current) {
    if (node.isLeaf()) {
        heights[current] = node.getHeight();
        reverseOrder[current] = node.getNr();
        current++;
    } else {
        current = collectHeights(node.getLeft(), heights, reverseOrder, current);
        heights[current] = node.getHeight();
        reverseOrder[current] = node.getNr();
        current++;
        current = collectHeights(node.getRight(), heights, reverseOrder, current);
    }
    return current;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:18,代码来源:NodeReheight2.java


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