From: jprocter Date: Tue, 17 Mar 2009 17:00:20 +0000 (+0000) Subject: quantitative shading of features by GraduatedColor X-Git-Tag: Release_2_5~327 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0184539662323bf40528927451f4a620c0e70fd2;p=jalview.git quantitative shading of features by GraduatedColor --- diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index b6806e7..ade8915 100755 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -29,6 +29,7 @@ import java.beans.PropertyChangeSupport; import javax.swing.*; import jalview.datamodel.*; +import jalview.schemes.GraduatedColor; /** * DOCUMENT ME! @@ -43,6 +44,7 @@ public class FeatureRenderer AlignViewport av; Color resBoxColour; + /** * global transparency for feature */ @@ -253,7 +255,7 @@ public class FeatureRenderer /** * show scores as heights */ - protected boolean varyHeight=false; + protected boolean varyHeight = false; synchronized public void drawSequence(Graphics g, SequenceI seq, int start, int end, int y1) @@ -373,19 +375,26 @@ public class FeatureRenderer } else - if (av.showSeqFeaturesHeight && sequenceFeatures[sfindex].score!=Float.NaN) - { - renderScoreFeature(g, seq, seq - .findIndex(sequenceFeatures[sfindex].begin) - 1, seq - .findIndex(sequenceFeatures[sfindex].end) - 1, - getColour(sequenceFeatures[sfindex].type), start, end, y1, normaliseScore(sequenceFeatures[sfindex])); - } else - { - renderFeature(g, seq, seq - .findIndex(sequenceFeatures[sfindex].begin) - 1, seq - .findIndex(sequenceFeatures[sfindex].end) - 1, - getColour(sequenceFeatures[sfindex].type), start, end, y1); - } + if (showFeature(sequenceFeatures[sfindex])) + { + if (av.showSeqFeaturesHeight + && sequenceFeatures[sfindex].score != Float.NaN) + { + renderScoreFeature(g, seq, seq + .findIndex(sequenceFeatures[sfindex].begin) - 1, + seq.findIndex(sequenceFeatures[sfindex].end) - 1, + getColour(sequenceFeatures[sfindex]), start, end, + y1, normaliseScore(sequenceFeatures[sfindex])); + } + else + { + renderFeature(g, seq, seq + .findIndex(sequenceFeatures[sfindex].begin) - 1, + seq.findIndex(sequenceFeatures[sfindex].end) - 1, + getColour(sequenceFeatures[sfindex]), start, end, + y1); + } + } } @@ -398,24 +407,31 @@ public class FeatureRenderer 1.0f)); } } + Hashtable minmax = new Hashtable(); + /** * normalise a score against the max/min bounds for the feature type. + * * @param sequenceFeature - * @return byte[] { signed, normalised signed (-127 to 127) or unsigned (0-255) value. + * @return byte[] { signed, normalised signed (-127 to 127) or unsigned + * (0-255) value. */ private final byte[] normaliseScore(SequenceFeature sequenceFeature) { - float[] mm = (float[]) minmax.get(sequenceFeature.type); - final byte[] r=new byte[] { 0, (byte) 255}; - if (mm!=null) + float[] mm = ((float[][]) minmax.get(sequenceFeature.type))[0]; + final byte[] r = new byte[] + { 0, (byte) 255 }; + if (mm != null) { - if (r[0]!=0 || mm[0]<0.0) + if (r[0] != 0 || mm[0] < 0.0) { - r[0]=1; - r[1]=(byte) ((int) 128.0+127.0*(sequenceFeature.score/mm[1])); - } else { - r[1]=(byte) ((int) 255.0*(sequenceFeature.score/mm[1])); + r[0] = 1; + r[1] = (byte) ((int) 128.0 + 127.0 * (sequenceFeature.score / mm[1])); + } + else + { + r[1] = (byte) ((int) 255.0 * (sequenceFeature.score / mm[1])); } } return r; @@ -468,6 +484,7 @@ public class FeatureRenderer } } } + void renderScoreFeature(Graphics g, SequenceI seq, int fstart, int fend, Color featureColour, int start, int end, int y1, byte[] bs) { @@ -484,21 +501,25 @@ public class FeatureRenderer fend = end; } int pady = (y1 + av.charHeight) - av.charHeight / 5; - int ystrt = 0,yend=av.charHeight; - if (bs[0]!=0) + int ystrt = 0, yend = av.charHeight; + if (bs[0] != 0) { // signed - zero is always middle of residue line. - if (bs[1]<128) + if (bs[1] < 128) { - yend = av.charHeight*(128-bs[1])/512; - ystrt = av.charHeight-yend/2; - } else { - ystrt = av.charHeight/2; - yend = av.charHeight*(bs[1]-128)/512; + yend = av.charHeight * (128 - bs[1]) / 512; + ystrt = av.charHeight - yend / 2; } - } else { - yend = av.charHeight*bs[1]/255; - ystrt = av.charHeight-yend; + else + { + ystrt = av.charHeight / 2; + yend = av.charHeight * (bs[1] - 128) / 512; + } + } + else + { + yend = av.charHeight * bs[1] / 255; + ystrt = av.charHeight - yend; } for (i = fstart; i <= fend; i++) @@ -511,10 +532,9 @@ public class FeatureRenderer } g.setColor(featureColour); - int x=(i-start)*av.charWidth; + int x = (i - start) * av.charWidth; g.drawRect(x, y1, av.charWidth, av.charHeight); - g.fillRect(x, y1+ystrt, av.charWidth, - yend); + g.fillRect(x, y1 + ystrt, av.charWidth, yend); if (offscreenRender || !av.validCharWidth) { @@ -600,7 +620,7 @@ public class FeatureRenderer } } } - if (minmax==null) + if (minmax == null) { minmax = new Hashtable(); } @@ -653,21 +673,29 @@ public class FeatureRenderer { allfeatures.addElement(features[index].getType()); } - if (features[index].score!=Float.NaN) - { - float[] mm = (float[]) minmax.get(features[index].getType()); - if (mm==null) + if (features[index].score != Float.NaN) + { + int nonpos= features[index].getBegin()>=1 ? 0 : 1; + float[][] mm = (float[][]) minmax.get(features[index].getType()); + if (mm == null) { - mm = new float[] { features[index].score,features[index].score}; + mm = new float[][] {null, null }; minmax.put(features[index].getType(), mm); - } else { - if (mm[0]>features[index].score) + } + if (mm[nonpos]==null) + { + mm[nonpos] = new float[] { features[index].score, features[index].score }; + + } + else + { + if (mm[nonpos][0] > features[index].score) { - mm[0] = features[index].score; + mm[nonpos][0] = features[index].score; } - if (mm[1]