2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.schemes;
23 import jalview.datamodel.AnnotatedCollectionI;
24 import jalview.datamodel.SequenceCollectionI;
25 import jalview.datamodel.SequenceGroup;
26 import jalview.datamodel.SequenceI;
28 import java.awt.Color;
32 * Base class for residue-based colour schemes
34 public abstract class ResidueColourScheme implements ColourSchemeI
36 public static final String NONE = "None";
39 * default display name for a user defined colour scheme
41 public static final String USER_DEFINED = "User Defined";
44 * name for (new) "User Defined.." colour scheme menu item
46 public static final String USER_DEFINED_MENU = "*User Defined*";
49 * the canonical name of the annotation colour scheme
50 * (may be used to identify it in menu items)
52 public static final String ANNOTATION_COLOUR = "Annotation";
55 * lookup up by character value e.g. 'G' to the colors array index
56 * e.g. if symbolIndex['K'] = 11 then colors[11] is the colour for K
58 final int[] symbolIndex;
61 * colour for residue characters as indexed by symbolIndex
63 Color[] colors = null;
65 /* Set when threshold colouring to either pid_gaps or pid_nogaps */
66 protected boolean ignoreGaps = false;
69 * Creates a new ResidueColourScheme object.
72 * int[] index table into colors (ResidueProperties.naIndex or
73 * ResidueProperties.aaIndex)
75 * colours for symbols in sequences
77 public ResidueColourScheme(int[] aaOrnaIndex, Color[] colours)
79 symbolIndex = aaOrnaIndex;
80 this.colors = colours;
84 * Creates a new ResidueColourScheme object with a lookup table for indexing
87 public ResidueColourScheme(int[] aaOrNaIndex)
89 symbolIndex = aaOrNaIndex;
93 * Creates a new ResidueColourScheme object - default constructor for
94 * non-sequence dependent colourschemes
96 public ResidueColourScheme()
102 * Find a colour without an index in a sequence
104 public Color findColour(char c)
106 Color colour = Color.white;
108 if (colors != null && symbolIndex != null && c < symbolIndex.length
109 && symbolIndex[c] < colors.length)
111 colour = colors[symbolIndex[c]];
118 * Default is to call the overloaded method that ignores consensus. A colour
119 * scheme that depends on consensus (for example, Blosum62), should override
120 * this method instead.
123 public Color findColour(char c, int j, SequenceI seq,
124 String consensusResidue, float pid)
126 return findColour(c, j, seq);
130 * Default implementation looks up the residue colour in a fixed scheme, or
131 * returns White if not found. Override this method for a colour scheme that
132 * depends on the column position or sequence.
139 protected Color findColour(char c, int j, SequenceI seq)
141 return findColour(c);
145 public void alignmentChanged(AnnotatedCollectionI alignment,
146 Map<SequenceI, SequenceCollectionI> hiddenReps)
151 * Answers false if the colour scheme is nucleotide or peptide specific, and
152 * the data does not match, else true. Override to modify or extend this test
156 public boolean isApplicableTo(AnnotatedCollectionI ac)
158 if (!isPeptideSpecific() && !isNucleotideSpecific())
167 * pop-up menu on selection group before group created
168 * (no alignment context)
170 // TODO: add nucleotide flag to SequenceGroup?
171 if (ac instanceof SequenceGroup && ac.getContext() == null)
177 * inspect the data context (alignment) for residue type
179 boolean nucleotide = ac.isNucleotide();
182 * does data type match colour scheme type?
184 return (nucleotide && isNucleotideSpecific())
185 || (!nucleotide && isPeptideSpecific());
189 * Answers true if the colour scheme is normally only for peptide data
193 public boolean isPeptideSpecific()
199 * Answers true if the colour scheme is normally only for nucleotide data
203 public boolean isNucleotideSpecific()
209 * Default method returns true. Override this to return false in colour
210 * schemes that are not determined solely by the sequence symbol.
213 public boolean isSimple()
219 * Default method returns false. Override this to return true in colour
220 * schemes that have a colour associated with gap residues.
223 public boolean hasGapColour()