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


Java Node.setParent方法代码示例

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


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

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

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

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

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

示例8: connectParentToChildren

import beast.evolution.tree.Node; //导入方法依赖的package包/类
public void connectParentToChildren(Node parent, Node left, Node right) {
    parent.setLeft(left);
    parent.setRight(right);
    left.setParent(parent);
    right.setParent(parent);
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:7,代码来源:SABDSkylineTreeSimulatorArbitraryRateChanges.java

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