X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=examples%2Fgroovy%2FvisibleFeaturesCounter.groovy;h=510f60059a0040c761a028d626f8043b0cc3426d;hb=HEAD;hp=b3180f8e46870cac8b871e158af9decd2759f049;hpb=136c0793b90b72b928c4d77dc109dd5c644e00d3;p=jalview.git diff --git a/examples/groovy/visibleFeaturesCounter.groovy b/examples/groovy/visibleFeaturesCounter.groovy index b3180f8..510f600 100644 --- a/examples/groovy/visibleFeaturesCounter.groovy +++ b/examples/groovy/visibleFeaturesCounter.groovy @@ -1,38 +1,37 @@ /* * 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 + * 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 + * + * 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.bin.Jalview import jalview.workers.FeatureSetCounterI import jalview.workers.AlignmentAnnotationFactory /* * Demonstration of FeatureSetCounterI - * compute annotation tracks counting number of displayed + * compute annotation tracks counting number of displayed * features of each type in each column */ /* * discover features on the current view */ - -def featuresDisp=Jalview.currentAlignFrame.currentView.featuresDisplayed + +def featuresDisp=Jalview.getCurrentAlignFrame().currentView.featuresDisplayed if (featuresDisp == null) { print 'Need at least one feature visible on alignment' } @@ -40,12 +39,12 @@ def visibleFeatures=featuresDisp.visibleFeatures.toList() assert 'java.util.ArrayList' == visibleFeatures.class.name /* - * A closure that returns an array of features present + * A closure that returns an array of features present * for each feature type in visibleFeatures - * Argument 'features' will be a list of SequenceFeature + * Argument 'features' will be a list of SequenceFeature */ -def getCounts = - { features -> +def getCounts = + { features -> int[] obs = new int[visibleFeatures.size] for (sf in features) { @@ -56,9 +55,9 @@ def getCounts = * or sf.getValue(attributeName) for GFF 'column 9' properties */ int pos = 0 - for (type in visibleFeatures) + for (type in visibleFeatures) { - if (type.equals(sf.type)) + if (type.equals(sf.type)) { obs[pos]++ } @@ -67,19 +66,19 @@ def getCounts = } obs } - + /* * Define something that counts each visible feature type */ def columnSetCounter = [ - getNames: { visibleFeatures as String[] }, + getNames: { visibleFeatures as String[] }, getDescriptions: { visibleFeatures as String[] }, getMinColour: { [0, 255, 255] as int[] }, // cyan getMaxColour: { [0, 0, 255] as int[] }, // blue - count: - { res, feats -> - getCounts.call(feats) + count: + { res, feats -> + getCounts.call(feats) } ] as FeatureSetCounterI