X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Frenderer%2Fseqfeatures%2FFeatureRenderer.java;h=5e071f90cc4d8de05313b3d6b4292b295c1f905d;hb=refs%2Fheads%2Ffeatures%2FJAL-2754findFeaturesByColumn;hp=02cfd05535f4366298b3af56bf412f2aa926dff2;hpb=5a5663e814e0af0dbe6061a257fb4fb1baebd4e3;p=jalview.git diff --git a/src/jalview/renderer/seqfeatures/FeatureRenderer.java b/src/jalview/renderer/seqfeatures/FeatureRenderer.java index 02cfd05..5e071f9 100644 --- a/src/jalview/renderer/seqfeatures/FeatureRenderer.java +++ b/src/jalview/renderer/seqfeatures/FeatureRenderer.java @@ -31,18 +31,13 @@ import java.awt.Color; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; +import java.util.List; public class FeatureRenderer extends FeatureRendererModel { private static final AlphaComposite NO_TRANSPARENCY = AlphaComposite .getInstance(AlphaComposite.SRC_OVER, 1.0f); - protected SequenceI lastSeq; - - private volatile SequenceFeature[] lastSequenceFeatures; - - int sfSize; - /** * Constructor given a viewport * @@ -220,34 +215,7 @@ public class FeatureRenderer extends FeatureRendererModel return null; } - SequenceFeature[] sequenceFeatures = seq.getSequenceFeatures(); - if (seq != lastSeq) - { - lastSeq = seq; - lastSequenceFeatures = sequenceFeatures; - if (lastSequenceFeatures != null) - { - sfSize = lastSequenceFeatures.length; - } - } - else - { - if (lastSequenceFeatures != sequenceFeatures) - { - lastSequenceFeatures = sequenceFeatures; - if (lastSequenceFeatures != null) - { - sfSize = lastSequenceFeatures.length; - } - } - } - - if (lastSequenceFeatures == null || sfSize == 0) - { - return null; - } - - if (Comparison.isGap(lastSeq.getCharAt(column))) + if (Comparison.isGap(seq.getCharAt(column))) { return Color.white; } @@ -258,7 +226,7 @@ public class FeatureRenderer extends FeatureRendererModel /* * simple case - just find the topmost rendered visible feature colour */ - renderedColour = findFeatureColour(seq, seq.findPosition(column)); + renderedColour = findFeatureColour(seq, column); } else { @@ -266,7 +234,7 @@ public class FeatureRenderer extends FeatureRendererModel * transparency case - draw all visible features in render order to * build up a composite colour on the graphics context */ - renderedColour = drawSequence(g, lastSeq, column, column, 0, true); + renderedColour = drawSequence(g, seq, column, column, 0, true); } return renderedColour; } @@ -295,21 +263,13 @@ 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; } updateFeatures(); - if (lastSeq == null || seq != lastSeq - || sequenceFeatures != lastSequenceFeatures) - { - lastSeq = seq; - lastSequenceFeatures = sequenceFeatures; - } - if (transparency != 1f && g != null) { Graphics2D g2 = (Graphics2D) g; @@ -317,10 +277,6 @@ public class FeatureRenderer extends FeatureRendererModel transparency)); } - int startPos = lastSeq.findPosition(start); - int endPos = lastSeq.findPosition(end); - - sfSize = lastSequenceFeatures.length; Color drawnColour = null; /* @@ -334,55 +290,44 @@ public class FeatureRenderer extends FeatureRendererModel continue; } - // loop through all features in sequence to find - // current feature to render - for (int sfindex = 0; sfindex < sfSize; sfindex++) + List overlaps = seq.findFeatures(start + 1, end + 1, + type); + for (SequenceFeature sf : overlaps) { - final SequenceFeature sequenceFeature = lastSequenceFeatures[sfindex]; - if (!sequenceFeature.type.equals(type)) - { - continue; - } - /* * a feature type may be flagged as shown but the group * an instance of it belongs to may be hidden */ - if (featureGroupNotShown(sequenceFeature)) + if (featureGroupNotShown(sf)) { continue; } - /* - * check feature overlaps the target range - * TODO: efficient retrieval of features overlapping a range - */ - if (sequenceFeature.getBegin() > endPos - || sequenceFeature.getEnd() < startPos) - { - continue; - } - - Color featureColour = getColour(sequenceFeature); - boolean isContactFeature = sequenceFeature.isContactFeature(); + Color featureColour = getColour(sf); + boolean isContactFeature = sf.isContactFeature(); + int featureStartCol = seq.findIndex(sf.begin); + int featureEndCol = sf.begin == sf.end ? featureStartCol : seq + .findIndex(sf.end); if (isContactFeature) { - boolean drawn = renderFeature(g, seq, - seq.findIndex(sequenceFeature.begin) - 1, - seq.findIndex(sequenceFeature.begin) - 1, featureColour, - start, end, y1, colourOnly); - drawn |= renderFeature(g, seq, - seq.findIndex(sequenceFeature.end) - 1, - seq.findIndex(sequenceFeature.end) - 1, featureColour, - start, end, y1, colourOnly); + boolean drawn = renderFeature(g, seq, featureStartCol - 1, + featureStartCol - 1, featureColour, start, end, y1, + colourOnly); + drawn |= renderFeature(g, seq, featureEndCol - 1, + featureEndCol - 1, featureColour, start, end, y1, + colourOnly); if (drawn) { drawnColour = featureColour; } } - else if (showFeature(sequenceFeature)) + else if (showFeature(sf)) { + /* + * showing feature score by height of colour + * is not implemented as a selectable option + * if (av.isShowSequenceFeaturesHeight() && !Float.isNaN(sequenceFeature.score)) { @@ -398,15 +343,16 @@ public class FeatureRenderer extends FeatureRendererModel } else { + */ 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) { drawnColour = featureColour; } - } + /*}*/ } } } @@ -424,24 +370,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. * @@ -449,28 +377,26 @@ public class FeatureRenderer extends FeatureRendererModel @Override public void featuresAdded() { - lastSeq = null; findAllFeatures(); } /** - * Returns the sequence feature colour rendered at the given sequence - * position, or null if none found. The feature of highest render order (i.e. - * on top) is found, subject to both feature type and feature group being - * visible, and its colour returned. + * Returns the sequence feature colour rendered at the given column position, + * or null if none found. The feature of highest render order (i.e. on top) is + * found, subject to both feature type and feature group being visible, and + * its colour returned. + *

+ * Note this method does not check for a gap in the column so would return the + * colour for features enclosing a gapped column. Check for gap before calling + * if different behaviour is wanted. * * @param seq - * @param pos + * @param column + * (1..) * @return */ - Color findFeatureColour(SequenceI seq, int pos) + Color findFeatureColour(SequenceI seq, int column) { - SequenceFeature[] sequenceFeatures = seq.getSequenceFeatures(); - if (sequenceFeatures == null || sequenceFeatures.length == 0) - { - return null; - } - /* * check for new feature added while processing */ @@ -488,31 +414,11 @@ public class FeatureRenderer extends FeatureRendererModel continue; } - for (int sfindex = 0; sfindex < sequenceFeatures.length; sfindex++) + List overlaps = seq.findFeatures(column, column, + type); + for (SequenceFeature sequenceFeature : overlaps) { - SequenceFeature sequenceFeature = sequenceFeatures[sfindex]; - if (!sequenceFeature.type.equals(type)) - { - continue; - } - - if (featureGroupNotShown(sequenceFeature)) - { - continue; - } - - /* - * check the column position is within the feature range - * (or is one of the two contact positions for a contact feature) - */ - boolean featureIsAtPosition = sequenceFeature.begin <= pos - && sequenceFeature.end >= pos; - if (sequenceFeature.isContactFeature()) - { - featureIsAtPosition = sequenceFeature.begin == pos - || sequenceFeature.end == pos; - } - if (featureIsAtPosition) + if (!featureGroupNotShown(sequenceFeature)) { return getColour(sequenceFeature); }