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 * lookup up by character value e.g. 'G' to the colors array index
50 * e.g. if symbolIndex['K'] = 11 then colors[11] is the colour for K
52 final int[] symbolIndex;
55 * colour for residue characters as indexed by symbolIndex
57 Color[] colors = null;
59 /* Set when threshold colouring to either pid_gaps or pid_nogaps */
60 protected boolean ignoreGaps = false;
63 * Creates a new ResidueColourScheme object.
66 * int[] index table into colors (ResidueProperties.naIndex or
67 * ResidueProperties.aaIndex)
69 * colours for symbols in sequences
71 public ResidueColourScheme(int[] aaOrnaIndex, Color[] colours)
73 symbolIndex = aaOrnaIndex;
74 this.colors = colours;
78 * Creates a new ResidueColourScheme object with a lookup table for indexing
81 public ResidueColourScheme(int[] aaOrNaIndex)
83 symbolIndex = aaOrNaIndex;
87 * Creates a new ResidueColourScheme object - default constructor for
88 * non-sequence dependent colourschemes
90 public ResidueColourScheme()
96 public Color findColour(char c)
98 Color colour = Color.white;
100 if (colors != null && symbolIndex != null && c < symbolIndex.length
101 && symbolIndex[c] < colors.length)
103 colour = colors[symbolIndex[c]];
110 * Default is to call the overloaded method that ignores consensus. A colour
111 * scheme that depends on consensus (for example, Blosum62), should override
112 * this method instead.
115 public Color findColour(char c, int j, SequenceI seq,
116 String consensusResidue, float pid)
118 return findColour(c, j, seq);
122 * Default implementation looks up the residue colour in a fixed scheme, or
123 * returns White if not found. Override this method for a colour scheme that
124 * depends on the column position or sequence.
131 protected Color findColour(char c, int j, SequenceI seq)
133 return findColour(c);
137 public void alignmentChanged(AnnotatedCollectionI alignment,
138 Map<SequenceI, SequenceCollectionI> hiddenReps)
143 * Answers false if the colour scheme is nucleotide or peptide specific, and
144 * the data does not match, else true. Override to modify or extend this test
148 public boolean isApplicableTo(AnnotatedCollectionI ac)
150 if (!isPeptideSpecific() && !isNucleotideSpecific())
159 * pop-up menu on selection group before group created
160 * (no alignment context)
162 // TODO: add nucleotide flag to SequenceGroup?
163 if (ac instanceof SequenceGroup && ac.getContext() == null)
169 * inspect the data context (alignment) for residue type
171 boolean nucleotide = ac.isNucleotide();
174 * does data type match colour scheme type?
176 return (nucleotide && isNucleotideSpecific())
177 || (!nucleotide && isPeptideSpecific());
181 * Answers true if the colour scheme is normally only for peptide data
185 public boolean isPeptideSpecific()
191 * Answers true if the colour scheme is normally only for nucleotide data
195 public boolean isNucleotideSpecific()
201 * Default method returns true. Override this to return false in colour
202 * schemes that are not determined solely by the sequence symbol.
205 public boolean isSimple()
211 * Default method returns false. Override this to return true in colour
212 * schemes that have a colour associated with gap residues.
215 public boolean hasGapColour()