initial commit
[jalview.git] / forester_applications / src / org / forester / applications / phylo2coloredgraphics.java
1
2 package org.forester.applications;
3
4 import java.awt.Color;
5 import java.io.File;
6 import java.io.IOException;
7 import java.util.HashMap;
8 import java.util.Map;
9
10 import org.forester.archaeopteryx.AptxUtil;
11 import org.forester.archaeopteryx.AptxUtil.GraphicsExportType;
12 import org.forester.archaeopteryx.Configuration;
13 import org.forester.archaeopteryx.Options;
14 import org.forester.archaeopteryx.TreeColorSet;
15 import org.forester.io.parsers.PhylogenyParser;
16 import org.forester.io.parsers.util.ParserUtils;
17 import org.forester.phylogeny.Phylogeny;
18 import org.forester.phylogeny.PhylogenyMethods;
19 import org.forester.phylogeny.PhylogenyNode;
20 import org.forester.phylogeny.data.BranchColor;
21 import org.forester.phylogeny.data.BranchWidth;
22 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
23
24 public class phylo2coloredgraphics {
25
26     public static void main( final String[] args ) {
27         try {
28             // Reading-in of a tree from a file.
29             final File treefile = new File( "/home/czmasek/tol_117_TEST.xml" );
30             final PhylogenyParser parser = ParserUtils.createParserDependingOnFileType( treefile, true );
31             final Phylogeny phy = PhylogenyMethods.readPhylogenies( parser, treefile )[ 0 ];
32             // Creating a node name -> color map.
33             final Map<String, Color> colors = new HashMap<String, Color>();
34             colors.put( "Primates", new Color( 255, 255, 0 ) );
35             colors.put( "PANTR", new Color( 255, 0, 255 ) );
36             colors.put( "HUMAN", new Color( 255, 0, 0 ) );
37             colors.put( "RAT", new Color( 155, 0, 0 ) );
38             colors.put( "MOUSE", new Color( 55, 155, 0 ) );
39             colors.put( "CAVPO", new Color( 155, 155, 0 ) );
40             colors.put( "LOTGI", new Color( 155, 155, 255 ) );
41             // Setting colors.
42             for( final PhylogenyNodeIterator it = phy.iteratorPostorder(); it.hasNext(); ) {
43                 final PhylogenyNode n = it.next();
44                 if ( colors.containsKey( n.getName() ) ) {
45                     n.getBranchData().setBranchColor( new BranchColor( colors.get( n.getName() ) ) );
46                     // To make colored subtrees thicker:
47                     n.getBranchData().setBranchWidth( new BranchWidth( 4 ) );
48                 }
49             }
50             // Setting up a configuration object.
51             final Configuration config = new Configuration();
52             config.putDisplayColors( TreeColorSet.BACKGROUND, new Color( 255, 255, 255 ) );
53             config.putDisplayColors( TreeColorSet.BRANCH, new Color( 0, 0, 0 ) );
54             config.putDisplayColors( TreeColorSet.TAXONOMY, new Color( 0, 0, 0 ) );
55             config.setPhylogenyGraphicsType( Options.PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR );
56             config.setTaxonomyColorize( false );
57             config.setColorizeBranches( true );
58             config.setUseBranchesWidths( true );
59             config.setDisplayTaxonomyCode( false );
60             // Writing to a graphics file.
61             AptxUtil.writePhylogenyToGraphicsFile( phy,
62                                                    new File( "/home/czmasek/000.png" ),
63                                                    1300,
64                                                    1300,
65                                                    GraphicsExportType.PNG,
66                                                    config );
67         }
68         catch ( final IOException e ) {
69             e.printStackTrace();
70         }
71     }
72 }