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=f4648c4977858830874904c629c6afeb582d880d;hpb=fa6001e965a3c35eaa93496d661a1f515dc0a426;p=jalview.git diff --git a/src/jalview/renderer/seqfeatures/FeatureRenderer.java b/src/jalview/renderer/seqfeatures/FeatureRenderer.java index f4648c4..5e071f9 100644 --- a/src/jalview/renderer/seqfeatures/FeatureRenderer.java +++ b/src/jalview/renderer/seqfeatures/FeatureRenderer.java @@ -215,13 +215,6 @@ 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))) { return Color.white; @@ -233,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 { @@ -270,8 +263,7 @@ 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; } @@ -285,9 +277,6 @@ public class FeatureRenderer extends FeatureRendererModel transparency)); } - int startPos = seq.findPosition(start); - int endPos = seq.findPosition(end); - Color drawnColour = null; /* @@ -301,38 +290,39 @@ public class FeatureRenderer extends FeatureRendererModel continue; } - List overlaps = seq.findFeatures(startPos, endPos, + List overlaps = seq.findFeatures(start + 1, end + 1, type); - for (SequenceFeature sequenceFeature : overlaps) + for (SequenceFeature sf : overlaps) { /* * 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; } - 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 @@ -355,8 +345,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 +381,21 @@ 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. + *

+ * 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 @@ -419,7 +414,8 @@ 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))