X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=examples%2Fgroovy%2FcolourUnconserved.groovy;fp=examples%2Fgroovy%2FcolourUnconserved.groovy;h=68730f39325bf71d2a64f53dcb976f6b54636a65;hb=f063821ed0be9c1581af74643a1aa5798731af65;hp=0000000000000000000000000000000000000000;hpb=fd18e2c73cd015d4e38ad91da0e5d7532ff0ef42;p=jalview.git diff --git a/examples/groovy/colourUnconserved.groovy b/examples/groovy/colourUnconserved.groovy new file mode 100644 index 0000000..68730f3 --- /dev/null +++ b/examples/groovy/colourUnconserved.groovy @@ -0,0 +1,84 @@ +/* + * 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 java.awt.Color +import jalview.schemes.ColourSchemeI +import jalview.schemes.ColourSchemes +import jalview.datamodel.AnnotatedCollectionI +import jalview.datamodel.SequenceI +import jalview.datamodel.SequenceCollectionI +import jalview.util.Comparison + +/* + * Closure that defines a colour scheme where non-consensus residues are pink, + * other residues (and gaps) are white + */ +def unconserved +unconserved = { -> + [ + /* + * name shown in the colour menu + */ + getSchemeName: { -> 'Unconserved' }, + + /* + * to make a new instance for each alignment view + */ + getInstance: { AnnotatedCollectionI coll, Map map -> unconserved() }, + + /* + * method only needed if colour scheme has to recalculate + * values when an alignment is modified + */ + alignmentChanged: { AnnotatedCollectionI coll, Map map -> }, + + /* + * determine colour for a residue at an aligned position of a + * sequence, given consensus residue(s) for the column and the + * consensus percentage identity score for the column + */ + findColour: { char res, int col, SequenceI seq, String consensus, float pid -> + if ('a' <= res && res <= 'z') + { + res -= ('a' - 'A'); + } + if (Comparison.isGap(res) || consensus.contains(String.valueOf(res))) + { + Color.white + } else + { + Color.pink + } + }, + + /* + * true means applicable to nucleotide or peptide data + */ + isApplicableTo: {AnnotatedCollectionI coll -> true}, + + /* + * simple colour schemes are those that depend on the residue + * only (these are also available to colour structure viewers) + */ + isSimple: { false } + ] as ColourSchemeI +} + +ColourSchemes.instance.registerColourScheme(unconserved())