X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Frenderer%2Fseqfeatures%2FFeatureRenderer.java;h=13885b45370b005378ac348fdbf7edca256bc3a2;hb=bc18effe68ba80213a6d03ca7e6175adc6be71d6;hp=f4648c4977858830874904c629c6afeb582d880d;hpb=fa6001e965a3c35eaa93496d661a1f515dc0a426;p=jalview.git diff --git a/src/jalview/renderer/seqfeatures/FeatureRenderer.java b/src/jalview/renderer/seqfeatures/FeatureRenderer.java index f4648c4..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; @@ -99,8 +101,7 @@ public class FeatureRenderer extends FeatureRendererModel g.setColor(featureColour); - g.fillRect((i - start) * charWidth, y1, charWidth, - charHeight); + g.fillRect((i - start) * charWidth, y1, charWidth, charHeight); if (colourOnly || !validCharWidth) { @@ -109,8 +110,8 @@ public class FeatureRenderer extends FeatureRendererModel g.setColor(Color.white); int charOffset = (charWidth - fm.charWidth(s)) / 2; - g.drawString(String.valueOf(s), charOffset - + (charWidth * (i - start)), pady); + g.drawString(String.valueOf(s), + charOffset + (charWidth * (i - start)), pady); } return true; } @@ -198,8 +199,8 @@ public class FeatureRenderer extends FeatureRendererModel g.setColor(Color.black); int charOffset = (charWidth - fm.charWidth(s)) / 2; - g.drawString(String.valueOf(s), charOffset - + (charWidth * (i - start)), pady); + g.drawString(String.valueOf(s), + charOffset + (charWidth * (i - start)), pady); } return true; } @@ -215,25 +216,23 @@ public class FeatureRenderer extends FeatureRendererModel return null; } - SequenceFeature[] sequenceFeatures = seq.getSequenceFeatures(); - - if (sequenceFeatures == null || sequenceFeatures.length == 0) + // 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 + */ return null; } - if (Comparison.isGap(seq.getCharAt(column))) - { - return Color.white; - } - Color renderedColour = null; if (transparency == 1.0f) { /* * simple case - just find the topmost rendered visible feature colour */ - renderedColour = findFeatureColour(seq, seq.findPosition(column)); + renderedColour = findFeatureColour(seq, column); } else { @@ -270,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; } @@ -285,9 +287,6 @@ public class FeatureRenderer extends FeatureRendererModel transparency)); } - int startPos = seq.findPosition(start); - int endPos = seq.findPosition(end); - Color drawnColour = null; /* @@ -301,38 +300,66 @@ public class FeatureRenderer extends FeatureRendererModel continue; } - List overlaps = seq.findFeatures(startPos, endPos, - type); - for (SequenceFeature sequenceFeature : overlaps) + FeatureColourI fc = getFeatureStyle(type); + List overlaps = seq.getFeatures().findFeatures( + visiblePositions.getBegin(), visiblePositions.getEnd(), type); + + if (fc.isSimpleColour()) { + filterFeaturesForDisplay(overlaps); + } + + for (SequenceFeature sf : overlaps) + { + Color featureColour = getColor(sf, fc); + if (featureColour == null) + { + /* + * feature excluded by visibility settings, filters, or colour threshold + */ + continue; + } + /* - * a feature type may be flagged as shown but the group - * an instance of it belongs to may be hidden + * if feature starts/ends outside the visible range, + * restrict to visible positions (or if a contact feature, + * to a single position) */ - if (featureGroupNotShown(sequenceFeature)) + int visibleStart = sf.getBegin(); + if (visibleStart < visiblePositions.getBegin()) { - continue; + visibleStart = sf.isContactFeature() ? sf.getEnd() + : visiblePositions.getBegin(); + } + int visibleEnd = sf.getEnd(); + if (visibleEnd > visiblePositions.getEnd()) + { + visibleEnd = sf.isContactFeature() ? sf.getBegin() + : visiblePositions.getEnd(); } - Color featureColour = getColour(sequenceFeature); - 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; } } - else if (showFeature(sequenceFeature)) + else { /* * showing feature score by height of colour @@ -355,8 +382,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) { @@ -391,16 +418,22 @@ 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) { /* * check for new feature added while processing @@ -411,7 +444,8 @@ public class FeatureRenderer extends FeatureRendererModel * inspect features in reverse renderOrder (the last in the array is * displayed on top) until we find one that is rendered at the position */ - for (int renderIndex = renderOrder.length - 1; renderIndex >= 0; renderIndex--) + for (int renderIndex = renderOrder.length + - 1; renderIndex >= 0; renderIndex--) { String type = renderOrder[renderIndex]; if (!showFeatureOfType(type)) @@ -419,16 +453,21 @@ public class FeatureRenderer extends FeatureRendererModel continue; } - List overlaps = seq.findFeatures(pos, pos, type); + List overlaps = seq.findFeatures(column, column, + type); for (SequenceFeature sequenceFeature : overlaps) { if (!featureGroupNotShown(sequenceFeature)) { - return getColour(sequenceFeature); + Color col = getColour(sequenceFeature); + if (col != null) + { + return col; + } } } } - + /* * no displayed feature found at position */