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;
27 import jalview.util.Comparison;
29 import java.awt.Color;
33 * Base class for residue-based colour schemes
35 public abstract class ResidueColourScheme implements ColourSchemeI
37 public static final String NONE = "None";
39 public static final String USER_DEFINED = "User Defined";
42 * lookup up by character value e.g. 'G' to the colors array index
43 * e.g. if symbolIndex['K'] = 11 then colors[11] is the colour for K
45 final int[] symbolIndex;
48 * colour for residue characters as indexed by symbolIndex
50 Color[] colors = null;
52 /* Set when threshold colouring to either pid_gaps or pid_nogaps */
53 protected boolean ignoreGaps = false;
56 * Creates a new ResidueColourScheme object.
58 * @param final int[] index table into colors (ResidueProperties.naIndex or
59 * ResidueProperties.aaIndex)
61 * colours for symbols in sequences
63 public ResidueColourScheme(int[] aaOrnaIndex, Color[] colours)
65 symbolIndex = aaOrnaIndex;
66 this.colors = colours;
70 * Creates a new ResidueColourScheme object with a lookup table for indexing
73 public ResidueColourScheme(int[] aaOrNaIndex)
75 symbolIndex = aaOrNaIndex;
79 * Creates a new ResidueColourScheme object - default constructor for
80 * non-sequence dependent colourschemes
82 public ResidueColourScheme()
88 * Find a colour without an index in a sequence
90 public Color findColour(char c)
92 Color colour = Color.white;
94 if (!Comparison.isGap(c) && colors != null && symbolIndex != null
95 && c < symbolIndex.length
96 && symbolIndex[c] < colors.length)
98 colour = colors[symbolIndex[c]];
105 * Default is to call the overloaded method that ignores consensus. A colour
106 * scheme that depends on consensus (for example, Blosum62), should override
107 * this method instead.
110 public Color findColour(char c, int j, SequenceI seq,
111 String consensusResidue, float pid)
113 return findColour(c, j, seq);
117 * Default implementation looks up the residue colour in a fixed scheme, or
118 * returns White if not found. Override this method for a colour scheme that
119 * depends on the column position or sequence.
126 protected Color findColour(char c, int j, SequenceI seq)
128 return findColour(c);
132 public void alignmentChanged(AnnotatedCollectionI alignment,
133 Map<SequenceI, SequenceCollectionI> hiddenReps)
138 * Answers false if the colour scheme is nucleotide or peptide specific, and
139 * the data does not match, else true. Override to modify or extend this test
143 public boolean isApplicableTo(AnnotatedCollectionI ac)
145 if (!isPeptideSpecific() && !isNucleotideSpecific())
154 * pop-up menu on selection group before group created
155 * (no alignment context)
157 // TODO: add nucleotide flag to SequenceGroup?
158 if (ac instanceof SequenceGroup && ac.getContext() == null)
164 * inspect the data context (alignment) for residue type
166 boolean nucleotide = ac.isNucleotide();
169 * does data type match colour scheme type?
171 return (nucleotide && isNucleotideSpecific())
172 || (!nucleotide && isPeptideSpecific());
176 * Answers true if the colour scheme is normally only for peptide data
180 public boolean isPeptideSpecific()
186 * Answers true if the colour scheme is normally only for nucleotide data
190 public boolean isNucleotideSpecific()
196 * Default method returns true. Override this to return false in colour
197 * schemes that are not determined solely by the sequence symbol.
200 public boolean isSimple()