JAL-2481 JAL-2593 JAL-2526 further optimisation of feature/index finding
[jalview.git] / src / jalview / renderer / seqfeatures / FeatureRenderer.java
index 8f4f139..541288e 100644 (file)
@@ -22,6 +22,7 @@ package jalview.renderer.seqfeatures;
 
 import jalview.api.AlignViewportI;
 import jalview.api.FeatureColourI;
+import jalview.datamodel.Range;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.util.Comparison;
@@ -218,7 +219,11 @@ public class FeatureRenderer extends FeatureRendererModel
 
     if (Comparison.isGap(seq.getCharAt(column)))
     {
-      return Color.white;
+      /*
+       * returning null allows the colour scheme to provide gap colour
+       * - normally white, but can be customised
+       */
+      return null;
     }
 
     Color renderedColour = null;
@@ -264,7 +269,11 @@ public class FeatureRenderer extends FeatureRendererModel
           final SequenceI seq, int start, int end, int y1,
           boolean colourOnly)
   {
-    if (!seq.getFeatures().hasFeatures())
+    /*
+     * if columns are all gapped, or sequence has no features, nothing to do
+     */
+    Range visiblePositions = seq.findPositions(start+1, end+1);
+    if (visiblePositions == null || !seq.getFeatures().hasFeatures())
     {
       return null;
     }
@@ -292,29 +301,22 @@ public class FeatureRenderer extends FeatureRendererModel
       }
 
       FeatureColourI fc = getFeatureStyle(type);
-      List<SequenceFeature> overlaps = seq.findFeatures(start + 1, end + 1,
-              type);
+      List<SequenceFeature> overlaps = seq.getFeatures().findFeatures(
+              visiblePositions.getBegin(), visiblePositions.getEnd(), type);
 
       filterFeaturesForDisplay(overlaps, fc);
 
       for (SequenceFeature sf : overlaps)
       {
-        /*
-         * a feature type may be flagged as shown but the group 
-         * an instance of it belongs to may be hidden
-         */
-        if (featureGroupNotShown(sf))
-        {
-          continue;
-        }
-
         Color featureColour = fc.getColor(sf);
-        boolean isContactFeature = sf.isContactFeature();
-
-        int featureStartCol = seq.findIndex(sf.begin);
+        int visibleStart = Math.max(sf.getBegin(),
+                visiblePositions.getBegin());
+        int featureStartCol = seq.findIndex(visibleStart);
+        int visibleEnd = Math.min(sf.getEnd(), visiblePositions.getEnd());
         int featureEndCol = sf.begin == sf.end ? featureStartCol : seq
-                .findIndex(sf.end);
-        if (isContactFeature)
+                .findIndex(visibleEnd);
+
+        if (sf.isContactFeature())
         {
           boolean drawn = renderFeature(g, seq, featureStartCol - 1,
                   featureStartCol - 1, featureColour, start, end, y1,