2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 import jalview.workers.FeatureCounterI;
23 import jalview.workers.AlignmentAnnotationFactory;
26 * Example script that registers two alignment annotation calculators
27 * - one that counts residues in a column with Pfam annotation
28 * - one that counts only charged residues with Pfam annotation
31 * 1. load uniref50.fa from the examples folder
32 * 2. load features onto it from from examples/exampleFeatures.txt
33 * 3. Open this script in the Groovy console.
34 * 4. Either execute this script from the console, or via Calculate->Run Groovy Script
36 * To explore further, try changing this script to count other kinds of occurrences of
37 * residue and sequence features at columns in an alignment.
41 * A closure that returns true for any Charged residue
43 def isCharged = { residue ->
45 case ['D', 'd', 'E', 'e', 'H', 'h', 'K', 'k', 'R', 'r']:
52 * A closure that returns 1 if sequence features include type 'Pfam', else 0
53 * Argument should be a list of SequenceFeature
55 def hasPfam = { features ->
59 * Here we inspect the type of the sequence feature.
60 * You can also test sf.description, sf.score, sf.featureGroup,
61 * sf.strand, sf.phase, sf.begin, sf.end
62 * or sf.getValue(attributeName) for GFF 'column 9' properties
64 if ("Pfam".equals(sf.type))
73 * Closure that computes an annotation based on
74 * presence of particular residues and features
76 * - the name (label) for the alignment annotation
77 * - the description (tooltip) for the annotation
78 * - a closure (groovy function) that tests whether to include a residue
79 * - a closure that tests whether to increment count based on sequence features
81 def getColumnCounter = { name, desc, acceptResidue, acceptFeatures ->
84 getDescription: { desc },
85 getMinColour: { [0, 255, 255] }, // cyan
86 getMaxColour: { [0, 0, 255] }, // blue
90 if (acceptResidue.call(res))
92 if (acceptFeatures.call(feats))
103 * Define an annotation row that counts any residue with Pfam domain annotation
105 def pfamAnnotation = getColumnCounter("Pfam", "Count of residues with Pfam domain annotation", {true}, hasPfam)
108 * Define an annotation row that counts charged residues with Pfam domain annotation
110 def chargedPfamAnnotation = getColumnCounter("Pfam charged", "Count of charged residues with Pfam domain annotation", isCharged, hasPfam)
113 * Register the annotations
115 AlignmentAnnotationFactory.newCalculator(pfamAnnotation)
116 AlignmentAnnotationFactory.newCalculator(chargedPfamAnnotation)