2 import jalview.schemes.ColourSchemeI;
3 import jalview.schemes.ColourSchemes;
4 import jalview.datamodel.AnnotatedCollectionI;
5 import jalview.datamodel.SequenceI;
6 import jalview.datamodel.SequenceCollectionI;
7 import jalview.api.AlignViewportI
10 * Example script that registers two new alignment colour schemes
14 * Closure that defines a colour scheme where consensus residues are pink,
15 * other residues are red in odd columns and blue in even columns, and
22 * name shown in the colour menu
24 getSchemeName: { -> 'candy' },
27 * to make a new instance for each alignment view
29 getInstance: { view, coll -> candy() },
32 * method only needed if colour scheme has to recalculate
33 * values when an alignment is modified
35 alignmentChanged: { AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> },
38 * determine colour for a residue at an aligned position of a
39 * sequence, given consensus residue(s) for the column and the
40 * consensus percentage identity score for the column
42 findColour: { char res, int col, SequenceI seq, String consensus, float pid ->
43 if (res == ' ' || res == '-' || res == '.')
46 } else if (consensus.contains(String.valueOf(res)))
49 } else if (col % 2 == 0)
59 * true means applicable to nucleotide or peptide data
61 isApplicableTo: {AnnotatedCollectionI coll -> true},
64 * simple colour schemes are those that depend on the residue
65 * only (these are also available to colour structure viewers)
72 * A closure that defines a colour scheme graduated
73 * (approximately) by amino acid weight
74 * here from lightest (G) Blue, to heaviest (W) Red
76 def makeColour = { weight ->
77 minWeight = 75 // Glycine
78 maxWeight = 204 // Tryptophan
79 int i = 255 * (weight - minWeight) / (maxWeight - minWeight);
80 new Color(i, 0, 255-i);
85 getSchemeName: { 'By Weight' },
86 // this colour scheme is peptide-specific:
87 isApplicableTo: { coll -> !coll.isNucleotide() },
88 alignmentChanged: { coll, map -> },
89 getInstance: { view, coll -> byWeight() },
91 findColour: {res, col, seq, consensus, pid ->
155 ColourSchemes.instance.registerColourScheme(candy())
156 ColourSchemes.instance.registerColourScheme(byWeight())