package jalview.renderer.seqfeatures;
import jalview.api.AlignViewportI;
+import jalview.api.FeatureColourI;
import jalview.datamodel.Range;
import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceI;
g.setColor(featureColour);
- g.fillRect((i - start) * charWidth, y1, charWidth,
- charHeight);
+ g.fillRect((i - start) * charWidth, y1, charWidth, charHeight);
if (colourOnly || !validCharWidth)
{
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;
}
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;
}
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)))
{
- return Color.white;
+ /*
+ * returning null allows the colour scheme to provide gap colour
+ * - normally white, but can be customised
+ */
+ return null;
}
Color renderedColour = null;
/*
* simple case - just find the topmost rendered visible feature colour
*/
- renderedColour = findFeatureColour(seq, seq.findPosition(column));
+ renderedColour = findFeatureColour(seq, column);
}
else
{
final SequenceI seq, int start, int end, int y1,
boolean colourOnly)
{
- if (!seq.getFeatures().hasFeatures())
+ /*
+ * if columns are all gapped, or sequence has no features, nothing to do
+ */
+ Range visiblePositions = seq.findPositions(start+1, end+1);
+ if (visiblePositions == null || !seq.getFeatures().hasFeatures())
{
return null;
}
transparency));
}
- /*
- * get range of sequence positions within column range
- */
- Range seqRange = seq.findPositions(start, end);
- if (seqRange == null)
- {
- return null;
- }
-
Color drawnColour = null;
/*
continue;
}
- List<SequenceFeature> overlaps = seq.findFeatures(seqRange.start,
- seqRange.end, type);
+ FeatureColourI fc = getFeatureStyle(type);
+ List<SequenceFeature> overlaps = seq.getFeatures().findFeatures(
+ visiblePositions.getBegin(), visiblePositions.getEnd(), type);
+
+ filterFeaturesForDisplay(overlaps, fc);
+
for (SequenceFeature sf : overlaps)
{
+ Color featureColour = fc.getColor(sf);
+ if (featureColour == null)
+ {
+ // score feature outwith threshold for colouring
+ 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(sf))
+ 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(sf);
+ int featureStartCol = seq.findIndex(visibleStart);
+ int featureEndCol = sf.begin == sf.end ? featureStartCol : seq
+ .findIndex(visibleEnd);
+
+ // Color featureColour = getColour(sequenceFeature);
+
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,
- featureStartCol - 1,
- featureStartCol - 1, featureColour,
- start, end, y1, colourOnly);
- drawn |= renderFeature(g, seq,
- featureEndCol - 1,
- featureEndCol - 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(sf))
+ else
{
/*
* showing feature score by height of colour
}
/**
- * 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).
+ * <p>
+ * 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
* 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))
continue;
}
- List<SequenceFeature> overlaps = seq.findFeatures(pos, pos, type);
+ List<SequenceFeature> 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
*/