JAL-2704 don't shade gap colour for PID/conservation
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 30 Aug 2017 16:31:29 +0000 (17:31 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 30 Aug 2017 16:31:29 +0000 (17:31 +0100)
src/jalview/renderer/ResidueShader.java
test/jalview/renderer/ResidueShaderTest.java

index 7e4f211..aa84816 100644 (file)
@@ -250,7 +250,10 @@ public class ResidueShader implements ResidueShaderI
     /*
      * apply PID threshold and consensus fading if in force
      */
-    colour = adjustColour(symbol, position, colour);
+    if (!Comparison.isGap(symbol))
+    {
+      colour = adjustColour(symbol, position, colour);
+    }
 
     return colour;
   }
index 76fd9b4..26d4b15 100644 (file)
@@ -10,7 +10,10 @@ import jalview.datamodel.ProfileI;
 import jalview.datamodel.Profiles;
 import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
+import jalview.schemes.ColourSchemeI;
 import jalview.schemes.PIDColourScheme;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.UserColourScheme;
 
 import java.awt.Color;
 import java.util.Collections;
@@ -163,4 +166,60 @@ public class ResidueShaderTest
     assertEquals(Color.WHITE, ccs.applyConservation(colour, 12));
   }
 
+  /**
+   * A custom gap colour should not be affected by Colour by Conservation
+   */
+  @Test(groups = "Functional")
+  public void testFindColour_gapColour()
+  {
+    Color[] colours = new Color[ResidueProperties.maxProteinIndex + 1];
+    colours[5] = Color.blue; // Q colour
+    colours[23] = Color.red; // gap colour
+    ColourSchemeI cs = new UserColourScheme(colours);
+    ResidueShader ccs = new ResidueShader(cs);
+  
+    assertEquals(Color.red, ccs.findColour(' ', 7, null));
+  
+    /*
+     * stub Conservation to return a given consensus string
+     */
+    final String consSequence = "0123456789+*-";
+    Conservation cons = new Conservation(null,
+            Collections.<SequenceI> emptyList(), 0, 0)
+    {
+      @Override
+      public SequenceI getConsSequence()
+      {
+        return new Sequence("seq", consSequence);
+      }
+    };
+    ccs.setConservation(cons);
+  
+    /*
+     * with 0% threshold, there should be no fading
+     */
+    ccs.setConservationInc(0);
+    assertEquals(Color.red, ccs.findColour(' ', 7, null));
+    assertEquals(Color.blue, ccs.findColour('Q', 7, null));
+  
+    /*
+     * with 40% threshold, 'fade factor' is 
+     * (11-score)/10 * 40/20 = (11-score)/5
+     * so position 7, score 7 fades 80% of the way to white (255, 255, 255)
+     */
+    ccs.setConservationInc(40);
+
+    /*
+     * gap colour is unchanged for Conservation
+     */
+    assertEquals(Color.red, ccs.findColour(' ', 7, null));
+
+    /*
+     * residue colour is faded 80% of the way from
+     * blue(0, 0, 255) to white(255, 255, 255)
+     * making (204, 204, 255)
+     */
+    assertEquals(new Color(204, 204, 255), ccs.findColour('Q', 7, null));
+  }
+
 }