2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
18 package jalview.schemes;
20 import java.awt.Color;
23 * ColourSchemeProperty Binds names to hardwired colourschemes and tries to deal
24 * intelligently with mapping unknown names to user defined colourschemes (that
25 * exist or can be created from the string representation of the colourscheme
26 * name - either a hex RGB triplet or a named colour under java.awt.color ). The
27 * values of the colourscheme constants is important for callers of
28 * getColourName(int i), since it can be used to enumerate the set of built in
29 * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
34 public class ColourSchemeProperty
36 /** Undefined Colourscheme Index */
37 public static final int UNDEFINED = -1;
39 /** for schemes defined on the fly */
40 public static final int USER_DEFINED = 0;
42 /** No Colourscheme Index */
43 public static final int NONE = 1;
46 public static final int CLUSTAL = 2;
49 public static final int BLOSUM = 3;
52 public static final int PID = 4;
55 public static final int ZAPPO = 5;
58 public static final int TAYLOR = 6;
61 public static final int HYDROPHOBIC = 7;
64 public static final int HELIX = 8;
67 public static final int STRAND = 9;
70 public static final int TURN = 10;
73 public static final int BURIED = 11;
76 public static final int NUCLEOTIDE = 12;
81 public static final int PURINEPYRIMIDINE = 13;
83 public static final int COVARIATION = 14;
85 public static final int TCOFFEE = 15;
89 * index of first colourscheme (includes 'None')
91 public static final int FIRST_COLOUR = NONE;
93 public static final int LAST_COLOUR = NUCLEOTIDE;
101 * @return DOCUMENT ME!
103 public static int getColourIndexFromName(String name)
107 if (name.equalsIgnoreCase("Clustal"))
111 else if (name.equalsIgnoreCase("Blosum62"))
115 else if (name.equalsIgnoreCase("% Identity"))
119 else if (name.equalsIgnoreCase("Zappo"))
123 else if (name.equalsIgnoreCase("Taylor"))
127 else if (name.equalsIgnoreCase("Hydrophobic"))
131 else if (name.equalsIgnoreCase("Helix Propensity"))
135 else if (name.equalsIgnoreCase("Strand Propensity"))
139 else if (name.equalsIgnoreCase("Turn Propensity"))
143 else if (name.equalsIgnoreCase("Buried Index"))
147 else if (name.equalsIgnoreCase("Nucleotide"))
151 else if (name.equalsIgnoreCase("T-Coffee scores"))
156 else if (name.equalsIgnoreCase("User Defined"))
160 else if (name.equalsIgnoreCase("None"))
174 * @return DOCUMENT ME!
176 public static String getColourName(ColourSchemeI cs)
181 if (cs instanceof ClustalxColourScheme)
185 else if (cs instanceof Blosum62ColourScheme)
189 else if (cs instanceof PIDColourScheme)
193 else if (cs instanceof ZappoColourScheme)
197 else if (cs instanceof TaylorColourScheme)
201 else if (cs instanceof HydrophobicColourScheme)
205 else if (cs instanceof HelixColourScheme)
209 else if (cs instanceof StrandColourScheme)
213 else if (cs instanceof TurnColourScheme)
217 else if (cs instanceof BuriedColourScheme)
221 else if (cs instanceof NucleotideColourScheme)
225 else if (cs instanceof UserColourScheme)
227 if ((((UserColourScheme) cs).getName() != null)
228 && (((UserColourScheme) cs).getName().length() > 0))
230 return ((UserColourScheme) cs).getName();
232 // get default colourscheme name
233 index = USER_DEFINED;
236 return getColourName(index);
245 * @return DOCUMENT ME!
247 public static String getColourName(int index)
283 ret = "Helix Propensity";
288 ret = "Strand Propensity";
293 ret = "Turn Propensity";
298 ret = "Buried Index";
308 ret = "User Defined";
329 * @return DOCUMENT ME!
331 public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al,
334 return getColour(al.getSequences(), al.getWidth(), name);
338 * retrieve or create colourscheme associated with name
341 * sequences to colour
343 * range of sequences to colour
345 * colourscheme name, applet colour parameter specification, or
346 * string to parse as colour for new coloursheme
347 * @return Valid Colourscheme
349 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
352 int colindex = getColourIndexFromName(name);
353 if (colindex == UNDEFINED)
355 if (name.indexOf('=') == -1)
357 // try to build a colour from the string directly
360 return new UserColourScheme(name);
361 } catch (Exception e)
363 // System.err.println("Ignoring unknown colourscheme name");
368 // try to parse the string as a residue colourscheme
371 // fix the launchApp user defined coloursheme transfer bug
372 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
374 ucs.parseAppletParameter(name);
376 } catch (Exception e)
378 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
382 return getColour(seqs, width, getColourIndexFromName(name));
386 * Construct an instance of ColourSchemeI corresponding to the given colourscheme index
389 * sequences to be coloured by colourscheme
391 * geometry of alignment
393 * colourscheme number
395 * @return null or an instance of the colourscheme configured to colour given sequence set
397 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
400 // TODO 3.0 2.8 refactor signature to take an alignmentI like container so colourschemes based on annotation can be initialised
401 ColourSchemeI cs = null;
406 cs = new ClustalxColourScheme(seqs, width);
411 cs = new Blosum62ColourScheme();
416 cs = new PIDColourScheme();
421 cs = new ZappoColourScheme();
426 cs = new TaylorColourScheme();
430 cs = new HydrophobicColourScheme();
435 cs = new HelixColourScheme();
440 cs = new StrandColourScheme();
445 cs = new TurnColourScheme();
450 cs = new BuriedColourScheme();
455 cs = new NucleotideColourScheme();
460 Color[] col = new Color[24];
461 for (int i = 0; i < 24; i++)
463 col[i] = Color.white;
465 cs = new UserColourScheme(col);
475 public static Color getAWTColorFromName(String name)
478 name = name.toLowerCase();
479 if (name.equals("black"))
483 else if (name.equals("blue"))
487 else if (name.equals("cyan"))
491 else if (name.equals("darkGray"))
493 col = Color.darkGray;
495 else if (name.equals("gray"))
499 else if (name.equals("green"))
503 else if (name.equals("lightGray"))
505 col = Color.lightGray;
507 else if (name.equals("magenta"))
511 else if (name.equals("orange"))
515 else if (name.equals("pink"))
519 else if (name.equals("red"))
523 else if (name.equals("white"))
527 else if (name.equals("yellow"))