X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fappletgui%2FSequenceRenderer.java;h=38031e4e43f27e2afeb17b871e1d89e4de7a8762;hb=0125cee3edfa0ba5584631bae3ad9c808ec0b30d;hp=0470f8349077c7156c71bdb952a14f96242b652f;hpb=c19d2a91ca05e052e3408bf5852d88eb5d0608f1;p=jalview.git diff --git a/src/jalview/appletgui/SequenceRenderer.java b/src/jalview/appletgui/SequenceRenderer.java index 0470f83..38031e4 100755 --- a/src/jalview/appletgui/SequenceRenderer.java +++ b/src/jalview/appletgui/SequenceRenderer.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2) - * Copyright (C) 2015 The Jalview Authors + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors * * This file is part of Jalview. * @@ -20,10 +20,10 @@ */ package jalview.appletgui; -import jalview.api.FeatureRenderer; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; -import jalview.schemes.ColourSchemeI; +import jalview.renderer.ResidueShaderI; +import jalview.renderer.seqfeatures.FeatureColourFinder; import java.awt.Color; import java.awt.Font; @@ -32,6 +32,8 @@ import java.awt.Graphics; public class SequenceRenderer implements jalview.api.SequenceRenderer { + final static int CHAR_TO_UPPER = 'A' - 'a'; + AlignViewport av; FontMetrics fm; @@ -67,7 +69,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer this.renderGaps = renderGaps; } - public Color getResidueBoxColour(SequenceI seq, int i) + protected Color getResidueBoxColour(SequenceI seq, int i) { allGroups = av.getAlignment().findAllGroups(seq); @@ -75,12 +77,12 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer { if (currentSequenceGroup.getDisplayBoxes()) { - getBoxColour(currentSequenceGroup.cs, seq, i); + getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, i); } } else if (av.getShowBoxes()) { - getBoxColour(av.getGlobalColourScheme(), seq, i); + getBoxColour(av.getResidueShading(), seq, i); } return resBoxColour; @@ -93,29 +95,29 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer * * @param seq * @param position - * @param fr + * @param finder * @return */ @Override public Color getResidueColour(final SequenceI seq, int position, - FeatureRenderer fr) + FeatureColourFinder finder) { // TODO replace 8 or so code duplications with calls to this method // (refactored as needed) Color col = getResidueBoxColour(seq, position); - if (fr != null) + if (finder != null) { - col = fr.findFeatureColour(col, seq, position); + col = finder.findFeatureColour(col, seq, position); } return col; } - void getBoxColour(ColourSchemeI cs, SequenceI seq, int i) + void getBoxColour(ResidueShaderI shader, SequenceI seq, int i) { - if (cs != null) + if (shader.getColourScheme() != null) { - resBoxColour = cs.findColour(seq.getCharAt(i), i, seq); + resBoxColour = shader.findColour(seq.getCharAt(i), i, seq); } else if (forOverview && !jalview.util.Comparison.isGap(seq.getCharAt(i))) @@ -173,12 +175,13 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer { if (currentSequenceGroup.getDisplayBoxes()) { - getBoxColour(currentSequenceGroup.cs, seq, i); + getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq, + i); } } else if (av.getShowBoxes()) { - getBoxColour(av.getGlobalColourScheme(), seq, i); + getBoxColour(av.getResidueShading(), seq, i); } } @@ -251,12 +254,12 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer 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 @@ -268,7 +271,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer if (av.getColourText()) { - getBoxColour(av.getGlobalColourScheme(), seq, i); + getBoxColour(av.getResidueShading(), seq, i); if (av.getShowBoxes()) { graphics.setColor(resBoxColour.darker()); @@ -280,7 +283,7 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer } if (av.getShowUnconserved()) { - s = getDisplayChar(srep, i, s, '.'); + s = getDisplayChar(srep, i, s, '.', null); } } @@ -312,20 +315,43 @@ public class SequenceRenderer implements jalview.api.SequenceRenderer } - private char getDisplayChar(final boolean usesrep, int position, char s, - char c) + /** + * 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 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)