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;
115 for( int i = 0; i < _seq.length; ++i ) {
116 final char c = _seq[ i ];
119 g.setColor( calculateColor( c ) );
120 _rectangle.setFrame( start + ( i * width ), y - 0.5, width + 1, getRenderingHeight() );
121 g.fill( _rectangle );
125 g.setColor( calculateColor( c ) );
126 g.drawString( String.valueOf( c ), start + ( i * width ), y - 0.5f );
132 public void setParameter( final double parameter ) {
133 throw new NoSuchMethodError();
136 public void setRenderingFactorWidth( final double rendering_factor_width ) {
137 _rendering_factor_width = rendering_factor_width;
141 public void setRenderingHeight( final float height ) {
146 public StringBuffer toNHX() {
147 throw new NoSuchMethodError();
151 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
152 throw new NoSuchMethodError();
155 private Color calculateColor( final char c ) {
156 if ( _type == TYPE.AA ) {
157 return calculateAAColor( c );
159 return calculateNucleotideColor( c );
162 private Color calculateNucleotideColor( final char c ) {
166 if ( ( c == 'T' ) || ( c == 'U' ) ) {
175 else if ( c == '-' ) {
183 private Color calculateAAColor( final char c ) {
184 if ( ( c == 'G' ) || ( c == 'A' ) || ( c == 'S' ) || ( c == 'T' ) ) {
187 else if ( ( c == 'N' ) || ( c == 'Q' ) || ( c == 'H' ) ) {
190 else if ( ( c == 'D' ) || ( c == 'E' ) ) {
193 else if ( ( c == 'K' ) || ( c == 'R' ) ) {
196 else if ( c == '-' ) {
199 else if ( c == 'X' ) {
207 private double getRenderingHeight() {
211 public static RenderableMsaSequence createInstance( final String seq,
213 final Configuration configuration ) {
214 if ( _instance == null ) {
215 _instance = new RenderableMsaSequence();
217 if ( type.equals( "protein" ) ) {
218 _instance._type = TYPE.AA;
220 else if ( type.equals( "dna" ) ) {
221 _instance._type = TYPE.DNA;
224 _instance._type = TYPE.RNA;
226 _instance._seq = seq.toCharArray();
227 if ( configuration != null ) {