Merge branch 'develop' into features/JAL-2446NCList
[jalview.git] / src / jalview / renderer / seqfeatures / FeatureRenderer.java
index e62b225..5dce2b8 100644 (file)
@@ -21,6 +21,7 @@
 package jalview.renderer.seqfeatures;
 
 import jalview.api.AlignViewportI;
+import jalview.datamodel.Range;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.util.Comparison;
@@ -215,13 +216,6 @@ public class FeatureRenderer extends FeatureRendererModel
       return null;
     }
 
-    SequenceFeature[] sequenceFeatures = seq.getSequenceFeatures();
-
-    if (sequenceFeatures == null || sequenceFeatures.length == 0)
-    {
-      return null;
-    }
-
     if (Comparison.isGap(seq.getCharAt(column)))
     {
       return Color.white;
@@ -270,8 +264,7 @@ public class FeatureRenderer extends FeatureRendererModel
           final SequenceI seq, int start, int end, int y1,
           boolean colourOnly)
   {
-    SequenceFeature[] sequenceFeatures = seq.getSequenceFeatures();
-    if (sequenceFeatures == null || sequenceFeatures.length == 0)
+    if (!seq.getFeatures().hasFeatures())
     {
       return null;
     }
@@ -285,8 +278,14 @@ public class FeatureRenderer extends FeatureRendererModel
               transparency));
     }
 
-    int startPos = seq.findPosition(start);
-    int endPos = seq.findPosition(end);
+    /*
+     * get range of sequence positions within column range
+     */
+    Range seqRange = seq.findPositions(start, end);
+    if (seqRange == null)
+    {
+      return null;
+    }
 
     Color drawnColour = null;
 
@@ -301,7 +300,8 @@ public class FeatureRenderer extends FeatureRendererModel
         continue;
       }
 
-      List<SequenceFeature> overlaps = seq.findFeatures(type, startPos, endPos);
+      List<SequenceFeature> overlaps = seq.findFeatures(seqRange.start,
+              seqRange.end, type);
       for (SequenceFeature sequenceFeature : overlaps)
       {
         /*
@@ -316,15 +316,18 @@ public class FeatureRenderer extends FeatureRendererModel
         Color featureColour = getColour(sequenceFeature);
         boolean isContactFeature = sequenceFeature.isContactFeature();
 
+        // todo overload findIndex using Location data
+        int featureStartCol = seq.findIndex(sequenceFeature.begin);
+        int featureEndCol = seq.findIndex(sequenceFeature.end);
         if (isContactFeature)
         {
           boolean drawn = renderFeature(g, seq,
-                  seq.findIndex(sequenceFeature.begin) - 1,
-                  seq.findIndex(sequenceFeature.begin) - 1, featureColour,
+                  featureStartCol - 1,
+                  featureStartCol - 1, featureColour,
                   start, end, y1, colourOnly);
           drawn |= renderFeature(g, seq,
-                  seq.findIndex(sequenceFeature.end) - 1,
-                  seq.findIndex(sequenceFeature.end) - 1, featureColour,
+                  featureEndCol - 1,
+                  featureEndCol - 1, featureColour,
                   start, end, y1, colourOnly);
           if (drawn)
           {
@@ -354,8 +357,8 @@ public class FeatureRenderer extends FeatureRendererModel
           {
           */
             boolean drawn = renderFeature(g, seq,
-                    seq.findIndex(sequenceFeature.begin) - 1,
-                    seq.findIndex(sequenceFeature.end) - 1, featureColour,
+                    featureStartCol - 1,
+                    featureEndCol - 1, featureColour,
                     start, end, y1, colourOnly);
             if (drawn)
             {
@@ -379,24 +382,6 @@ public class FeatureRenderer extends FeatureRendererModel
   }
 
   /**
-   * Answers true if the feature belongs to a feature group which is not
-   * currently displayed, else false
-   * 
-   * @param sequenceFeature
-   * @return
-   */
-  protected boolean featureGroupNotShown(
-          final SequenceFeature sequenceFeature)
-  {
-    return featureGroups != null
-            && sequenceFeature.featureGroup != null
-            && sequenceFeature.featureGroup.length() != 0
-            && featureGroups.containsKey(sequenceFeature.featureGroup)
-            && !featureGroups.get(sequenceFeature.featureGroup)
-                    .booleanValue();
-  }
-
-  /**
    * Called when alignment in associated view has new/modified features to
    * discover and display.
    * 
@@ -436,7 +421,7 @@ public class FeatureRenderer extends FeatureRendererModel
         continue;
       }
 
-      List<SequenceFeature> overlaps = seq.findFeatures(type, pos, pos);
+      List<SequenceFeature> overlaps = seq.findFeatures(pos, pos, type);
       for (SequenceFeature sequenceFeature : overlaps)
       {
         if (!featureGroupNotShown(sequenceFeature))