0e9508e5995db190cfa5c5a124e7a1072ff1ae54
[jalview.git] / wiki / forester.wiki
1 = Introduction =
2
3 Under development!
4
5 Documentation, tutorial, and examples for [http://www.phylosoft.org/forester/ forester].
6
7 Author: [http://www.cmzmasek.net/ Christian M Zmasek], Sanford-Burnham Medical Research Institute
8
9  
10 Copyright (C) 2011 Christian M Zmasek. All rights reserved.
11
12
13
14 = Parsing of phylogenetic trees and displaying them with Archaeopteryx =
15
16 This needs file "forester.jar" to be in the class-path.
17
18 {{{
19
20 package examples;
21
22 import java.io.File;
23 import java.io.IOException;
24
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;
29
30 public class Example1 {
31
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;
36         try {
37             parser = ForesterUtil.createParserDependingOnFileType( treefile, true );
38         }
39         catch ( final IOException e ) {
40             e.printStackTrace();
41         }
42         Phylogeny[] phys = null;
43         try {
44             phys = ForesterUtil.readPhylogenies( parser, treefile );
45         }
46         catch ( final IOException e ) {
47             e.printStackTrace();
48         }
49         // Display of the tree(s) with Archaeopteryx.
50         Archaeopteryx.createApplication( phys );
51     }
52 }
53
54 }}}
55
56
57
58
59 = Creating a new tree and displaying it with Archaeopteryx =
60
61 This needs file "forester.jar" to be in the class-path.
62
63 {{{
64
65 package examples;
66
67 import org.forester.archaeopteryx.Archaeopteryx;
68 import org.forester.phylogeny.Phylogeny;
69 import org.forester.phylogeny.PhylogenyNode;
70
71 public class Example2 {
72
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 );
84         phy.setRoot( root );
85         phy.setRooted( true );
86         // Displaying the newly created tree with Archaeopteryx.
87         Archaeopteryx.createApplication( phy );
88     }
89 }
90
91 }}}
92
93
94
95
96
97
98 = Using iterators to visit tree nodes in certain orders=
99
100 This needs file "forester.jar" to be in the class-path.
101
102 {{{
103
104 package examples;
105
106 import org.forester.phylogeny.Phylogeny;
107 import org.forester.phylogeny.PhylogenyNode;
108 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
109
110 public class Example3 {
111
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" );
121         d1.setName( "1" );
122         d2.setName( "2" );
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 );
129         phy.setRoot( root );
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() );
135         }
136         System.out.println( "pre-order:" );
137         for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) {
138             System.out.println( it.next().getName() );
139         }
140         System.out.println( "level-order:" );
141         for( final PhylogenyNodeIterator it = phy.iteratorLevelOrder(); it.hasNext(); ) {
142             System.out.println( it.next().getName() );
143         }
144         System.out.println( "external nodes only:" );
145         for( final PhylogenyNodeIterator it = phy.iteratorExternalForward(); it.hasNext(); ) {
146             System.out.println( it.next().getName() );
147         }
148     }
149 }
150
151 }}}