*/
package jalview.appletgui;
-import jalview.datamodel.AlignmentAnnotation;
-import jalview.datamodel.SequenceGroup;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.ColourSchemeI;
-import jalview.util.MessageManager;
-
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Vector;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.SequenceGroup;
+import jalview.schemes.AnnotationColourGradient;
+import jalview.schemes.ColourSchemeI;
+import jalview.util.MessageManager;
+
public class AnnotationColourChooser extends Panel implements
ActionListener, AdjustmentListener, ItemListener, MouseListener
{
ColourSchemeI oldcs;
- Hashtable oldgroupColours;
+ Map<SequenceGroup, ColourSchemeI> oldgroupColours;
+
+ /*
+ * map from annotation to its menu item display label
+ * - so we know which item to pre-select on restore
+ */
+ private Map<AlignmentAnnotation, String> annotationLabels;
- jalview.datamodel.AlignmentAnnotation currentAnnotation;
+ AlignmentAnnotation currentAnnotation;
boolean adjusting = false;
oldcs = av.getGlobalColourScheme();
if (av.getAlignment().getGroups() != null)
{
- oldgroupColours = new Hashtable();
+ oldgroupColours = new HashMap<SequenceGroup, ColourSchemeI>();
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
if (sg.cs != null)
{
oldgroupColours.put(sg, sg.cs);
}
- else
- {
- oldgroupColours.put(sg, "null");
- }
}
}
this.av = av;
// seqAssociated.setState(acg.isSeqAssociated());
}
- Vector<String> list = new Vector<String>();
- int index = 1;
- for (int i = 0; i < anns.length; i++)
- {
- String label = anns[i].label;
- if (anns[i].sequenceRef != null)
- {
- label = label + "_" + anns[i].sequenceRef.getName();
- }
- if (!list.contains(label))
- {
- list.addElement(label);
- }
- else
- {
- list.addElement(label + "_" + (index++));
- }
- }
+ Vector<String> list = getAnnotationItems();
for (int i = 0; i < list.size(); i++)
{
if (oldcs instanceof AnnotationColourGradient)
{
AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
- annotations.select(acg.getAnnotation());
+ String label = annotationLabels.get(acg.getAnnotation());
+ annotations.select(label);
switch (acg.getAboveThreshold())
{
case AnnotationColourGradient.NO_THRESHOLD:
MessageManager
.getString("error.implementation_error_dont_know_threshold_annotationcolourgradient"));
}
- thresholdIsMin.setState(acg.thresholdIsMinMax);
+ thresholdIsMin.setState(acg.isThresholdIsMinMax());
thresholdValue.setText("" + acg.getAnnotationThreshold());
}
validate();
}
+ /**
+ * Builds and returns a list of menu items (display text) for choice of
+ * annotation. Also builds a map between annotations and their display labels.
+ *
+ * @return
+ */
+ protected Vector<String> getAnnotationItems()
+ {
+ // TODO remove duplication with gui.AnnotationRowFilter
+ // TODO add 'per sequence only' option / parameter
+
+ annotationLabels = new HashMap<AlignmentAnnotation, String>();
+ Vector<String> list = new Vector<String>();
+ AlignmentAnnotation[] anns = av.getAlignment().getAlignmentAnnotation();
+ if (anns == null)
+ {
+ return list;
+ }
+ int index = 1;
+ for (int i = 0; i < anns.length; i++)
+ {
+ String label = anns[i].label;
+ if (anns[i].sequenceRef != null)
+ {
+ /*
+ * be helpful and include sequence id in label for
+ * sequence-associated annotation (JAL-2236)
+ */
+ label = label + "_" + anns[i].sequenceRef.getName();
+ }
+ if (!list.contains(label))
+ {
+ list.addElement(label);
+ annotationLabels.put(anns[i], label);
+ }
+ else
+ {
+ label = label + "_" + (index++);
+ list.addElement(label);
+ annotationLabels.put(anns[i], label);
+ }
+ }
+ return list;
+ }
+
private void setDefaultMinMax()
{
minColour.setBackground(av.applet.getDefaultColourParameter(
acg.setPredefinedColours(true);
}
- acg.thresholdIsMinMax = thresholdIsMin.getState();
+ acg.setThresholdIsMinMax(thresholdIsMin.getState());
av.setGlobalColourScheme(acg);
{
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
-
if (sg.cs == null)
{
continue;
minColour.getBackground(), maxColour.getBackground(),
aboveThreshold);
}
-
}
}
{
for (SequenceGroup sg : ap.av.getAlignment().getGroups())
{
- Object cs = oldgroupColours.get(sg);
- if (cs instanceof ColourSchemeI)
- {
- sg.cs = (ColourSchemeI) cs;
- }
- else
- {
- // probably the "null" string we set it to if it was null originally.
- sg.cs = null;
- }
+ sg.cs = oldgroupColours.get(sg);
}
}
ap.paintAlignment(true);
*/
package jalview.gui;
-import jalview.bin.Cache;
-import jalview.datamodel.SequenceGroup;
-import jalview.schemes.AnnotationColourGradient;
-import jalview.schemes.ColourSchemeI;
-import jalview.util.MessageManager;
-
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Hashtable;
+import java.util.Vector;
+
+import jalview.bin.Cache;
+import jalview.datamodel.SequenceGroup;
+import jalview.schemes.AnnotationColourGradient;
+import jalview.schemes.ColourSchemeI;
+import jalview.util.MessageManager;
import javax.swing.BorderFactory;
import javax.swing.JButton;
seqAssociated.setSelected(acg.isSeqAssociated());
}
- annotations = new JComboBox<String>(
- getAnnotationItems(seqAssociated.isSelected()));
+ Vector<String> annotItems = getAnnotationItems(seqAssociated
+ .isSelected());
+ annotations = new JComboBox<String>(annotItems);
populateThresholdComboBox(threshold);
if (oldcs instanceof AnnotationColourGradient)
{
AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
- annotations.setSelectedItem(acg.getAnnotation());
+ String label = getAnnotationMenuLabel(acg.getAnnotation());
+ annotations.setSelectedItem(label);
switch (acg.getAboveThreshold())
{
case AnnotationColourGradient.NO_THRESHOLD:
MessageManager
.getString("error.implementation_error_dont_know_about_threshold_setting"));
}
- thresholdIsMin.setSelected(acg.thresholdIsMinMax);
+ thresholdIsMin.setSelected(acg.isThresholdIsMinMax());
thresholdValue.setText("" + acg.getAnnotationThreshold());
}
thresholdValue.setEnabled(true);
adjusting = false;
}
- colorAlignmContaining(getCurrentAnnotation(), selectedThresholdItem);
+ colorAlignmentContaining(getCurrentAnnotation(), selectedThresholdItem);
ap.alignmentChanged();
// ensure all associated views (overviews, structures, etc) are notified of
*/
package jalview.gui;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Vector;
+
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.GraphLine;
import jalview.datamodel.SequenceGroup;
import jalview.schemes.AnnotationColourGradient;
import jalview.util.MessageManager;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.util.Vector;
-
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
protected int[] annmap;
+ /*
+ * map from annotation to its menu item display label
+ * - so we know which item to pre-select on restore
+ */
+ private Map<AlignmentAnnotation, String> annotationLabels;
+
protected boolean enableSeqAss = false;
private AlignmentAnnotation currentAnnotation;
}
+ /**
+ * Builds and returns a list of menu items (display text) for choice of
+ * annotation. Also builds maps between annotations, their positions in the
+ * list, and their display labels in the list.
+ *
+ * @param isSeqAssociated
+ * @return
+ */
public Vector<String> getAnnotationItems(boolean isSeqAssociated)
{
+ annotationLabels = new HashMap<AlignmentAnnotation, String>();
+
Vector<String> list = new Vector<String>();
int index = 1;
int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
{
- if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
+ AlignmentAnnotation annotation = av.getAlignment()
+ .getAlignmentAnnotation()[i];
+ if (annotation.sequenceRef == null)
{
if (isSeqAssociated)
{
{
enableSeqAss = true;
}
- String label = av.getAlignment().getAlignmentAnnotation()[i].label;
+ String label = annotation.label;
// add associated sequence ID if available
- if (!isSeqAssociated
- && av.getAlignment().getAlignmentAnnotation()[i].sequenceRef != null)
+ if (!isSeqAssociated && annotation.sequenceRef != null)
{
- label = label
- + "_"
- + av.getAlignment().getAlignmentAnnotation()[i].sequenceRef
- .getName();
+ label = label + "_" + annotation.sequenceRef.getName();
}
// make label unique
if (!list.contains(label))
{
anmap[list.size()] = i;
list.add(label);
+ annotationLabels.put(annotation, label);
}
else
{
if (!isSeqAssociated)
{
anmap[list.size()] = i;
- list.add(label + "_" + (index++));
+ label = label + "_" + (index++);
+ list.add(label);
+ annotationLabels.put(annotation, label);
}
}
}
.getString("label.threshold_feature_below_threshold"));
}
+ /**
+ * Rebuilds the drop-down list of annotations to choose from when the 'per
+ * sequence only' checkbox is checked or unchecked.
+ *
+ * @param annotations
+ */
protected void seqAssociated_actionPerformed(JComboBox<String> annotations)
{
adjusting = true;
}
}
- protected boolean colorAlignmContaining(AlignmentAnnotation currentAnn,
- int selectedThresholdOption)
+ protected boolean colorAlignmentContaining(
+ AlignmentAnnotation currentAnn, int selectedThresholdOption)
{
AnnotationColourGradient acg = null;
acg.setPredefinedColours(true);
}
- acg.thresholdIsMinMax = thresholdIsMin.isSelected();
+ acg.setThresholdIsMinMax(thresholdIsMin.isSelected());
av.setGlobalColourScheme(acg);
selectedThresholdOption);
((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
.isSelected());
-
}
else
{
((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
.isSelected());
}
-
}
}
return false;
}
- public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
+ public AlignmentAnnotation getCurrentAnnotation()
{
return currentAnnotation;
}
- public void setCurrentAnnotation(
- jalview.datamodel.AlignmentAnnotation currentAnnotation)
+ public void setCurrentAnnotation(AlignmentAnnotation currentAnnotation)
{
this.currentAnnotation = currentAnnotation;
}
public abstract void updateView();
public abstract void reset();
+
+ protected String getAnnotationMenuLabel(AlignmentAnnotation ann)
+ {
+ return annotationLabels.get(ann);
+ }
}
*/
package jalview.schemes;
+import java.awt.Color;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceI;
-import java.awt.Color;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
public class AnnotationColourGradient extends FollowerColourScheme
{
public static final int NO_THRESHOLD = -1;
public static final int ABOVE_THRESHOLD = 1;
- public AlignmentAnnotation annotation;
+ private final AlignmentAnnotation annotation;
+
+ private final int aboveAnnotationThreshold;
+
+ private boolean thresholdIsMinMax = false;
- int aboveAnnotationThreshold = -1;
+ private GraphLine annotationThreshold;
- public boolean thresholdIsMinMax = false;
+ private int redMin;
- GraphLine annotationThreshold;
+ private int greenMin;
- float r1, g1, b1, rr, gg, bb;
+ private int blueMin;
+
+ private int redRange;
+
+ private int greenRange;
+
+ private int blueRange;
private boolean predefinedColours = false;
*/
private boolean noGradient = false;
- IdentityHashMap<SequenceI, AlignmentAnnotation> seqannot = null;
+ private IdentityHashMap<SequenceI, AlignmentAnnotation> seqannot = null;
@Override
public ColourSchemeI applyTo(AnnotatedCollectionI sg,
acg.thresholdIsMinMax = thresholdIsMinMax;
acg.annotationThreshold = (annotationThreshold == null) ? null
: new GraphLine(annotationThreshold);
- acg.r1 = r1;
- acg.g1 = g1;
- acg.b1 = b1;
- acg.rr = rr;
- acg.gg = gg;
- acg.bb = bb;
+ acg.redMin = redMin;
+ acg.greenMin = greenMin;
+ acg.blueMin = blueMin;
+ acg.redRange = redRange;
+ acg.greenRange = greenRange;
+ acg.blueRange = blueRange;
acg.predefinedColours = predefinedColours;
acg.seqAssociated = seqAssociated;
acg.noGradient = noGradient;
annotationThreshold = annotation.threshold;
}
// clear values so we don't get weird black bands...
- r1 = 254;
- g1 = 254;
- b1 = 254;
- rr = 0;
- gg = 0;
- bb = 0;
+ redMin = 254;
+ greenMin = 254;
+ blueMin = 254;
+ redRange = 0;
+ greenRange = 0;
+ blueRange = 0;
noGradient = true;
checkLimits();
annotationThreshold = annotation.threshold;
}
- r1 = minColour.getRed();
- g1 = minColour.getGreen();
- b1 = minColour.getBlue();
+ redMin = minColour.getRed();
+ greenMin = minColour.getGreen();
+ blueMin = minColour.getBlue();
- rr = maxColour.getRed() - r1;
- gg = maxColour.getGreen() - g1;
- bb = maxColour.getBlue() - b1;
+ redRange = maxColour.getRed() - redMin;
+ greenRange = maxColour.getGreen() - greenMin;
+ blueRange = maxColour.getBlue() - blueMin;
noGradient = false;
checkLimits();
float aamin = 0f, aamax = 0f;
- public String getAnnotation()
+ public AlignmentAnnotation getAnnotation()
{
- return annotation.label;
+ return annotation;
}
public int getAboveThreshold()
public Color getMinColour()
{
- return new Color((int) r1, (int) g1, (int) b1);
+ return new Color(redMin, greenMin, blueMin);
}
public Color getMaxColour()
{
- return new Color((int) (r1 + rr), (int) (g1 + gg), (int) (b1 + bb));
+ return new Color(redMin + redRange, greenMin + greenRange, blueMin
+ + blueRange);
}
/**
*
* @return DOCUMENT ME!
*/
+ @Override
public Color findColour(char c)
{
return Color.red;
public Color findColour(char c, int j, SequenceI seq)
{
Color currentColour = Color.white;
- AlignmentAnnotation annotation = (seqAssociated && seqannot != null ? seqannot
+ AlignmentAnnotation ann = (seqAssociated && seqannot != null ? seqannot
.get(seq) : this.annotation);
- if (annotation == null)
+ if (ann == null)
{
return currentColour;
}
if ((threshold == 0) || aboveThreshold(c, j))
{
- if (annotation.annotations != null
- && j < annotation.annotations.length
- && annotation.annotations[j] != null
+ if (ann.annotations != null
+ && j < ann.annotations.length
+ && ann.annotations[j] != null
&& !jalview.util.Comparison.isGap(c))
{
- Annotation aj = annotation.annotations[j];
+ Annotation aj = ann.annotations[j];
// 'use original colours' => colourScheme != null
// -> look up colour to be used
// predefined colours => preconfigured shading
{
currentColour = aj.colour;
}
- else if (annotation.hasIcons
- && annotation.graph == AlignmentAnnotation.NO_GRAPH)
+ else if (ann.hasIcons
+ && ann.graph == AlignmentAnnotation.NO_GRAPH)
{
if (aj.secondaryStructure > ' ' && aj.secondaryStructure != '.'
&& aj.secondaryStructure != '-')
}
else
{
- if (annotation.isRNA())
+ if (ann.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
+ currentColour = ann.annotations[j].secondaryStructure == 'H' ? jalview.renderer.AnnotationRenderer.HELIX_COLOUR
+ : ann.annotations[j].secondaryStructure == 'E' ? jalview.renderer.AnnotationRenderer.SHEET_COLOUR
: jalview.renderer.AnnotationRenderer.STEM_COLOUR;
}
}
}
else
{
- currentColour = shadeCalculation(annotation, j);
+ currentColour = shadeCalculation(ann, j);
}
}
if (conservationColouring)
return currentColour;
}
- private Color shadeCalculation(AlignmentAnnotation annotation, int j)
+ private Color shadeCalculation(AlignmentAnnotation ann, int j)
{
// calculate a shade
float range = 1f;
- if (thresholdIsMinMax
- && annotation.threshold != null
+ if (thresholdIsMinMax && ann.threshold != null
&& aboveAnnotationThreshold == ABOVE_THRESHOLD
- && annotation.annotations[j].value >= annotation.threshold.value)
+ && ann.annotations[j].value >= ann.threshold.value)
{
- range = (annotation.annotations[j].value - annotation.threshold.value)
- / (annotation.graphMax - annotation.threshold.value);
+ range = (ann.annotations[j].value - ann.threshold.value)
+ / (ann.graphMax - ann.threshold.value);
}
- else if (thresholdIsMinMax && annotation.threshold != null
+ else if (thresholdIsMinMax && ann.threshold != null
&& aboveAnnotationThreshold == BELOW_THRESHOLD
- && annotation.annotations[j].value >= annotation.graphMin)
+ && ann.annotations[j].value >= ann.graphMin)
{
- range = (annotation.annotations[j].value - annotation.graphMin)
- / (annotation.threshold.value - annotation.graphMin);
+ range = (ann.annotations[j].value - ann.graphMin)
+ / (ann.threshold.value - ann.graphMin);
}
else
{
- if (annotation.graphMax != annotation.graphMin)
+ if (ann.graphMax != ann.graphMin)
{
- range = (annotation.annotations[j].value - annotation.graphMin)
- / (annotation.graphMax - annotation.graphMin);
+ range = (ann.annotations[j].value - ann.graphMin)
+ / (ann.graphMax - ann.graphMin);
}
else
{
}
}
- int dr = (int) (rr * range + r1), dg = (int) (gg * range + g1), db = (int) (bb
- * range + b1);
+ int dr = (int) (redRange * range + redMin);
+ int dg = (int) (greenRange * range + greenMin);
+ int db = (int) (blueRange * range + blueMin);
return new Color(dr, dg, db);
{
seqAssociated = sassoc;
}
+
+ public boolean isThresholdIsMinMax()
+ {
+ return thresholdIsMinMax;
+ }
+
+ public void setThresholdIsMinMax(boolean thresholdIsMinMax)
+ {
+ this.thresholdIsMinMax = thresholdIsMinMax;
+ }
}