From 02be3ae9f384eb3af819a79ed3a2f7e54fb17851 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 9 Nov 2015 14:39:53 +0000 Subject: [PATCH] JAL-1950 - JAL-1958 hardwired hack to explore shading whole sequence by the annotation row score, and modulating shade with positional score. --- src/jalview/schemes/AnnotationColourGradient.java | 64 +++++++++++++++++++-- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index 89b8f07..8511d86 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -34,6 +34,16 @@ import java.util.Map; public class AnnotationColourGradient extends FollowerColourScheme { + /** + * map positional scores to transparency rather than colour + */ + boolean positionToTransparency = true; + + /** + * compute shade based on annotation row score + */ + boolean perLineScore = true; + public static final int NO_THRESHOLD = -1; public static final int BELOW_THRESHOLD = 0; @@ -81,6 +91,8 @@ public class AnnotationColourGradient extends FollowerColourScheme acg.predefinedColours = predefinedColours; acg.seqAssociated = seqAssociated; acg.noGradient = noGradient; + acg.positionToTransparency = positionToTransparency; + acg.perLineScore = perLineScore; return acg; } @@ -177,7 +189,8 @@ public class AnnotationColourGradient extends FollowerColourScheme // resolve the context containing all the annotation for the sequence AnnotatedCollectionI alcontext = alignment instanceof AlignmentI ? alignment : alignment.getContext(); - boolean f = true, rna = false; + boolean f = true, sf = true, rna = false; + long plcount = 0, ancount = 0; for (AlignmentAnnotation alan : alcontext.findAnnotation(annotation .getCalcId())) { @@ -185,6 +198,7 @@ public class AnnotationColourGradient extends FollowerColourScheme && (alan.label != null && annotation != null && alan.label .equals(annotation.label))) { + ancount++; if (!rna && alan.isRNA()) { rna = true; @@ -199,8 +213,26 @@ public class AnnotationColourGradient extends FollowerColourScheme aamin = alan.graphMin; } f = false; + if (alan.score == alan.score) + { + if (sf || alan.score < plmin) + { + plmin = alan.score; + } + if (sf || alan.score > plmax) + { + plmax = alan.score; + } + sf = false; + plcount++; + } } } + if (plcount > 0 && plcount == ancount) + { + perLineScore = plcount == ancount; + aamax=plmax; + } if (rna) { ColourSchemeProperty.initRnaHelicesShading(1 + (int) aamax); @@ -208,7 +240,15 @@ public class AnnotationColourGradient extends FollowerColourScheme } } - float aamin = 0f, aamax = 0f; + /** + * positional annotation max/min + */ + double aamin = 0.0, aamax = 0.0; + + /** + * per line score max/min + */ + double plmin = Double.NaN, plmax = Double.NaN; public String getAnnotation() { @@ -250,6 +290,7 @@ public class AnnotationColourGradient extends FollowerColourScheme * * @return DOCUMENT ME! */ + @Override public Color findColour(char c) { return Color.red; @@ -392,12 +433,23 @@ public class AnnotationColourGradient extends FollowerColourScheme range = 0f; } } - + int trans = 0; + if (perLineScore) + { + trans = (int) ((1f - range) * 255.0); + range = (float) ((annotation.score - plmin) / (plmax - aamin)); + } int dr = (int) (rr * range + r1), dg = (int) (gg * range + g1), db = (int) (bb * range + b1); - - return new Color(dr, dg, db); - + if (annotation.score == annotation.score && positionToTransparency) + { + return new Color(Integer.min(dr + trans, 255), Integer.min( + dg + trans, 255), Integer.min(db + trans, 255)); + } + else + { + return new Color(dr, dg, db); + } } public boolean isPredefinedColours() -- 1.7.10.2