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


Java Node.setNr方法代码示例

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


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

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

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

示例3: randomYuleTree

import beast.evolution.tree.Node; //导入方法依赖的package包/类
static Tree randomYuleTree (int nodes, double l) throws Exception {
	Tree tr = new Tree();
	ArrayList<Node> nodeList = new ArrayList<Node>();
	double t = 0.0;
	int label = 1;
	for (int i = 0; i < nodes; i++) {
		Node n = new Node();
		n.setHeight(t);
		n.setNr(label);
		label++;
		nodeList.add(n);
	}

	while (nodeList.size() > 1) {
		t += Randomizer.nextExponential(nodeList.size()*l);

		int p_1_index = Randomizer.nextInt(nodeList.size());
		Node p1 = nodeList.remove(p_1_index);
		int p_2_index = Randomizer.nextInt(nodeList.size());
		Node p2 = nodeList.remove(p_2_index);

		Node parent = new Node();
		parent.setHeight(t);

		parent.setNr(label);
		label++;
		p1.setParent(parent);
		parent.addChild(p1);
		p2.setParent(parent);
		parent.addChild(p2);

		nodeList.add(parent);
	}
	tr.setRoot(nodeList.get(0));
	return new Tree(tr.toString());

}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:38,代码来源:BorrowingComparisonTests.java

示例4: randomYuleTree

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private static Tree randomYuleTree (int nodes, double l) throws Exception {
	Tree tr = new Tree();
	ArrayList<Node> nodeList = new ArrayList<Node>();
	double t = 0.0;
	int label = 1;
	for (int i = 0; i < nodes; i++) {
		Node n = new Node();
		n.setHeight(t);
		n.setNr(label);
		label++;
		nodeList.add(n);
	}

	while (nodeList.size() > 1) {
		t += Randomizer.nextExponential(nodeList.size()*l);

		int p_1_index = Randomizer.nextInt(nodeList.size());
		Node p1 = nodeList.remove(p_1_index);
		int p_2_index = Randomizer.nextInt(nodeList.size());
		Node p2 = nodeList.remove(p_2_index);

		Node parent = new Node();
		parent.setHeight(t);

		parent.setNr(label);
		label++;
		p1.setParent(parent);
		parent.addChild(p1);
		p2.setParent(parent);
		parent.addChild(p2);

		nodeList.add(parent);
	}
	tr.setRoot(nodeList.get(0));
	return new Tree(tr.toString());

}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:38,代码来源:BeastBorrowingPluginTest.java

示例5: numberUnnumberedNodes

import beast.evolution.tree.Node; //导入方法依赖的package包/类
/**
 * Number any nodes in a clade which were not explicitly numbered by
 * the parsed string.
 *
 * @param node clade parent
 */
private void numberUnnumberedNodes(Node node) {
    if (node.isLeaf())
        return;

    for (Node child : node.getChildren()) {
        numberUnnumberedNodes(child);
    }

    if (node.getNr()<0)
        node.setNr(numberedNodeCount);

    numberedNodeCount += 1;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:20,代码来源:TreeParser.java

示例6: buildClusterer

import beast.evolution.tree.Node; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Node buildClusterer() {
    final int taxonCount = taxaNames.size();
    if (taxonCount == 1) {
        // pathological case
        final Node node = newNode();
        node.setHeight(1);
        node.setNr(0);
        return node;
    }

    // use array of integer vectors to store cluster indices,
    // starting with one cluster per instance
    final List<Integer>[] clusterID = new ArrayList[taxonCount];
    for (int i = 0; i < taxonCount; i++) {
        clusterID[i] = new ArrayList<>();
        clusterID[i].add(i);
    }
    // calculate distance matrix
    final int clusters = taxonCount;

    // used for keeping track of hierarchy
    final NodeX[] clusterNodes = new NodeX[taxonCount];
    if (linkType == Type.neighborjoining || linkType == Type.neighborjoining2) {
        neighborJoining(clusters, clusterID, clusterNodes);
    } else {
        doLinkClustering(clusters, clusterID, clusterNodes);
    }

    // move all clusters in m_nClusterID array
    // & collect hierarchy
    for (int i = 0; i < taxonCount; i++) {
        if (clusterID[i].size() > 0) {
            return clusterNodes[i].toNode();
        }
    }
    return null;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:39,代码来源:ClusterTree.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: numberNodes

import beast.evolution.tree.Node; //导入方法依赖的package包/类
public void numberNodes(Node node, int[] nextNr) {

        if (node.isLeaf()) {
            node.setNr(extantTaxa.indexOf(node.getID()));
        } else {
            for (Node child:node.getChildren()) {
                numberNodes(child, nextNr);
            }
            node.setNr(nextNr[0]);
            nextNr[0]++;
        }

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

示例9: labelNonLabeledNodes

import beast.evolution.tree.Node; //导入方法依赖的package包/类
private void labelNonLabeledNodes(Node node, int[] lastLabel) {

        for (Node child : node.getChildren()) {
            labelNonLabeledNodes(child, lastLabel);
        }
        if (node.getNr() == -1) {
            node.setNr(lastLabel[0] + 1);
            lastLabel[0] += 1;
        } else if (labels != null && node.getNr() < labels.size()) {
            node.setID(labels.get(node.getNr()));
        }
    }
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:13,代码来源:ZeroBranchSATreeParser.java

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

示例11: buildClusterer

import beast.evolution.tree.Node; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public Node buildClusterer() {
    final int nTaxa = taxaNames.size();
    if (nTaxa == 1) {
        // patalogical case
        final Node node = newNode();
        node.setHeight(1);
        node.setNr(0);
        return node;
    }


    // use array of integer vectors to store cluster indices,
    // starting with one cluster per instance
    final List<Integer>[] nClusterID = new ArrayList[nTaxa];
    for (int i = 0; i < nTaxa; i++) {
        nClusterID[i] = new ArrayList<Integer>();
        nClusterID[i].add(i);
    }
    // calculate distance matrix
    final int nClusters = nTaxa;

    // used for keeping track of hierarchy
    final NodeX[] clusterNodes = new NodeX[nTaxa];
    if (m_nLinkType == NEIGHBOR_JOINING || m_nLinkType == NEIGHBOR_JOINING2) {
        neighborJoining(nClusters, nClusterID, clusterNodes);
    } else {
        doLinkClustering(nClusters, nClusterID, clusterNodes);
    }

    // move all clusters in m_nClusterID array
    // & collect hierarchy
    for (int i = 0; i < nTaxa; i++) {
        if (nClusterID[i].size() > 0) {
            return clusterNodes[i].toNode();
        }
    }
    return null;
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:40,代码来源:ClusterZBSATree.java

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

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

示例14: main

import beast.evolution.tree.Node; //导入方法依赖的package包/类
public static void main (String[] arg) throws Exception{


        Node root = new Node();
        root.setNr(4);
        root.setHeight(2.0);
        Node left = new Node();
        left.setNr(3);
        left.setHeight(1.0);
        root.setLeft(left);
        left.setParent(root);
        Node right = new Node();
        right.setNr(2);
        right.setHeight(2.0);
        root.setRight(right);
        right.setParent(root);
        Node leftLeft = new Node();
        leftLeft.setNr(0);
        leftLeft.setHeight(0.0);
        left.setLeft(leftLeft);
        leftLeft.setParent(left);
        Node leftRight = new Node();
        leftRight.setNr(1);
        leftRight.setHeight(1.0);
        left.setRight(leftRight);
        leftRight.setParent(left);
        Tree tree = new Tree(root);

        System.out.println("The tree is " + tree.getRoot().toShortNewick(false));


        SATreeComparingAnalysis analysis = new SATreeComparingAnalysis();
        //process tree. consider Fake SA trees
        ArrayList<Integer> dAPattern = new ArrayList<Integer>();
        for (int i=tree.getLeafNodeCount(); i< tree.getNodeCount(); i++){
            if (((ZeroBranchSANode)tree.getNode(i)).isFake()) {
                int descendantsCount = tree.getNode(i).getLeafNodeCount() - 1;
                if (descendantsCount > 0) {
                    for(int j=dAPattern.size(); j<descendantsCount; j++){
                        dAPattern.add(0);
                    }
                    int tmp = dAPattern.get(descendantsCount-1);
                    tmp++;
                    dAPattern.set(descendantsCount - 1, tmp);
                }
            }
        }

        SATreeComparingAnalysis.TreeSummary treeSummary = analysis.new TreeSummary(tree.getRoot().getHeight(), tree.getLeafNodeCount() - ((ZeroBranchSATree)tree).getDirectAncestorNodeCount(), dAPattern);

        System.out.println(treeSummary.dAPattern.toString());
        ArrayList<Integer> a = new ArrayList<Integer> (Arrays.asList(new Integer[]{1, 1}));
        System.out.println(treeSummary.dAPattern.equals(a));
    }
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:55,代码来源:SATreeComparingAnalysis.java


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