From: gmungoc Date: Wed, 18 Jan 2017 15:36:36 +0000 (+0000) Subject: JAL-2228 removed FeatureCounterI in favour of FeatureSetCounterI with X-Git-Tag: Release_2_10_2~3^2~93^2~3 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=e811386cfe6d7ab7d73db56a31ac83732e185861 JAL-2228 removed FeatureCounterI in favour of FeatureSetCounterI with associated simplifications --- diff --git a/examples/groovy/FeatureSetCounter.groovy b/examples/groovy/FeatureSetCounter.groovy deleted file mode 100644 index 43f44a4..0000000 --- a/examples/groovy/FeatureSetCounter.groovy +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.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 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()) diff --git a/examples/groovy/featureCounter.groovy b/examples/groovy/featureCounter.groovy deleted file mode 100644 index 9059dd0..0000000 --- a/examples/groovy/featureCounter.groovy +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.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/examples/groovy/featuresCounter.groovy b/examples/groovy/featuresCounter.groovy new file mode 100644 index 0000000..ccbb830 --- /dev/null +++ b/examples/groovy/featuresCounter.groovy @@ -0,0 +1,48 @@ +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. + */ +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) diff --git a/examples/groovy/multipleFeatureAnnotations.groovy b/examples/groovy/multipleFeatureAnnotations.groovy deleted file mode 100644 index 592c7f5..0000000 --- a/examples/groovy/multipleFeatureAnnotations.groovy +++ /dev/null @@ -1,110 +0,0 @@ -import jalview.workers.AlignmentAnnotationFactory; -import jalview.workers.AnnotationProviderI; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.Annotation; -import jalview.util.ColorUtils; -import jalview.util.Comparison; -import java.awt.Color; - -/* - * 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. - */ - -/* - * A closure that returns true if value includes "PHOSPHORYLATION" - */ -def phosCounter = { type -> type.contains("PHOSPHORYLATION") } - -/* - * A closure that returns true if value includes "TURN" - */ -def turnCounter = { type -> type.contains("TURN") } - -/* - * A closure that computes and returns an array of Annotation values, - * one for each column of the alignment - */ -def getAnnotations(al, fr, counter) -{ - def width = al.width - def counts = new int[width] - def max = 0 - - /* - * count features in each column, record the maximum value - */ - for (col = 0 ; col < width ; col++) - { - def count = 0 - for (row = 0 ; row < al.height ; row++) - { - seq = al.getSequenceAt(row) - if (seq != null && col < seq.getLength()) - { - def res = seq.getCharAt(col) - if (!Comparison.isGap(res)) - { - pos = seq.findPosition(col) - features = fr.findFeaturesAtRes(seq, pos) - for (feature in features) - { - if (counter.call(feature.type)) - { - count++ - } - } - } - } - } - counts[col] = count - if (count > max) - { - max = count - } - } - - /* - * make the Annotation objects, with a graduated colour scale - * (from min value to max value) for the histogram bars - */ - def zero = '0' as char - def anns = new Annotation[width] - for (col = 0 ; col < width ; col++) - { - def c = counts[col] - if (c > 0) - { - Color color = ColorUtils.getGraduatedColour(c, 0, Color.cyan, - max, Color.blue) - anns[col] = AlignmentAnnotationFactory.newAnnotation(String.valueOf(c), - String.valueOf(c), zero, c, color) - } - } - anns -} - -/* - * Define the method that performs the calculations, and builds two - * AlignmentAnnotation objects - */ -def annotator = - [ calculateAnnotation: { al, fr -> - def phosAnns = getAnnotations(al, fr, phosCounter) - def ann1 = AlignmentAnnotationFactory.newAlignmentAnnotation("Phosphorylation", "Count of Phosphorylation features", phosAnns) - def turnAnns = getAnnotations(al, fr, turnCounter) - def ann2 = AlignmentAnnotationFactory.newAlignmentAnnotation("Turn", "Count of Turn features", turnAnns) - return [ann1, ann2] - } - ] as AnnotationProviderI - -/* - * Register the annotation calculator with Jalview - */ -AlignmentAnnotationFactory.newCalculator(annotator) diff --git a/examples/groovy/visibleFeaturesCounter.groovy b/examples/groovy/visibleFeaturesCounter.groovy new file mode 100644 index 0000000..b3180f8 --- /dev/null +++ b/examples/groovy/visibleFeaturesCounter.groovy @@ -0,0 +1,89 @@ +/* + * 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.bin.Jalview +import jalview.workers.FeatureSetCounterI +import jalview.workers.AlignmentAnnotationFactory + +/* + * Demonstration of FeatureSetCounterI + * 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 +if (featuresDisp == null) { + print 'Need at least one feature visible on alignment' +} +def visibleFeatures=featuresDisp.visibleFeatures.toList() +assert 'java.util.ArrayList' == visibleFeatures.class.name + +/* + * A closure that returns an array of features present + * for each feature type in visibleFeatures + * Argument 'features' will be a list of SequenceFeature + */ +def getCounts = + { features -> + int[] obs = new int[visibleFeatures.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 visibleFeatures) + { + if (type.equals(sf.type)) + { + obs[pos]++ + } + pos++ + } + } + obs +} + +/* + * Define something that counts each visible feature type + */ +def columnSetCounter = + [ + 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) + } + ] as FeatureSetCounterI + +/* + * and register the counter + */ +AlignmentAnnotationFactory.newCalculator(columnSetCounter) diff --git a/src/jalview/workers/AlignmentAnnotationFactory.java b/src/jalview/workers/AlignmentAnnotationFactory.java index 4e11c70..68c2295 100644 --- a/src/jalview/workers/AlignmentAnnotationFactory.java +++ b/src/jalview/workers/AlignmentAnnotationFactory.java @@ -1,6 +1,5 @@ package jalview.workers; -import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.bin.Jalview; import jalview.datamodel.AlignmentAnnotation; @@ -8,7 +7,6 @@ import jalview.datamodel.Annotation; import jalview.gui.AlignFrame; import java.awt.Color; -import java.lang.reflect.Method; /** * Factory class with methods which allow clients (including external scripts @@ -29,83 +27,17 @@ public class AlignmentAnnotationFactory * @param counter * provider of feature counts per alignment position */ - public static void newCalculator(ColumnCounterI counter) + public static void newCalculator(FeatureSetCounterI counter) { - // TODO need an interface for AlignFrame by which to access - // its AlignViewportI and AlignmentViewPanel AlignmentViewPanel currentAlignFrame = Jalview.getCurrentAlignFrame().alignPanel; - if (currentAlignFrame != null) - { - Method newCalcMethod = null; - try - { - for (Method m : AlignmentAnnotationFactory.class.getMethods()) - { - if (m.getName().equals("newCalculator")) - { - if (m.getParameterTypes().length == 3 - && m.getParameterTypes()[2].isInstance(counter)) - { - newCalcMethod = m; - break; - } - } - } - } catch (Exception q) - { - } - if (newCalcMethod == null) - { - - System.err - .println("Couldn't find a newCalculator method for ColumnCounterI type " - + counter.getClass().getName()); - } - try - { - newCalcMethod.invoke(null, currentAlignFrame.getAlignViewport(), - currentAlignFrame, counter); - } catch (Exception ie) - { - System.err - .println("Exception when reporting newCalculator method for ColumnCounterI type " - + counter.getClass().getName()); - } - } - else + if (currentAlignFrame == null) { System.err .println("Can't register calculator as no alignment window has focus"); + return; } - } - - /** - * Constructs and registers a new alignment annotation worker - * - * @param viewport - * @param panel - * @param counter - * provider of feature counts per alignment position - */ - public static void newCalculator(AlignViewportI viewport, - AlignmentViewPanel panel, FeatureCounterI counter) - { - new ColumnCounterWorker(viewport, panel, counter); - } - - /** - * Constructs and registers a new alignment annotation worker for a set of - * column counters - * - * @param viewport - * @param panel - * @param counter - * provider of feature counts per alignment position - */ - public static void newCalculator(AlignViewportI viewport, - AlignmentViewPanel panel, FeatureSetCounterI counter) - { - new ColumnCounterSetWorker(viewport, panel, counter); + new ColumnCounterSetWorker(currentAlignFrame.getAlignViewport(), + currentAlignFrame, counter); } /** @@ -116,13 +48,11 @@ public class AlignmentAnnotationFactory */ public static void newCalculator(AnnotationProviderI calculator) { - // TODO need an interface for AlignFrame by which to access - // its AlignViewportI and AlignmentViewPanel AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame(); if (currentAlignFrame != null) { - newCalculator(currentAlignFrame.getViewport(), currentAlignFrame - .getAlignPanels().get(0), calculator); + new AnnotationWorker(currentAlignFrame.getViewport(), + currentAlignFrame.getAlignPanels().get(0), calculator); } else { @@ -132,20 +62,6 @@ public class AlignmentAnnotationFactory } /** - * Constructs and registers a new alignment annotation worker - * - * @param viewport - * @param panel - * @param calculator - * provider of AlignmentAnnotation for the alignment - */ - public static void newCalculator(AlignViewportI viewport, - AlignmentViewPanel panel, AnnotationProviderI calculator) - { - new AnnotationWorker(viewport, panel, calculator); - } - - /** * Factory method to construct an Annotation object * * @param displayChar diff --git a/src/jalview/workers/ColumnCounterSetWorker.java b/src/jalview/workers/ColumnCounterSetWorker.java index cf6a229..e1cbd2a 100644 --- a/src/jalview/workers/ColumnCounterSetWorker.java +++ b/src/jalview/workers/ColumnCounterSetWorker.java @@ -140,6 +140,12 @@ class ColumnCounterSetWorker extends AlignCalcWorker { max[crow] = 0; } + + int[] minC = counter.getMinColour(); + int[] maxC = counter.getMaxColour(); + Color minColour = new Color(minC[0], minC[1], minC[2]); + Color maxColour = new Color(maxC[0], maxC[1], maxC[2]); + for (int col = 0; col < width; col++) { int[] count = counts[col]; @@ -175,8 +181,8 @@ class ColumnCounterSetWorker extends AlignCalcWorker int count = counts[i][anrow]; if (count > 0) { - Color color = ColorUtils.getGraduatedColour(count, 0, Color.cyan, - max[anrow], Color.blue); + Color color = ColorUtils.getGraduatedColour(count, 0, minColour, + max[anrow], maxColour); String str = String.valueOf(count); anns[i] = new Annotation(str, str, '0', count, color); } @@ -185,11 +191,11 @@ class ColumnCounterSetWorker extends AlignCalcWorker /* * construct or update the annotation */ + String description = counter.getDescriptions()[anrow]; AlignmentAnnotation ann = alignViewport.getAlignment() .findOrCreateAnnotation(counter.getNames()[anrow], - counter.getDescriptions()[anrow], false, null, - null); - ann.description = counter.getDescriptions()[anrow]; + description, false, null, null); + ann.description = description; ann.showAllColLabels = true; ann.scaleColLabel = true; ann.graph = AlignmentAnnotation.BAR_GRAPH; diff --git a/src/jalview/workers/ColumnCounterWorker.java b/src/jalview/workers/ColumnCounterWorker.java deleted file mode 100644 index 2f73cb5..0000000 --- a/src/jalview/workers/ColumnCounterWorker.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * 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. - */ -package jalview.workers; - -import jalview.api.AlignViewportI; -import jalview.api.AlignmentViewPanel; -import jalview.datamodel.AlignmentAnnotation; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.Annotation; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceI; -import jalview.renderer.seqfeatures.FeatureRenderer; -import jalview.util.ColorUtils; -import jalview.util.Comparison; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; - -/** - * A class to compute an alignment annotation with column counts of any - * properties of interest of positions in an alignment.
- * This is designed to be extensible, by supplying to the constructor an object - * that computes a count for each residue position, based on the residue value - * and any sequence features at that position. - * - */ -class ColumnCounterWorker extends AlignCalcWorker -{ - FeatureCounterI counter; - - /** - * Constructor registers the annotation for the given alignment frame - * - * @param af - * @param counter - */ - public ColumnCounterWorker(AlignViewportI viewport, - AlignmentViewPanel panel, FeatureCounterI counter) - { - super(viewport, panel); - ourAnnots = new ArrayList(); - this.counter = counter; - calcMan.registerWorker(this); - } - - /** - * method called under control of AlignCalcManager to recompute the annotation - * when the alignment changes - */ - @Override - public void run() - { - try - { - calcMan.notifyStart(this); - - while (!calcMan.notifyWorking(this)) - { - try - { - Thread.sleep(200); - } catch (InterruptedException ex) - { - ex.printStackTrace(); - } - } - if (alignViewport.isClosed()) - { - abortAndDestroy(); - return; - } - - if (alignViewport.getAlignment() != null) - { - try - { - computeAnnotations(); - } catch (IndexOutOfBoundsException x) - { - // probable race condition. just finish and return without any fuss. - return; - } - } - } catch (OutOfMemoryError error) - { - ap.raiseOOMWarning("calculating feature counts", error); - calcMan.disableWorker(this); - } finally - { - calcMan.workerComplete(this); - } - - if (ap != null) - { - ap.adjustAnnotationHeight(); - ap.paintAlignment(true); - } - - } - - /** - * Scan each column of the alignment to calculate a count by feature type. Set - * the count as the value of the alignment annotation for that feature type. - */ - void computeAnnotations() - { - FeatureRenderer fr = new FeatureRenderer(alignViewport); - // TODO use the commented out code once JAL-2075 is fixed - // to get adequate performance on genomic length sequence - AlignmentI alignment = alignViewport.getAlignment(); - // AlignmentView alignmentView = alignViewport.getAlignmentView(false); - // AlignmentI alignment = alignmentView.getVisibleAlignment(' '); - - // int width = alignmentView.getWidth(); - int width = alignment.getWidth(); - int height = alignment.getHeight(); - int[] counts = new int[width]; - int max = 0; - - for (int col = 0; col < width; col++) - { - int count = 0; - for (int row = 0; row < height; row++) - { - count += countFeaturesAt(alignment, col, row, fr); - } - counts[col] = count; - max = Math.max(count, max); - } - - Annotation[] anns = new Annotation[width]; - /* - * add non-zero counts as annotations - */ - for (int i = 0; i < counts.length; i++) - { - int count = counts[i]; - if (count > 0) - { - Color color = ColorUtils.getGraduatedColour(count, 0, Color.cyan, - max, Color.blue); - String str = String.valueOf(count); - anns[i] = new Annotation(str, str, '0', count, color); - } - } - - /* - * construct or update the annotation - */ - AlignmentAnnotation ann = alignViewport.getAlignment() - .findOrCreateAnnotation(counter.getName(), - counter.getDescription(), false, null, - null); - ann.description = counter.getDescription(); - ann.showAllColLabels = true; - ann.scaleColLabel = true; - ann.graph = AlignmentAnnotation.BAR_GRAPH; - ann.annotations = anns; - setGraphMinMax(ann, anns); - ann.validateRangeAndDisplay(); - if (!ourAnnots.contains(ann)) - { - ourAnnots.add(ann); - } - } - - /** - * Returns a count of any feature types present at the specified position of - * the alignment - * - * @param alignment - * @param col - * @param row - * @param fr - */ - int countFeaturesAt(AlignmentI alignment, int col, int row, - FeatureRenderer fr) - { - SequenceI seq = alignment.getSequenceAt(row); - if (seq == null) - { - return 0; - } - if (col >= seq.getLength()) - { - return 0;// sequence doesn't extend this far - } - char res = seq.getCharAt(col); - if (Comparison.isGap(res)) - { - return 0; - } - int pos = seq.findPosition(col); - - /* - * compute a count for any displayed features at residue - */ - // NB have to adjust pos if using AlignmentView.getVisibleAlignment - // see JAL-2075 - List features = fr.findFeaturesAtRes(seq, pos); - int count = this.counter.count(String.valueOf(res), features); - return count; - } - - /** - * Method called when the user changes display options that may affect how the - * annotation is rendered, but do not change its values. Currently no such - * options affect user-defined annotation, so this method does nothing. - */ - @Override - public void updateAnnotation() - { - // do nothing - } - - /** - * Answers true to indicate that if this worker's annotation is deleted from - * the display, the worker should also be removed. This prevents it running - * and recreating the annotation when the alignment changes. - */ - @Override - public boolean isDeletable() - { - return true; - } -} diff --git a/src/jalview/workers/FeatureCounterI.java b/src/jalview/workers/FeatureCounterI.java deleted file mode 100644 index 153f89f..0000000 --- a/src/jalview/workers/FeatureCounterI.java +++ /dev/null @@ -1,63 +0,0 @@ -package jalview.workers; - -import jalview.datamodel.SequenceFeature; - -import java.util.List; - -/** - * An interface for a type that returns counts of any value of interest at a - * sequence position that can be determined from the sequence character and any - * features present at that position - * - */ -public interface FeatureCounterI extends ColumnCounterI -{ - /** - * Returns a count of some property of interest, for example - *
    - *
  • the number of variant features at the position
  • - *
  • the number of Cath features of status 'True Positive'
  • - *
  • 1 if the residue is hydrophobic, else 0
  • - *
  • etc
  • - *
- * - * @param residue - * the residue (or gap) at the position - * @param a - * list of any sequence features which include the position - */ - int count(String residue, List features); - - /** - * Returns a name for the annotation that this is counting, for use as the - * displayed label - * - * @return - */ - String getName(); - - /** - * Returns a description for the annotation, for display as a tooltip - * - * @return - */ - String getDescription(); - - /** - * Returns the colour (as [red, green, blue] values in the range 0-255) to use - * for the minimum value on histogram bars. If this is different to - * getMaxColour(), then bars will have a graduated colour. - * - * @return - */ - int[] getMinColour(); - - /** - * Returns the colour (as [red, green, blue] values in the range 0-255) to use - * for the maximum value on histogram bars. If this is the same as - * getMinColour(), then bars will have a single colour (not graduated). - * - * @return - */ - int[] getMaxColour(); -} diff --git a/src/jalview/workers/FeatureSetCounterI.java b/src/jalview/workers/FeatureSetCounterI.java index a8cb059..3bbf8ec 100644 --- a/src/jalview/workers/FeatureSetCounterI.java +++ b/src/jalview/workers/FeatureSetCounterI.java @@ -36,7 +36,7 @@ import java.util.List; public interface FeatureSetCounterI extends ColumnCounterI { /** - * Returns a count of some property of interest, for example + * Returns counts of some properties of interest, for example *
    *
  • the number of variant features at the position
  • *
  • the number of Cath features of status 'True Positive'
  • @@ -52,15 +52,15 @@ public interface FeatureSetCounterI extends ColumnCounterI int[] count(String residue, List features); /** - * Returns a name for the annotation that this is counting, for use as the - * displayed label + * Returns names for the annotation that this is counting, for use as the + * displayed labels * * @return */ String[] getNames(); /** - * Returns a description for the annotation, for display as a tooltip + * Returns descriptions for the annotation, for display as tooltips * * @return */