3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.archaeopteryx.phylogeny.data;
29 import java.awt.Color;
30 import java.awt.Dimension;
31 import java.awt.Graphics2D;
32 import java.awt.geom.Rectangle2D;
33 import java.io.IOException;
34 import java.io.Writer;
36 import org.forester.archaeopteryx.Configuration;
37 import org.forester.archaeopteryx.TreePanel;
38 import org.forester.phylogeny.data.PhylogenyData;
39 import org.forester.sequence.MolecularSequence;
40 import org.forester.sequence.MolecularSequence.TYPE;
42 public final class RenderableMsaSequence implements RenderablePhylogenyData {
44 final static int DEFAULT_HEIGHT = 12;
45 final public static int DEFAULT_WIDTH = 400;
46 private double _rendering_factor_width = 1.0;
48 private final Rectangle2D _rectangle = new Rectangle2D.Float();
49 private double _height = DEFAULT_HEIGHT;
50 private final float _width = DEFAULT_WIDTH;
51 private MolecularSequence.TYPE _type;
52 private static RenderableMsaSequence _instance = null;
54 private RenderableMsaSequence() {
59 public StringBuffer asSimpleText() {
60 return new StringBuffer( _seq.toString() );
64 public StringBuffer asText() {
65 return asSimpleText();
69 public Object clone() {
70 throw new NoSuchMethodError();
74 public PhylogenyData copy() {
75 throw new NoSuchMethodError();
79 public Dimension getOriginalSize() {
80 return new Dimension( getTotalLength(), ( int ) getRenderingHeight() );
84 public Object getParameter() {
88 public double getRenderingFactorWidth() {
89 return _rendering_factor_width;
93 public Dimension getRenderingSize() {
94 return getOriginalSize();
97 public int getTotalLength() {
102 public boolean isEqual( final PhylogenyData data ) {
103 throw new NoSuchMethodError();
107 public void render( final float x1,
110 final TreePanel tree_panel,
111 final boolean to_pdf ) {
113 final float start = x1 + 20;
114 final float width = (_width / _seq.length)*5;
115 g.setFont(g.getFont().deriveFont( width ));
116 for( int i = 0; i < _seq.length; ++i ) {
117 final char c = _seq[ i ];
120 g.setColor( calculateColor( c ) );
121 _rectangle.setFrame( start + ( i * width ), y - 0.5, width + 1, getRenderingHeight() );
122 g.drawString( String.valueOf( c ), start + ( i * width ), y - 0.5f );
123 //g.fill( _rectangle );
127 g.setColor( calculateColor( c ) );
128 g.drawString( String.valueOf( c ), start + ( i * width ), y - 0.5f );
134 public void setParameter( final double parameter ) {
135 throw new NoSuchMethodError();
138 public void setRenderingFactorWidth( final double rendering_factor_width ) {
139 _rendering_factor_width = rendering_factor_width;
143 public void setRenderingHeight( final float height ) {
148 public StringBuffer toNHX() {
149 throw new NoSuchMethodError();
153 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
154 throw new NoSuchMethodError();
157 private Color calculateColor( final char c ) {
158 if ( _type == TYPE.AA ) {
159 return calculateAAColor( c );
161 return calculateNucleotideColor( c );
164 private Color calculateNucleotideColor( final char c ) {
168 if ( ( c == 'T' ) || ( c == 'U' ) ) {
177 else if ( c == '-' ) {
185 private Color calculateAAColor( final char c ) {
186 if ( ( c == 'G' ) || ( c == 'A' ) || ( c == 'S' ) || ( c == 'T' ) ) {
189 else if ( ( c == 'N' ) || ( c == 'Q' ) || ( c == 'H' ) ) {
192 else if ( ( c == 'D' ) || ( c == 'E' ) ) {
195 else if ( ( c == 'K' ) || ( c == 'R' ) ) {
198 else if ( c == '-' ) {
201 else if ( c == 'X' ) {
209 private double getRenderingHeight() {
213 public static RenderableMsaSequence createInstance( final String seq,
215 final Configuration configuration ) {
216 if ( _instance == null ) {
217 _instance = new RenderableMsaSequence();
219 if ( type.equals( "protein" ) ) {
220 _instance._type = TYPE.AA;
222 else if ( type.equals( "dna" ) ) {
223 _instance._type = TYPE.DNA;
226 _instance._type = TYPE.RNA;
228 _instance._seq = seq.toCharArray();
229 if ( configuration != null ) {