X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2Fphylogeny%2Fdata%2FRenderableDomainArchitecture.java;h=5b66db8d8fcdc6310e16360d10c889b4ae83efc0;hb=362bd0a813f302f28631d9c9447dd8aa9ee0ceda;hp=df45fe53866c9e6bab030c6441d5efdcb7b747fb;hpb=ccf4c584032d16ed0ed8d0678f01305887724f96;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableDomainArchitecture.java b/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableDomainArchitecture.java index df45fe5..5b66db8 100644 --- a/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableDomainArchitecture.java +++ b/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableDomainArchitecture.java @@ -6,7 +6,7 @@ // Copyright (C) 2008-2009 Christian M. Zmasek // Copyright (C) 2008-2009 Burnham Institute for Medical Research // All rights reserved -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -16,55 +16,61 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. -// +// // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.archaeopteryx.phylogeny.data; +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; +import java.awt.Stroke; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.Writer; +import java.math.BigDecimal; import java.util.Map; import java.util.SortedMap; -import org.forester.archaeopteryx.Configuration; +import org.forester.archaeopteryx.AptxUtil; +import org.forester.archaeopteryx.Constants; import org.forester.archaeopteryx.TreePanel; import org.forester.phylogeny.data.DomainArchitecture; import org.forester.phylogeny.data.PhylogenyData; -import org.forester.phylogeny.data.PhylogenyDataUtil; import org.forester.phylogeny.data.ProteinDomain; import org.forester.util.ForesterUtil; public final class RenderableDomainArchitecture extends DomainArchitecture implements RenderablePhylogenyData { - static private Map Domain_colors; + final static private String SPECIAL_DOMAIN = "RRMa"; final static private int BRIGHTEN_COLOR_BY = 200; final static private int E_VALUE_THRESHOLD_EXP_DEFAULT = 0; - private static int _Next_default_domain_color = 0; - private final static String[] DEFAULT_DOMAINS_COLORS = { "0xFF0000", "0x0000FF", "0xAAAA00", "0xFF00FF", - "0x00FFFF", "0x800000", "0x000080", "0x808000", "0x800080", "0x008080", "0xE1B694" }; - private int _e_value_threshold_exp = RenderableDomainArchitecture.E_VALUE_THRESHOLD_EXP_DEFAULT; - private double _rendering_factor_width = 1.0; - private double _rendering_height = 0; + final static private BasicStroke STROKE_1 = new BasicStroke( 1f ); + private static Map _domain_colors; private final DomainArchitecture _domain_structure; + private int _e_value_threshold_exp = E_VALUE_THRESHOLD_EXP_DEFAULT; private final Rectangle2D _rectangle = new Rectangle2D.Float(); - private final Configuration _configuration; + private float _rendering_factor_width = 1; + private float _rendering_height = 0; + private String _node_name; + + public RenderableDomainArchitecture( final DomainArchitecture domain_structure ) { + _domain_structure = domain_structure; + } - public RenderableDomainArchitecture( final DomainArchitecture domain_structure, final Configuration configuration ) { + public RenderableDomainArchitecture( final DomainArchitecture domain_structure, final String node_name ) { _domain_structure = domain_structure; - _configuration = configuration; + _node_name = node_name; } - private Configuration getConfiguration() { - return _configuration; + public static void setColorMap( final Map domain_colors ) { + _domain_colors = domain_colors; } @Override @@ -94,7 +100,29 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple final Color color_two = getColorTwo( color_one ); double step = 1; if ( to_pdf ) { - step = 0.1; + step = 0.05; + } + for( double i = 0; i < heigth; i += step ) { + g.setColor( org.forester.util.ForesterUtil + .calcColor( i >= h2 ? heigth - i : i, 0, h2, color_one, color_two ) ); + _rectangle.setFrame( x, i + y, width, step ); + g.fill( _rectangle ); + } + } + + private final void drawDomainGrey( final double x, + final double y, + final double width, + final double heigth, + final String name, + final Graphics2D g, + final boolean to_pdf ) { + final double h2 = heigth / 2.0; + final Color color_one = Color.GRAY; + final Color color_two = getColorTwo( color_one ); + double step = 1; + if ( to_pdf ) { + step = 0.05; } for( double i = 0; i < heigth; i += step ) { g.setColor( org.forester.util.ForesterUtil @@ -104,20 +132,14 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple } } - private Color getColorOne( final String name ) { - Color c = getConfiguration().getDomainStructureBaseColor(); - if ( RenderableDomainArchitecture.Domain_colors != null ) { - c = RenderableDomainArchitecture.Domain_colors.get( name ); + private final Color getColorOne( final String name ) { + Color c = _domain_colors.get( name ); + if ( c == null ) { + c = AptxUtil.calculateColorFromString( name, false ); if ( c == null ) { - if ( RenderableDomainArchitecture._Next_default_domain_color < RenderableDomainArchitecture.DEFAULT_DOMAINS_COLORS.length ) { - c = Color - .decode( RenderableDomainArchitecture.DEFAULT_DOMAINS_COLORS[ RenderableDomainArchitecture._Next_default_domain_color++ ] ); - RenderableDomainArchitecture.Domain_colors.put( name, c ); - } - else { - c = getConfiguration().getDomainStructureBaseColor(); - } + throw new IllegalStateException(); } + _domain_colors.put( name, c ); } return c; } @@ -135,7 +157,7 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple } @Override - public SortedMap getDomains() { + public SortedMap getDomains() { return _domain_structure.getDomains(); } @@ -144,20 +166,23 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple return _domain_structure.getNumberOfDomains(); } + @Override public Dimension getOriginalSize() { return new Dimension( _domain_structure.getTotalLength(), ForesterUtil.roundToInt( _rendering_height ) ); } + @Override public Object getParameter() { return new Integer( _e_value_threshold_exp ); } - public double getRenderingFactorWidth() { + public float getRenderingFactorWidth() { return _rendering_factor_width; } + @Override public Dimension getRenderingSize() { - return new Dimension( ForesterUtil.roundToInt( _domain_structure.getTotalLength() * _rendering_factor_width ), + return new Dimension( ForesterUtil.roundToInt( _domain_structure.getTotalLength() * getRenderingFactorWidth() ), ForesterUtil.roundToInt( _rendering_height ) ); } @@ -171,42 +196,73 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple return _domain_structure.isEqual( data ); } - public void render( final double x1, - final double y1, + @Override + public void render( final float x1, + final float y1, final Graphics2D g, final TreePanel tree_panel, final boolean to_pdf ) { - final double f = getRenderingFactorWidth(); - final double y = y1 + ( _rendering_height / 2 ); - final double start = x1 + 20.0; - g.setColor( getConfiguration().getDomainStructureFontColor() ); + final float f = getRenderingFactorWidth(); + final float y = y1 + ( _rendering_height / 2 ); + final float start = x1 + 20; + final Stroke s = g.getStroke(); + g.setStroke( STROKE_1 ); + if ( !to_pdf ) { + g.setColor( tree_panel.getTreeColorSet().getDomainBaseColor() ); + } + else { + g.setColor( Constants.DOMAIN_BASE_COLOR_FOR_PDF ); + } _rectangle.setFrame( start, y - 0.5, _domain_structure.getTotalLength() * f, 1 ); g.fill( _rectangle ); + short special_domain_count = 0; for( int i = 0; i < _domain_structure.getDomains().size(); ++i ) { final ProteinDomain d = _domain_structure.getDomain( i ); - if ( d.getConfidence() <= Math.pow( 10, _e_value_threshold_exp ) ) { - final double xa = start + d.getFrom() * f; - final double xb = xa + d.getLength() * f; - if ( tree_panel.getMainPanel().getOptions().isShowDomainLabels() ) { + if ( ( d.getConfidence() <= Math.pow( 10, _e_value_threshold_exp ) ) + || ( TreePanel.SPECIAL_DOMAIN_COLORING && ( d.getName().equals( SPECIAL_DOMAIN ) ) && ( ( d + .getConfidence() <= 1 ) ) ) ) { + if ( TreePanel.SPECIAL_DOMAIN_COLORING && ( d.getName().equals( SPECIAL_DOMAIN ) ) ) { + special_domain_count++; + } + final float xa = start + ( d.getFrom() * f ); + final float xb = xa + ( d.getLength() * f ); + if ( tree_panel.getMainPanel().getOptions().isShowDomainLabels() + && ( tree_panel.getMainPanel().getTreeFontSet().getFontMetricsSmall().getHeight() > 4 ) ) { g.setFont( tree_panel.getMainPanel().getTreeFontSet().getSmallFont() ); - g.setColor( getConfiguration().getDomainStructureFontColor() ); - PhylogenyDataUtil.drawString( d.getName(), xa, y1 - + tree_panel.getMainPanel().getTreeFontSet()._fm_small.getAscent() + 6, g ); + if ( !to_pdf ) { + g.setColor( tree_panel.getTreeColorSet().getDomainLabelColor() ); + } + else { + g.setColor( Constants.DOMAIN_LABEL_COLOR_FOR_PDF ); + } + g.drawString( d.getName(), xa, y1 + + tree_panel.getMainPanel().getTreeFontSet().getFontMetricsSmall().getAscent() + + _rendering_height ); + } + if ( TreePanel.SPECIAL_DOMAIN_COLORING && ( _node_name.indexOf( "~" ) > 1 ) + && ( d.getName().equals( SPECIAL_DOMAIN ) ) + && ( _node_name.indexOf( "~" + special_domain_count + "-" ) < 1 ) ) { + drawDomainGrey( xa, y1, xb - xa, _rendering_height, d.getName(), g, to_pdf ); + } + else { + drawDomain( xa, y1, xb - xa, _rendering_height, d.getName(), g, to_pdf ); } - drawDomain( xa, y1, xb - xa, _rendering_height, d.getName(), g, to_pdf ); } } + g.setStroke( s ); } + @Override public void setParameter( final double e_value_threshold_exp ) { _e_value_threshold_exp = ( int ) e_value_threshold_exp; } - public void setRenderingFactorWidth( final double rendering_factor_width ) { + public void setRenderingFactorWidth( final float rendering_factor_width ) { _rendering_factor_width = rendering_factor_width; } - public void setRenderingHeight( final double rendering_height ) { + @Override + public void setRenderingHeight( final float rendering_height ) { _rendering_height = rendering_height; } @@ -219,8 +275,4 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException { _domain_structure.toPhyloXML( writer, level, indentation ); } - - public static void setColorMap( final Map domain_colors ) { - RenderableDomainArchitecture.Domain_colors = domain_colors; - } }