import jalview.api.FeatureRenderer;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.schemes.ColourSchemeI;
+import jalview.schemes.CollectionColourSchemeI;
import java.awt.Color;
import java.awt.Font;
public class SequenceRenderer implements jalview.api.SequenceRenderer
{
+ final static int CHAR_TO_UPPER = 'A' - 'a';
+
AlignViewport av;
FontMetrics fm;
this.renderGaps = renderGaps;
}
+ @Override
public Color getResidueBoxColour(SequenceI seq, int i)
{
allGroups = av.getAlignment().findAllGroups(seq);
{
if (currentSequenceGroup.getDisplayBoxes())
{
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, i);
}
}
else if (av.getShowBoxes())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getViewportColourScheme(), seq, i);
}
return resBoxColour;
return col;
}
- void getBoxColour(ColourSchemeI cs, SequenceI seq, int i)
+ void getBoxColour(CollectionColourSchemeI collectionColourSchemeI,
+ SequenceI seq, int i)
{
- if (cs != null)
+ if (collectionColourSchemeI != null)
{
- resBoxColour = cs.findColour(seq.getCharAt(i), i, seq);
+ resBoxColour = collectionColourSchemeI.findColour(seq.getCharAt(i),
+ i, seq);
}
else if (forOverview
&& !jalview.util.Comparison.isGap(seq.getCharAt(i)))
{
if (currentSequenceGroup.getDisplayBoxes())
{
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq,
+ i);
}
}
else if (av.getShowBoxes())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getViewportColourScheme(), seq, i);
}
}
if (currentSequenceGroup.getColourText())
{
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, i);
graphics.setColor(resBoxColour.darker());
}
if (currentSequenceGroup.getShowNonconserved())
{
- s = getDisplayChar(srep, i, s,
- '.');
+ s = getDisplayChar(srep, i, s, '.', currentSequenceGroup);
}
}
else
if (av.getColourText())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getViewportColourScheme(), seq, i);
if (av.getShowBoxes())
{
graphics.setColor(resBoxColour.darker());
}
if (av.getShowUnconserved())
{
- s = getDisplayChar(srep, i, s,
- '.');
+ s = getDisplayChar(srep, i, s, '.', null);
}
}
}
+ /**
+ * Returns 'conservedChar' to represent the given position if the sequence
+ * character at that position is equal to the consensus (ignoring case), else
+ * returns the sequence character
+ *
+ * @param usesrep
+ * @param position
+ * @param sequenceChar
+ * @param conservedChar
+ * @return
+ */
private char getDisplayChar(final boolean usesrep, int position,
- char s, char c)
+ char sequenceChar, char conservedChar, SequenceGroup currentGroup)
{
// TODO - use currentSequenceGroup rather than alignment
// currentSequenceGroup.getConsensus()
- char conschar = (usesrep) ? av.getAlignment().getSeqrep().getCharAt(position) : av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter
- .charAt(0);
- if (!jalview.util.Comparison.isGap(conschar) && s == conschar)
+ char conschar = (usesrep) ? (currentGroup == null
+ || position < currentGroup.getStartRes()
+ || position > currentGroup.getEndRes() ? av.getAlignment()
+ .getSeqrep().getCharAt(position)
+ : (currentGroup.getSeqrep() != null ? currentGroup.getSeqrep()
+ .getCharAt(position) : av.getAlignment().getSeqrep()
+ .getCharAt(position)))
+ : (currentGroup != null && currentGroup.getConsensus() != null
+ && position >= currentGroup.getStartRes()
+ && position <= currentGroup.getEndRes() && currentGroup
+ .getConsensus().annotations.length > position) ? currentGroup
+ .getConsensus().annotations[position].displayCharacter
+ .charAt(0)
+ : av.getAlignmentConsensusAnnotation().annotations[position].displayCharacter
+ .charAt(0);
+ if (!jalview.util.Comparison.isGap(conschar)
+ && (sequenceChar == conschar || sequenceChar + CHAR_TO_UPPER == conschar))
{
- s = c;
+ sequenceChar = conservedChar;
}
- return s;
+ return sequenceChar;
}
boolean inCurrentSequenceGroup(int res)