JAL-3612 use _last_ drawn colour per feature type in Overview bug/JAL-3612_overviewFeatureOrdering
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 11 Dec 2020 12:44:42 +0000 (12:44 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 11 Dec 2020 12:44:42 +0000 (12:44 +0000)
src/jalview/renderer/seqfeatures/FeatureRenderer.java
test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java

index aa3328b..fe80e63 100644 (file)
@@ -539,10 +539,15 @@ public class FeatureRenderer extends FeatureRendererModel
         continue;
       }
 
+      /*
+       * find features of this type, and the colour of the _last_ one
+       * (the one that would be drawn on top) that has a colour
+       */
       List<SequenceFeature> overlaps = seq.findFeatures(column, column,
               type);
-      for (SequenceFeature sequenceFeature : overlaps)
+      for (int i = overlaps.size() - 1 ; i >= 0 ; i--)
       {
+        SequenceFeature sequenceFeature = overlaps.get(i);
         if (!featureGroupNotShown(sequenceFeature))
         {
           Color col = getColour(sequenceFeature);
index 6b1fbd2..308adda 100644 (file)
@@ -6,6 +6,13 @@ import static org.testng.Assert.assertNotEquals;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
+import java.awt.Color;
+import java.util.List;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
 import jalview.api.FeatureColourI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
@@ -17,13 +24,6 @@ import jalview.schemes.FeatureColour;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean;
 
-import java.awt.Color;
-import java.util.List;
-
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
-
 /**
  * Unit tests for feature colour determination, including but not limited to
  * <ul>
@@ -58,8 +58,7 @@ public class FeatureColourFinderTest
   {
     // aligned column 8 is sequence position 6
     String s = ">s1\nABCDE---FGHIJKLMNOPQRSTUVWXYZ\n";
-    af = new FileLoader().LoadFileWaitTillLoaded(s,
-            DataSourceType.PASTE);
+    af = new FileLoader().LoadFileWaitTillLoaded(s, DataSourceType.PASTE);
     av = af.getViewport();
     seq = av.getAlignment().getSequenceAt(0);
     fr = af.getFeatureRenderer();
@@ -134,8 +133,8 @@ public class FeatureColourFinderTest
   @Test(groups = "Functional")
   public void testFindFeatureColour_gapPosition()
   {
-    seq.addSequenceFeature(new SequenceFeature("Metal", "Metal", 2, 12, 0f,
-            null));
+    seq.addSequenceFeature(
+            new SequenceFeature("Metal", "Metal", 2, 12, 0f, null));
     fr.setColour("Metal", new FeatureColour(Color.red));
     fr.featuresAdded();
     av.setShowSequenceFeatures(true);
@@ -143,6 +142,27 @@ public class FeatureColourFinderTest
     assertNull(c);
   }
 
+  /**
+   * Nested features coloured by label - expect the colour of the enclosed
+   * feature
+   */
+  @Test(groups = "Functional")
+  public void testFindFeatureColour_nestedFeatures()
+  {
+    SequenceFeature sf1 = new SequenceFeature("domain", "peptide", 1, 120, 0f, null);
+    seq.addSequenceFeature(sf1);
+    SequenceFeature sf2 = new SequenceFeature("domain", "binding", 10, 20,
+            0f, null);
+    seq.addSequenceFeature(sf2);
+    FeatureColourI fc = new FeatureColour(Color.red);
+    fc.setColourByLabel(true);
+    fr.setColour("domain", fc);
+    fr.featuresAdded();
+    av.setShowSequenceFeatures(true);
+    Color c = finder.findFeatureColour(null, seq, 15);
+    assertEquals(c, fr.getColor(sf2, fc));
+  }
+
   @Test(groups = "Functional")
   public void testFindFeatureColour_multipleFeaturesAtPositionNoTransparency()
   {
@@ -265,8 +285,8 @@ public class FeatureColourFinderTest
     /*
      * currently contact feature == type "Disulphide Bond" or "Disulfide Bond" !!
      */
-    seq.addSequenceFeature(new SequenceFeature("Disulphide Bond",
-            "Contact", 2, 12, Float.NaN, "Disulphide"));
+    seq.addSequenceFeature(new SequenceFeature("Disulphide Bond", "Contact",
+            2, 12, Float.NaN, "Disulphide"));
     fr.setColour("Disulphide Bond", new FeatureColour(Color.red));
     fr.featuresAdded();
     av.setShowSequenceFeatures(true);
@@ -311,12 +331,12 @@ public class FeatureColourFinderTest
   @Test(groups = "Functional")
   public void testFindFeatureColour_graduatedFeatureColour()
   {
-    seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 2,
-            2, 0f, "KdGroup"));
-    seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 4,
-            4, 5f, "KdGroup"));
-    seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 7,
-            7, 10f, "KdGroup"));
+    seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 2, 2,
+            0f, "KdGroup"));
+    seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 4, 4,
+            5f, "KdGroup"));
+    seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 7, 7,
+            10f, "KdGroup"));
 
     /*
      * graduated colour from 0 to 10
@@ -356,7 +376,7 @@ public class FeatureColourFinderTest
     fr.setColour("Metal", red);
     fr.featuresAdded();
     av.setShowSequenceFeatures(true);
-  
+
     /*
      * the FeatureSettings transparency slider has range 0-70 which
      * corresponds to a transparency value of 1 - 0.3
@@ -382,7 +402,7 @@ public class FeatureColourFinderTest
     fr.setColour("Domain", green);
     fr.featuresAdded();
     av.setShowSequenceFeatures(true);
-  
+
     /*
      * Domain (green) rendered above Metal (red) above background (cyan)
      * 1) 0.6 * red(255, 0, 0) + 0.4 * cyan(0, 255, 255) = (153, 102, 102)
@@ -391,7 +411,7 @@ public class FeatureColourFinderTest
     fr.setTransparency(0.6f);
     Color c = finder.findFeatureColour(Color.cyan, seq, 10);
     assertEquals(c, new Color(61, 194, 41));
-  
+
     /*
      * now promote Metal above Domain
      * - currently no way other than mimicking reordering of
@@ -406,7 +426,7 @@ public class FeatureColourFinderTest
     fr.setFeaturePriority(data);
     c = finder.findFeatureColour(Color.cyan, seq, 10);
     assertEquals(c, new Color(153, 102, 41));
-  
+
     /*
      * ..and turn off display of Metal
      * Domain (green) above background (pink)
@@ -478,15 +498,15 @@ public class FeatureColourFinderTest
   {
     String kdFeature = "kd";
     String metalFeature = "Metal";
-    seq.addSequenceFeature(new SequenceFeature(kdFeature, "hydrophobicity", 2,
-            2, 0f, "KdGroup"));
-    seq.addSequenceFeature(new SequenceFeature(kdFeature, "hydrophobicity", 4,
-            4, 5f, "KdGroup"));
-    seq.addSequenceFeature(new SequenceFeature(metalFeature, "Fe", 4, 4,
-            5f, "MetalGroup"));
-    seq.addSequenceFeature(new SequenceFeature(kdFeature, "hydrophobicity", 7,
-            7, 10f, "KdGroup"));
-  
+    seq.addSequenceFeature(new SequenceFeature(kdFeature, "hydrophobicity",
+            2, 2, 0f, "KdGroup"));
+    seq.addSequenceFeature(new SequenceFeature(kdFeature, "hydrophobicity",
+            4, 4, 5f, "KdGroup"));
+    seq.addSequenceFeature(new SequenceFeature(metalFeature, "Fe", 4, 4, 5f,
+            "MetalGroup"));
+    seq.addSequenceFeature(new SequenceFeature(kdFeature, "hydrophobicity",
+            7, 7, 10f, "KdGroup"));
+
     /*
      * kd feature has graduated colour from 0 to 10
      * above threshold value of 5
@@ -510,7 +530,7 @@ public class FeatureColourFinderTest
     fr.setFeaturePriority(data);
 
     av.setShowSequenceFeatures(true);
-  
+
     /*
      * position 2, column 1, score 0 - below threshold - default colour
      */
@@ -523,7 +543,7 @@ public class FeatureColourFinderTest
      */
     c = finder.findFeatureColour(Color.blue, seq, 3);
     assertEquals(c, Color.green);
-  
+
     /*
      * position 7, column 9, score 10 - maximum colour in range
      */