本文整理汇总了Java中beast.util.TreeParser类的典型用法代码示例。如果您正苦于以下问题:Java TreeParser类的具体用法?Java TreeParser怎么用?Java TreeParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TreeParser类属于beast.util包,在下文中一共展示了TreeParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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);
state.initByName("stateNode", speciesTree);
tipPopSizesParameter.initByName("dimension", String.valueOf(nSpecies), "value", 1.0);
topPopSizesParameter.initByName("dimension", String.valueOf(nSpecies * 2 - 2), "value", 1.0);
state.initByName("stateNode", tipPopSizesParameter);
state.initByName("stateNode", topPopSizesParameter);
state.initialise();
popModel = new LinearWithConstantRoot();
popModel.initByName("tipPopulationSizes", tipPopSizesParameter, "topPopulationSizes", topPopSizesParameter, "speciesTree", speciesTree);
popModel.initPopSizes(popSize);
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,代码行数:31,代码来源:LinearWithConstantRootTest.java
示例17: 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);
state.initByName("stateNode", speciesTree);
final int nBranches = nSpecies * 2 - 1;
popsizeParameter.initByName("value", String.valueOf(popSize), "dimension", String.valueOf(nBranches));
state.initByName("stateNode", popsizeParameter);
state.initialise();
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,代码行数:29,代码来源:ConstantPopulationTest.java
示例18: main
import beast.util.TreeParser; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
String newickTree = "((((1:0.1,2:0.1):0.1,3:0.2):0.1,4:0.3):0.1,5:0.4);";
List<Sequence> sequences = new ArrayList<Sequence>();
sequences.add(new Sequence("A", "A"));
sequences.add(new Sequence("B", "A"));
sequences.add(new Sequence("C", "A"));
sequences.add(new Sequence("D", "A"));
sequences.add(new Sequence("E", "A"));
Alignment alignment = new Alignment(sequences, 4, "nucleotide");
RootedTreeDrawing treeDrawing = new RootedTreeDrawing(new TreeParser(alignment, newickTree));
treeDrawing.leafLabelOffsetInput.setValue(10.0, treeDrawing);
treeDrawing.treeOrientationInput.setValue(RootedTreeDrawing.TreeOrientation.left, treeDrawing);
treeDrawing.showLeafLabelsInput.setValue(true, treeDrawing);
treeDrawing.initAndValidate();
TreeComponent treeComponent = treeDrawing.treeComponent;
// TikzGraphics2D tikzGraphics2D = new TikzGraphics2D();
// treeComponent.paintComponent(tikzGraphics2D);
// tikzGraphics2D.flush();
JFrame frame = new JFrame();
frame.getContentPane().add(treeComponent, BorderLayout.CENTER);
frame.setSize(500, 500);
treeComponent.setBounds(new Rectangle2D.Double(50, 50, 400, 400));
frame.setVisible(true);
}
开发者ID:CompEvol,项目名称:beastshell,代码行数:34,代码来源:TreeComponent.java
示例19: main
import beast.util.TreeParser; //导入依赖的package包/类
public static void main(String[] args) {
try {
Sequence a = new Sequence("A", "A");
Sequence b = new Sequence("B", "A");
Sequence c = new Sequence("C", "A");
Sequence d = new Sequence("D", "A");
Alignment data = new Alignment();
data.initByName("sequence", a, "sequence", b, "sequence", c, "sequence", d, "dataType", "nucleotide");
TreeParser tree = new TreeParser();
tree.initByName("taxa", data,
"newick", "(((A:1,B:1):1,C:2):1,D:3)",
"IsLabelledNewick", true);
JukesCantor JC = new JukesCantor();
JC.initAndValidate();
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", JC);
BeagleTreeLikelihood likelihood = new BeagleTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Success");
// if we got this far, exit with status 0
System.exit(0);
}
开发者ID:CompEvol,项目名称:beast2,代码行数:34,代码来源:Utils.java
示例20: testNewickTargetTree
import beast.util.TreeParser; //导入依赖的package包/类
@Test
public void testNewickTargetTree() throws Exception {
// create target tree file in temp folder
TreeParser tree = new TreeParser("((A,B),(C,D))");
String tmpFolder = org.fest.util.Files.temporaryFolder().toString();
File target = new File(tmpFolder + "/target.tree");
PrintStream outfile = new PrintStream(target);
tree.init(outfile);
outfile.println();
tree.log(0, outfile);
outfile.println();
tree.close(outfile);
outfile.close();
// create input tree set
File source = new File(tmpFolder + "/source.trees");
outfile = new PrintStream(source);
for (String treeString : 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);"}) {
outfile.println(treeString);
};
outfile.close();
File summary = new File(tmpFolder + "/summary.tree");
// run tree annotator
String [] args = new String[]{"-target", target.getPath(), source.getPath(), summary.getPath()};
TreeAnnotator.main(args);
// make sure we get output
String summaryString = BeautiDoc.load(summary);
System.out.println(summaryString);
}
开发者ID:CompEvol,项目名称:beast2,代码行数:36,代码来源:TreeAnnotatorTest.java
注:本文中的beast.util.TreeParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论