1 import jalview.workers.FeatureCounterI;
2 import jalview.workers.AlignmentAnnotationFactory;
5 * Example script that registers two alignment annotation calculators
6 * - one that counts residues in a column with Pfam annotation
7 * - one that counts only charged residues with Pfam annotation
8 * Modify this example as required to count by column any desired value that can be
9 * derived from the residue and sequence features at each position of an alignment.
13 * A closure that returns true for any Charged residue
15 def isCharged = { residue ->
17 case ['D', 'd', 'E', 'e', 'H', 'h', 'K', 'k', 'R', 'r']:
24 * A closure that returns 1 if sequence features include type 'Pfam', else 0
25 * Argument should be a list of SequenceFeature
27 def hasPfam = { features ->
31 * Here we inspect the type of the sequence feature.
32 * You can also test sf.description, sf.score, sf.featureGroup,
33 * sf.strand, sf.phase, sf.begin, sf.end
34 * or sf.getValue(attributeName) for GFF 'column 9' properties
36 if ("Pfam".equals(sf.type))
45 * Closure that counts residues with a Pfam feature annotation
47 * - the name (label) for the alignment annotation
48 * - the description (tooltip) for the annotation
49 * - a closure (groovy function) that tests whether to include a residue
50 * - a closure that tests whether to increment count based on sequence features
52 def getColumnCounter = { name, desc, residueTester, featureCounter ->
55 getDescription: { desc },
56 getMinColour: { [0, 255, 255] }, // cyan
57 getMaxColour: { [0, 0, 255] }, // blue
61 if (residueTester.call(res))
63 if (featureCounter.call(feats))
74 * Define annotation that counts any residue with Pfam domain annotation
76 def pfamAnnotation = getColumnCounter("Pfam", "Count of residues with Pfam domain annotation", {true}, hasPfam)
79 * Define annotation that counts charged residues with Pfam domain annotation
81 def chargedPfamAnnotation = getColumnCounter("Pfam charged", "Count of charged residues with Pfam domain annotation", isCharged, hasPfam)
84 * Register the annotations
86 AlignmentAnnotationFactory.newCalculator(pfamAnnotation)
87 AlignmentAnnotationFactory.newCalculator(chargedPfamAnnotation)