import jalview.schemes.ResidueColourScheme;
import jalview.schemes.ColourSchemes;
import jalview.datamodel.AnnotatedCollectionI;
-import java.util.Map;
import jalview.datamodel.SequenceI;
/*
Stripy() { }
String getSchemeName() { "stripy" }
Stripy getInstance(AnnotatedCollectionI coll, Map map) { new Stripy() }
- Color findColour(char res, int col, SequenceI seq) {
- // determine the colour
- Color colour = findColour(res, col)
- // let Jalview apply conservation or consensus shading
- adjustColour(res, col, colour);
- }
- Color findColour(char res, int col) {
+ Color findColour(char res, int col, SequenceI seq)
+ {
if (res == ' ' || res == '-' || res == '.')
{
Color.yellow
boolean isPeptideSpecific() {true}
String getSchemeName() { "By Weight" }
ByWeight getInstance(AnnotatedCollectionI coll, Map map) { new ByWeight() }
- Color makeColour(int weight) {
+ Color makeColour(int weight)
+ {
int i = 255 * (weight - min) / (max - min);
new Color(i, 0, i);
}
- Color findColour(char res, int col, SequenceI seq) {
- // determine the colour
- Color colour = findColour(res, col)
- // let Jalview apply any conservation or consensus shading
- adjustColour(res, col, colour);
- }
- Color findColour(char res, int col) {
+ Color findColour(char res, int col, SequenceI seq)
+ {
switch (res) {
case ' ':
case '-':
*
* @return Conservation sequence
*/
- public Sequence getConsSequence()
+ public SequenceI getConsSequence()
{
return consSequence;
}
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.schemes.CollectionColourSchemeI;
import jalview.schemes.ColourSchemeI;
import java.awt.Color;
ColourSchemeI getGlobalColourScheme();
+ CollectionColourSchemeI getViewportColourScheme();
+
AlignmentI getAlignment();
ColumnSelection getColumnSelection();
import jalview.schemes.Blosum62ColourScheme;
import jalview.schemes.BuriedColourScheme;
import jalview.schemes.ClustalxColourScheme;
+import jalview.schemes.CollectionColourScheme;
import jalview.schemes.HelixColourScheme;
import jalview.schemes.HydrophobicColourScheme;
import jalview.schemes.NucleotideColourScheme;
protected void clustalColour_actionPerformed()
{
SequenceGroup sg = getGroup();
- sg.cs = new ClustalxColourScheme(sg, ap.av.getHiddenRepSequences());
+ sg.cs = new CollectionColourScheme(new ClustalxColourScheme(sg,
+ ap.av.getHiddenRepSequences()));
refresh();
}
protected void zappoColour_actionPerformed()
{
- getGroup().cs = new ZappoColourScheme();
+ getGroup().cs = new CollectionColourScheme(new ZappoColourScheme());
refresh();
}
protected void taylorColour_actionPerformed()
{
- getGroup().cs = new TaylorColourScheme();
+ getGroup().cs = new CollectionColourScheme(new TaylorColourScheme());
refresh();
}
protected void hydrophobicityColour_actionPerformed()
{
- getGroup().cs = new HydrophobicColourScheme();
+ getGroup().cs = new CollectionColourScheme(new HydrophobicColourScheme());
refresh();
}
protected void helixColour_actionPerformed()
{
- getGroup().cs = new HelixColourScheme();
+ getGroup().cs = new CollectionColourScheme(new HelixColourScheme());
refresh();
}
protected void strandColour_actionPerformed()
{
- getGroup().cs = new StrandColourScheme();
+ getGroup().cs = new CollectionColourScheme(new StrandColourScheme());
refresh();
}
protected void turnColour_actionPerformed()
{
- getGroup().cs = new TurnColourScheme();
+ getGroup().cs = new CollectionColourScheme(new TurnColourScheme());
refresh();
}
protected void buriedColour_actionPerformed()
{
- getGroup().cs = new BuriedColourScheme();
+ getGroup().cs = new CollectionColourScheme(new BuriedColourScheme());
refresh();
}
public void nucleotideMenuItem_actionPerformed()
{
- getGroup().cs = new NucleotideColourScheme();
+ getGroup().cs = new CollectionColourScheme(new NucleotideColourScheme());
refresh();
}
public void purinePyrimidineColour_actionPerformed()
{
- getGroup().cs = new PurinePyrimidineColourScheme();
+ getGroup().cs = new CollectionColourScheme(
+ new PurinePyrimidineColourScheme());
refresh();
}
protected void PIDColour_actionPerformed()
{
SequenceGroup sg = getGroup();
- sg.cs = new PIDColourScheme();
+ sg.cs = new CollectionColourScheme(new PIDColourScheme());
sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
.getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
refresh();
{
SequenceGroup sg = getGroup();
- sg.cs = new Blosum62ColourScheme();
+ sg.cs = new CollectionColourScheme(new Blosum62ColourScheme());
sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av
.getHiddenRepSequences()), 0, ap.av.getAlignment().getWidth()));
if (conservationMenuItem.getState())
{
- sg.cs.setConservation(Conservation.calculateConservation("Group", sg
+ Conservation conservation = Conservation.calculateConservation("Group", sg
.getSequences(ap.av.getHiddenRepSequences()), 0, ap.av
.getAlignment().getWidth(), false, ap.av.getConsPercGaps(),
- false));
+ false);
+ sg.getGroupColourScheme().setConservation(conservation);
SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
SliderPanel.showConservationSlider();
}
import jalview.schemes.PIDColourScheme;
import jalview.schemes.PurinePyrimidineColourScheme;
import jalview.schemes.RNAHelicesColour;
-import jalview.schemes.RNAHelicesColourChooser;
import jalview.schemes.StrandColourScheme;
import jalview.schemes.TCoffeeColourScheme;
import jalview.schemes.TaylorColourScheme;
@Override
public void changeColour(ColourSchemeI cs)
{
-
+ // FIXME threshold, conservation, increment belong inside
+ // AlignmentColourScheme and/or ViewStyleI, not ColourSchemeI
if (cs != null)
{
if (viewport.getAbovePIDThreshold())
{
viewport.setThreshold(SliderPanel.setPIDSliderSource(alignPanel,
- cs, "Background"));
+ viewport.getViewportColourScheme(), "Background"));
}
if (viewport.getConservationSelected())
{
- cs.setConservationApplied(true);
+ // cs.setConservationApplied(true);
viewport.setIncrement(SliderPanel.setConservationSlider(alignPanel,
- cs, "Background"));
- }
- else
- {
- cs.setConservationApplied(false);
+ viewport.getViewportColourScheme(), "Background"));
}
+ // else
+ // {
+ // cs.setConservationApplied(false);
+ // }
}
viewport.setGlobalColourScheme(cs);
+ viewport.getViewportColourScheme().setConservationApplied(
+ viewport.getConservationSelected());
alignPanel.paintAlignment(true);
}
&& viewport.getGlobalColourScheme() != null)
{
SliderPanel.setPIDSliderSource(alignPanel,
- viewport.getGlobalColourScheme(), "Background");
+ viewport.getViewportColourScheme(), "Background");
SliderPanel.showPIDSlider();
}
}
&& viewport.getGlobalColourScheme() != null)
{
SliderPanel.setConservationSlider(alignPanel,
- viewport.getGlobalColourScheme(), "Background");
+ viewport.getViewportColourScheme(), "Background");
SliderPanel.showConservationSlider();
}
}
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.schemes.CollectionColourScheme;
import jalview.schemes.ColourSchemeProperty;
import jalview.schemes.UserColourScheme;
import jalview.structure.CommandListener;
if (colour != null)
{
- globalColourScheme = ColourSchemeProperty.getColourScheme(
- alignment, colour);
+ globalColourScheme = new CollectionColourScheme(
+ ColourSchemeProperty.getColourScheme(alignment, colour));
if (globalColourScheme != null)
{
globalColourScheme.setConsensus(hconsensus);
if (applet.getParameter("userDefinedColour") != null)
{
- globalColourScheme = new UserColourScheme(
- applet.getParameter("userDefinedColour"));
+ globalColourScheme = new CollectionColourScheme(
+ new UserColourScheme(
+ applet.getParameter("userDefinedColour")));
}
}
initAutoAnnotation();
oldgroupColours = new Hashtable();
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- if (sg.cs != null)
+ if (sg.getColourScheme() != null)
{
- oldgroupColours.put(sg, sg.cs);
+ oldgroupColours.put(sg, sg.getColourScheme());
}
else
{
AnnotationColourGradient acg = null;
if (currentColours.getState())
{
- acg = new AnnotationColourGradient(currentAnnotation,
- av.getGlobalColourScheme(), aboveThreshold);
}
else
{
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- if (sg.cs == null)
+ if (sg.getColourScheme() == null)
{
continue;
}
if (currentColours.getState())
{
- sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
- aboveThreshold);
+ sg.setColourScheme(new AnnotationColourGradient(
+ currentAnnotation, sg.getColourScheme(), aboveThreshold));
}
else
{
- sg.cs = new AnnotationColourGradient(currentAnnotation,
- minColour.getBackground(), maxColour.getBackground(),
- aboveThreshold);
+ sg.setColourScheme(new AnnotationColourGradient(
+ currentAnnotation, minColour.getBackground(), maxColour
+ .getBackground(), aboveThreshold));
}
}
Object cs = oldgroupColours.get(sg);
if (cs instanceof ColourSchemeI)
{
- sg.cs = (ColourSchemeI) cs;
+ sg.setColourScheme((ColourSchemeI) cs);
}
else
{
// probably the "null" string we set it to if it was null originally.
- sg.cs = null;
+ sg.setColourScheme(null);
}
}
}
if (av.getConservationSelected())
{
- SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
+ SliderPanel.setConservationSlider(ap, av.getViewportColourScheme(),
"Background");
}
if (av.getAbovePIDThreshold())
{
- SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
+ SliderPanel.setPIDSliderSource(ap, av.getViewportColourScheme(),
"Background");
}
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;
{
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())
if (av.getColourText())
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getViewportColourScheme(), seq, i);
if (av.getShowBoxes())
{
graphics.setColor(resBoxColour.darker());
package jalview.appletgui;
import jalview.datamodel.SequenceGroup;
-import jalview.schemes.ColourSchemeI;
+import jalview.schemes.CollectionColourSchemeI;
import jalview.util.MessageManager;
import java.awt.BorderLayout;
boolean forConservation = true;
- ColourSchemeI cs;
+ CollectionColourSchemeI cs;
static Frame conservationSlider;
static Frame PIDSlider;
public static int setConservationSlider(AlignmentPanel ap,
- ColourSchemeI cs, String source)
+ CollectionColourSchemeI collectionColourSchemeI, String source)
{
SliderPanel sp = null;
if (conservationSlider == null)
{
- sp = new SliderPanel(ap, cs.getConservationInc(), true, cs);
+ sp = new SliderPanel(ap,
+ collectionColourSchemeI.getConservationInc(), true,
+ collectionColourSchemeI);
conservationSlider = new Frame();
conservationSlider.add(sp);
}
else
{
sp = (SliderPanel) conservationSlider.getComponent(0);
- sp.cs = cs;
+ sp.cs = collectionColourSchemeI;
}
conservationSlider
conservationSlider.getTitle(), 420, 100);
conservationSlider.addWindowListener(new WindowAdapter()
{
+ @Override
public void windowClosing(WindowEvent e)
{
conservationSlider = null;
}
- public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
- String source)
+ public static int setPIDSliderSource(AlignmentPanel ap,
+ CollectionColourSchemeI collectionColourSchemeI, String source)
{
SliderPanel pid = null;
if (PIDSlider == null)
{
- pid = new SliderPanel(ap, 50, false, cs);
+ pid = new SliderPanel(ap, 50, false, collectionColourSchemeI);
PIDSlider = new Frame();
PIDSlider.add(pid);
}
else
{
pid = (SliderPanel) PIDSlider.getComponent(0);
- pid.cs = cs;
+ pid.cs = collectionColourSchemeI;
}
PIDSlider
.setTitle(MessageManager.formatMessage(
420, 100);
PIDSlider.addWindowListener(new WindowAdapter()
{
+ @Override
public void windowClosing(WindowEvent e)
{
PIDSlider = null;
}
public SliderPanel(AlignmentPanel ap, int value, boolean forConserve,
- ColourSchemeI cs)
+ CollectionColourSchemeI collectionColourSchemeI)
{
try
{
e.printStackTrace();
}
this.ap = ap;
- this.cs = cs;
+ this.cs = collectionColourSchemeI;
forConservation = forConserve;
undoButton.setVisible(false);
applyButton.setVisible(false);
return;
}
- ColourSchemeI toChange = cs;
+ CollectionColourSchemeI toChange = cs;
Iterator<SequenceGroup> allGroups = null;
if (allGroupsCheck.getState())
allGroupsCheck.setEnabled(b);
}
+ @Override
public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == applyButton)
}
}
+ @Override
public void adjustmentValueChanged(AdjustmentEvent evt)
{
valueField.setText(slider.getValue() + "");
{
}
+ @Override
public void mousePressed(MouseEvent evt)
{
}
+ @Override
public void mouseReleased(MouseEvent evt)
{
ap.paintAlignment(true);
}
+ @Override
public void mouseClicked(MouseEvent evt)
{
}
+ @Override
public void mouseEntered(MouseEvent evt)
{
}
+ @Override
public void mouseExited(MouseEvent evt)
{
}
.getGlobalColourScheme()));
}
// cs is null if shading is an annotationColourGradient
- if (cs != null)
- {
- cs.setThreshold(av.getGlobalColourScheme().getThreshold(),
- av.isIgnoreGapsConsensus());
- }
+ // if (cs != null)
+ // {
+ // cs.setThreshold(av.getViewportColourScheme().getThreshold(),
+ // av.isIgnoreGapsConsensus());
+ // }
}
// TODO: cs used to be initialized with a sequence collection and
// recalcConservation called automatically
// instead we set it manually - recalc called after updateAnnotation
- sg.cs = cs;
+ sg.setColourScheme(cs);
+ sg.getGroupColourScheme().setThreshold(
+ av.getViewportColourScheme().getThreshold(),
+ av.isIgnoreGapsConsensus());
sg.setName("JTreeGroup:" + sg.hashCode());
sg.setIdColour(col);
if (av.getGlobalColourScheme() != null
- && av.getGlobalColourScheme().conservationApplied())
+ && av.getViewportColourScheme().conservationApplied())
{
Conservation c = new Conservation("Group", sg.getSequences(null),
sg.getStartRes(), sg.getEndRes());
c.calculate();
c.verdict(false, av.getConsPercGaps());
- cs.setConservation(c);
-
- sg.cs = cs;
+ sg.setColourScheme(cs);
+ sg.getGroupColourScheme().setConservation(c);
}
av.getAlignment().addGroup(sg);
import jalview.api.FeatureColourI;
import jalview.datamodel.SequenceGroup;
+import jalview.schemes.CollectionColourScheme;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.FeatureColour;
import jalview.schemes.ResidueProperties;
if (seqGroup != null)
{
- oldColourScheme = seqGroup.cs;
+ oldColourScheme = seqGroup.getColourScheme();
}
else
{
{
final Button button = new Button();
Color col = Color.white;
- if (oldColourScheme != null)
+ if (oldColourScheme != null && oldColourScheme.isSimple())
{
- try
- {
- col = oldColourScheme.findColour(aa.charAt(0), -1, null);
- } catch (Exception ex)
- {
- }
+ col = oldColourScheme.findColour(aa.charAt(0));
}
button.setBackground(col);
oldColours.addElement(col);
}
UserColourScheme ucs = new UserColourScheme(newColours);
- if (ap != null)
- {
- ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
- }
+ // if (ap != null)
+ // {
+ // ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
+ // }
if (ap != null)
{
if (seqGroup != null)
{
- seqGroup.cs = ucs;
+ seqGroup.cs = new CollectionColourScheme(ucs);
+ seqGroup.getGroupColourScheme().setThreshold(0,
+ ap.av.isIgnoreGapsConsensus());
}
else
{
ap.av.setGlobalColourScheme(ucs);
+ ap.av.getViewportColourScheme().setThreshold(0,
+ ap.av.isIgnoreGapsConsensus());
}
ap.seqPanel.seqCanvas.img = null;
ap.paintAlignment(true);
{
if (seqGroup != null)
{
- seqGroup.cs = ucs;
+ seqGroup.cs = new CollectionColourScheme(ucs);
}
else
{
import jalview.analysis.AAFrequency;
import jalview.analysis.Conservation;
+import jalview.schemes.CollectionColourScheme;
+import jalview.schemes.CollectionColourSchemeI;
import jalview.schemes.ColourSchemeI;
import java.awt.Color;
/**
* Colourscheme applied to group if any
*/
- public ColourSchemeI cs;
+ public CollectionColourSchemeI cs;
// start column (base 0)
int startRes = 0;
public SequenceGroup()
{
groupName = "JGroup:" + this.hashCode();
+ cs = new CollectionColourScheme();
}
/**
ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
boolean colourText, int start, int end)
{
+ this();
this.sequences = sequences;
this.groupName = groupName;
this.displayBoxes = displayBoxes;
this.displayText = displayText;
this.colourText = colourText;
- this.cs = scheme;
+ this.cs = new CollectionColourScheme(scheme);
startRes = start;
endRes = end;
recalcConservation();
*/
public SequenceGroup(SequenceGroup seqsel)
{
+ this();
if (seqsel != null)
{
sequences = new ArrayList<SequenceI>();
{
return context;
}
+
+ public void setColourScheme(ColourSchemeI scheme)
+ {
+ cs.setColourScheme(scheme);
+ }
+
+ public void setGroupColourScheme(CollectionColourSchemeI scheme)
+ {
+ cs = scheme;
+ }
+
+ public ColourSchemeI getColourScheme()
+ {
+ return cs == null ? null : cs.getColourScheme();
+ }
+
+ public CollectionColourSchemeI getGroupColourScheme()
+ {
+ return cs;
+ }
}
{
ColourMenuHelper.setColourSelected(colourMenu, cs.getSchemeName());
// Make sure viewport is up to date w.r.t. any sliders
- if (viewport.getAbovePIDThreshold())
- {
- int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
- "Background");
- viewport.setThreshold(threshold);
- }
-
- if (viewport.getConservationSelected())
- {
- cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
- cs, "Background"));
- }
+ // ? not needed as handled by SliderPanel.valueChanged?
+// if (viewport.getAbovePIDThreshold())
+// {
+ // int threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
+// "Background");
+ //todo is threshold held in viewport style or in colour scheme?
+// viewport.setThreshold(threshold);
+ // }
+ //
+ // if (viewport.getConservationSelected())
+ // {
+ // cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
+ // cs, "Background"));
+ // }
}
viewport.setGlobalColourScheme(cs);
+ if (viewport.getConservationSelected())
+ {
+ int conservationInc = SliderPanel.getConservationValue();
+ viewport.getViewportColourScheme()
+ .setConservationInc(conservationInc);
+ }
alignPanel.paintAlignment(true);
}
@Override
protected void modifyPID_actionPerformed()
{
- if (viewport.getAbovePIDThreshold()
- && viewport.getGlobalColourScheme() != null)
+ if (viewport.getAbovePIDThreshold())
{
SliderPanel.setPIDSliderSource(alignPanel,
- viewport.getGlobalColourScheme(), "Background");
+ viewport.getViewportColourScheme(), "Background");
SliderPanel.showPIDSlider();
}
}
&& viewport.getGlobalColourScheme() != null)
{
SliderPanel.setConservationSlider(alignPanel,
- viewport.getGlobalColourScheme(), "Background");
+ viewport.getViewportColourScheme(), "Background");
SliderPanel.showConservationSlider();
}
}
colourMenu.add(modifyPID);
colourMenu.add(annotationColour);
- /*
- * select the default colour for the alignment (this may be
- * overridden later)
- */
- boolean nucleotide = viewport.getAlignment().isNucleotide();
- String defaultColourScheme = Cache.getDefault(
- nucleotide ? Preferences.DEFAULT_COLOUR_NUC
- : Preferences.DEFAULT_COLOUR_PROT,
- ResidueColourScheme.NONE);
+ ColourSchemeI colourScheme = viewport.getGlobalColourScheme();
+ String schemeName = colourScheme == null ? null : colourScheme
+ .getSchemeName();
- ColourMenuHelper.setColourSelected(colourMenu, defaultColourScheme);
+ ColourMenuHelper.setColourSelected(colourMenu, schemeName);
}
}
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.schemes.CollectionColourScheme;
+import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
import jalview.schemes.UserColourScheme;
import jalview.structure.CommandListener;
import java.util.Vector;
import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
/**
* DOCUMENT ME!
}
if (propertyValue != null)
{
- globalColourScheme = ColourSchemeProperty.getColourScheme(alignment,
- propertyValue);
+ ColourSchemeI colourScheme = ColourSchemeProperty.getColourScheme(
+ alignment, propertyValue);
+ globalColourScheme = new CollectionColourScheme(colourScheme);
- if (globalColourScheme instanceof UserColourScheme)
+ if (colourScheme instanceof UserColourScheme)
{
- globalColourScheme = UserDefinedColours.loadDefaultColours();
- ((UserColourScheme) globalColourScheme).setThreshold(0,
- isIgnoreGapsConsensus());
+ globalColourScheme = new CollectionColourScheme(
+ UserDefinedColours.loadDefaultColours());
+ globalColourScheme.setThreshold(0, isIgnoreGapsConsensus());
}
if (globalColourScheme != null)
oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- if (sg.cs != null)
+ if (sg.getColourScheme() != null)
{
- oldgroupColours.put(sg, sg.cs);
+ oldgroupColours.put(sg, sg.getColourScheme());
}
}
}
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- sg.cs = oldgroupColours.get(sg);
+ sg.setColourScheme(oldgroupColours.get(sg));
}
}
}
continue;
}
+ AnnotationColourGradient scheme = null;
if (currentColours.isSelected())
{
- sg.cs = new AnnotationColourGradient(currentAnn, sg.cs,
- selectedThresholdOption);
- ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
- .isSelected());
-
+ scheme = new AnnotationColourGradient(currentAnn,
+ sg.getColourScheme(), selectedThresholdOption);
}
else
{
- sg.cs = new AnnotationColourGradient(currentAnn,
+ scheme = new AnnotationColourGradient(currentAnn,
minColour.getBackground(), maxColour.getBackground(),
selectedThresholdOption);
- ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
- .isSelected());
}
-
+ scheme.setSeqAssociated(seqAssociated.isSelected());
+ sg.setColourScheme(scheme);
}
}
return false;
import jalview.schemabinding.version2.UserColours;
import jalview.schemabinding.version2.Viewport;
import jalview.schemes.AnnotationColourGradient;
+import jalview.schemes.CollectionColourSchemeI;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
import jalview.schemes.FeatureColour;
// group has references so set its ID field
jGroup.setId(groupRefs.get(sg));
}
- if (sg.cs != null)
+ ColourSchemeI colourScheme = sg.getColourScheme();
+ if (colourScheme != null)
{
- if (sg.cs.conservationApplied())
+ CollectionColourSchemeI groupColourScheme = sg
+ .getGroupColourScheme();
+ if (groupColourScheme.conservationApplied())
{
- jGroup.setConsThreshold(sg.cs.getConservationInc());
+ jGroup.setConsThreshold(groupColourScheme.getConservationInc());
- if (sg.cs instanceof jalview.schemes.UserColourScheme)
+ if (colourScheme instanceof jalview.schemes.UserColourScheme)
{
- jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
+ jGroup.setColour(setUserColourScheme(colourScheme,
+ userColours, jms));
}
else
{
- jGroup.setColour(sg.cs.getSchemeName());
+ jGroup.setColour(colourScheme.getSchemeName());
}
}
- else if (sg.cs instanceof jalview.schemes.AnnotationColourGradient)
+ else if (colourScheme instanceof jalview.schemes.AnnotationColourGradient)
{
jGroup.setColour("AnnotationColourGradient");
jGroup.setAnnotationColours(constructAnnotationColours(
- (jalview.schemes.AnnotationColourGradient) sg.cs,
+ (jalview.schemes.AnnotationColourGradient) colourScheme,
userColours, jms));
}
- else if (sg.cs instanceof jalview.schemes.UserColourScheme)
+ else if (colourScheme instanceof jalview.schemes.UserColourScheme)
{
- jGroup.setColour(setUserColourScheme(sg.cs, userColours, jms));
+ jGroup.setColour(setUserColourScheme(colourScheme,
+ userColours, jms));
}
else
{
- jGroup.setColour(sg.cs.getSchemeName());
+ jGroup.setColour(colourScheme.getSchemeName());
}
- jGroup.setPidThreshold(sg.cs.getThreshold());
+ jGroup.setPidThreshold(groupColourScheme.getThreshold());
}
jGroup.setOutlineColour(sg.getOutlineColour().getRGB());
.getGlobalColourScheme()));
}
+ CollectionColourSchemeI vcs = av.getViewportColourScheme();
ColourSchemeI cs = av.getGlobalColourScheme();
if (cs != null)
{
- if (cs.conservationApplied())
+ if (vcs.conservationApplied())
{
- view.setConsThreshold(cs.getConservationInc());
+ view.setConsThreshold(vcs.getConservationInc());
if (cs instanceof jalview.schemes.UserColourScheme)
{
view.setBgColour(setUserColourScheme(cs, userColours, jms));
}
}
-
- if (cs instanceof ResidueColourScheme)
- {
- view.setPidThreshold(cs.getThreshold());
- }
+ view.setPidThreshold(vcs.getThreshold());
}
view.setConservationSelected(av.getConservationSelected());
&& jGroup.getAnnotationColours() != null)
{
addAnnotSchemeGroup = true;
- cs = null;
}
else
{
cs = ColourSchemeProperty.getColourScheme(al, jGroup.getColour());
}
-
- if (cs != null)
- {
- cs.setThreshold(jGroup.getPidThreshold(), true);
- }
}
+ int pidThreshold = jGroup.getPidThreshold();
Vector<SequenceI> seqs = new Vector<SequenceI>();
SequenceGroup sg = new SequenceGroup(seqs, jGroup.getName(), cs,
jGroup.getDisplayBoxes(), jGroup.getDisplayText(),
jGroup.getColourText(), jGroup.getStart(), jGroup.getEnd());
-
+ sg.getGroupColourScheme().setThreshold(pidThreshold, true);
sg.setOutlineColour(new java.awt.Color(jGroup.getOutlineColour()));
sg.textColour = new java.awt.Color(jGroup.getTextCol1());
if (addAnnotSchemeGroup)
{
// reconstruct the annotation colourscheme
- sg.cs = constructAnnotationColour(jGroup.getAnnotationColours(),
- null, al, jms, false);
+ sg.setColourScheme(constructAnnotationColour(
+ jGroup.getAnnotationColours(), null, al, jms, false));
}
}
}
cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour());
}
- if (cs != null)
- {
- cs.setThreshold(view.getPidThreshold(), true);
- cs.setConsensus(af.viewport.getSequenceConsensusHash());
- }
+ // if (cs != null)
+ // {
+ // cs.setThreshold(view.getPidThreshold(), true);
+ // cs.setConsensus(af.viewport.getSequenceConsensusHash());
+ // }
}
af.viewport.setGlobalColourScheme(cs);
+ af.viewport.getViewportColourScheme().setThreshold(
+ view.getPidThreshold(), true);
+ af.viewport.getViewportColourScheme().setConsensus(
+ af.viewport.getSequenceConsensusHash());
af.viewport.setColourAppliesToAllGroups(false);
if (view.getConservationSelected() && cs != null)
{
- cs.setConservationInc(view.getConsThreshold());
+ af.viewport.getViewportColourScheme().setConservationInc(
+ view.getConsThreshold());
}
af.changeColour(cs);
propagateAnnColour = true;
for (jalview.datamodel.SequenceGroup sg : al.getGroups())
{
- if (sg.cs instanceof AnnotationColourGradient)
+ if (sg.getColourScheme() instanceof AnnotationColourGradient)
{
propagateAnnColour = false;
}
* viewAnnColour.getAboveThreshold()); } else
*/
{
- sg.cs = new AnnotationColourGradient(
- annAlignment.getAlignmentAnnotation()[i], sg.cs,
- viewAnnColour.getAboveThreshold());
+ sg.setColourScheme(new AnnotationColourGradient(
+ annAlignment.getAlignmentAnnotation()[i], sg
+ .getColourScheme(), viewAnnColour
+ .getAboveThreshold()));
if (cs instanceof AnnotationColourGradient)
{
if (viewAnnColour.hasPerSequence())
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
-import javax.swing.JOptionPane;
-
/**
* DOCUMENT ME!
*
{
cs = ColourSchemeProperty.getColourScheme(al, groups[i].getColour());
}
-
- if (cs != null)
- {
- cs.setThreshold(groups[i].getPidThreshold(), true);
- }
-
}
+ int pidThreshold = groups[i].getPidThreshold();
Vector seqs = new Vector();
int[] ids = groups[i].getSeq();
seqs, groups[i].getName(), cs, groups[i].getDisplayBoxes(),
groups[i].getDisplayText(), groups[i].getColourText(),
groups[i].getStart(), groups[i].getEnd());
+ sg.getGroupColourScheme().setThreshold(pidThreshold, true);
sg.setOutlineColour(new java.awt.Color(groups[i].getOutlineColour()));
cs = ColourSchemeProperty.getColourScheme(al, view.getBgColour());
}
- if (cs != null)
- {
- cs.setThreshold(view.getPidThreshold(), true);
- cs.setConsensus(af.viewport.getSequenceConsensusHash());
- }
+ // if (cs != null)
+ // {
+ // cs.setThreshold(view.getPidThreshold(), true);
+ // cs.setConsensus(af.viewport.getSequenceConsensusHash());
+ // }
}
- af.viewport.setGlobalColourScheme(cs);
+ af.viewport.getViewportColourScheme().setThreshold(
+ view.getPidThreshold(), true);
+ af.viewport.getViewportColourScheme().setConsensus(
+ af.viewport.getSequenceConsensusHash());
af.viewport.setColourAppliesToAllGroups(false);
af.alignPanel.updateLayout();
af.changeColour(cs);
if (view.getConservationSelected() && cs != null)
{
- cs.setConservationInc(view.getConsThreshold());
+ af.viewport.getViewportColourScheme().setConservationInc(
+ view.getConsThreshold());
}
af.viewport.setColourAppliesToAllGroups(true);
import jalview.io.SequenceAnnotationReport;
import jalview.schemes.AnnotationColourGradient;
import jalview.schemes.Blosum62ColourScheme;
+import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemes;
import jalview.schemes.PIDColourScheme;
import jalview.schemes.ResidueColourScheme;
groupName.setText(MessageManager
.getString("label.edit_name_and_description_current_group"));
- ColourMenuHelper.setColourSelected(colourMenu, sg.cs);
+ ColourMenuHelper.setColourSelected(colourMenu, sg.getColourScheme());
if (sg.cs != null && sg.cs.conservationApplied())
{
sg.getSequences(ap.av.getHiddenRepSequences()),
sg.getStartRes(), sg.getEndRes() + 1));
- int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
+ int threshold = SliderPanel.setPIDSliderSource(ap,
+ sg.getGroupColourScheme(), getGroup()
.getName());
sg.cs.setThreshold(threshold, ap.av.isIgnoreGapsConsensus());
c.calculate();
c.verdict(false, ap.av.getConsPercGaps());
-
sg.cs.setConservation(c);
- SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
+ SliderPanel.setConservationSlider(ap, sg.getGroupColourScheme(),
+ sg.getName());
SliderPanel.showConservationSlider();
}
else
AnnotationColourGradient.NO_THRESHOLD);
acg.setPredefinedColours(true);
- sg.cs = acg;
+ sg.setColourScheme(acg);
refresh();
}
/*
* switch to the chosen colour scheme (or null for None)
*/
- sg.cs = ColourSchemes.getInstance().getColourScheme(colourSchemeName,
- sg, ap.av.getHiddenRepSequences());
- if (sg.cs instanceof Blosum62ColourScheme
- || sg.cs instanceof PIDColourScheme)
+ ColourSchemeI colourScheme = ColourSchemes.getInstance().getColourScheme(
+ colourSchemeName, sg, ap.av.getHiddenRepSequences());
+ sg.setColourScheme(colourScheme);
+ if (colourScheme instanceof Blosum62ColourScheme
+ || colourScheme instanceof PIDColourScheme)
{
sg.cs.setConsensus(AAFrequency.calculate(
sg.getSequences(ap.av.getHiddenRepSequences()),
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.io.SequenceAnnotationReport;
+import jalview.schemes.CollectionColourSchemeI;
import jalview.schemes.ResidueProperties;
import jalview.structure.SelectionListener;
import jalview.structure.SelectionSource;
import java.util.ArrayList;
import java.util.List;
-import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
if (av.getConservationSelected())
{
- SliderPanel.setConservationSlider(ap, av.getGlobalColourScheme(),
+ SliderPanel.setConservationSlider(ap, av.getViewportColourScheme(),
"Background");
}
if (av.getAbovePIDThreshold())
{
- SliderPanel.setPIDSliderSource(ap, av.getGlobalColourScheme(),
+ SliderPanel.setPIDSliderSource(ap, av.getViewportColourScheme(),
"Background");
}
if ((stretchGroup != null) && (stretchGroup.getEndRes() == res))
stretchGroup.cs.alignmentChanged(stretchGroup,
av.getHiddenRepSequences());
+ CollectionColourSchemeI groupColourScheme = stretchGroup.getGroupColourScheme();
+ String name = stretchGroup.getName();
if (stretchGroup.cs.conservationApplied())
{
- SliderPanel.setConservationSlider(ap, stretchGroup.cs,
- stretchGroup.getName());
+ SliderPanel.setConservationSlider(ap, groupColourScheme, name);
}
else
{
- SliderPanel.setPIDSliderSource(ap, stretchGroup.cs,
- stretchGroup.getName());
+ SliderPanel.setPIDSliderSource(ap, groupColourScheme, name);
}
}
PaintRefresher.Refresh(this, av.getSequenceSetId());
import jalview.api.FeatureRenderer;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
-import jalview.schemes.ColourSchemeI;
+import jalview.schemes.CollectionColourSchemeI;
+import jalview.util.Comparison;
import java.awt.Color;
import java.awt.FontMetrics;
{
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;
/**
* DOCUMENT ME!
*
- * @param cs
+ * @param collectionColourSchemeI
* DOCUMENT ME!
* @param seq
* DOCUMENT ME!
* @param i
* DOCUMENT ME!
*/
- 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)))
+ else if (forOverview && !Comparison.isGap(seq.getCharAt(i)))
{
resBoxColour = Color.lightGray;
}
{
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 (resBoxColour != tempColour)
|| currentSequenceGroup.getColourText())
{
getboxColour = true;
- getBoxColour(currentSequenceGroup.cs, seq, i);
+ getBoxColour(currentSequenceGroup.getGroupColourScheme(), seq,
+ i);
if (currentSequenceGroup.getColourText())
{
if (av.getColourText())
{
getboxColour = true;
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getViewportColourScheme(), seq, i);
if (av.getShowBoxes())
{
{
if (!getboxColour)
{
- getBoxColour(av.getGlobalColourScheme(), seq, i);
+ getBoxColour(av.getViewportColourScheme(), seq, i);
}
if (resBoxColour.getRed() + resBoxColour.getBlue()
import jalview.datamodel.SequenceGroup;
import jalview.jbgui.GSliderPanel;
-import jalview.schemes.ColourSchemeI;
+import jalview.schemes.CollectionColourSchemeI;
import jalview.util.MessageManager;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
-import java.util.Iterator;
import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
boolean forConservation = true;
- ColourSchemeI cs;
+ CollectionColourSchemeI cs;
/**
* Creates a new SliderPanel object.
* DOCUMENT ME!
* @param forConserve
* DOCUMENT ME!
- * @param cs
+ * @param scheme
* DOCUMENT ME!
*/
public SliderPanel(final AlignmentPanel ap, int value,
- boolean forConserve, ColourSchemeI cs)
+ boolean forConserve, CollectionColourSchemeI scheme)
{
this.ap = ap;
- this.cs = cs;
+ this.cs = scheme;
forConservation = forConserve;
undoButton.setVisible(false);
applyButton.setVisible(false);
slider.addChangeListener(new ChangeListener()
{
+ @Override
public void stateChanged(ChangeEvent evt)
{
valueField.setText(slider.getValue() + "");
slider.addMouseListener(new MouseAdapter()
{
+ @Override
public void mouseReleased(MouseEvent evt)
{
ap.paintAlignment(true);
* @return DOCUMENT ME!
*/
public static int setConservationSlider(AlignmentPanel ap,
- ColourSchemeI cs, String source)
+ CollectionColourSchemeI cs, String source)
{
SliderPanel sp = null;
conservationSlider
.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
{
+ @Override
public void internalFrameClosed(
javax.swing.event.InternalFrameEvent e)
{
*
* @param ap
* DOCUMENT ME!
- * @param cs
+ * @param collectionColourScheme
* DOCUMENT ME!
* @param source
* DOCUMENT ME!
*
* @return DOCUMENT ME!
*/
- public static int setPIDSliderSource(AlignmentPanel ap, ColourSchemeI cs,
+ public static int setPIDSliderSource(AlignmentPanel ap,
+ CollectionColourSchemeI collectionColourScheme,
String source)
{
SliderPanel pid = null;
- int threshold = cs.getThreshold();
+ int threshold = collectionColourScheme.getThreshold();
if (PIDSlider == null)
{
- pid = new SliderPanel(ap, threshold, false, cs);
+ pid = new SliderPanel(ap, threshold, false, collectionColourScheme);
PIDSlider = new JInternalFrame();
PIDSlider.setContentPane(pid);
PIDSlider.setLayer(JLayeredPane.PALETTE_LAYER);
else
{
pid = (SliderPanel) PIDSlider.getContentPane();
- pid.cs = cs;
+ pid.cs = collectionColourScheme;
}
PIDSlider
PIDSlider
.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
{
+ @Override
public void internalFrameClosed(
javax.swing.event.InternalFrameEvent e)
{
}
/**
- * DOCUMENT ME!
+ * Updates the colour scheme with the current (identity threshold or
+ * conservation) percentage value. Also updates all groups if 'apply to all
+ * groups' is selected.
*
- * @param i
- * DOCUMENT ME!
+ * @param percent
*/
- public void valueChanged(int i)
+ public void valueChanged(int percent)
{
- if (cs == null)
+ if (!forConservation)
{
- return;
+ ap.av.setThreshold(percent);
}
-
- ColourSchemeI toChange = cs;
- Iterator<SequenceGroup> allGroups = null;
+ updateColourScheme(percent, cs);
if (allGroupsCheck.isSelected())
{
- allGroups = ap.av.getAlignment().getGroups().listIterator();
- }
-
- while (toChange != null)
- {
- if (forConservation)
- {
- toChange.setConservationInc(i);
- }
- else
- {
- toChange.setThreshold(i, ap.av.isIgnoreGapsConsensus());
- }
- if (allGroups != null && allGroups.hasNext())
- {
- while ((toChange = allGroups.next().cs) == null
- && allGroups.hasNext())
- {
- ;
- }
- }
- else
+ for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- toChange = null;
+ updateColourScheme(percent, sg.getGroupColourScheme());
}
}
}
/**
+ * Updates the colour scheme (if not null) with the current (identity
+ * threshold or conservation) percentage value
+ *
+ * @param percent
+ * @param scheme
+ */
+ protected void updateColourScheme(int percent, CollectionColourSchemeI scheme)
+ {
+ if (scheme == null)
+ {
+ return;
+ }
+ if (forConservation)
+ {
+ scheme.setConservationInc(percent);
+ }
+ else
+ {
+ scheme.setThreshold(percent, ap.av.isIgnoreGapsConsensus());
+ }
+ }
+
+ /**
* DOCUMENT ME!
*
* @param b
* @param e
* DOCUMENT ME!
*/
+ @Override
public void valueField_actionPerformed(ActionEvent e)
{
try
return Integer.parseInt(valueField.getText());
}
+ @Override
public void slider_mouseReleased(MouseEvent e)
{
if (ap.overviewPanel != null)
}
}
+ public static int getConservationValue()
+ {
+ return getValue(conservationSlider);
+ }
+
+ static int getValue(JInternalFrame slider)
+ {
+ return slider == null ? 0 : ((SliderPanel) slider.getContentPane())
+ .getValue();
+ }
+
+ public static int getPIDValue()
+ {
+ return getValue(PIDSlider);
+ }
+
}
.getGlobalColourScheme()));
}
// cs is null if shading is an annotationColourGradient
- if (cs != null)
- {
- cs.setThreshold(av.getGlobalColourScheme().getThreshold(),
- av.isIgnoreGapsConsensus());
- }
+ // if (cs != null)
+ // {
+ // cs.setThreshold(av.getViewportColourScheme().getThreshold(),
+ // av.isIgnoreGapsConsensus());
+ // }
}
- sg.cs = cs;
+ sg.setColourScheme(cs);
+ sg.getGroupColourScheme().setThreshold(
+ av.getViewportColourScheme().getThreshold(),
+ av.isIgnoreGapsConsensus());
// sg.recalcConservation();
sg.setName("JTreeGroup:" + sg.hashCode());
sg.setIdColour(col);
for (int a = 0; a < aps.length; a++)
{
if (aps[a].av.getGlobalColourScheme() != null
- && aps[a].av.getGlobalColourScheme().conservationApplied())
+ && aps[a].av.getViewportColourScheme()
+ .conservationApplied())
{
Conservation c = new Conservation("Group", sg.getSequences(null),
sg.getStartRes(), sg.getEndRes());
if (seqGroup != null)
{
- oldColourScheme = seqGroup.cs;
+ oldColourScheme = seqGroup.getColourScheme();
}
else
{
if (seqGroup != null)
{
- seqGroup.cs = ucs;
+ seqGroup.setColourScheme(ucs);
ap.paintAlignment(true);
}
else if (ap != null)
ucs.setLowerCaseColours(newColours);
}
- if (ap != null)
- {
- ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
- }
+ // if (ap != null)
+ // {
+ // ucs.setThreshold(0, ap.av.isIgnoreGapsConsensus());
+ // }
return ucs;
}
{
if (seqGroup != null)
{
- seqGroup.cs = oldColourScheme;
+ seqGroup.setColourScheme(oldColourScheme);
}
else
{
if (sg != null)
{
String keyValue, key, value;
- ColourSchemeI def = sg.cs;
- sg.cs = null;
+ ColourSchemeI def = sg.getColourScheme();
while (st.hasMoreTokens())
{
keyValue = st.nextToken();
}
else if (key.equalsIgnoreCase("colour"))
{
- sg.cs = ColourSchemeProperty.getColourScheme(al, value);
+ sg.cs.setColourScheme(ColourSchemeProperty
+ .getColourScheme(al, value));
}
else if (key.equalsIgnoreCase("pidThreshold"))
{
}
sg.recalcConservation();
}
- if (sg.cs == null)
+ if (sg.getColourScheme() == null)
{
- sg.cs = def;
+ sg.setColourScheme(def);
}
}
}
{
SequenceGrpPojo seqGrpPojo = new SequenceGrpPojo();
seqGrpPojo.setGroupName(seqGrp.getName());
- seqGrpPojo.setColourScheme(seqGrp.cs.getSchemeName());
+ seqGrpPojo.setColourScheme(seqGrp.getColourScheme()
+ .getSchemeName());
seqGrpPojo.setColourText(seqGrp.getColourText());
seqGrpPojo.setDescription(seqGrp.getDescription());
seqGrpPojo.setDisplayBoxes(seqGrp.getDisplayBoxes());
}
SequenceGroup seqGrp = new SequenceGroup(grpSeqs, grpName, null,
displayBoxes, displayText, colourText, startRes, endRes);
- seqGrp.cs = ColourSchemeMapper.getJalviewColourScheme(colourScheme,
- seqGrp);
+ seqGrp.setColourScheme(ColourSchemeMapper.getJalviewColourScheme(
+ colourScheme, seqGrp));
seqGrp.setShowNonconserved(showNonconserved);
seqGrp.setDescription(description);
this.seqGroups.add(seqGrp);
profcolour = av.getGlobalColourScheme();
if (profcolour == null)
{
- // Set the default colour for sequence logo if the alignnent has no
+ // Set the default colour for sequence logo if the alignment has no
// colourscheme set
profcolour = av.getAlignment().isNucleotide() ? new jalview.schemes.NucleotideColourScheme()
: new jalview.schemes.ZappoColourScheme();
{
final String codonTranslation = ResidueProperties
.codonTranslate(new String(dc));
- colour = profcolour.findColour(codonTranslation.charAt(0),
- column, null);
+ colour = profcolour.findColour(codonTranslation.charAt(0));
}
else
{
- colour = profcolour.findColour(dc[0], column, null);
+ colour = profcolour.findColour(dc[0]);
}
g.setColor(colour == Color.white ? Color.lightGray : colour);
Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
AnnotationColourGradient acg = new AnnotationColourGradient(annotation,
- colourScheme, aboveAnnotationThreshold);
+ getColourScheme(), aboveAnnotationThreshold);
acg.thresholdIsMinMax = thresholdIsMinMax;
acg.annotationThreshold = (annotationThreshold == null) ? null
: new GraphLine(annotationThreshold);
{
if (originalColour instanceof AnnotationColourGradient)
{
- colourScheme = ((AnnotationColourGradient) originalColour).colourScheme;
+ setColourScheme(((AnnotationColourGradient) originalColour)
+ .getColourScheme());
}
else
{
- colourScheme = originalColour;
+ setColourScheme(originalColour);
}
this.annotation = annotation;
{
return currentColour;
}
- if ((threshold == 0) || aboveThreshold(c, j))
+ // if ((threshold == 0) || aboveThreshold(c, j))
+ // {
+ if (annotation.annotations != null && j < annotation.annotations.length
+ && annotation.annotations[j] != null
+ && !jalview.util.Comparison.isGap(c))
{
- if (annotation.annotations != null
- && j < annotation.annotations.length
- && annotation.annotations[j] != null
- && !jalview.util.Comparison.isGap(c))
+ Annotation aj = annotation.annotations[j];
+ // 'use original colours' => colourScheme != null
+ // -> look up colour to be used
+ // predefined colours => preconfigured shading
+ // -> only use original colours reference if thresholding enabled &
+ // minmax exists
+ // annotation.hasIcons => null or black colours replaced with glyph
+ // colours
+ // -> reuse original colours if present
+ // -> if thresholding enabled then return colour on non-whitespace glyph
+
+ if (aboveAnnotationThreshold == NO_THRESHOLD
+ || (annotationThreshold != null && (aboveAnnotationThreshold == ABOVE_THRESHOLD ? aj.value >= annotationThreshold.value
+ : aj.value <= annotationThreshold.value)))
{
- Annotation aj = annotation.annotations[j];
- // 'use original colours' => colourScheme != null
- // -> look up colour to be used
- // predefined colours => preconfigured shading
- // -> only use original colours reference if thresholding enabled &
- // minmax exists
- // annotation.hasIcons => null or black colours replaced with glyph
- // colours
- // -> reuse original colours if present
- // -> if thresholding enabled then return colour on non-whitespace glyph
-
- if (aboveAnnotationThreshold == NO_THRESHOLD
- || (annotationThreshold != null && (aboveAnnotationThreshold == ABOVE_THRESHOLD ? aj.value >= annotationThreshold.value
- : aj.value <= annotationThreshold.value)))
+ if (predefinedColours && aj.colour != null
+ && !aj.colour.equals(Color.black))
{
- if (predefinedColours && aj.colour != null
- && !aj.colour.equals(Color.black))
- {
- currentColour = aj.colour;
- }
- else if (annotation.hasIcons
- && annotation.graph == AlignmentAnnotation.NO_GRAPH)
+ currentColour = aj.colour;
+ }
+ else if (annotation.hasIcons
+ && annotation.graph == AlignmentAnnotation.NO_GRAPH)
+ {
+ if (aj.secondaryStructure > ' ' && aj.secondaryStructure != '.'
+ && aj.secondaryStructure != '-')
{
- if (aj.secondaryStructure > ' ' && aj.secondaryStructure != '.'
- && aj.secondaryStructure != '-')
+ if (getColourScheme() != null)
+ {
+ currentColour = getColourScheme().findColour(c, j, seq, null,
+ 0f);
+ }
+ else
{
- if (colourScheme != null)
+ if (annotation.isRNA())
{
- currentColour = colourScheme.findColour(c, j, seq);
+ currentColour = ColourSchemeProperty.rnaHelices[(int) aj.value];
}
else
{
- if (annotation.isRNA())
- {
- currentColour = ColourSchemeProperty.rnaHelices[(int) aj.value];
- }
- else
- {
- currentColour = annotation.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR
- : annotation.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR
- : jalview.renderer.AnnotationRenderer.STEM_COLOUR;
- }
+ currentColour = annotation.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR
+ : annotation.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR
+ : jalview.renderer.AnnotationRenderer.STEM_COLOUR;
}
}
- else
- {
- //
- return Color.white;
- }
}
- else if (noGradient)
+ else
{
- if (colourScheme != null)
- {
- currentColour = colourScheme.findColour(c, j, seq);
- }
- else
- {
- if (aj.colour != null)
- {
- currentColour = aj.colour;
- }
- }
+ //
+ return Color.white;
+ }
+ }
+ else if (noGradient)
+ {
+ if (getColourScheme() != null)
+ {
+ currentColour = getColourScheme().findColour(c, j, seq, null,
+ 0f);
}
else
{
- currentColour = shadeCalculation(annotation, j);
+ if (aj.colour != null)
+ {
+ currentColour = aj.colour;
+ }
}
}
- if (conservationColouring)
+ else
{
- currentColour = applyConservation(currentColour, j);
+ currentColour = shadeCalculation(annotation, j);
}
}
+ // if (conservationColouring)
+ // {
+ // currentColour = applyConservation(currentColour, j);
+ // }
}
+ // }
return currentColour;
}
}
@Override
- public Color findColour(char res, int j, SequenceI seq)
+ public Color findColour(char res, int j, SequenceI seq,
+ String consensusResidue, float pid)
{
+ /*
+ * compare as upper case; note toUpperCase does nothing
+ * if the string is already uppercase
+ */
+ consensusResidue = consensusResidue.toUpperCase();
if ('a' <= res && res <= 'z')
{
- // TO UPPERCASE !!!
res -= ('a' - 'A');
}
- if (consensus == null || consensus.get(j) == null
- || (threshold != 0 && !aboveThreshold(res, j)))
+ if (Comparison.isGap(res) || consensusResidue == null)
{
return Color.white;
}
- Color currentColour;
+ Color colour;
- if (!Comparison.isGap(res))
+ if (consensusResidue.indexOf(res) > -1)
{
- /*
- * test if this is the consensus (or joint consensus) residue
- */
- String max = consensus.get(j).getModalResidue();
+ colour = DARK_BLUE;
+ }
+ else
+ {
+ int c = 0;
- if (max.indexOf(res) > -1)
+ for (char consensus : consensusResidue.toCharArray())
{
- currentColour = DARK_BLUE;
+ c += ResidueProperties.getBLOSUM62(consensus, res);
}
- else
- {
- int c = 0;
- int max_aa = 0;
- int n = max.length();
-
- do
- {
- c += ResidueProperties.getBLOSUM62(max.charAt(max_aa), res);
- } while (++max_aa < n);
- if (c > 0)
- {
- currentColour = LIGHT_BLUE;
- }
- else
- {
- currentColour = Color.white;
- }
+ if (c > 0)
+ {
+ colour = LIGHT_BLUE;
}
-
- if (conservationColouring)
+ else
{
- currentColour = applyConservation(currentColour, j);
+ colour = Color.white;
}
}
- else
- {
- return Color.white;
- }
-
- return currentColour;
+ return colour;
}
@Override
}
@Override
- public Color findColour(char c, int j, SequenceI seq)
+ protected Color findColour(char c, int j, SequenceI seq)
{
Color currentColour;
+ // TODO why the test for includeGaps here?
if (cons2.length <= j
- || (includeGaps && threshold != 0 && !aboveThreshold(c, j)))
+ /*|| (includeGaps && threshold != 0 && !aboveThreshold(c, j))*/)
{
return Color.white;
}
}
}
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
-
return currentColour;
}
--- /dev/null
+package jalview.schemes;
+
+import jalview.analysis.Conservation;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.ProfileI;
+import jalview.datamodel.ProfilesI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+import jalview.util.ColorUtils;
+import jalview.util.Comparison;
+
+import java.awt.Color;
+import java.util.Map;
+
+/**
+ * A data bean that holds the information to determine the colour scheme of an
+ * alignment (or subgroup), consisting of
+ * <ul>
+ * <li>the colour scheme that determines the colour of a residue</li>
+ * <li>any threshold for colour, based on percentage identity with consensus</li>
+ * <li>any graduation based on consensus</li>
+ * <li>the consensus data</li>
+ * </ul>
+ *
+ * @author gmcarstairs
+ *
+ */
+public class CollectionColourScheme implements CollectionColourSchemeI
+{
+ private ColourSchemeI colourScheme;
+
+ private ProfilesI consensus;
+
+ private boolean conservationColouring;
+
+ private char[] conservation;
+
+ private int threshold;
+
+ private boolean ignoreGaps;
+
+ private int inc;
+
+ public CollectionColourScheme(ColourSchemeI cs)
+ {
+ colourScheme = cs;
+ }
+
+ /**
+ * Default constructor
+ */
+ public CollectionColourScheme()
+ {
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#setConsensus(jalview.datamodel.ProfilesI)
+ */
+ @Override
+ public void setConsensus(ProfilesI cons)
+ {
+ consensus = cons;
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#conservationApplied()
+ */
+ @Override
+ public boolean conservationApplied()
+ {
+ return conservationColouring;
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#setConservationApplied(boolean)
+ */
+ @Override
+ public void setConservationApplied(boolean conservationApplied)
+ {
+ conservationColouring = conservationApplied;
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#setConservation(jalview.analysis.Conservation)
+ */
+ @Override
+ public void setConservation(Conservation cons)
+ {
+ if (cons == null)
+ {
+ conservationColouring = false;
+ conservation = null;
+ }
+ else
+ {
+ conservationColouring = true;
+ conservation = cons.getConsSequence().getSequenceAsString()
+ .toCharArray();
+ }
+
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#alignmentChanged(jalview.datamodel.AnnotatedCollectionI,
+ * java.util.Map)
+ */
+ @Override
+ public void alignmentChanged(AnnotatedCollectionI alignment,
+ Map<SequenceI, SequenceCollectionI> hiddenReps)
+ {
+ if (colourScheme != null)
+ {
+ colourScheme.alignmentChanged(alignment, hiddenReps);
+ }
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#setThreshold(int, boolean)
+ */
+ @Override
+ public void setThreshold(int consensusThreshold, boolean ignoreGaps)
+ {
+ threshold = consensusThreshold;
+ this.ignoreGaps = ignoreGaps;
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#setConservationInc(int)
+ */
+ @Override
+ public void setConservationInc(int i)
+ {
+ inc = i;
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#getConservationInc()
+ */
+ @Override
+ public int getConservationInc()
+ {
+ return inc;
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#getThreshold()
+ */
+ @Override
+ public int getThreshold()
+ {
+ return threshold;
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#findColour(char, int,
+ * jalview.datamodel.SequenceI)
+ */
+ @Override
+ public Color findColour(char symbol, int position, SequenceI seq)
+ {
+ /*
+ * get 'base' colour
+ */
+ ProfileI profile = consensus == null ? null : consensus.get(position);
+ String modalResidue = profile == null ? null : profile
+ .getModalResidue();
+ float pid = profile == null ? 0f : profile
+ .getPercentageIdentity(ignoreGaps);
+ Color colour = colourScheme == null ? Color.white : colourScheme
+ .findColour(symbol, position, seq, modalResidue, pid);
+
+ /*
+ * apply PID threshold and consensus fading if in force
+ */
+ colour = adjustColour(symbol, position, colour);
+
+ return colour;
+ }
+
+ /**
+ * Adjusts colour by applying thresholding or conservation shading, if in
+ * force. That is
+ * <ul>
+ * <li>if there is a threshold set for colouring, and the residue doesn't
+ * match the consensus (or a joint consensus) residue, or the consensus score
+ * is not above the threshold, then the colour is set to white</li>
+ * <li>if conservation colouring is selected, the colour is faded by an amount
+ * depending on the conservation score for the column, and the conservation
+ * colour threshold</li>
+ * </ul>
+ *
+ * @param symbol
+ * @param column
+ * @param colour
+ * @return
+ */
+ protected Color adjustColour(char symbol, int column, Color colour)
+ {
+ if (!aboveThreshold(symbol, column))
+ {
+ colour = Color.white;
+ }
+
+ if (conservationColouring)
+ {
+ colour = applyConservation(colour, column);
+ }
+ return colour;
+ }
+
+ /**
+ * Answers true if there is a consensus profile for the specified column, and
+ * the given residue matches the consensus (or joint consensus) residue for
+ * the column, and the percentage identity for the profile is equal to or
+ * greater than the current threshold; else answers false. The percentage
+ * calculation depends on whether or not we are ignoring gapped sequences.
+ *
+ * @param residue
+ * @param column
+ * (index into consensus profiles)
+ *
+ * @return
+ * @see #setThreshold(int, boolean)
+ */
+ protected boolean aboveThreshold(char residue, int column)
+ {
+ if (threshold == 0)
+ {
+ return true;
+ }
+ if ('a' <= residue && residue <= 'z')
+ {
+ // TO UPPERCASE !!!
+ // Faster than toUpperCase
+ residue -= ('a' - 'A');
+ }
+
+ if (consensus == null)
+ {
+ return false;
+ }
+
+ ProfileI profile = consensus.get(column);
+
+ /*
+ * test whether this is the consensus (or joint consensus) residue
+ */
+ if (profile != null
+ && profile.getModalResidue().contains(String.valueOf(residue)))
+ {
+ if (profile.getPercentageIdentity(ignoreGaps) >= threshold)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Applies a combination of column conservation score, and conservation
+ * percentage slider, to 'bleach' out the residue colours towards white.
+ * <p>
+ * If a column is fully conserved (identical residues, conservation score 11,
+ * shown as *), or all 10 physico-chemical properties are conserved
+ * (conservation score 10, shown as +), then the colour is left unchanged.
+ * <p>
+ * Otherwise a 'bleaching' factor is computed and applied to the colour. This
+ * is designed to fade colours for scores of 0-9 completely to white at slider
+ * positions ranging from 18% - 100% respectively.
+ *
+ * @param currentColour
+ * @param column
+ *
+ * @return bleached (or unmodified) colour
+ */
+ protected Color applyConservation(Color currentColour, int column)
+ {
+ if (conservation == null || conservation.length <= column)
+ {
+ return currentColour;
+ }
+ char conservationScore = conservation[column];
+
+ /*
+ * if residues are fully conserved (* or 11), or all properties
+ * are conserved (+ or 10), leave colour unchanged
+ */
+ if (conservationScore == '*' || conservationScore == '+'
+ || conservationScore == (char) 10
+ || conservationScore == (char) 11)
+ {
+ return currentColour;
+ }
+
+ if (Comparison.isGap(conservationScore))
+ {
+ return Color.white;
+ }
+
+ /*
+ * convert score 0-9 to a bleaching factor 1.1 - 0.2
+ */
+ float bleachFactor = (11 - (conservationScore - '0')) / 10f;
+
+ /*
+ * scale this up by 0-5 (percentage slider / 20)
+ * as a result, scores of: 0 1 2 3 4 5 6 7 8 9
+ * fade to white at slider value: 18 20 22 25 29 33 40 50 67 100%
+ */
+ bleachFactor *= (inc / 20f);
+
+ return ColorUtils.bleachColour(currentColour, bleachFactor);
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#getColourScheme()
+ */
+ @Override
+ public ColourSchemeI getColourScheme()
+ {
+ return this.colourScheme;
+ }
+
+ /**
+ * @see jalview.schemes.CollectionColourSchemeI#setColourScheme(jalview.schemes.ColourSchemeI)
+ */
+ @Override
+ public void setColourScheme(ColourSchemeI cs)
+ {
+ colourScheme = cs;
+ }
+}
--- /dev/null
+package jalview.schemes;
+
+import jalview.analysis.Conservation;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.ProfilesI;
+import jalview.datamodel.SequenceCollectionI;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+import java.util.Map;
+
+public interface CollectionColourSchemeI
+{
+
+ public abstract void setConsensus(ProfilesI cons);
+
+ public abstract boolean conservationApplied();
+
+ public abstract void setConservationApplied(boolean conservationApplied);
+
+ public abstract void setConservation(Conservation cons);
+
+ public abstract void alignmentChanged(AnnotatedCollectionI alignment,
+ Map<SequenceI, SequenceCollectionI> hiddenReps);
+
+ /**
+ * Sets the percentage consensus threshold value, and whether gaps are ignored
+ * in percentage identity calculation
+ *
+ * @param consensusThreshold
+ * @param ignoreGaps
+ */
+ public abstract void setThreshold(int consensusThreshold,
+ boolean ignoreGaps);
+
+ public abstract void setConservationInc(int i);
+
+ public abstract int getConservationInc();
+
+ /**
+ * Get the percentage threshold for this colour scheme
+ *
+ * @return Returns the percentage threshold
+ */
+ public abstract int getThreshold();
+
+ /**
+ * Returns the possibly context dependent colour for the given symbol at the
+ * aligned position in the given sequence. For example, the colour may depend
+ * on the symbol's relationship to the consensus residue for the column.
+ *
+ * @param symbol
+ * @param position
+ * @param seq
+ * @return
+ */
+ public abstract Color findColour(char symbol, int position, SequenceI seq);
+
+ public abstract ColourSchemeI getColourScheme();
+
+ public abstract void setColourScheme(ColourSchemeI cs);
+
+}
\ No newline at end of file
*/
package jalview.schemes;
-import jalview.analysis.Conservation;
import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
* @param symbol
* @param position
* @param seq
+ * @param consensusResidue
+ * the modal symbol (e.g. K) or symbols (e.g. KF) for the column
+ * @param pid
+ * the percentage identity of the column's consensus (if known)
* @return
*/
- Color findColour(char symbol, int position, SequenceI seq);
-
- /**
- * Assigns the given consensus profile for the colourscheme
- */
- void setConsensus(ProfilesI hconsensus);
-
- /**
- * Assigns the given conservation to the colourscheme
- *
- * @param c
- */
- void setConservation(Conservation c);
-
- /**
- * Enable or disable conservation shading for this colourscheme
- *
- * @param conservationApplied
- */
- void setConservationApplied(boolean conservationApplied);
-
- /**
- * Answers true if conservation shading is enabled for this colourscheme
- *
- * @return
- */
- boolean conservationApplied();
-
- /**
- * Sets the scale factor for bleaching of colour in unconserved regions
- *
- * @param i
- */
- void setConservationInc(int i);
-
- /**
- * Returns the scale factor for bleaching colour in unconserved regions
- *
- * @return
- */
- int getConservationInc();
-
- /**
- * Returns the percentage identity threshold for applying colourscheme
- *
- * @return
- */
- int getThreshold();
-
- /**
- * Sets the percentage identity threshold and type of %age identity
- * calculation for shading
- *
- * @param pct
- * 0..100 percentage identity for applying this colourscheme
- * @param ignoreGaps
- * when true, calculate PID without including gapped positions
- */
- void setThreshold(int pct, boolean ignoreGaps);
+ Color findColour(char symbol, int position, SequenceI seq,
+ String consensusResidue, float pid);
/**
* Recalculate dependent data using the given sequence collection, taking
*/
package jalview.schemes;
-import jalview.analysis.Conservation;
import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
public class FollowerColourScheme extends ResidueColourScheme
{
- protected ColourSchemeI colourScheme;
+ private ColourSchemeI colourScheme;
public ColourSchemeI getBaseColour()
{
}
@Override
- public void setConsensus(ProfilesI consensus)
- {
- if (colourScheme != null)
- {
- colourScheme.setConsensus(consensus);
- }
- }
-
- @Override
- public void setConservation(Conservation cons)
- {
- if (colourScheme != null)
- {
- colourScheme.setConservation(cons);
- }
- }
-
- @Override
- public void setConservationInc(int i)
- {
- if (colourScheme != null)
- {
- colourScheme.setConservationInc(i);
- }
- }
-
- @Override
public String getSchemeName()
{
return "Follower";
return new FollowerColourScheme();
}
+ protected ColourSchemeI getColourScheme()
+ {
+ return colourScheme;
+ }
+
+ protected void setColourScheme(ColourSchemeI colourScheme)
+ {
+ this.colourScheme = colourScheme;
+ }
+
}
*/
public NucleotideColourScheme()
{
- super(ResidueProperties.nucleotideIndex, ResidueProperties.nucleotide,
- 0);
+ super(ResidueProperties.nucleotideIndex, ResidueProperties.nucleotide);
}
/**
@Override
public Color findColour(char c)
{
- // System.out.println("called"); log.debug
return colors[ResidueProperties.nucleotideIndex[c]];
}
- /**
- * DOCUMENT ME!
- *
- * @param n
- * DOCUMENT ME!
- * @param j
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- @Override
- public Color findColour(char c, int j, SequenceI seq)
- {
- Color currentColour;
- if ((threshold == 0) || aboveThreshold(c, j))
- {
- try
- {
- currentColour = colors[ResidueProperties.nucleotideIndex[c]];
- } catch (Exception ex)
- {
- return Color.white;
- }
- }
- else
- {
- return Color.white;
- }
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
-
- return currentColour;
- }
-
@Override
public boolean isNucleotideSpecific()
{
package jalview.schemes;
import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.ProfileI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
}
@Override
- public Color findColour(char c, int j, SequenceI seq)
+ public Color findColour(char c, int j, SequenceI seq,
+ String consensusResidue, float pid)
{
+ /*
+ * make everything uppercase; note this does nothing (fast)
+ * if consensusResidue is already uppercase
+ */
+ consensusResidue = consensusResidue.toUpperCase();
if ('a' <= c && c <= 'z')
{
c -= ('a' - 'A');
}
- if (consensus == null || consensus.get(j) == null)
- {
- return Color.white;
- }
-
- if ((threshold != 0) && !aboveThreshold(c, j))
+ if (consensusResidue == null)
{
return Color.white;
}
- Color currentColour = Color.white;
-
- double sc = 0;
-
+ Color colour = Color.white;
/*
* test whether this is the consensus (or joint consensus) residue
*/
- ProfileI profile = consensus.get(j);
- boolean matchesConsensus = profile.getModalResidue().contains(
+ boolean matchesConsensus = consensusResidue.contains(
String.valueOf(c));
if (matchesConsensus)
{
- sc = profile.getPercentageIdentity(ignoreGaps);
-
if (!Comparison.isGap(c))
{
for (int i = 0; i < thresholds.length; i++)
{
- if (sc > thresholds[i])
+ if (pid > thresholds[i])
{
- currentColour = pidColours[i];
+ colour = pidColours[i];
break;
}
}
}
}
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
-
- return currentColour;
+ return colour;
}
@Override
public PurinePyrimidineColourScheme()
{
super(ResidueProperties.purinepyrimidineIndex,
- ResidueProperties.purinepyrimidine, 0);
+ ResidueProperties.purinepyrimidine);
}
/**
return colors[ResidueProperties.purinepyrimidineIndex[c]];
}
- /**
- * Returns color based on conservation
- *
- * @param c
- * Character in sequence
- * @param j
- * Threshold
- *
- * @return Color in RGB
- */
- public Color findColour(char c, int j)
- {
- Color currentColour;
- if ((threshold == 0) || aboveThreshold(c, j))
- {
- try
- {
- currentColour = colors[ResidueProperties.purinepyrimidineIndex[c]];
- } catch (Exception ex)
- {
- return Color.white;
- }
- }
- else
- {
- return Color.white;
- }
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
-
- return currentColour;
- }
-
@Override
public boolean isNucleotideSpecific()
{
oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
for (SequenceGroup sg : ap.getAlignment().getGroups())
{
- if (sg.cs != null)
+ if (sg.getColourScheme() != null)
{
- oldgroupColours.put(sg, sg.cs);
+ oldgroupColours.put(sg, sg.getColourScheme());
}
}
}
public Color findColour(char c, int j, SequenceI seq)
{
// FIXME this is just a copy of NucleotideColourScheme
- Color currentColour;
- if ((threshold == 0) || aboveThreshold(c, j))
+ Color currentColour = Color.white;
+ try
{
- try
- {
- currentColour = colors[ResidueProperties.nucleotideIndex[c]];
- } catch (Exception ex)
- {
- return Color.white;
- }
- }
- else
- {
- return Color.white;
- }
-
- if (conservationColouring)
+ currentColour = colors[ResidueProperties.nucleotideIndex[c]];
+ } catch (Exception ex)
{
- currentColour = applyConservation(currentColour, j);
}
return currentColour;
*/
package jalview.schemes;
-import jalview.analysis.Conservation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AnnotatedCollectionI;
-import jalview.datamodel.ProfileI;
-import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
-import jalview.util.ColorUtils;
-import jalview.util.Comparison;
import java.awt.Color;
import java.util.Map;
*/
final int[] symbolIndex;
- boolean conservationColouring = false;
-
/*
* colour for residue characters as indexed by symbolIndex
*/
Color[] colors = null;
- int threshold = 0;
-
/* Set when threshold colouring to either pid_gaps or pid_nogaps */
protected boolean ignoreGaps = false;
- /*
- * Consensus data indexed by column
- */
- ProfilesI consensus;
-
- /*
- * Conservation string as a char array
- */
- char[] conservation;
-
- /*
- * The conservation slider percentage setting
- */
- int inc = 30;
-
/**
* Creates a new ResidueColourScheme object.
*
* ResidueProperties.aaIndex)
* @param colors
* colours for symbols in sequences
- * @param threshold
- * threshold for conservation shading
*/
- public ResidueColourScheme(int[] aaOrnaIndex, Color[] colours,
- int threshold)
+ public ResidueColourScheme(int[] aaOrnaIndex, Color[] colours)
{
symbolIndex = aaOrnaIndex;
this.colors = colours;
- this.threshold = threshold;
}
/**
return colors == null ? Color.white : colors[symbolIndex[c]];
}
- @Override
- public Color findColour(char c, int j, SequenceI seq)
- {
- Color colour = Color.white;
-
- if (colors != null && symbolIndex != null)
- {
- colour = colors[symbolIndex[c]];
- }
- colour = adjustColour(c, j, colour);
-
- return colour;
- }
-
- /**
- * Adjusts colour by applying thresholding or conservation shading, if in
- * force. That is
- * <ul>
- * <li>if there is a threshold set for colouring, and the residue doesn't
- * match the consensus (or a joint consensus) residue, or the consensus score
- * is not above the threshold, then the colour is set to white</li>
- * <li>if conservation colouring is selected, the colour is faded by an amount
- * depending on the conservation score for the column, and the conservation
- * colour threshold</li>
- * </ul>
- *
- * @param symbol
- * @param column
- * @param colour
- * @return
- */
- protected Color adjustColour(char symbol, int column, Color colour)
- {
- if (!aboveThreshold(symbol, column))
- {
- colour = Color.white;
- }
-
- if (conservationColouring)
- {
- colour = applyConservation(colour, column);
- }
- return colour;
- }
-
- /**
- * Get the percentage threshold for this colour scheme
- *
- * @return Returns the percentage threshold
- */
- @Override
- public int getThreshold()
- {
- return threshold;
- }
-
- /**
- * Sets the percentage consensus threshold value, and whether gaps are ignored
- * in percentage identity calculation
- *
- * @param consensusThreshold
- * @param ignoreGaps
- */
- @Override
- public void setThreshold(int consensusThreshold, boolean ignoreGaps)
- {
- threshold = consensusThreshold;
- this.ignoreGaps = ignoreGaps;
- }
-
- /**
- * Answers true if there is a consensus profile for the specified column, and
- * the given residue matches the consensus (or joint consensus) residue for
- * the column, and the percentage identity for the profile is equal to or
- * greater than the current threshold; else answers false. The percentage
- * calculation depends on whether or not we are ignoring gapped sequences.
- *
- * @param residue
- * @param column
- * (index into consensus profiles)
- *
- * @return
- * @see #setThreshold(int, boolean)
- */
- public boolean aboveThreshold(char residue, int column)
- {
- if (threshold == 0)
- {
- return true;
- }
- if ('a' <= residue && residue <= 'z')
- {
- // TO UPPERCASE !!!
- // Faster than toUpperCase
- residue -= ('a' - 'A');
- }
-
- if (consensus == null)
- {
- return false;
- }
-
- ProfileI profile = consensus.get(column);
-
- /*
- * test whether this is the consensus (or joint consensus) residue
- */
- if (profile != null
- && profile.getModalResidue().contains(String.valueOf(residue)))
- {
- if (profile.getPercentageIdentity(ignoreGaps) >= threshold)
- {
- return true;
- }
- }
-
- return false;
- }
-
- @Override
- public boolean conservationApplied()
- {
- return conservationColouring;
- }
-
- @Override
- public void setConservationApplied(boolean conservationApplied)
- {
- conservationColouring = conservationApplied;
- }
-
- @Override
- public void setConservationInc(int i)
- {
- inc = i;
- }
-
- @Override
- public int getConservationInc()
- {
- return inc;
- }
-
/**
- * DOCUMENT ME!
- *
- * @param consensus
- * DOCUMENT ME!
+ * Default is to call the overloaded method that ignores consensus. A colour
+ * scheme that depends on consensus (for example, Blosum62), should override
+ * this method instead.
*/
@Override
- public void setConsensus(ProfilesI consensus)
- {
- if (consensus == null)
- {
- return;
- }
-
- this.consensus = consensus;
- }
-
- @Override
- public void setConservation(Conservation cons)
+ public Color findColour(char c, int j, SequenceI seq,
+ String consensusResidue, float pid)
{
- if (cons == null)
- {
- conservationColouring = false;
- conservation = null;
- }
- else
- {
- conservationColouring = true;
- int iSize = cons.getConsSequence().getLength();
- conservation = new char[iSize];
- for (int i = 0; i < iSize; i++)
- {
- conservation[i] = cons.getConsSequence().getCharAt(i);
- }
- }
-
+ return findColour(c, j, seq);
}
- /**
- * Applies a combination of column conservation score, and conservation
- * percentage slider, to 'bleach' out the residue colours towards white.
- * <p>
- * If a column is fully conserved (identical residues, conservation score 11,
- * shown as *), or all 10 physico-chemical properties are conserved
- * (conservation score 10, shown as +), then the colour is left unchanged.
- * <p>
- * Otherwise a 'bleaching' factor is computed and applied to the colour. This
- * is designed to fade colours for scores of 0-9 completely to white at slider
- * positions ranging from 18% - 100% respectively.
- *
- * @param currentColour
- * @param column
- *
- * @return bleached (or unmodified) colour
- */
- Color applyConservation(Color currentColour, int column)
+ protected Color findColour(char c, int j, SequenceI seq)
{
- if (conservation == null || conservation.length <= column)
- {
- return currentColour;
- }
- char conservationScore = conservation[column];
-
- /*
- * if residues are fully conserved (* or 11), or all properties
- * are conserved (+ or 10), leave colour unchanged
- */
- if (conservationScore == '*' || conservationScore == '+'
- || conservationScore == (char) 10
- || conservationScore == (char) 11)
- {
- return currentColour;
- }
+ Color colour = Color.white;
- if (Comparison.isGap(conservationScore))
+ if (colors != null && symbolIndex != null && c < symbolIndex.length
+ && symbolIndex[c] < colors.length)
{
- return Color.white;
+ colour = colors[symbolIndex[c]];
}
+ // colour = adjustColour(c, j, colour);
- /*
- * convert score 0-9 to a bleaching factor 1.1 - 0.2
- */
- float bleachFactor = (11 - (conservationScore - '0')) / 10f;
-
- /*
- * scale this up by 0-5 (percentage slider / 20)
- * as a result, scores of: 0 1 2 3 4 5 6 7 8 9
- * fade to white at slider value: 18 20 22 25 29 33 40 50 67 100%
- */
- bleachFactor *= (inc / 20f);
-
- return ColorUtils.bleachColour(currentColour, bleachFactor);
+ return colour;
}
@Override
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
+import jalview.util.Comparison;
import java.awt.Color;
import java.util.Map;
@Override
public Color findColour(char c, int j, SequenceI seq)
{
- if (threshold > 0)
- {
- if (!aboveThreshold(c, j))
- {
- return Color.white;
- }
- }
-
- if (jalview.util.Comparison.isGap(c))
+ if (Comparison.isGap(c))
{
return Color.white;
}
- Color currentColour = colors[ResidueProperties.aaIndex[c]];
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
- }
-
- return currentColour;
+ return colors[ResidueProperties.aaIndex[c]];
}
/**
{
public TaylorColourScheme()
{
- super(ResidueProperties.aaIndex, ResidueProperties.taylor, 0);
+ super(ResidueProperties.aaIndex, ResidueProperties.taylor);
}
@Override
@Override
public Color findColour(char c, int j, SequenceI seq)
{
- Color currentColour;
+ Color colour;
int index = ResidueProperties.aaIndex[c];
- if ((threshold == 0) || aboveThreshold(c, j))
+ if (lowerCaseColours != null && 'a' <= c && c <= 'z')
{
- if (lowerCaseColours != null && 'a' <= c && c <= 'z')
- {
- currentColour = lowerCaseColours[index];
- }
- else
- {
- currentColour = colors[index];
- }
+ colour = lowerCaseColours[index];
}
else
{
- currentColour = Color.white;
- }
-
- if (conservationColouring)
- {
- currentColour = applyConservation(currentColour, j);
+ colour = colors[index];
}
- return currentColour;
+ return colour;
}
public void setLowerCaseColours(Color[] lcolours)
*/
public ZappoColourScheme()
{
- super(ResidueProperties.aaIndex, ResidueProperties.zappo, 0);
+ super(ResidueProperties.aaIndex, ResidueProperties.zappo);
}
@Override
* Copy group name, colours etc, but not sequences or sequence colour scheme
*/
SequenceGroup mappedGroup = new SequenceGroup(sg);
- mappedGroup.cs = mapTo.getGlobalColourScheme();
+ mappedGroup.setColourScheme(mapTo.getGlobalColourScheme());
mappedGroup.clear();
int minStartCol = -1;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.schemes.Blosum62ColourScheme;
+import jalview.schemes.CollectionColourScheme;
+import jalview.schemes.CollectionColourSchemeI;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.PIDColourScheme;
import jalview.structure.CommandListener;
protected boolean ignoreGapsInConsensusCalculation = false;
- protected ColourSchemeI globalColourScheme = null;
+ protected CollectionColourScheme globalColourScheme;
@Override
public void setGlobalColourScheme(ColourSchemeI cs)
// - means that caller decides if they want to just modify state and defer
// calculation till later or to do all calculations in thread.
// via changecolour
- globalColourScheme = cs;
+
+ /*
+ * only instantiate colour scheme once, thereafter update it
+ */
+ if (globalColourScheme == null)
+ {
+ globalColourScheme = new CollectionColourScheme();
+ }
+ globalColourScheme.setColourScheme(cs);
+
boolean recalc = false;
if (cs != null)
{
|| cs instanceof Blosum62ColourScheme)
{
recalc = true;
- cs.setThreshold(viewStyle.getThreshold(),
+ globalColourScheme.setThreshold(viewStyle.getThreshold(),
ignoreGapsInConsensusCalculation);
}
else
{
- cs.setThreshold(0, ignoreGapsInConsensusCalculation);
+ globalColourScheme
+ .setThreshold(0, ignoreGapsInConsensusCalculation);
}
if (recalc)
{
- cs.setConsensus(hconsensus);
- cs.setConservation(hconservation);
+ globalColourScheme.setConsensus(hconsensus);
+ globalColourScheme.setConservation(hconservation);
}
- cs.setConservationApplied(getConservationSelected());
- cs.alignmentChanged(alignment, hiddenRepSequences);
+ globalColourScheme.setConservationApplied(getConservationSelected());
+ globalColourScheme.alignmentChanged(alignment, hiddenRepSequences);
}
if (getColourAppliesToAllGroups())
{
{
if (cs == null)
{
- sg.cs = null;
+ sg.setColourScheme(null);
continue;
}
- sg.cs = cs.getInstance(sg, getHiddenRepSequences());
+ CollectionColourScheme groupColour = new CollectionColourScheme(cs.getInstance(sg,
+ getHiddenRepSequences()));
+ sg.setGroupColourScheme(groupColour);
sg.setConsPercGaps(ConsPercGaps);
if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
|| cs instanceof Blosum62ColourScheme)
{
- sg.cs.setThreshold(viewStyle.getThreshold(),
+ groupColour.setThreshold(viewStyle.getThreshold(),
isIgnoreGapsConsensus());
recalc = true;
}
else
{
- sg.cs.setThreshold(0, isIgnoreGapsConsensus());
+ groupColour.setThreshold(0, isIgnoreGapsConsensus());
}
if (getConservationSelected())
{
- sg.cs.setConservationApplied(true);
+ groupColour.setConservationApplied(true);
recalc = true;
}
else
{
- sg.cs.setConservation(null);
+ groupColour.setConservation(null);
// sg.cs.setThreshold(0, getIgnoreGapsConsensus());
}
if (recalc)
}
else
{
- sg.cs.alignmentChanged(sg, hiddenRepSequences);
+ groupColour.alignmentChanged(sg, hiddenRepSequences);
}
}
}
@Override
public ColourSchemeI getGlobalColourScheme()
{
+ return globalColourScheme == null ? null : globalColourScheme
+ .getColourScheme();
+ }
+
+ @Override
+ public CollectionColourSchemeI getViewportColourScheme()
+ {
return globalColourScheme;
}
*/
void resetAllColourSchemes()
{
- ColourSchemeI cs = globalColourScheme;
+ CollectionColourScheme cs = globalColourScheme;
if (cs != null)
{
cs.alignmentChanged(alignment, hiddenRepSequences);
import jalview.datamodel.Annotation;
import jalview.datamodel.ProfilesI;
import jalview.datamodel.SequenceI;
-import jalview.schemes.ColourSchemeI;
+import jalview.schemes.CollectionColourSchemeI;
public class ConsensusThread extends AlignCalcWorker
{
*/
protected void setColourSchemeConsensus(ProfilesI hconsensus)
{
- ColourSchemeI globalColourScheme = alignViewport
- .getGlobalColourScheme();
- if (globalColourScheme != null)
+ CollectionColourSchemeI cs = alignViewport.getViewportColourScheme();
+ if (cs != null)
{
- globalColourScheme.setConsensus(hconsensus);
+ cs.setConsensus(hconsensus);
}
}
"examples/uniref50.fa", DataSourceType.FILE);
ColourSchemeI cs = new PIDColourScheme();
af.getViewport().setGlobalColourScheme(cs);
- assertFalse(cs.conservationApplied());
+ assertFalse(af.getViewport().getViewportColourScheme()
+ .conservationApplied());
}
@Test(groups = { "Functional" })
null, true, true, false, 21, 29);
ColourSchemeI scheme = ColourSchemeMapper.getJalviewColourScheme(
"zappo", seqGrp);
- seqGrp.cs = scheme;
+ seqGrp.cs.setColourScheme(scheme);
seqGrp.setShowNonconserved(false);
seqGrp.setDescription(null);
SequenceGroup sg = new SequenceGroup();
sg.setStartRes(57);
sg.setEndRes(92);
- sg.cs = gcs;
+ sg.cs.setColourScheme(gcs);
af.getViewport().getAlignment().addGroup(sg);
sg.addSequence(af.getViewport().getAlignment().getSequenceAt(1), false);
sg.addSequence(af.getViewport().getAlignment().getSequenceAt(2), true);
ColourSchemeI _rcs = af.getViewport().getGlobalColourScheme();
ColourSchemeI _rgcs = af.getViewport().getAlignment().getGroups()
- .get(0).cs;
+ .get(0).getColourScheme();
assertNotNull("Didn't recover global colourscheme", _rcs);
assertTrue("Didn't recover annotation colour global scheme",
_rcs instanceof AnnotationColourGradient);
for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
&& (!diffseqcols || !diffgseqcols); p++)
{
- if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0]) != _rcs
- .findColour(sqs[5].getCharAt(p), p, sqs[5]))
+ if (_rcs.findColour(sqs[0].getCharAt(p), p, sqs[0], null, 0f) != _rcs
+ .findColour(sqs[5].getCharAt(p), p, sqs[5], null, 0f))
{
diffseqcols = true;
}
for (int p = 0, pSize = af.getViewport().getAlignment().getWidth(); p < pSize
&& (!diffseqcols || !diffgseqcols); p++)
{
- if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1]) != _rgcs
- .findColour(sqs[2].getCharAt(p), p, sqs[2]))
+ if (_rgcs.findColour(sqs[1].getCharAt(p), p, sqs[1], null, 0f) != _rgcs
+ .findColour(sqs[2].getCharAt(p), p, sqs[2], null, 0f))
{
diffgseqcols = true;
}
Desktop.getAlignFrames().length,
Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
Assert.assertEquals(
- oldviews,
- Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length);
+ Desktop.getAlignmentPanels(af.getViewport().getSequenceSetId()).length,
+ oldviews);
}
/**
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class Blosum62ColourSchemeTest
+{
+ /**
+ * Test the method that determines colour as:
+ * <ul>
+ * <li>white if there is no consensus</li>
+ * <li>white if 'residue' is a gap</li>
+ * <li>dark blue if residue matches consensus (or joint consensus)</li>
+ * <li>else, total the residue's Blosum score with the consensus residue(s)</li>
+ * <ul>
+ * <li>if positive, light blue, else white</li>
+ * </ul>
+ * <ul>
+ */
+ @Test
+ public void testFindColour()
+ {
+ ColourSchemeI blosum = new Blosum62ColourScheme();
+ Color lightBlue = new Color(204, 204, 255);
+ Color darkBlue = new Color(154, 154, 255);
+
+ /*
+ * findColour does not use column, sequence or pid score
+ */
+ assertEquals(blosum.findColour('A', 0, null, "A", 0f), darkBlue);
+ assertEquals(blosum.findColour('a', 0, null, "A", 0f), darkBlue);
+ assertEquals(blosum.findColour('A', 0, null, "a", 0f), darkBlue);
+ assertEquals(blosum.findColour('a', 0, null, "a", 0f), darkBlue);
+
+ /*
+ * L has a Blosum score of
+ * -1 with A
+ * -4 with B
+ * 0 with F
+ * 2 with I
+ * -1 with T
+ * 1 with V
+ * etc
+ */
+ assertEquals(blosum.findColour('L', 0, null, "A", 0f), Color.white); // -1
+ assertEquals(blosum.findColour('L', 0, null, "B", 0f), Color.white); // -4
+ assertEquals(blosum.findColour('L', 0, null, "F", 0f), Color.white); // 0
+ assertEquals(blosum.findColour('L', 0, null, "I", 0f), lightBlue); // 2
+ assertEquals(blosum.findColour('L', 0, null, "TV", 0f), Color.white); // 0
+ assertEquals(blosum.findColour('L', 0, null, "IV", 0f), lightBlue); // 3
+ assertEquals(blosum.findColour('L', 0, null, "IT", 0f), lightBlue); // 1
+ assertEquals(blosum.findColour('L', 0, null, "IAT", 0f), Color.white); // 0
+ }
+}
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
DataSourceType.PASTE);
AlignmentI al = af.getViewport().getAlignment();
- ColourSchemeI cs = new ClustalxColourScheme(al, null);
+ ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
/*
* column 1 is 70% A which is above Clustalx threshold of 60%
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+import jalview.analysis.Conservation;
+import jalview.datamodel.Profile;
+import jalview.datamodel.ProfileI;
+import jalview.datamodel.Profiles;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+import java.awt.Color;
+import java.util.Collections;
+
+import org.testng.annotations.Test;
+
+public class CollectionColourSchemeTest
+{
+
+ @Test(groups = "Functional")
+ public void testAboveThreshold()
+ {
+ /*
+ * make up profiles for this alignment:
+ * AR-Q
+ * AR--
+ * SR-T
+ * SR-T
+ */
+ ProfileI[] profiles = new ProfileI[4];
+ profiles[0] = new Profile(4, 0, 2, "AS");
+ profiles[1] = new Profile(4, 0, 4, "R");
+ profiles[2] = new Profile(4, 4, 0, "");
+ profiles[3] = new Profile(4, 1, 2, "T");
+ CollectionColourScheme ccs = new CollectionColourScheme(
+ new PIDColourScheme());
+ ccs.setConsensus(new Profiles(profiles));
+
+ /*
+ * no threshold
+ */
+ ccs.setThreshold(0, true);
+ assertTrue(ccs.aboveThreshold('a', 0));
+ assertTrue(ccs.aboveThreshold('S', 0));
+ assertTrue(ccs.aboveThreshold('W', 0));
+ assertTrue(ccs.aboveThreshold('R', 1));
+ assertTrue(ccs.aboveThreshold('W', 2));
+ assertTrue(ccs.aboveThreshold('t', 3));
+ assertTrue(ccs.aboveThreshold('Q', 3));
+
+ /*
+ * with threshold, include gaps
+ */
+ ccs.setThreshold(60, false);
+ assertFalse(ccs.aboveThreshold('a', 0));
+ assertFalse(ccs.aboveThreshold('S', 0));
+ assertTrue(ccs.aboveThreshold('R', 1));
+ assertFalse(ccs.aboveThreshold('W', 2));
+ assertFalse(ccs.aboveThreshold('t', 3)); // 50% < 60%
+
+ /*
+ * with threshold, ignore gaps
+ */
+ ccs.setThreshold(60, true);
+ assertFalse(ccs.aboveThreshold('a', 0));
+ assertFalse(ccs.aboveThreshold('S', 0));
+ assertTrue(ccs.aboveThreshold('R', 1));
+ assertFalse(ccs.aboveThreshold('W', 2));
+ assertTrue(ccs.aboveThreshold('t', 3)); // 67% > 60%
+ }
+
+ /**
+ * Test colour bleaching based on conservation score and conservation slider.
+ * Scores of 10 or 11 should leave colours unchanged. Gap is always white.
+ */
+ @Test(groups = "Functional")
+ public void testApplyConservation()
+ {
+ CollectionColourScheme ccs = new CollectionColourScheme(
+ new PIDColourScheme());
+
+ // no conservation present - no fading
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 12));
+
+ /*
+ * stub Conservation to return a given consensus string
+ */
+ final String consSequence = "0123456789+*-";
+ Conservation cons = new Conservation(null,
+ Collections.<SequenceI> emptyList(), 0, 0)
+ {
+ @Override
+ public SequenceI getConsSequence() {
+ return new Sequence("seq", consSequence);
+ }
+ };
+ ccs.setConservation(cons);
+
+ // column out of range:
+ assertEquals(Color.RED,
+ ccs.applyConservation(Color.RED, consSequence.length()));
+
+ /*
+ * with 100% threshold, 'fade factor' is
+ * (11-score)/10 * 100/20 = (11-score)/2
+ * which is >= 1 for all scores i.e. all fade to white except +, *
+ */
+ ccs.setConservationInc(100);
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 0));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 1));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 2));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 3));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 4));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 5));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 6));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 7));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 8));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 9));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 10));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 11));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 12));
+
+ /*
+ * with 0% threshold, there should be no fading
+ */
+ ccs.setConservationInc(0);
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 0));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 1));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 2));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 3));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 4));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 5));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 6));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 7));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 8));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 9));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 10));
+ assertEquals(Color.RED, ccs.applyConservation(Color.RED, 11));
+ assertEquals(Color.WHITE, ccs.applyConservation(Color.RED, 12)); // gap
+
+ /*
+ * with 40% threshold, 'fade factor' is
+ * (11-score)/10 * 40/20 = (11-score)/5
+ * which is {>1, >1, >1, >1, >1, >1, 1, 0.8, 0.6, 0.4} for score 0-9
+ * e.g. score 7 colour fades 80% of the way to white (255, 255, 255)
+ */
+ ccs.setConservationInc(40);
+ Color colour = new Color(155, 105, 55);
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 0));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 1));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 2));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 3));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 4));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 5));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 6));
+ assertEquals(new Color(235, 225, 215), ccs.applyConservation(colour, 7));
+ assertEquals(new Color(215, 195, 175), ccs.applyConservation(colour, 8));
+ assertEquals(new Color(195, 165, 135), ccs.applyConservation(colour, 9));
+ assertEquals(colour, ccs.applyConservation(colour, 10));
+ assertEquals(colour, ccs.applyConservation(colour, 11));
+ assertEquals(Color.WHITE, ccs.applyConservation(colour, 12));
+ }
+
+}
*/
class Stripy extends ResidueColourScheme
{
- private ColourSchemeI odd;
+ private ResidueColourScheme odd;
- private ColourSchemeI even;
+ private ResidueColourScheme even;
private Stripy()
{
*/
private Stripy(ColourSchemeI cs1, ColourSchemeI cs2)
{
- odd = cs1;
- even = cs2;
+ odd = (ResidueColourScheme) cs1;
+ even = (ResidueColourScheme) cs2;
}
@Override
*/
class MyClustal extends ResidueColourScheme
{
- ColourSchemeI delegate;
+ ClustalxColourScheme delegate;
private MyClustal()
{
}
- private MyClustal(ColourSchemeI scheme)
+ private MyClustal(AnnotatedCollectionI sg,
+ Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
- delegate = scheme;
+ delegate = new ClustalxColourScheme(sg, hiddenRepSequences);
}
@Override
public ColourSchemeI getInstance(AnnotatedCollectionI sg,
Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
{
- return new MyClustal(new ClustalxColourScheme().getInstance(sg,
- hiddenRepSequences));
+ return new MyClustal(sg, hiddenRepSequences);
}
@Override
--- /dev/null
+package jalview.schemes;
+
+import static org.testng.Assert.assertEquals;
+
+import java.awt.Color;
+
+import org.testng.annotations.Test;
+
+public class PIDColourSchemeTest
+{
+ /**
+ * Test findColour for cases:
+ * <ul>
+ * <li>gap: white</li>
+ * <li>no match to consensus: white</li>
+ * <li>match consensus with pid > 80%: 100,100,255</li>
+ * <li>match consensus with pid > 60%: 153, 153, 255</li>
+ * <li>match consensus with pid > 40%: 204, 204, 255</li>
+ * <li>match consensus with pid <= 40%: white</li>
+ * <li>joint consensus matching</li>
+ * <li>case insensitive matching</li>
+ * <ul>
+ */
+ @Test
+ public void testFindColour()
+ {
+ ColourSchemeI scheme = new PIDColourScheme();
+
+ Color over40 = new Color(204, 204, 255);
+ Color over60 = new Color(153, 153, 255);
+ Color over80 = new Color(100, 100, 255);
+
+ /*
+ * doesn't use column or sequence
+ */
+ assertEquals(scheme.findColour('A', 0, null, "A", 0f), Color.white);
+ assertEquals(scheme.findColour('A', 0, null, "A", 40f), Color.white);
+ assertEquals(scheme.findColour('A', 0, null, "A", 40.1f), over40);
+ assertEquals(scheme.findColour('A', 0, null, "A", 60f), over40);
+ assertEquals(scheme.findColour('A', 0, null, "A", 60.1f), over60);
+ assertEquals(scheme.findColour('A', 0, null, "A", 80f), over60);
+ assertEquals(scheme.findColour('A', 0, null, "A", 80.1f), over80);
+ assertEquals(scheme.findColour('A', 0, null, "A", 100f), over80);
+
+ assertEquals(scheme.findColour('a', 0, null, "A", 80f), over60);
+ assertEquals(scheme.findColour('A', 0, null, "a", 80f), over60);
+ assertEquals(scheme.findColour('a', 0, null, "a", 80f), over60);
+ assertEquals(scheme.findColour('A', 0, null, "AC", 80f), over60);
+ assertEquals(scheme.findColour('A', 0, null, "KCA", 80f), over60);
+ }
+}
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.Annotation;
-import jalview.datamodel.Profile;
-import jalview.datamodel.ProfileI;
-import jalview.datamodel.Profiles;
import jalview.datamodel.Sequence;
import jalview.datamodel.SequenceI;
import jalview.gui.JvOptionPane;
import jalview.io.TCoffeeScoreFile;
-import java.awt.Color;
-
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
}
@Test(groups = "Functional")
- public void testAboveThreshold()
- {
- /*
- * make up profiles for this alignment:
- * AR-Q
- * AR--
- * SR-T
- * SR-T
- */
- ProfileI[] profiles = new ProfileI[4];
- profiles[0] = new Profile(4, 0, 2, "AS");
- profiles[1] = new Profile(4, 0, 4, "R");
- profiles[2] = new Profile(4, 4, 0, "");
- profiles[3] = new Profile(4, 1, 2, "T");
- ResidueColourScheme rcs = new PIDColourScheme();
- rcs.setConsensus(new Profiles(profiles));
-
- /*
- * no threshold
- */
- rcs.setThreshold(0, true);
- assertTrue(rcs.aboveThreshold('a', 0));
- assertTrue(rcs.aboveThreshold('S', 0));
- assertTrue(rcs.aboveThreshold('W', 0));
- assertTrue(rcs.aboveThreshold('R', 1));
- assertTrue(rcs.aboveThreshold('W', 2));
- assertTrue(rcs.aboveThreshold('t', 3));
- assertTrue(rcs.aboveThreshold('Q', 3));
-
- /*
- * with threshold, include gaps
- */
- rcs.setThreshold(60, false);
- assertFalse(rcs.aboveThreshold('a', 0));
- assertFalse(rcs.aboveThreshold('S', 0));
- assertTrue(rcs.aboveThreshold('R', 1));
- assertFalse(rcs.aboveThreshold('W', 2));
- assertFalse(rcs.aboveThreshold('t', 3)); // 50% < 60%
-
- /*
- * with threshold, ignore gaps
- */
- rcs.setThreshold(60, true);
- assertFalse(rcs.aboveThreshold('a', 0));
- assertFalse(rcs.aboveThreshold('S', 0));
- assertTrue(rcs.aboveThreshold('R', 1));
- assertFalse(rcs.aboveThreshold('W', 2));
- assertTrue(rcs.aboveThreshold('t', 3)); // 67% > 60%
- }
-
- /**
- * Test colour bleaching based on conservation score and conservation slider.
- * Scores of 10 or 11 should leave colours unchanged. Gap is always white.
- */
- @Test(groups = "Functional")
- public void testApplyConservation()
- {
- ResidueColourScheme rcs = new PIDColourScheme();
-
- // no conservation present - no fading
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 12));
-
- // cheat by setting conservation sequence directly
- // rather than calculating it - good enough for this test
- String consensus = "0123456789+*-";
- rcs.conservation = consensus.toCharArray();
-
- // column out of range:
- assertEquals(Color.RED,
- rcs.applyConservation(Color.RED, consensus.length()));
-
- /*
- * with 100% threshold, 'fade factor' is
- * (11-score)/10 * 100/20 = (11-score)/2
- * which is >= 1 for all scores i.e. all fade to white except +, *
- */
- rcs.setConservationInc(100);
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 0));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 1));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 2));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 3));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 4));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 5));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 6));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 7));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 8));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 9));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 10));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 11));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 12));
-
- /*
- * with 0% threshold, there should be no fading
- */
- rcs.setConservationInc(0);
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 0));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 1));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 2));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 3));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 4));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 5));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 6));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 7));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 8));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 9));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 10));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 11));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 12)); // gap
-
- /*
- * with 40% threshold, 'fade factor' is
- * (11-score)/10 * 40/20 = (11-score)/5
- * which is {>1, >1, >1, >1, >1, >1, 1, 0.8, 0.6, 0.4} for score 0-9
- * e.g. score 7 colour fades 80% of the way to white (255, 255, 255)
- */
- rcs.setConservationInc(40);
- Color colour = new Color(155, 105, 55);
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 0));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 1));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 2));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 3));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 4));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 5));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 6));
- assertEquals(new Color(235, 225, 215), rcs.applyConservation(colour, 7));
- assertEquals(new Color(215, 195, 175), rcs.applyConservation(colour, 8));
- assertEquals(new Color(195, 165, 135), rcs.applyConservation(colour, 9));
- assertEquals(colour, rcs.applyConservation(colour, 10));
- assertEquals(colour, rcs.applyConservation(colour, 11));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 12));
- }
-
- @Test(groups = "Functional")
public void testIsApplicableTo()
{
SequenceI pep1 = new Sequence("pep1", "APQTWLS");