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;
9 * Example script that registers two new alignment colour schemes
13 * Closure that defines a colour scheme where consensus residues are pink,
14 * other residues are red in odd columns and blue in even columns, and
21 * name shown in the colour menu
23 getSchemeName: { -> 'candy' },
26 * to make a new instance for each alignment view
28 getInstance: { AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> candy() },
31 * method only needed if colour scheme has to recalculate
32 * values when an alignment is modified
34 alignmentChanged: { AnnotatedCollectionI coll, Map<SequenceI, SequenceCollectionI> map -> },
37 * determine colour for a residue at an aligned position of a
38 * sequence, given consensus residue(s) for the column and the
39 * consensus percentage identity score for the column
41 findColour: { char res, int col, SequenceI seq, String consensus, float pid ->
42 if (res == ' ' || res == '-' || res == '.')
45 } else if (consensus.contains(String.valueOf(res)))
48 } else if (col % 2 == 0)
58 * true means applicable to nucleotide or peptide data
60 isApplicableTo: {AnnotatedCollectionI coll -> true},
63 * simple colour schemes are those that depend on the residue
64 * only (these are also available to colour structure viewers)
71 * A closure that defines a colour scheme graduated
72 * (approximately) by amino acid weight
73 * here from lightest (G) Blue, to heaviest (W) Red
75 def makeColour = { weight ->
76 minWeight = 75 // Glycine
77 maxWeight = 204 // Tryptophan
78 int i = 255 * (weight - minWeight) / (maxWeight - minWeight);
79 new Color(i, 0, 255-i);
84 getSchemeName: { 'By Weight' },
85 // this colour scheme is peptide-specific:
86 isApplicableTo: { coll -> !coll.isNucleotide() },
87 alignmentChanged: { coll, map -> },
88 getInstance: { coll, map -> byWeight() },
90 findColour: {res, col, seq, consensus, pid ->
154 ColourSchemes.instance.registerColourScheme(candy())
155 ColourSchemes.instance.registerColourScheme(byWeight())