From 442ca8fed9a8cd9a65388c5537ebbbc078b02961 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 22 Jan 2019 14:39:47 +0000 Subject: [PATCH] JAL-3187 clunky sort by renderorder in findComplementFeaturesAtResidue --- .../renderer/seqfeatures/FeatureRenderer.java | 7 +++-- .../seqfeatures/FeatureRendererModel.java | 27 +++++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/jalview/renderer/seqfeatures/FeatureRenderer.java b/src/jalview/renderer/seqfeatures/FeatureRenderer.java index ac8f6d9..3989b0c 100644 --- a/src/jalview/renderer/seqfeatures/FeatureRenderer.java +++ b/src/jalview/renderer/seqfeatures/FeatureRenderer.java @@ -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 features = fr2 .findComplementFeaturesAtResidue(seq, pos); for (SequenceFeature sf : features) @@ -478,8 +478,11 @@ public class FeatureRenderer extends FeatureRendererModel List features = fr2.findComplementFeaturesAtResidue( seq, seq.findPosition(column)); // todo: ensure ordered by feature render order - for (SequenceFeature sf : features) + ReverseListIterator it = new ReverseListIterator<>( + features); + while (it.hasNext()) { + SequenceFeature sf = it.next(); if (!fr2.featureGroupNotShown(sf)) { Color col = fr2.getColour(sf); diff --git a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java index 7faf7ea..2324a64 100644 --- a/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java +++ b/src/jalview/viewmodel/seqfeatures/FeatureRendererModel.java @@ -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 findComplementFeaturesAtResidue(SequenceI sequence, int pos) { SequenceI ds = sequence.getDatasetSequence(); - List result = new ArrayList<>(); + List found = new ArrayList<>(); List 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 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; } } } -- 1.7.10.2