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.SequenceI;
26 import jalview.util.ColorUtils;
28 import java.awt.Color;
30 import java.util.StringTokenizer;
32 public class UserColourScheme extends ResidueColourScheme
34 Color[] lowerCaseColours;
36 protected String schemeName;
38 public UserColourScheme()
40 super(ResidueProperties.aaIndex);
43 public UserColourScheme(Color[] newColors)
45 super(ResidueProperties.aaIndex);
50 public ColourSchemeI applyTo(AnnotatedCollectionI sg,
51 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
53 UserColourScheme usc = new UserColourScheme(colors);
54 if (lowerCaseColours != null)
56 usc.schemeName = new String(schemeName);
57 usc.lowerCaseColours = new Color[lowerCaseColours.length];
58 System.arraycopy(lowerCaseColours, 0, usc.lowerCaseColours, 0,
59 lowerCaseColours.length);
64 public UserColourScheme(String colour)
66 super(ResidueProperties.aaIndex);
67 Color col = ColorUtils.parseColourString(colour);
71 System.out.println("Making colour from name: " + colour);
72 col = ColorUtils.createColourFromName(colour);
75 colors = new Color[24];
76 for (int i = 0; i < 24; i++)
83 public Color[] getColours()
88 public Color[] getLowerCaseColours()
90 return lowerCaseColours;
93 public void setName(String name)
98 public String getName()
104 * Parse and save residue colours specified as (for example)
107 * D,E=red; K,R,H=0022FF; c=100,50,75
110 * This should be a semi-colon separated list of colours, which may be defined
111 * by colour name, hex value or comma-separated RGB triple. Each colour is
112 * defined for a comma-separated list of amino acid single letter codes. (Note
113 * that this also allows a colour scheme to be defined for ACGT, but not for
118 public void parseAppletParameter(String paramValue)
120 // TODO: need a function to generate appletParameter colour string from a
122 StringTokenizer st = new StringTokenizer(paramValue, ";");
124 String token = null, colour, residues;
127 while (st.hasMoreElements())
129 token = st.nextToken().trim();
130 residues = token.substring(0, token.indexOf("="));
131 colour = token.substring(token.indexOf("=") + 1);
133 st2 = new StringTokenizer(residues, " ,");
134 while (st2.hasMoreTokens())
136 String residue = st2.nextToken();
138 int colIndex = ResidueProperties.aaIndex[residue.charAt(0)];
144 if (residue.equalsIgnoreCase("lowerCase"))
146 if (lowerCaseColours == null)
148 lowerCaseColours = new Color[23];
150 for (int i = 0; i < 23; i++)
152 if (lowerCaseColours[i] == null)
154 lowerCaseColours[i] = ColorUtils.parseColourString(colour);
161 if (residue.equals(residue.toLowerCase()))
163 if (lowerCaseColours == null)
165 lowerCaseColours = new Color[23];
167 lowerCaseColours[colIndex] = ColorUtils.parseColourString(colour);
171 colors[colIndex] = ColorUtils.parseColourString(colour);
175 } catch (Exception ex)
177 System.out.println("Error parsing userDefinedColours:\n" + token
184 public Color findColour(char c, int j, SequenceI seq)
187 int index = ResidueProperties.aaIndex[c];
189 if ((threshold == 0) || aboveThreshold(c, j))
191 if (lowerCaseColours != null && 'a' <= c && c <= 'z')
193 currentColour = lowerCaseColours[index];
197 currentColour = colors[index];
202 currentColour = Color.white;
205 if (conservationColouring)
207 currentColour = applyConservation(currentColour, j);
210 return currentColour;
213 public void setLowerCaseColours(Color[] lcolours)
215 lowerCaseColours = lcolours;
219 * Returns the colour for the given residue character. If the residue is
220 * lower-case, and there is a specific colour defined for lower case, that
221 * colour is returned, else the colour for the upper case residue.
224 public Color findColour(char c)
226 if ('a' <= c && c <= 'z' && lowerCaseColours != null)
228 Color colour = lowerCaseColours[symbolIndex[c]];
234 return super.findColour(c);
238 * Answers the customised name of the colour scheme, if it has one, else
242 public String getSchemeName()
244 if (schemeName != null && schemeName.length() > 0)
248 return JalviewColourScheme.UserDefined.toString();