From 1accb13ab2b4c22d52eb068fcd9749876f8446d9 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 3 Nov 2014 15:51:04 +0000 Subject: [PATCH] JAL-795 JAL-674 tweaked logic to avoid black annotation shading and hard-wire secondary structure colours when no custom colours available --- src/jalview/schemes/AnnotationColourGradient.java | 156 +++++++++++++-------- 1 file changed, 99 insertions(+), 57 deletions(-) diff --git a/src/jalview/schemes/AnnotationColourGradient.java b/src/jalview/schemes/AnnotationColourGradient.java index 3bca94b..713e55d 100755 --- a/src/jalview/schemes/AnnotationColourGradient.java +++ b/src/jalview/schemes/AnnotationColourGradient.java @@ -23,6 +23,7 @@ package jalview.schemes; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; +import jalview.datamodel.Annotation; import jalview.datamodel.GraphLine; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceI; @@ -47,12 +48,18 @@ public class AnnotationColourGradient extends FollowerColourScheme GraphLine annotationThreshold; - float r1, g1, b1, rr, gg, bb, dr, dg, db; + float r1, g1, b1, rr, gg, bb; private boolean predefinedColours = false; private boolean seqAssociated = false; + /** + * false if the scheme was constructed without a minColour and maxColour used + * to decide if existing colours should be taken from annotation elements when + * they exist + */ + private boolean noGradient = false; IdentityHashMap seqannot = null; @Override @@ -70,12 +77,9 @@ public class AnnotationColourGradient extends FollowerColourScheme acg.rr = rr; acg.gg = gg; acg.bb = bb; - acg.dr = dr; - acg.dg = dg; - acg.db = db; acg.predefinedColours = predefinedColours; acg.seqAssociated = seqAssociated; - + acg.noGradient = noGradient; return acg; } @@ -102,6 +106,15 @@ public class AnnotationColourGradient extends FollowerColourScheme { annotationThreshold = annotation.threshold; } + // clear values so we don't get weird black bands... + r1 = 254; + g1 = 254; + b1 = 254; + rr = 0; + gg = 0; + bb = 0; + + noGradient = true; } /** @@ -126,6 +139,8 @@ public class AnnotationColourGradient extends FollowerColourScheme rr = maxColour.getRed() - r1; gg = maxColour.getGreen() - g1; bb = maxColour.getBlue() - b1; + + noGradient = false; } @Override @@ -232,74 +247,101 @@ public class AnnotationColourGradient extends FollowerColourScheme && annotation.annotations[j] != null && !jalview.util.Comparison.isGap(c)) { + Annotation aj = annotation.annotations[j]; + // 'use original colours' => colourScheme != null + // -> look up colour to be used + // predefined colours => preconfigured shading + // -> only use original colours reference if thresholding enabled & + // minmax exists + // annotation.hasIcons => null or black colours replaced with glyph + // colours + // -> reuse original colours if present + // -> if thresholding enabled then return colour on non-whitespace glyph - if (annotation.annotations[j].colour != null) - { - if (predefinedColours || annotation.hasIcons) - { - return annotation.annotations[j].colour; - } - } - else - { - if (predefinedColours) - { - return (annotation.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR - : annotation.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR - : annotation.annotations[j].secondaryStructure != ' ' ? jalview.renderer.AnnotationRenderer.STEM_COLOUR - : currentColour); - } - } if (aboveAnnotationThreshold == NO_THRESHOLD - || (annotationThreshold != null - && aboveAnnotationThreshold == ABOVE_THRESHOLD && annotation.annotations[j].value >= annotationThreshold.value) - || (annotationThreshold != null - && aboveAnnotationThreshold == BELOW_THRESHOLD && annotation.annotations[j].value <= annotationThreshold.value)) + || (annotationThreshold != null && (aboveAnnotationThreshold == ABOVE_THRESHOLD ? aj.value >= annotationThreshold.value + : aj.value <= annotationThreshold.value))) { - - float range = 1f; - if (thresholdIsMinMax - && annotation.threshold != null - && aboveAnnotationThreshold == ABOVE_THRESHOLD - && annotation.annotations[j].value >= annotation.threshold.value) - { - range = (annotation.annotations[j].value - annotation.threshold.value) - / (annotation.graphMax - annotation.threshold.value); - } - else if (thresholdIsMinMax && annotation.threshold != null - && aboveAnnotationThreshold == BELOW_THRESHOLD - && annotation.annotations[j].value >= annotation.graphMin) + if (predefinedColours && aj.colour != null) { - range = (annotation.annotations[j].value - annotation.graphMin) - / (annotation.threshold.value - annotation.graphMin); + currentColour = aj.colour; } - else + else if (annotation.hasIcons + && annotation.graph == AlignmentAnnotation.NO_GRAPH) { - range = (annotation.annotations[j].value - annotation.graphMin) - / (annotation.graphMax - annotation.graphMin); + if (aj.secondaryStructure > ' ' && aj.secondaryStructure != '.' + && aj.secondaryStructure != '-') + { + if (colourScheme != null) + { + currentColour = colourScheme.findColour(c, j, seq); + } + else + { + currentColour = annotation.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR + : annotation.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR + : jalview.renderer.AnnotationRenderer.STEM_COLOUR; + } + } + else + { + // + return Color.white; + } } - - if (colourScheme != null) + else if (noGradient) { - currentColour = colourScheme.findColour(c, j, seq); + if (colourScheme != null) + { + currentColour = colourScheme.findColour(c, j, seq); + } + else + { + if (aj.colour != null) + { + currentColour = aj.colour; + } + } } else { - dr = rr * range + r1; - dg = gg * range + g1; - db = bb * range + b1; + // calculate a shade + float range = 1f; + if (thresholdIsMinMax + && annotation.threshold != null + && aboveAnnotationThreshold == ABOVE_THRESHOLD + && annotation.annotations[j].value >= annotation.threshold.value) + { + range = (annotation.annotations[j].value - annotation.threshold.value) + / (annotation.graphMax - annotation.threshold.value); + } + else if (thresholdIsMinMax + && annotation.threshold != null + && aboveAnnotationThreshold == BELOW_THRESHOLD + && annotation.annotations[j].value >= annotation.graphMin) + { + range = (annotation.annotations[j].value - annotation.graphMin) + / (annotation.threshold.value - annotation.graphMin); + } + else + { + range = (annotation.annotations[j].value - annotation.graphMin) + / (annotation.graphMax - annotation.graphMin); + } + + int dr = (int) (rr * range + r1), dg = (int) (gg * range + g1), db = (int) (bb + * range + b1); + + currentColour = new Color(dr, dg, db); - currentColour = new Color((int) dr, (int) dg, (int) db); } } + if (conservationColouring) + { + currentColour = applyConservation(currentColour, j); + } } } - - if (conservationColouring) - { - currentColour = applyConservation(currentColour, j); - } - return currentColour; } -- 1.7.10.2