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


Java Node.getID方法代码示例

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


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

示例1: 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

示例2: translateLeafIds

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * Given a map of name translations (string to string),
 * rewrites all leaf ids that match a key in the map
 * to the respective value in the matching key/value pair.
 * If current leaf id is null, then interpret translation keys as node numbers (origin 1)
 * and set leaf id of node n to map.get(n-1).
 *
 * @param translationMap map of name translations
 */
public void translateLeafIds(final Map<String, String> translationMap) {

    for (final Node leaf : getExternalNodes()) {
        String id = leaf.getID();

        if (id == null || !integerLeafLabels) {
            id = Integer.toString(leaf.getNr() + 1);
        }

        final String newId = translationMap.get(id);
        if (newId != null) {
            leaf.setID(newId);
        }
    }
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:25,代码来源:TreeParser.java

示例3: extractSAClade

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 *
 * @param node
 * @return a sampled ancestor clade in the format:
 * [SA < A_1, A_n], where SA is the MRCA of (SA, A_1,..., A_n)
 */

private String extractSAClade(Node node) {
    String tmp = new String();
    String ancestor = node.getID();
    tmp += ancestor + '<';
    if (node.isDirectAncestor()) {
        ArrayList<String> descendants = listSampledNodeIDsUnder(node.getParent());
        tmp+= descendants;
        for (String des:descendants) {
            if (!des.equals(ancestor)) {
                pairs.add(ancestor + "<" + des);
            }
        }
    }
    return tmp;
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:23,代码来源:SATreeTraceAnalysis.java

示例4: translateLeafIds

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * Given a map of name translations (string to string),
 * rewrites all leaf ids that match a key in the map
 * to the respective value in the matching key/value pair.
 * If current leaf id is null, then interpret translation keys as node numbers (origin 1)
 * and set leaf id of node n to map.get(n-1).
 *
 * @param translationMap
 */
public void translateLeafIds(Map<String, String> translationMap) {

    for (Node leaf : getExternalNodes()) {
        String id = leaf.getID();

        if (id == null) {
            id = (leaf.getNr() + 1) + "";
        }

        String newId = translationMap.get(id);
        if (newId != null) {
            leaf.setID(newId);
        }
    }
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:25,代码来源:ZeroBranchSATreeParser.java

示例5: findMovedPairs

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private boolean findMovedPairs(Node geneTreeNode, Map<Node, Node> movedNodes, Set<String> chosenDescendants, double lowerHeight, double upperHeight) {
    if (geneTreeNode.isLeaf()) {
        final String descendantName = geneTreeNode.getID();
        // returns true if this leaf is a descendant of the chosen species
        return chosenDescendants.contains(descendantName);
    }

    final Node leftChild = geneTreeNode.getLeft();
    final Node rightChild = geneTreeNode.getRight();

    // left child descendants are exclusively descendants of the chosen species tree node
    final boolean leftExclusive = findMovedPairs(leftChild, movedNodes, chosenDescendants, lowerHeight, upperHeight);
    // right child descendants are exclusively descendants of the chosen species tree node
    final boolean rightExclusive = findMovedPairs(rightChild, movedNodes, chosenDescendants, lowerHeight, upperHeight);

    final double nodeHeight = geneTreeNode.getHeight();
    if (nodeHeight >= lowerHeight && nodeHeight < upperHeight) {
        if (leftExclusive ^ rightExclusive) {
            if (leftExclusive) { // leave right child attached to original parent
                movedNodes.put(geneTreeNode, rightChild);
            } else { // leaf left child attached to original parent
                movedNodes.put(geneTreeNode, leftChild);
            }
        }
    }

    // returns true if all descendants of this gene tree node are also descendants of the chosen species tree node
    return leftExclusive && rightExclusive;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:30,代码来源:CoordinatedExchange.java

示例6: initStateNodes

import beast.evolution.tree.Node; //导入方法依赖的package包/类
@Override
public void initStateNodes() {
    final SpeciesTree speciesTree = speciesTreeInput.get();
    final Set<BEASTInterface> treeOutputs = speciesTreeInput.get().getOutputs();
    final Method method = initMethod.get();
    final String newick = newickInput.get();

    final List<MRCAPrior> calibrations = new ArrayList<>();
    for (final Object plugin : treeOutputs ) {
        if (plugin instanceof MRCAPrior) {
            calibrations.add((MRCAPrior) plugin);
        }
    }

    boolean geneTreesNeedInit = true;
    if (newick != null) {
        Log.info.println("StarBEAST2: using initFromNewick to initialize species tree.");
        initFromNewick(speciesTree, newick);
    } else if (method == Method.ALL_RANDOM) {
        Log.info.println("StarBEAST2: using randomInit to initialize species tree.");
        randomInit(speciesTree, calibrations);
    } else if (!checkSpeciesAlwaysRepresented())  {
        Log.info.println("StarBEAST2: using randomInit to initialize species tree (required by missing data)).");
        randomInit(speciesTree, calibrations);
    } else if (calibrations.size() > 0)  {
        Log.info.println("StarBEAST2: using randomInit to initialize species tree (required by calibrations)).");
        randomInit(speciesTree, calibrations);
    } else if (speciesTree.hasDateTrait()) {
        Log.info.println("StarBEAST2: using randomInit to initialize species tree (required by tip dates).");
        randomInit(speciesTree, calibrations);
    } else if (method == Method.POINT) {
        Log.info.println("StarBEAST2: using fullInit to initialize all trees.");
        fullInit(speciesTree);
        geneTreesNeedInit = false;
    }

    if (geneTreesNeedInit) {
        final double rootHeight = speciesTree.getRoot().getHeight();
        Log.info.println(String.format("StarBEAST2: using randomInitGeneTrees to initialize gene trees (%f).", rootHeight));

        final List<Tree> geneTrees = genes.get();
        for (final Tree gtree : geneTrees) {
            gtree.makeCaterpillar(rootHeight, rootHeight/gtree.getInternalNodeCount(), true);
        }

        // make sure the heights of all gene tree tips is equal to the height of corresponding species tree tips
        resetGeneTreeTipHeights();
    }

    // initialize population sizes to equal average branch length
    // this is equivalent to 2Ne = E[1/lambda]
    final double speciesTreeLength = TreeStats.getLength(speciesTree);
    final int nBranches = speciesTree.getNodeCount();
    final double averageBranchLength = speciesTreeLength / (nBranches - 1);

    final PopulationModel populationModel = populationFunctionInput.get();
    if (populationModel != null) populationModel.initPopSizes(averageBranchLength);
    
    final Set<String> tipNames = speciesTree.getTipNumberMap().keySet();
    for (Tree geneTree: genes.get()) {
    	for (Node geneNode: geneTree.getNodesAsArray()) {
    		if (geneNode.isLeaf()) {
    			final String tipName = geneNode.getID();
    			if (!tipNames.contains(tipName)) {
    	            throw new RuntimeException(String.format("ERROR: Gene tree tip name '%s' is missing from taxon map. "
    	            		+ "This typically occurs when a sequence or sample name is identical to a species name. "
    	            		+ "Make sure all species names are distinct from sequence or sample names.", tipName));
    			}
    		}
    	}
    }
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:73,代码来源:StarBeastInitializer.java

示例7: sample

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * Sampling only implemented for no-origin case currently.
 */
@Override
public void sample(State state, Random random) {

    if (sampledFlag)
        return;

    sampledFlag = true;

    // Cause conditional parameters to be sampled

    sampleConditions(state, random);

    Tree tree = (Tree) treeInput.get();
    RealParameter birthRate = birthDiffRateParameterInput.get();

    // Simulate tree conditional on new parameters

    List<Node> activeLineages = new ArrayList<>();
    for (Node oldLeaf : tree.getExternalNodes()) {
        Node newLeaf = new Node(oldLeaf.getID());
        newLeaf.setNr(oldLeaf.getNr());
        newLeaf.setHeight(0.0);
        activeLineages.add(newLeaf);
    }

    int nextNr = activeLineages.size();

    double t = 0.0;
    while (activeLineages.size() > 1) {
        int k = activeLineages.size();
        double a = birthRate.getValue() * k;

        t += -Math.log(random.nextDouble())/a;

        Node node1 = activeLineages.get(random.nextInt(k));
        Node node2;
        do {
            node2 = activeLineages.get(random.nextInt(k));
        } while (node2.equals(node1));

        Node newParent = new Node();
        newParent.setNr(nextNr++);
        newParent.setHeight(t);
        newParent.addChild(node1);
        newParent.addChild(node2);

        activeLineages.remove(node1);
        activeLineages.remove(node2);
        activeLineages.add(newParent);
    }

    tree.assignFromWithoutID(new Tree(activeLineages.get(0)));
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:57,代码来源:YuleModel.java


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