special domain coloring
[jalview.git] / forester / java / src / org / forester / archaeopteryx / phylogeny / data / RenderableDomainArchitecture.java
index 05d5a5d..5b66db8 100644 (file)
@@ -43,12 +43,12 @@ 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 {
 
+    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;
     final static private BasicStroke  STROKE_1                      = new BasicStroke( 1f );
@@ -56,13 +56,19 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple
     private final DomainArchitecture  _domain_structure;
     private int                       _e_value_threshold_exp        = E_VALUE_THRESHOLD_EXP_DEFAULT;
     private final Rectangle2D         _rectangle                    = new Rectangle2D.Float();
-    private double                    _rendering_factor_width       = 1.0;
-    private double                    _rendering_height             = 0;
+    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 String node_name ) {
+        _domain_structure = domain_structure;
+        _node_name = node_name;
+    }
+
     public static void setColorMap( final Map<String, Color> domain_colors ) {
         _domain_colors = domain_colors;
     }
@@ -104,6 +110,28 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple
         }
     }
 
+    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
+                    .calcColor( i >= h2 ? heigth - i : i, 0, h2, color_one, color_two ) );
+            _rectangle.setFrame( x, i + y, width, step );
+            g.fill( _rectangle );
+        }
+    }
+
     private final Color getColorOne( final String name ) {
         Color c = _domain_colors.get( name );
         if ( c == null ) {
@@ -148,7 +176,7 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple
         return new Integer( _e_value_threshold_exp );
     }
 
-    public double getRenderingFactorWidth() {
+    public float getRenderingFactorWidth() {
         return _rendering_factor_width;
     }
 
@@ -169,14 +197,14 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple
     }
 
     @Override
-    public void render( final double x1,
-                        final double y1,
+    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;
+        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 ) {
@@ -187,11 +215,17 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple
         }
         _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 ( ( 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() );
@@ -201,11 +235,18 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple
                     else {
                         g.setColor( Constants.DOMAIN_LABEL_COLOR_FOR_PDF );
                     }
-                    PhylogenyDataUtil.drawString( d.getName(), xa, y1
+                    g.drawString( d.getName(), xa, y1
                             + tree_panel.getMainPanel().getTreeFontSet().getFontMetricsSmall().getAscent()
-                            + _rendering_height, g );
+                            + _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 );
@@ -216,12 +257,12 @@ public final class RenderableDomainArchitecture extends DomainArchitecture imple
         _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;
     }
 
     @Override
-    public void setRenderingHeight( final double rendering_height ) {
+    public void setRenderingHeight( final float rendering_height ) {
         _rendering_height = rendering_height;
     }