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


Java Tree类代码示例

本文整理汇总了Java中beast.evolution.tree.Tree的典型用法代码示例。如果您正苦于以下问题:Java Tree类的具体用法?Java Tree怎么用?Java Tree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testHKY85Likelihood

import beast.evolution.tree.Tree; //导入依赖的package包/类
@Test
public void testHKY85Likelihood() throws Exception {
    // Set up HKY85 model: estimated freqs, kappa = 29.739445, 0 gamma categories
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = BEASTTestCase.getTree(data);

    Frequencies freqs = new Frequencies();
    freqs.initByName("data", data);

    HKY hky = new HKY();
    hky.initByName("kappa", "29.739445", "frequencies", freqs);

    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", hky);

    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);

    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1825.2131708068507, BEASTTestCase.PRECISION);

    likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1825.2131708068507, BEASTTestCase.PRECISION);
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:27,代码来源:TreeLikelihoodTest.java

示例2: log

import beast.evolution.tree.Tree; //导入依赖的package包/类
/**
 * log this sample for current state to PrintStream,
 * e.g. value of a parameter, list of parameters or Newick tree
 *
 * @param nSample chain sample number
 * @param out     log stream
 */
public void log(int nSample, PrintStream out) {
	out.print(nSample+"\t");
	Tree tree = (Tree)treeInput.get().getCurrent();
	Node root = tree.getRoot();
	StateProbabilities sp = densityInput.get().getStateProbabilities();
	DoubleMatrix probs = sp.getStateProbs(root.getNr());
	if (probs != null) {
		for(int i=0; i < numStates; i++)
			out.print(probs.get(i)+"\t");
	} else {
		for(int i=0; i < numStates; i++)
			out.print(0.00+"\t");
	}
	// out.println("");
}
 
开发者ID:mrc-ide,项目名称:PhyDyn,代码行数:23,代码来源:STreeRootLogger.java

示例3: mutateOverTree

import beast.evolution.tree.Tree; //导入依赖的package包/类
public Tree mutateOverTree(Tree base) throws Exception {
	ArrayList<Node> currParents = new ArrayList<Node>();
	ArrayList<Node> newParents = new ArrayList<Node>();
	currParents.add(base.getRoot());
	while (currParents.size() > 0) {
		for (Node parent : currParents) {
			List<Node> children = parent.getChildren();
			for (Node child : children) {
				double T = Math.abs(child.getHeight() - parent.getHeight());
				Sequence parentLang = getSequence(parent);
				Sequence newLang = mutateLang(parentLang, T);
				child.setMetaData("lang", newLang);
				newParents.add(child);
				addEmptyTrait(base, child);
			}
		}
		currParents = new ArrayList<Node>(newParents);
		newParents = new ArrayList<Node>();
	}
	return base;
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:22,代码来源:ExplicitBinaryStochasticDollo.java

示例4: addEmptyTrait

import beast.evolution.tree.Tree; //导入依赖的package包/类
protected void addEmptyTrait(Tree t, Node newLangNode) throws Exception {
	// Get all nodes in two lists.
	List<Node> children = newLangNode.getAllChildNodes();
	// Find nodes that aren't children (or trait lang).
	List<Node> allNodes = t.getInternalNodes();
	allNodes.addAll(t.getExternalNodes());
	allNodes.removeAll(children);
	allNodes.remove(newLangNode);

	// Calculate number of [new] mutations in new language.
	Sequence newLang = getSequence(newLangNode);
	for (Node n : allNodes) {
		Sequence nLang = getSequence(n);
		String s = nLang.getData();
		Sequence newNodeLang = new Sequence("", s);
		while (newNodeLang.getData().length() < newLang.getData().length()) {
			String sNew = newNodeLang.getData() + '0';
			// System.out.println(newNodeLang);
			newNodeLang.dataInput.setValue(sNew, this);
		}
		n.setMetaData("lang", newNodeLang);
	}
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:24,代码来源:ExplicitBinaryStochasticDollo.java

示例5: getEvents

import beast.evolution.tree.Tree; //导入依赖的package包/类
protected Double[] getEvents(Tree tr) {
	Node[] nodes = tr.getNodesAsArray();
	Double[] events = new Double[nodes.length];
	for (int i = 0; i < nodes.length; i++) {
		events[i] = nodes[i].getHeight();
	}
	Arrays.sort(events, Collections.reverseOrder());
	return events;
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:10,代码来源:LanguageSubsitutionModel.java

示例6: mutateOverTree

import beast.evolution.tree.Tree; //导入依赖的package包/类
public Tree mutateOverTree(Tree base) throws Exception {
	ArrayList<Node> currParents = new ArrayList<Node>();
	ArrayList<Node> newParents = new ArrayList<Node>();
	currParents.add(base.getRoot());
	while (currParents.size() > 0) {
		for (Node parent : currParents) {
			List<Node> children = parent.getChildren();
			for (Node child : children) {
				double T = Math.abs(child.getHeight() - parent.getHeight());
				Sequence parentLang = getSequence(parent);
				Sequence newLang = mutateLang(parentLang, T);
				child.setMetaData("lang", newLang);
				newParents.add(child);
			}
		}
		currParents = new ArrayList<Node>(newParents);
		newParents = new ArrayList<Node>();
	}
	return base;
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:21,代码来源:ExplicitBinaryGTR.java

示例7: getConstraintNodes

import beast.evolution.tree.Tree; //导入依赖的package包/类
private static List<Node> getConstraintNodes (Tree tree, double minConstraintHeight) {
	List<Node> constraintNodes = new ArrayList<Node>();
	List<Node> possibleConstraintNodes = new ArrayList<Node>();
	for (Node n : tree.getNodesAsArray()) {
		if (n.getHeight() < minConstraintHeight) {
			continue;
		}
		List<Node> c2Children = n.getAllChildNodes();
		for (Node c1 : possibleConstraintNodes) {
			List<Node> c1Children = c1.getAllChildNodes();
			if (Collections.disjoint(c1Children, c2Children)) {
				constraintNodes.add(n);
				constraintNodes.add(c1);
				break;
			}
		}
		if (!constraintNodes.isEmpty()) {
			break;
		}
		possibleConstraintNodes.add(n);
	}
	return constraintNodes;
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:24,代码来源:BorrowingComparisonTests.java

示例8: TreeSDBorrowingTest

import beast.evolution.tree.Tree; //导入依赖的package包/类
private static void TreeSDBorrowingTest(String seq) throws Exception {
	seq = "";
	for (int j = 0; j < 5; j++) {
		seq += '1';
	}
	Sequence l = new Sequence("", seq);

	ExplicitBinaryStochasticDollo sd_mod = new ExplicitBinaryStochasticDollo(0.1, 0.2, 0.0, 0.0,
			false);

	System.out.println("Tree SD Borrowing Test");
	Tree tree = randomYuleTree(2, 0.01);
	tree.getRoot().setMetaData("lang", l);
	sd_mod.mutateOverTreeBorrowing(tree);
	for (Node n : tree.getExternalNodes()) {
		Sequence l2 = (Sequence) n.getMetaData("lang");
		System.out.println(l2.getData());
	}
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:20,代码来源:BeastBorrowingPluginTest.java

示例9: randomTreeTest

import beast.evolution.tree.Tree; //导入依赖的package包/类
private static void randomTreeTest() throws Exception {
	StringBuilder traitSB = new StringBuilder();
	List<Sequence> seqList = new ArrayList<Sequence>();

	for (int i = 0; i < 10; i++) {
		String taxonID = "t " + i;
		seqList.add(new Sequence(taxonID, "?"));

		if (i > 0)
			traitSB.append(",");
		traitSB.append(taxonID).append("=").append(i);
	}

	Alignment alignment = new Alignment(seqList, "nucleotide");
	ConstantPopulation popFunc = new ConstantPopulation();
	popFunc.initByName("popSize", new RealParameter("1.0"));
	RandomTree t = new RandomTree();
	t.initByName("taxa", alignment, "populationModel", popFunc);

	Sequence l = new Sequence("", "");

	System.out.println("Tree GTR Borrowing Test");
	Tree tree = randomYuleTree(2, 0.01);
	tree.getRoot().setMetaData("lang", l);
	System.out.println(TreeUtils.getTreeLength(tree, tree.getRoot()));
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:27,代码来源:BeastBorrowingPluginTest.java

示例10: NoEmptyTraitTest

import beast.evolution.tree.Tree; //导入依赖的package包/类
private static void NoEmptyTraitTest() throws Exception {
	for (int i = 0; i < 1; i++) {
		System.out.println(i);
		Sequence l = new Sequence("", "00000000000001");
		Tree tree = randomYuleTree(3, 0.06);
		tree.getRoot().setMetaData("lang", l);
		ExplicitBinaryStochasticDollo sd_mod = new ExplicitBinaryStochasticDollo(0.0, 0.5, 0.0, 0.0, true);
		tree = sd_mod.mutateOverTree(tree);

		for (Node n : tree.getExternalNodes()) {
			Sequence l2 = (Sequence) n.getMetaData("lang");
			System.out.println(l2.getData());
		}

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

示例11: GTRTreeValidation

import beast.evolution.tree.Tree; //导入依赖的package包/类
private static void GTRTreeValidation() throws Exception {
	ArrayList<Integer> births = new ArrayList<Integer>();
	for (int i = 0; i < 10000; i++) {
		System.out.println(i);
		ExplicitBinaryGTR gtr_mod = new ExplicitBinaryGTR(0.5, 0.0, 0.0, false);
		String seq = "";
		for (int j = 0; j < 20; j++) {
			seq += Integer.toString(Randomizer.nextInt(2));
		}
		Sequence l = new Sequence("", seq);
		Tree tree = randomYuleTree(8, 0.001);
		tree.getRoot().setMetaData("lang", l);
		tree = gtr_mod.mutateOverTree(tree);
		for (Node n : tree.getExternalNodes()) {
			Sequence l2 = (Sequence) n.getMetaData("lang");
			births.add(LanguageSubsitutionModel.getBirths(l2));
		}

	}
	listToCSV(births, "Utilities/Thesis Graph Generation/gtrtree.csv");
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:22,代码来源:BeastBorrowingPluginTest.java

示例12: SDTreeValidation

import beast.evolution.tree.Tree; //导入依赖的package包/类
private static void SDTreeValidation() throws Exception {
	ArrayList<Integer> births = new ArrayList<Integer>();

	for (int i = 0; i < 10000; i++) {
		System.out.println(i);
		ExplicitBinaryStochasticDollo sd_mod = new ExplicitBinaryStochasticDollo(0.5, 0.5, 0.0, 0.0, false);
		String seq = "";
		Sequence l = new Sequence("", seq);
		Tree tree = randomYuleTree(8, 0.01);
		tree.getRoot().setMetaData("lang", l);
		tree = sd_mod.mutateOverTreeBorrowing(tree);
		for (Node n : tree.getExternalNodes()) {
			Sequence l2 = (Sequence) n.getMetaData("lang");
			births.add(LanguageSubsitutionModel.getBirths(l2));
		}
	}
	listToCSV(births, "Utilities/Thesis Graph Generation/sdtree.csv");
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:19,代码来源:BeastBorrowingPluginTest.java

示例13: getConnectingNodes

import beast.evolution.tree.Tree; //导入依赖的package包/类
private SetMultimap<Integer, Node> getConnectingNodes(Node speciesTreeNode, MinimumDouble tipwardFreedom) {
    final Node leftChildNode = speciesTreeNode.getLeft();
    final Node rightChildNode = speciesTreeNode.getRight();
    final int leftChildNodeNumber = leftChildNode.getNr();
    final int rightChildNodeNumber = rightChildNode.getNr();
    final Set<String> leftChildDescendants = findDescendants(leftChildNode, leftChildNodeNumber);
    final Set<String> rightChildDescendants = findDescendants(rightChildNode, rightChildNodeNumber);

    final SetMultimap<Integer, Node> allConnectingNodes = HashMultimap.create();
    final List<Tree> geneTrees = geneTreeInput.get();
    for (int j = 0; j < nGeneTrees; j++) {
        final Tree geneTree = geneTrees.get(j);
        final Node geneTreeRootNode = geneTree.getRoot();
        final Set<Node> jConnectingNodes = new HashSet<Node>();
        findConnectingNodes(geneTreeRootNode, jConnectingNodes, leftChildDescendants, rightChildDescendants, tipwardFreedom);
        allConnectingNodes.putAll(j, jConnectingNodes);
        geneTree.startEditing(null); // hack to stop beast.core.State.Trie memory leak
    }

    return allConnectingNodes;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:22,代码来源:CoordinatedExponential.java

示例14: pruneAndRegraft

import beast.evolution.tree.Tree; //导入依赖的package包/类
private static void pruneAndRegraft(final Node nodeToMove, final Node newChild, final Node disownedChild) {
    final Node sourceParent = nodeToMove.getParent();
    final Node destinationParent = newChild.getParent();

    // debug string
    // System.out.println(String.format("%d-%d-%d > %d-%d", parent.getNr(), nodeToMove.getNr(), disownedChild.getNr(), destinationParent.getNr(), newChild.getNr()));

    nodeToMove.removeChild(disownedChild);
    sourceParent.removeChild(nodeToMove);
    destinationParent.removeChild(newChild);

    nodeToMove.addChild(newChild);
    sourceParent.addChild(disownedChild);
    destinationParent.addChild(nodeToMove);

    nodeToMove.makeDirty(Tree.IS_FILTHY);
    sourceParent.makeDirty(Tree.IS_FILTHY);
    destinationParent.makeDirty(Tree.IS_FILTHY);
    newChild.makeDirty(Tree.IS_FILTHY);
    disownedChild.makeDirty(Tree.IS_FILTHY);
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:22,代码来源:CoordinatedExchange.java

示例15: getGraftBranches

import beast.evolution.tree.Tree; //导入依赖的package包/类
protected SetMultimap<Integer, Node> getGraftBranches(Node yNode) {
    final int yNumber = yNode.getNr();
    final Set<String> cousinDescendants = findDescendants(yNode, yNumber);

    final SetMultimap<Integer, Node> allGraftBranches = HashMultimap.create();
    final List<Tree> geneTrees = geneTreeInput.get();
    for (int j = 0; j < nGeneTrees; j++) {
        final Tree geneTree = geneTrees.get(j);
        final Node geneTreeRootNode = geneTree.getRoot();
        final Set<Node> jGraftBranches = new LinkedHashSet<>();
        findGraftBranches(geneTreeRootNode, jGraftBranches, cousinDescendants);
        allGraftBranches.putAll(j, jGraftBranches);
    }

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


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