in progress
[jalview.git] / forester / java / src / org / forester / archaeopteryx / phylogeny / data / RenderableMsaSequence.java
1 // $Id:
2 // $
3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
5 //
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
8 // All rights reserved
9 //
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.
14 //
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.
19 //
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
23 //
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
26
27 package org.forester.archaeopteryx.phylogeny.data;
28
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;
35 import java.util.List;
36
37 import org.forester.archaeopteryx.AptxUtil;
38 import org.forester.archaeopteryx.Configuration;
39 import org.forester.archaeopteryx.TreePanel;
40 import org.forester.phylogeny.data.PhylogenyData;
41 import org.forester.phylogeny.data.PhylogenyDataUtil;
42 import org.forester.util.DescriptiveStatistics;
43 import org.forester.util.ForesterUtil;
44
45 public final class RenderableMsaSequence implements RenderablePhylogenyData {
46
47     final static int                VECTOR_DEFAULT_HEIGHT   = 12;
48     public final static int         VECTOR_DEFAULT_WIDTH    = 120;
49     private double                  _rendering_factor_width = 1.0;
50     private String            _seq;
51     private final Rectangle2D       _rectangle              = new Rectangle2D.Float();
52     private double                  _height                 = VECTOR_DEFAULT_HEIGHT;
53     private double                  _min;
54     private double                  _max;
55     private double                  _mean;
56     private Color                   _min_color              = Color.BLUE;
57     private Color                   _max_color              = Color.YELLOW;
58     private Color                   _mean_color             = Color.WHITE;
59     private int                     _width                  = VECTOR_DEFAULT_WIDTH;
60     private static RenderableMsaSequence _instance               = null;
61
62     private RenderableMsaSequence() {
63         _seq = null;
64     }
65
66     @Override
67     public StringBuffer asSimpleText() {
68         return new StringBuffer( _seq );
69     }
70
71     @Override
72     public StringBuffer asText() {
73         return asSimpleText();
74     }
75
76     @Override
77     public Object clone() {
78         throw new NoSuchMethodError();
79     }
80
81     @Override
82     public PhylogenyData copy() {
83         throw new NoSuchMethodError();
84     }
85
86     @Override
87     public Dimension getOriginalSize() {
88         return new Dimension( getTotalLength(), ( int ) getRenderingHeight() );
89     }
90
91     @Override
92     public Object getParameter() {
93         return null;
94     }
95
96     public double getRenderingFactorWidth() {
97         return _rendering_factor_width;
98     }
99
100     @Override
101     public Dimension getRenderingSize() {
102         return getOriginalSize();
103     }
104
105     public int getTotalLength() {
106         return _seq.length();
107     }
108
109     @Override
110     public boolean isEqual( final PhylogenyData data ) {
111         throw new NoSuchMethodError();
112     }
113
114     @Override
115     public void render( final float x1,
116                         final float y1,
117                         final Graphics2D g,
118                         final TreePanel tree_panel,
119                         final boolean to_pdf ) {
120         final double y = y1;
121         final double start = x1 + 20.0;
122         g.drawString( _seq, x1, y1
123                                        );
124     }
125
126     @Override
127     public void setParameter( final double parameter ) {
128         throw new NoSuchMethodError();
129     }
130
131     public void setRenderingFactorWidth( final double rendering_factor_width ) {
132         _rendering_factor_width = rendering_factor_width;
133     }
134
135     @Override
136     public void setRenderingHeight( final float height ) {
137         _height = height;
138     }
139
140     @Override
141     public StringBuffer toNHX() {
142         throw new NoSuchMethodError();
143     }
144
145     @Override
146     public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
147         throw new NoSuchMethodError();
148     }
149
150     private Color calculateColor( final double v ) {
151         return ForesterUtil.calcColor( v, _min, _max, _mean, _min_color, _max_color, _mean_color );
152     }
153
154     private double getRenderingHeight() {
155         return _height;
156     }
157
158     public static RenderableMsaSequence createInstance( final String seq,
159                                                    final Configuration configuration ) {
160         if ( _instance == null ) {
161             _instance = new RenderableMsaSequence();
162         }
163         _instance._seq = seq;
164         if ( configuration != null ) {
165           
166         }
167        
168         return _instance;
169     }
170 }