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


Java TreeParser类代码示例

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


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

示例1: findNode

import beast.util.TreeParser; //导入依赖的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: initialize

import beast.util.TreeParser; //导入依赖的package包/类
private void initialize(TaxonSet speciesSuperset) throws Exception {
    speciesTree = new SpeciesTreeParser();
    speciesTree.initByName("newick", newickSpeciesTree, "IsLabelledNewick", true, "taxonset", speciesSuperset);

    for (String geneTreeNewick: newickGeneTrees) {
        TreeParser geneTree = new TreeParser();
        geneTree.initByName("newick", geneTreeNewick, "IsLabelledNewick", true);
        geneTrees.add(geneTree);

        GeneTree geneTreeWrapper = new GeneTree();
        geneTreeWrapper.initByName("tree", geneTree, "ploidy", ploidy, "speciesTree", speciesTree);
        geneTreeWrappers.add(geneTreeWrapper);
    }

    state.initByName("stateNode", alphaParameter);
    state.initByName("stateNode", meanParameter);

    msc = new MultispeciesCoalescent();
    msc.initByName("populationShape", alphaParameter, "populationMean", meanParameter, "distribution", geneTreeWrappers);

    for (GeneTree gt: geneTreeWrappers) gt.calculateLogP();
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:23,代码来源:MissingDataConstantIO.java

示例3: testLogP

import beast.util.TreeParser; //导入依赖的package包/类
@Test
public void testLogP() throws Exception {
    TaxonSet speciesSuperset = generateSuperset();
    speciesTree = new SpeciesTreeParser();
    speciesTree.initByName("newick", newickSpeciesTree, "IsLabelledNewick", true, "taxonset", speciesSuperset);

    final int nBranches = nSpecies * 2 - 1;
    popsizeParameter.initByName("value", String.valueOf(popSize), "dimension", String.valueOf(nBranches));
    state.initByName("stateNode", popsizeParameter);

    popModel = new ConstantPopulations();
    popModel.initByName("populationSizes", popsizeParameter, "speciesTree", speciesTree);

    double calculatedLogP = 0.0;
    for (String geneTreeNewick: newickGeneTrees) {
        TreeParser geneTree = new TreeParser();
        geneTree.initByName("newick", geneTreeNewick, "IsLabelledNewick", true);

        GeneTree geneTreeWrapper = new GeneTree();
        geneTreeWrapper.initByName("tree", geneTree, "ploidy", ploidy, "speciesTree", speciesTree, "populationModel", popModel);
        calculatedLogP += geneTreeWrapper.calculateLogP();
    }

    // System.out.println(String.format("expected %f, calculated %f", expectedLogP, calculatedLogP));
    assertEquals(expectedLogP, calculatedLogP, allowedError);
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:27,代码来源:IncompatibleTreeTest.java

示例4: initialize

import beast.util.TreeParser; //导入依赖的package包/类
private void initialize(TaxonSet speciesSuperset) throws Exception {
    speciesTree = new SpeciesTreeParser();
    speciesTree.initByName("newick", newickSpeciesTree, "IsLabelledNewick", true, "taxonset", speciesSuperset);

    for (String geneTreeNewick: newickGeneTrees) {
        TreeParser geneTree = new TreeParser();
        geneTree.initByName("newick", geneTreeNewick, "IsLabelledNewick", true);
        geneTrees.add(geneTree);

        GeneTree geneTreeWrapper = new GeneTree();
        geneTreeWrapper.initByName("tree", geneTree, "ploidy", ploidy, "speciesTree", speciesTree);
        geneTreeWrappers.add(geneTreeWrapper);
    }

    state.initByName("stateNode", alphaParameter);
    state.initByName("stateNode", meanParameter);

    msc = new MultispeciesCoalescent();
    msc.initByName("populationShape", alphaParameter, "populationMean", meanParameter, "distribution", geneTreeWrappers);
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:21,代码来源:ConstantIOTest.java

示例5: fromXML

import beast.util.TreeParser; //导入依赖的package包/类
/**
 * reconstruct tree from XML fragment in the form of a DOM node *
 */
@Override
public void fromXML(final org.w3c.dom.Node node) {
    final String newick = node.getTextContent();
    final TreeParser parser = new TreeParser();
    try {
        parser.thresholdInput.setValue(1e-10, parser);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    try {
        parser.offsetInput.setValue(0, parser);
        setRoot(parser.parseNewick(newick));
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    initArrays();
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:22,代码来源:Tree.java

示例6: setUp

import beast.util.TreeParser; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    final String[] treesString = new String[]{"((A:1,B:1):1,(C:1,D:1):1);",
            "(((A:1,B:1):1,C:2):2,D:3);", "((A:2,(B:1,C:1):1):2,D:3);"};
    final String[] treesSAString = new String[]{"((((0:0.5,1:1.0):1.0,2:2.0):1.0,3:0.0):2.0,4:4.0);",
            "((((0:1.0,2:1.5):1.0,1:2.5):0.5,3:0.0):2.0,4:4.0);", "(((0:0.5,2:1.0):1.0,1:2.0):3.0,(3:0.2,4:2.2):1.8);", "((((0:1.0,2:1.5):1.0,1:2.5):0.2,4:1.7):0.3,3:0.0):0.0;"};

    treeAnnotator = new TreeAnnotator();
    treeAnnotatorSA = new TreeAnnotator();
    trees = new Tree[treesString.length];
    for (int i = 0; i < trees.length; i++) {
        trees[i] = new TreeParser(treesString[i], false, false, true, 1);
    }
    treesSA = new Tree[treesSAString.length];
    for (int i = 0; i < treesSA.length; i++) {
        treesSA[i] = new TreeParser(treesSAString[i], false, false, false, 0);
    }

    cladeSystem = new CladeSystem();
    cladeSystemSA = new CladeSystem();
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:22,代码来源:TreeAnnotatorTest.java

示例7: testNonBinarySortedNewickTest

import beast.util.TreeParser; //导入依赖的package包/类
@Test
public void testNonBinarySortedNewickTest() {

    String newick = "((A:1.0,B:1.0,C:1.0):1.0,(D:1.0,E:1.0,F:1.0,G:1.0):1.0):0.0;";

    TreeParser treeParser = new TreeParser();
    treeParser.initByName("IsLabelledNewick", true,
    		"newick", newick,
    		"adjustTipHeights", false,
            "binarizeMultifurcations", false);

    String sortedNewick = treeParser.getRoot().toSortedNewick(new int[1], false);
    String goal = "((1:1.0,2:1.0,3:1.0):1.0,(4:1.0,5:1.0,6:1.0,7:1.0):1.0):0.0";

    assertEquals(goal.split(";")[0], sortedNewick);
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:17,代码来源:NodeTest.java

示例8: testDuplicates

import beast.util.TreeParser; //导入依赖的package包/类
@Test
public void testDuplicates() throws Exception {

    String newick = "((A:1.0,B:1.0):1.0,(C:1.0,A:1.0):1.0):0.0;";

    boolean exceptionRaised = false;

    try {
        boolean isLabeled = true;
        TreeParser treeParser = new TreeParser(newick, false, false, isLabeled, 1);
        System.out.println(treeParser.getRoot().toNewick());
    } catch (RuntimeException e) {
        e.printStackTrace();
        exceptionRaised = true;
    }

    Assert.assertTrue(exceptionRaised);
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:19,代码来源:TreeParserTest.java

示例9: testClusterTree

import beast.util.TreeParser; //导入依赖的package包/类
@Test
public void testClusterTree() throws Exception {
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = new Tree();
    tree.initAndValidate();
    assertEquals(true, tree.getNodeCount() == 1);

    TreeParser tree2 = new TreeParser();
    tree2.initByName(
            "initial", tree,
            "taxa", data,
            "newick", "((((human:0.024003,(chimp:0.010772,bonobo:0.010772):0.013231):0.012035,gorilla:0.036038):0.033087000000000005,orangutan:0.069125):0.030456999999999998,siamang:0.099582);",
            "IsLabelledNewick", true);

    assertEquals(true, tree.getNodeCount() > 1);
    assertEquals(11, tree.getNodeCount());
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:18,代码来源:StateNodeInitialiserTest.java

示例10: testTreeHeightMap

import beast.util.TreeParser; //导入依赖的package包/类
@Test
public void testTreeHeightMap() throws Exception {

    List<Sequence> sequences = new ArrayList<>();
                                    //01234567890123456789
    sequences.add(new Sequence("t1", "GGGGGGGGGGGGGGGGGGGG"));
    sequences.add(new Sequence("t2", "CCCCCCCCCCCCCCCCCCCC"));
    sequences.add(new Sequence("t3", "TTTTTTTTTTTTTTTTTTTT"));
    Alignment alignment = new Alignment(sequences, "nucleotide");
    Locus locus = new Locus("locus", alignment);

    TreeParser tree = new TreeParser(alignment, "((t1:1,t2:1):1,t3:2):0;");
    ConversionGraph acg = new ConversionGraph();
    acg.assignFrom(tree);
    acg.initByName("locus", locus);

    ACGLikelihoodApprox likelihoodApprox = new ACGLikelihoodApprox();
    likelihoodApprox.initByName(
            "acg", acg,
            "substitutionRate", "1.0",
            "alignment", alignment,
            "locus", locus);

    Map<Double, Coalescence> heightMap = likelihoodApprox.getCoalescenceHeights();

    Assert.assertEquals(2, heightMap.size());
    Assert.assertTrue(heightMap.containsKey(1.0));
    Assert.assertTrue(heightMap.containsKey(2.0));
    Assert.assertTrue(heightMap.get(1.0).equals(new Coalescence("[0,20]{0}{1}")));
    Assert.assertTrue(heightMap.get(2.0).equals(new Coalescence("[0,20]{0,1}{2}")));
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:32,代码来源:ACGLikelihoodApproxTest.java

示例11: assignTaxaAndAnnotateTree

import beast.util.TreeParser; //导入依赖的package包/类
@Deprecated
public static void assignTaxaAndAnnotateTree(String workPath, String stem, String cleanedNewickTree) throws Exception {
    Tree newickTree = new TreeParser(cleanedNewickTree, false, false, true, 1);
    simplifyLabelsOfTree(newickTree);

    // annotate tree by database
    List<String> mixedOTUs = getMixedOTUs(workPath + "clusters.uc");
    annotateTreeByOTUs(newickTree, mixedOTUs);
    TreeFileIO.writeNexusTree(newickTree.getRoot().toNewick() + ";", workPath + "new-" + stem + NameSpace.SUFFIX_NEX);

    // taxa break
    Taxon bioClassification = new Taxon("Insecta", "50557");
    BioSortedSet<Element> taxaFromTree = getTaxaTraitsFromTree(newickTree);
    TaxonSet taxonSet = new TaxonSet(taxaFromTree);
    TaxonomicAssignment taxonomicAssignment = new TaxonomicAssignment(taxonSet, Rank.ORDER, bioClassification); // default to check prefix
    taxonomicAssignment.writeTaxaSortTable(workPath);

    // annotate tree by traits (taxa)
    annotateTree(newickTree, taxonomicAssignment.taxaAssignementMap);
    TreeFileIO.writeNexusTree(newickTree.getRoot().toNewick() + ";", workPath + "taxa-" + stem + NameSpace.SUFFIX_NEX);
}
 
开发者ID:CompEvol,项目名称:NZGOT,代码行数:22,代码来源:TreeUtil.java

示例12: initializeGeneTrees

import beast.util.TreeParser; //导入依赖的package包/类
public void initializeGeneTrees() throws Exception {
    for (String geneTreeNewick: newickGeneTrees) {
        TreeParser geneTree = new TreeParser();
        geneTree.initByName("newick", geneTreeNewick, "IsLabelledNewick", true);
        geneTrees.add(geneTree);

        GeneTree geneTreeWrapper = new GeneTree();
        geneTreeWrapper.initByName("tree", geneTree, "ploidy", ploidy, "speciesTree", speciesTreeWrapper);
        geneTreeWrappers.add(geneTreeWrapper);
    }
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:12,代码来源:ExchangeTestHelper.java

示例13: testRates

import beast.util.TreeParser; //导入依赖的package包/类
@Test
public void testRates() throws Exception {
    testTree = new TreeParser();
    testTree.initByName("newick", newickTree, "IsLabelledNewick", true);

    // Create dummy state to allow statenode editing
    State state = new State();
    state.initialise();

    treeLengthLogger = new TreeLengthLogger();
    treeLengthLogger.initByName("tree", testTree);
    final double computedLength = treeLengthLogger.getArrayValue();

    assertEquals(expectedLength, computedLength, allowedError);
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:16,代码来源:TreeLengthLoggerTest.java

示例14: setRate

import beast.util.TreeParser; //导入依赖的package包/类
private boolean setRate(int rate, TreeParser tree, String[] target) {
    final Node targetNode = findNode(tree, target);
    if (targetNode == null) {
        return false;
    } else {
        branchRatesParameter.setValue(targetNode.getNr(), rate);
        return true;
    }
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:10,代码来源:UncorrelatedRatesTest.java

示例15: initializeTrees

import beast.util.TreeParser; //导入依赖的package包/类
public void initializeTrees(TaxonSet speciesSuperSet) throws Exception {
    speciesTree = new SpeciesTreeParser();
    speciesTree.initByName("newick", newickSpeciesTree, "IsLabelledNewick", true, "taxonset", speciesSuperSet);

    geneTree = new TreeParser();
    geneTree.initByName("newick", newickGeneTree, "IsLabelledNewick", true);

    geneTreeWrapper = new GeneTree();
    geneTreeWrapper.initByName("tree", geneTree, "ploidy", ploidy, "speciesTree", speciesTree);
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:11,代码来源:StarbeastClockTest.java


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