5 Documentation, tutorial, and examples for [http://www.phylosoft.org/forester/ forester].
7 Author: [http://www.cmzmasek.net/ Christian M Zmasek], Sanford-Burnham Medical Research Institute
10 Copyright (C) 2011 Christian M Zmasek. All rights reserved.
14 = Parsing of phylogenetic trees and displaying them with Archaeopteryx =
16 This needs file "forester.jar" to be in the class-path.
23 import java.io.IOException;
25 import org.forester.archaeopteryx.Archaeopteryx;
26 import org.forester.io.parsers.PhylogenyParser;
27 import org.forester.phylogeny.Phylogeny;
28 import org.forester.util.ForesterUtil;
30 public class Example1 {
32 public static void main( final String[] args ) {
33 // Reads in (a) tree(s) from a file.
34 final File treefile = new File( "/path/to/tree.xml" );
35 PhylogenyParser parser = null;
37 parser = ForesterUtil.createParserDependingOnFileType( treefile, true );
39 catch ( final IOException e ) {
42 Phylogeny[] phys = null;
44 phys = ForesterUtil.readPhylogenies( parser, treefile );
46 catch ( final IOException e ) {
49 // Display of the tree(s) with Archaeopteryx.
50 Archaeopteryx.createApplication( phys );
59 = Creating a new tree and displaying it with Archaeopteryx =
61 This needs file "forester.jar" to be in the class-path.
67 import org.forester.archaeopteryx.Archaeopteryx;
68 import org.forester.phylogeny.Phylogeny;
69 import org.forester.phylogeny.PhylogenyNode;
71 public class Example2 {
73 public static void main( final String[] args ) {
74 // Creating a new rooted tree with two external nodes.
75 final Phylogeny phy = new Phylogeny();
76 final PhylogenyNode root = new PhylogenyNode();
77 final PhylogenyNode d1 = new PhylogenyNode();
78 final PhylogenyNode d2 = new PhylogenyNode();
79 root.setName( "root" );
80 d1.setName( "descendant 1" );
81 d2.setName( "descendant 2" );
82 root.addAsChild( d1 );
83 root.addAsChild( d2 );
85 phy.setRooted( true );
86 // Displaying the newly created tree with Archaeopteryx.
87 Archaeopteryx.createApplication( phy );
98 = Using iterators to visit tree nodes in certain orders=
100 This needs file "forester.jar" to be in the class-path.
106 import org.forester.phylogeny.Phylogeny;
107 import org.forester.phylogeny.PhylogenyNode;
108 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
110 public class Example3 {
112 public static void main( final String[] args ) {
113 // Creating a new rooted tree with four external nodes.
114 final Phylogeny phy = new Phylogeny();
115 final PhylogenyNode root = new PhylogenyNode();
116 final PhylogenyNode d1 = new PhylogenyNode();
117 final PhylogenyNode d2 = new PhylogenyNode();
118 final PhylogenyNode d11 = new PhylogenyNode();
119 final PhylogenyNode d12 = new PhylogenyNode();
120 root.setName( "root" );
123 d11.setName( "1-1" );
124 d12.setName( "1-2" );
125 root.addAsChild( d1 );
126 root.addAsChild( d2 );
127 d2.addAsChild( d11 );
128 d2.addAsChild( d12 );
130 phy.setRooted( true );
131 // Using a variety of iterators to visit the nodes of the newly created tree.
132 System.out.println( "post-order:" );
133 for( final PhylogenyNodeIterator it = phy.iteratorPostorder(); it.hasNext(); ) {
134 System.out.println( it.next().getName() );
136 System.out.println( "pre-order:" );
137 for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) {
138 System.out.println( it.next().getName() );
140 System.out.println( "level-order:" );
141 for( final PhylogenyNodeIterator it = phy.iteratorLevelOrder(); it.hasNext(); ) {
142 System.out.println( it.next().getName() );
144 System.out.println( "external nodes only:" );
145 for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
146 System.out.println( it.next().getName() );