JAL-3187 clunky sort by renderorder in findComplementFeaturesAtResidue
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 22 Jan 2019 14:39:47 +0000 (14:39 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 22 Jan 2019 14:39:47 +0000 (14:39 +0000)
src/jalview/renderer/seqfeatures/FeatureRenderer.java
src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java

index ac8f6d9..3989b0c 100644 (file)
@@ -28,6 +28,7 @@ import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.util.Comparison;
+import jalview.util.ReverseListIterator;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
 
 import java.awt.AlphaComposite;
@@ -408,7 +409,6 @@ public class FeatureRenderer extends FeatureRendererModel
       for (int pos = visiblePositions.start; pos <= visiblePositions.end; pos++)
       {
         int column = seq.findIndex(pos);
-        // TODO ensure these are in complement's render order (last on top)
         List<SequenceFeature> features = fr2
                 .findComplementFeaturesAtResidue(seq, pos);
         for (SequenceFeature sf : features)
@@ -478,8 +478,11 @@ public class FeatureRenderer extends FeatureRendererModel
       List<SequenceFeature> features = fr2.findComplementFeaturesAtResidue(
               seq, seq.findPosition(column));
       // todo: ensure ordered by feature render order
-      for (SequenceFeature sf : features)
+      ReverseListIterator<SequenceFeature> it = new ReverseListIterator<>(
+              features);
+      while (it.hasNext())
       {
+        SequenceFeature sf = it.next();
         if (!fr2.featureGroupNotShown(sf))
         {
           Color col = fr2.getColour(sf);
index 7faf7ea..2324a64 100644 (file)
@@ -1157,7 +1157,8 @@ public abstract class FeatureRendererModel
   /**
    * Answers a (possibly empty) list of features in this alignment at a position
    * (or range) which is mappable from the given sequence residue position in a
-   * mapped alignment.
+   * mapped alignment. Features are returned in render order of feature type (on
+   * top last), with order within feature type undefined.
    * 
    * @param sequence
    * @param pos
@@ -1166,7 +1167,7 @@ public abstract class FeatureRendererModel
   public List<SequenceFeature> findComplementFeaturesAtResidue(SequenceI sequence, int pos)
   {
     SequenceI ds = sequence.getDatasetSequence();
-    List<SequenceFeature> result = new ArrayList<>();
+    List<SequenceFeature> found = new ArrayList<>();
     List<AlignedCodonFrame> mappings = this.av.getAlignment()
             .getCodonFrame(sequence);
 
@@ -1192,9 +1193,27 @@ public abstract class FeatureRendererModel
                 match.getSequence(), fromRes, toRes);
         for (SequenceFeature sf : fs)
         {
-          if (!result.contains(sf))
+          if (!found.contains(sf))
+          {
+            found.add(sf);
+          }
+        }
+      }
+    }
+    /*
+     * sort by renderorder, inefficiently
+     */
+    List<SequenceFeature> result = new ArrayList<>();
+    for (String type : renderOrder)
+    {
+      for (SequenceFeature sf : found)
+      {
+        if (type.equals(sf.getType()))
+        {
+          result.add(sf);
+          if (result.size() == found.size())
           {
-            result.add(sf);
+            return result;
           }
         }
       }