1 import jalview.workers.AlignmentAnnotationFactory;
2 import jalview.workers.AnnotationProviderI;
3 import jalview.datamodel.AlignmentAnnotation;
4 import jalview.datamodel.Annotation;
5 import jalview.util.ColorUtils;
6 import jalview.util.Comparison;
10 * Example script to compute two alignment annotations
11 * - count of Phosphorylation features
12 * - count of Turn features
13 * To try this, first load example file uniref50.fa and load on features file
14 * exampleFeatures.txt, before running this script
16 * The script only needs to be run once - it will be registered by Jalview
17 * and recalculated automatically when the alignment changes.
21 * A closure that returns true if value includes "PHOSPHORYLATION"
23 def phosCounter = { type -> type.contains("PHOSPHORYLATION") }
26 * A closure that returns true if value includes "TURN"
28 def turnCounter = { type -> type.contains("TURN") }
31 * A closure that computes and returns an array of Annotation values,
32 * one for each column of the alignment
34 def getAnnotations(al, fr, counter)
37 def counts = new int[width]
41 * count features in each column, record the maximum value
43 for (col = 0 ; col < width ; col++)
46 for (row = 0 ; row < al.height ; row++)
48 seq = al.getSequenceAt(row)
49 if (seq != null && col < seq.getLength())
51 def res = seq.getCharAt(col)
52 if (!Comparison.isGap(res))
54 pos = seq.findPosition(col)
55 features = fr.findFeaturesAtRes(seq, pos)
56 for (feature in features)
58 if (counter.call(feature.type))
74 * make the Annotation objects, with a graduated colour scale
75 * (from min value to max value) for the histogram bars
77 def zero = '0' as char
78 def anns = new Annotation[width]
79 for (col = 0 ; col < width ; col++)
84 Color color = ColorUtils.getGraduatedColour(c, 0, Color.cyan,
86 anns[col] = AlignmentAnnotationFactory.newAnnotation(String.valueOf(c),
87 String.valueOf(c), zero, c, color)
94 * Define the method that performs the calculations, and builds two
95 * AlignmentAnnotation objects
98 [ calculateAnnotation: { al, fr ->
99 def phosAnns = getAnnotations(al, fr, phosCounter)
100 def ann1 = AlignmentAnnotationFactory.newAlignmentAnnotation("Phosphorylation", "Count of Phosphorylation features", phosAnns)
101 def turnAnns = getAnnotations(al, fr, turnCounter)
102 def ann2 = AlignmentAnnotationFactory.newAlignmentAnnotation("Turn", "Count of Turn features", turnAnns)
105 ] as AnnotationProviderI
108 * Register the annotation calculator with Jalview
110 AlignmentAnnotationFactory.newCalculator(annotator)