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.AlignmentI;
24 import jalview.datamodel.AnnotatedCollectionI;
25 import jalview.datamodel.SequenceCollectionI;
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";
38 public static final String USER_DEFINED = "User Defined";
41 * lookup up by character value e.g. 'G' to the colors array index
42 * e.g. if symbolIndex['K'] = 11 then colors[11] is the colour for K
44 final int[] symbolIndex;
47 * colour for residue characters as indexed by symbolIndex
49 Color[] colors = null;
51 /* Set when threshold colouring to either pid_gaps or pid_nogaps */
52 protected boolean ignoreGaps = false;
55 * Creates a new ResidueColourScheme object.
57 * @param final int[] index table into colors (ResidueProperties.naIndex or
58 * ResidueProperties.aaIndex)
60 * colours for symbols in sequences
62 public ResidueColourScheme(int[] aaOrnaIndex, Color[] colours)
64 symbolIndex = aaOrnaIndex;
65 this.colors = colours;
69 * Creates a new ResidueColourScheme object with a lookup table for indexing
72 public ResidueColourScheme(int[] aaOrNaIndex)
74 symbolIndex = aaOrNaIndex;
78 * Creates a new ResidueColourScheme object - default constructor for
79 * non-sequence dependent colourschemes
81 public ResidueColourScheme()
87 * Find a colour without an index in a sequence
90 public Color findColour(char c)
92 return colors == null ? Color.white : colors[symbolIndex[c]];
96 * Default is to call the overloaded method that ignores consensus. A colour
97 * scheme that depends on consensus (for example, Blosum62), should override
98 * this method instead.
101 public Color findColour(char c, int j, SequenceI seq,
102 String consensusResidue, float pid)
104 return findColour(c, j, seq);
107 protected Color findColour(char c, int j, SequenceI seq)
109 Color colour = Color.white;
111 if (colors != null && symbolIndex != null && c < symbolIndex.length
112 && symbolIndex[c] < colors.length)
114 colour = colors[symbolIndex[c]];
116 // colour = adjustColour(c, j, colour);
122 public void alignmentChanged(AnnotatedCollectionI alignment,
123 Map<SequenceI, SequenceCollectionI> hiddenReps)
128 * Answers false if the colour scheme is nucleotide or peptide specific, and
129 * the data does not match, else true. Override to modify or extend this test
133 public boolean isApplicableTo(AnnotatedCollectionI ac)
135 if (!isPeptideSpecific() && !isNucleotideSpecific())
141 * inspect the data context (alignment) for residue type
143 boolean nucleotide = false;
144 if (ac instanceof AlignmentI)
146 nucleotide = ((AlignmentI) ac).isNucleotide();
150 AnnotatedCollectionI context = ac.getContext();
151 if (context instanceof AlignmentI)
153 nucleotide = ((AlignmentI) context).isNucleotide();
157 // not sure what's going on, play safe
163 * does data type match colour scheme type?
165 return (nucleotide && isNucleotideSpecific())
166 || (!nucleotide && isPeptideSpecific());
170 * Answers true if the colour scheme is normally only for peptide data
174 public boolean isPeptideSpecific()
180 * Answers true if the colour scheme is normally only for nucleotide data
184 public boolean isNucleotideSpecific()
190 * Default method returns true. Override this to return false in colour
191 * schemes that are not determined solely by the sequence symbol.
194 public boolean isSimple()