--- /dev/null
+/*
+ * 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.FeatureSetCounterI;
+import jalview.workers.AlignmentAnnotationFactory;
+
+/*
+ * Demonstration of FeatureSetWorker
+ * compute annotation tracks counting number of displayed
+ * features of each type in each column
+ */
+
+/*
+ * discover features on the current view
+ */
+
+def featuresVis=jalview.bin.Jalview.currentAlignFrame.getCurrentView().getFeaturesDisplayed().getVisibleFeatures().toList();
+assert 'java.util.ArrayList' == featuresVis.class.name
+
+/*
+ * A closure that returns a vector for featuresVis of 1 or 0 for any features of type observed
+ * Argument should be a list of SequenceFeature
+ */
+def hasType = { features ->
+ int[] obs=new int[featuresVis.size()];
+ 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
+ */
+ int pos = 0;
+ for (type in featuresVis) {
+ if (type.equals(sf.type)) {
+ obs[pos]=1;
+ } else {
+ obs[pos]=0;
+ }
+ pos++;
+ }
+ }
+ obs;
+ }
+
+/*
+ * Closure to generate a counter for feature types in featuresVis
+ * calls hasType to count types in the int[] count(String res, List<SequenceFeature> feats) method
+ */
+def getColumnSetCounter = {
+ [
+ getNames: { featuresVis as String[] },
+ getDescriptions: { featuresVis as String[] },
+ getMinColour: { [0, 255, 255] }, // cyan
+ getMaxColour: { [0, 0, 255] }, // blue
+ count:
+ { res, feats ->
+ hasType.call(feats)
+ }
+ ] as FeatureSetCounterI }
+
+/*
+ * and register a FeatuerSetCounter instance
+ */
+AlignmentAnnotationFactory.newCalculator(getColumnSetCounter.call())