From e1f743ce6752c9182e2ea38928fc6aedf150ec42 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Fri, 12 May 2017 14:29:28 +0100 Subject: [PATCH] JAL-2228 updated script in help docs, renamed docs, and added note about non-backwards compatibility of feature counter script --- examples/groovy/featuresCounter.groovy | 25 +++ help/help.jhm | 2 +- help/helpTOC.xml | 3 +- help/html/features/groovy.html | 2 +- help/html/groovy/featureCounter.html | 269 -------------------------------- help/html/groovy/featuresCounter.html | 123 +++++++++++++++ 6 files changed, 152 insertions(+), 272 deletions(-) delete mode 100644 help/html/groovy/featureCounter.html create mode 100644 help/html/groovy/featuresCounter.html diff --git a/examples/groovy/featuresCounter.groovy b/examples/groovy/featuresCounter.groovy index ccbb830..dc4c97c 100644 --- a/examples/groovy/featuresCounter.groovy +++ b/examples/groovy/featuresCounter.groovy @@ -1,3 +1,24 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ + import jalview.workers.AlignmentAnnotationFactory; import jalview.workers.FeatureSetCounterI; @@ -10,7 +31,11 @@ import jalview.workers.FeatureSetCounterI; * * The script only needs to be run once - it will be registered by Jalview * and recalculated automatically when the alignment changes. + * + * Note: The feature api provided by 2.10.2 is not compatible with scripts + * that worked with earlier Jalview versions. Apologies for the inconvenience. */ + def annotator = [ getNames: { ['Phosphorylation', 'Turn'] as String[] }, diff --git a/help/help.jhm b/help/help.jhm index 984c2d1..d86faf1 100755 --- a/help/help.jhm +++ b/help/help.jhm @@ -130,7 +130,7 @@ - + diff --git a/help/helpTOC.xml b/help/helpTOC.xml index 482ccdf..6e7f5ac 100755 --- a/help/helpTOC.xml +++ b/help/helpTOC.xml @@ -24,6 +24,7 @@ + @@ -157,7 +158,7 @@ - + diff --git a/help/html/features/groovy.html b/help/html/features/groovy.html index 254f92e..d9bf76e 100644 --- a/help/html/features/groovy.html +++ b/help/html/features/groovy.html @@ -108,7 +108,7 @@ print currentAlFrame.getTitle(); simplified the alignment analysis programming interface in Jalview 2.10 to make it easy for you to add your own dynamic annotation tracks with Groovy. Have a look at the featureCounter.groovy + href="../groovy/featuresCounter.html">featuresCounter.groovy example for more information.

diff --git a/help/html/groovy/featureCounter.html b/help/html/groovy/featureCounter.html deleted file mode 100644 index 2ebaf45..0000000 --- a/help/html/groovy/featureCounter.html +++ /dev/null @@ -1,269 +0,0 @@ - - - -Extending Jalview with Groovy - Feature Counter Example - - -

- Extending Jalview with Groovy - A customisable - feature counter

The groovy script below shows how to - add a new calculation track to a Jalview alignment window. -

-

As currently written, it will add two tracks to a protein - alignment view which count Pfam features in each column, and ones - where a charge residue also occur.

-

To try it for yourself:

-
    -
  1. Copy and paste it into the groovy script console
  2. -
  3. Load the example Feredoxin project (the one that opens by - default when you first launched Jalview)
  4. -
  5. Select Calculations→Execute Groovy - Script from the alignment window's menu bar to run the script on - the current view. -
  6. -
- http://www.jalview.org/examples/groovy/featureCounter.groovy - - rendered with hilite.me - -
-
-/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.10)
- * Copyright (C) 2016 The Jalview Authors
- * 
- * This file is part of Jalview.
- * 
- * Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3
- * of the License, or (at your option) any later version.
- *  
- * Jalview is distributed in the hope that it will be useful, but 
- * WITHOUT ANY WARRANTY; without even the implied warranty 
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
- * PURPOSE.  See the GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU General Public License
- * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
- * The Jalview Authors are detailed in the 'AUTHORS' file.
- */
- 
-import jalview.workers.FeatureCounterI;
-import jalview.workers.AlignmentAnnotationFactory;
-
-/*
- * Example script that registers two alignment annotation calculators
- * - one that counts residues in a column with Pfam annotation
- * - one that counts only charged residues with Pfam annotation
- *
- * To try:
- * 1. load uniref50.fa from the examples folder
- * 2. load features onto it from from examples/exampleFeatures.txt
- * 3. Open this script in the Groovy console.
- * 4. Either execute this script from the console, or via Calculate->Run Groovy Script
- 
- * To explore further, try changing this script to count other kinds of occurrences of 
- * residue and sequence features at columns in an alignment.
- */
-
-/*
- * A closure that returns true for any Charged residue
- */
-def isCharged = { residue ->
-    switch(residue) {
-        case ['D', 'd', 'E', 'e', 'H', 'h', 'K', 'k', 'R', 'r']:
-            return true
-    }
-    false
-} 
-
-/*
- * A closure that returns 1 if sequence features include type 'Pfam', else 0
- * Argument should be a list of SequenceFeature 
- */
-def hasPfam = { features -> 
-    for (sf in features)
-    {
-        /*
-         * Here we inspect the type of the sequence feature.
-         * You can also test sf.description, sf.score, sf.featureGroup,
-         * sf.strand, sf.phase, sf.begin, sf.end
-         * or sf.getValue(attributeName) for GFF 'column 9' properties
-         */
-        if ("Pfam".equals(sf.type))
-        {
-            return true
-        }
-    }
-    false
-}
-
-/*
- * Closure that computes an annotation based on 
- * presence of particular residues and features
- * Parameters are
- * - the name (label) for the alignment annotation
- * - the description (tooltip) for the annotation
- * - a closure (groovy function) that tests whether to include a residue
- * - a closure that tests whether to increment count based on sequence features  
- */
-def getColumnCounter = { name, desc, acceptResidue, acceptFeatures ->
-    [
-     getName: { name }, 
-     getDescription: { desc },
-     getMinColour: { [0, 255, 255] }, // cyan
-     getMaxColour: { [0, 0, 255] }, // blue
-     count: 
-         { res, feats -> 
-            def c = 0
-            if (acceptResidue.call(res))
-            {
-                if (acceptFeatures.call(feats))
-                {
-                    c++
-                }
-            }
-            c
-         }
-     ] as FeatureCounterI
-}
-
-/*
- * Define an annotation row that counts any residue with Pfam domain annotation
- */
-def pfamAnnotation = getColumnCounter("Pfam", "Count of residues with Pfam domain annotation", {true}, hasPfam)
-
-/*
- * Define an annotation row that counts charged residues with Pfam domain annotation
- */
-def chargedPfamAnnotation = getColumnCounter("Pfam charged", "Count of charged residues with Pfam domain annotation", isCharged, hasPfam)
-
-/*
- * Register the annotations
- */
-AlignmentAnnotationFactory.newCalculator(pfamAnnotation) 
-AlignmentAnnotationFactory.newCalculator(chargedPfamAnnotation)
-
-
- - diff --git a/help/html/groovy/featuresCounter.html b/help/html/groovy/featuresCounter.html new file mode 100644 index 0000000..3b6705b --- /dev/null +++ b/help/html/groovy/featuresCounter.html @@ -0,0 +1,123 @@ + + + +Extending Jalview with Groovy - Feature Counter Example + + +

+ Extending Jalview with Groovy - A customisable + feature counter

The groovy script below shows how to + add a new calculation track to a Jalview alignment window. +

+

As currently written, it will add two tracks to a protein + alignment view which count Pfam features in each column, and ones + where a charge residue also occur.

+

To try it for yourself:

+
    +
  1. Copy and paste it into the groovy script console
  2. +
  3. Load the example Feredoxin project (the one that opens by + default when you first launched Jalview)
  4. +
  5. Select Calculations→Execute Groovy + Script from the alignment window's menu bar to run the script on + the current view. +
  6. +
+ Please note: The 2.10.2 feature counting interface is not compatible with earlier versions.

+ http://www.jalview.org/examples/groovy/featuresCounter.groovy + - rendered with hilite.me +
/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+
+import jalview.workers.AlignmentAnnotationFactory;
+import jalview.workers.FeatureSetCounterI;
+
+/*
+ * Example script to compute two alignment annotations
+ * - count of Phosphorylation features
+ * - count of Turn features
+ * To try this, first load example file uniref50.fa and load on features file
+ * exampleFeatures.txt, before running this script
+ *
+ * The script only needs to be run once - it will be registered by Jalview
+ * and recalculated automatically when the alignment changes.
+ * 
+ * Note: The feature api provided by 2.10.2 is not compatible with scripts
+ * that worked with earlier Jalview versions. Apologies for the inconvenience.
+ */
+ 
+def annotator = 
+    [
+     getNames: { ['Phosphorylation', 'Turn'] as String[] }, 
+     getDescriptions:  { ['Count of Phosphorylation features', 'Count of Turn features'] as String[] },
+     getMinColour: { [0, 255, 255] as int[] }, // cyan
+     getMaxColour: { [0, 0, 255] as int[] }, // blue
+     count: 
+         { res, feats -> 
+                int phos
+                int turn
+                for (sf in feats)
+                {
+ 		          /*
+		           * Here we inspect the type of the sequence feature.
+		           * You can also test sf.description, sf.score, sf.featureGroup,
+		           * sf.strand, sf.phase, sf.begin, sf.end
+		           * or sf.getValue(attributeName) for GFF 'column 9' properties
+		           */
+		           if (sf.type.contains('TURN'))
+                   {
+                      turn++
+                   }
+                   if (sf.type.contains('PHOSPHORYLATION'))
+                   {
+                      phos++
+                   }
+                }
+                [phos, turn] as int[]
+         }
+     ] as FeatureSetCounterI
+    
+/*
+ * Register the annotation calculator with Jalview
+ */
+AlignmentAnnotationFactory.newCalculator(annotator) 
+
+ + -- 1.7.10.2