JAL-2228 removed FeatureCounterI in favour of FeatureSetCounterI with
[jalview.git] / examples / groovy / featuresCounter.groovy
1 import jalview.workers.AlignmentAnnotationFactory;
2 import jalview.workers.FeatureSetCounterI;
3
4 /*
5  * Example script to compute two alignment annotations
6  * - count of Phosphorylation features
7  * - count of Turn features
8  * To try this, first load example file uniref50.fa and load on features file
9  * exampleFeatures.txt, before running this script
10  *
11  * The script only needs to be run once - it will be registered by Jalview
12  * and recalculated automatically when the alignment changes.
13  */
14 def annotator = 
15     [
16      getNames: { ['Phosphorylation', 'Turn'] as String[] }, 
17      getDescriptions:  { ['Count of Phosphorylation features', 'Count of Turn features'] as String[] },
18      getMinColour: { [0, 255, 255] as int[] }, // cyan
19      getMaxColour: { [0, 0, 255] as int[] }, // blue
20      count: 
21          { res, feats -> 
22                 int phos
23                 int turn
24                 for (sf in feats)
25                 {
26                           /*
27                            * Here we inspect the type of the sequence feature.
28                            * You can also test sf.description, sf.score, sf.featureGroup,
29                            * sf.strand, sf.phase, sf.begin, sf.end
30                            * or sf.getValue(attributeName) for GFF 'column 9' properties
31                            */
32                            if (sf.type.contains('TURN'))
33                    {
34                       turn++
35                    }
36                    if (sf.type.contains('PHOSPHORYLATION'))
37                    {
38                       phos++
39                    }
40                 }
41                 [phos, turn] as int[]
42          }
43      ] as FeatureSetCounterI
44     
45 /*
46  * Register the annotation calculator with Jalview
47  */
48 AlignmentAnnotationFactory.newCalculator(annotator)