import java.awt.Color;
-import jalview.schemes.ResidueColourScheme;
+import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemes;
import jalview.datamodel.AnnotatedCollectionI;
import jalview.datamodel.SequenceI;
+import jalview.datamodel.SequenceCollectionI;
/*
* Example script that registers two new alignment colour schemes
*/
/*
- * Class that defines a colour scheme where odd columns are red,
- * even numbered columns are blue, and gaps are yellow
+ * Closure that defines a colour scheme where consensus residues are pink,
+ * other residues are red in odd columns and blue in even columns, and
+ * gaps are yellow
*/
-class Stripy extends ResidueColourScheme {
- Stripy() { }
- String getSchemeName() { "stripy" }
- Stripy getInstance(AnnotatedCollectionI coll, Map map) { new Stripy() }
- Color findColour(char res, int col, SequenceI seq)
- {
+def candy
+candy = { ->
+ [
+ /*
+ * name shown in the colour menu
+ */
+ getSchemeName: { -> 'candy' },
+
+ /*
+ * to make a new instance for each alignment view
+ */
+ getInstance: { AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> candy() },
+
+ /*
+ * method only needed if colour scheme has to recalculate
+ * values when an alignment is modified
+ */
+ alignmentChanged: { AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> },
+
+ /*
+ * determine colour for a residue at an aligned position of a
+ * sequence, given consensus residue(s) for the column and the
+ * consensus percentage identity score for the column
+ */
+ findColour: { char res, int col, SequenceI seq, String consensus, float pid ->
if (res == ' ' || res == '-' || res == '.')
{
Color.yellow
- } else if (col % 2 == 0)
- {
+ } else if (consensus.contains(String.valueOf(res)))
+ {
+ Color.pink
+ } else if (col % 2 == 0)
+ {
Color.blue
- } else
- {
+ } else
+ {
Color.red
- }
- }
+ }
+ },
+
+ /*
+ * true means applicable to nucleotide or peptide data
+ */
+ isApplicableTo: {AnnotatedCollectionI coll -> true},
+
+ /*
+ * simple colour schemes are those that depend on the residue
+ * only (these are also available to colour structure viewers)
+ */
+ isSimple: { false }
+ ] as ColourSchemeI
}
/*
- * Class that defines a colour scheme graduated
- * (approximately) by amino acid weight
+ * A closure that defines a colour scheme graduated
+ * (approximately) by amino acid weight
+ * here from lightest (G) Blue, to heaviest (W) Red
*/
-class ByWeight extends ResidueColourScheme {
- int min = 75
- int max = 204
- ByWeight() { }
- boolean isPeptideSpecific() {true}
- String getSchemeName() { "By Weight" }
- ByWeight getInstance(AnnotatedCollectionI coll, Map map) { new ByWeight() }
- Color makeColour(int weight)
- {
- int i = 255 * (weight - min) / (max - min);
- new Color(i, 0, i);
- }
- Color findColour(char res, int col, SequenceI seq)
- {
+def makeColour = { weight ->
+ minWeight = 75 // Glycine
+ maxWeight = 204 // Tryptophan
+ int i = 255 * (weight - minWeight) / (maxWeight - minWeight);
+ new Color(i, 0, 255-i);
+}
+def byWeight
+byWeight = { ->
+ [
+ getSchemeName: { 'By Weight' },
+ isApplicableTo: { coll -> true },
+ alignmentChanged: { coll, map -> },
+ getInstance: { coll, map -> byWeight() },
+ isSimple: { true },
+ findColour: {res, col, seq, consensus, pid ->
switch (res) {
case ' ':
case '-':
makeColour(150)
}
}
+ ] as ColourSchemeI
}
-ColourSchemes.instance.registerColourScheme(new Stripy())
-ColourSchemes.instance.registerColourScheme(new ByWeight())
+ColourSchemes.instance.registerColourScheme(candy())
+ColourSchemes.instance.registerColourScheme(byWeight())