JAL-2326 updated references of JOptionPane to JvOptionPane
[jalview.git] / examples / groovy / featureCounter.groovy
index 08d038d..9059dd0 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 import jalview.workers.FeatureCounterI;
 import jalview.workers.AlignmentAnnotationFactory;
 
@@ -5,8 +26,15 @@ 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
- * Modify this example as required to count by column any desired value that can be 
- * derived from the residue and sequence features at each position of an alignment.
+ *
+ * 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.
  */
 
 /*
@@ -42,14 +70,15 @@ def hasPfam = { features ->
 }
 
 /*
- * Closure that counts residues with a Pfam feature annotation
+ * 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, residueTester, featureCounter ->
+def getColumnCounter = { name, desc, acceptResidue, acceptFeatures ->
     [
      getName: { name }, 
      getDescription: { desc },
@@ -58,9 +87,9 @@ def getColumnCounter = { name, desc, residueTester, featureCounter ->
      count: 
          { res, feats -> 
             def c = 0
-            if (residueTester.call(res))
+            if (acceptResidue.call(res))
             {
-                if (featureCounter.call(feats))
+                if (acceptFeatures.call(feats))
                 {
                     c++
                 }
@@ -71,12 +100,12 @@ def getColumnCounter = { name, desc, residueTester, featureCounter ->
 }
 
 /*
- * Define annotation that counts any residue with Pfam domain annotation
+ * 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 annotation that counts charged residues with Pfam domain annotation
+ * 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)