X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=examples%2Fgroovy%2FfeatureCounter.groovy;h=42d3187fa95bb4ca18522781d79f844820542672;hb=aa942b856b678f7461f041850495698a46e9c7c7;hp=08d038de75eabfa6dd32b2c15d83b8334a841716;hpb=32cb25af86f1710205b6fdca0df00aed0a0211bb;p=jalview.git diff --git a/examples/groovy/featureCounter.groovy b/examples/groovy/featureCounter.groovy index 08d038d..42d3187 100644 --- a/examples/groovy/featureCounter.groovy +++ b/examples/groovy/featureCounter.groovy @@ -5,6 +5,9 @@ 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 this, first load uniref50.fa from the examples folder, then load features + * from examples/exampleFeatures.txt, before running this script from the Groovy console. + * 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. */ @@ -49,7 +52,7 @@ def hasPfam = { features -> * - 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 +61,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 +74,12 @@ def getColumnCounter = { name, desc, residueTester, featureCounter -> } /* - * Define annotation that counts any residue with Pfam domain annotation + * Define an annotation 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 that counts charged residues with Pfam domain annotation */ def chargedPfamAnnotation = getColumnCounter("Pfam charged", "Count of charged residues with Pfam domain annotation", isCharged, hasPfam)