X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Frenderer%2Fseqfeatures%2FFeatureRenderer.java;h=13885b45370b005378ac348fdbf7edca256bc3a2;hb=1413ed295402b90cccddc8ee814cb5be0d1fc75e;hp=9f575103e0ee8c013b906928dae680ee51c5421b;hpb=3d0101179759ef157b088ea135423cd909512d9f;p=jalview.git diff --git a/src/jalview/renderer/seqfeatures/FeatureRenderer.java b/src/jalview/renderer/seqfeatures/FeatureRenderer.java index 9f57510..13885b4 100644 --- a/src/jalview/renderer/seqfeatures/FeatureRenderer.java +++ b/src/jalview/renderer/seqfeatures/FeatureRenderer.java @@ -21,6 +21,8 @@ package jalview.renderer.seqfeatures; import jalview.api.AlignViewportI; +import jalview.api.FeatureColourI; +import jalview.datamodel.ContiguousI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.util.Comparison; @@ -31,6 +33,7 @@ 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 { @@ -213,18 +216,12 @@ 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))) + // column is 'base 1' but getCharAt is an array index (ie from 0) + if (Comparison.isGap(seq.getCharAt(column - 1))) { /* * returning null allows the colour scheme to provide gap colour - * - normally white, but can be customised otherwise + * - normally white, but can be customised */ return null; } @@ -235,7 +232,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 { @@ -272,8 +269,11 @@ 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 columns are all gapped, or sequence has no features, nothing to do + */ + ContiguousI visiblePositions = seq.findPositions(start + 1, end + 1); + if (visiblePositions == null || !seq.getFeatures().hasFeatures()) { return null; } @@ -287,10 +287,6 @@ public class FeatureRenderer extends FeatureRendererModel transparency)); } - int startPos = seq.findPosition(start); - int endPos = seq.findPosition(end); - - int sfSize = sequenceFeatures.length; Color drawnColour = null; /* @@ -304,54 +300,60 @@ 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++) + FeatureColourI fc = getFeatureStyle(type); + List overlaps = seq.getFeatures().findFeatures( + visiblePositions.getBegin(), visiblePositions.getEnd(), type); + + if (fc.isSimpleColour()) { - final SequenceFeature sequenceFeature = sequenceFeatures[sfindex]; - if (!sequenceFeature.type.equals(type)) - { - continue; - } + filterFeaturesForDisplay(overlaps); + } - /* - * a feature type may be flagged as shown but the group - * an instance of it belongs to may be hidden - */ - if (featureGroupNotShown(sequenceFeature)) + for (SequenceFeature sf : overlaps) + { + Color featureColour = getColor(sf, fc); + if (featureColour == null) { + /* + * feature excluded by visibility settings, filters, or colour threshold + */ continue; } /* - * check feature overlaps the target range - * TODO: efficient retrieval of features overlapping a range + * if feature starts/ends outside the visible range, + * restrict to visible positions (or if a contact feature, + * to a single position) */ - if (sequenceFeature.getBegin() > endPos - || sequenceFeature.getEnd() < startPos) + int visibleStart = sf.getBegin(); + if (visibleStart < visiblePositions.getBegin()) { - continue; + visibleStart = sf.isContactFeature() ? sf.getEnd() + : visiblePositions.getBegin(); } - - Color featureColour = getColour(sequenceFeature); - if (featureColour == null) + int visibleEnd = sf.getEnd(); + if (visibleEnd > visiblePositions.getEnd()) { - // score feature outwith threshold for colouring - continue; + visibleEnd = sf.isContactFeature() ? sf.getBegin() + : visiblePositions.getEnd(); } - boolean isContactFeature = sequenceFeature.isContactFeature(); + int featureStartCol = seq.findIndex(visibleStart); + int featureEndCol = sf.begin == sf.end ? featureStartCol : seq + .findIndex(visibleEnd); + + // Color featureColour = getColour(sequenceFeature); + + boolean isContactFeature = sf.isContactFeature(); 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; @@ -359,6 +361,10 @@ public class FeatureRenderer extends FeatureRendererModel } else { + /* + * showing feature score by height of colour + * is not implemented as a selectable option + * if (av.isShowSequenceFeaturesHeight() && !Float.isNaN(sequenceFeature.score)) { @@ -374,15 +380,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; } - } + /*}*/ } } } @@ -400,23 +407,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. * @@ -428,23 +418,23 @@ public class FeatureRenderer extends FeatureRendererModel } /** - * 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. This method is suitable when no feature transparency + * applied (only the topmost visible feature colour is rendered). + *

+ * 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 */ @@ -463,33 +453,17 @@ 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)) + if (!featureGroupNotShown(sequenceFeature)) { - 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) - { - return getColour(sequenceFeature); + Color col = getColour(sequenceFeature); + if (col != null) + { + return col; + } } } }