2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, 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"))
164 else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
166 ret = PURINEPYRIMIDINE;
168 // else if (name.equalsIgnoreCase("Covariation"))
170 // ret = COVARIATION;
182 * @return DOCUMENT ME!
184 public static String getColourName(ColourSchemeI cs)
189 if (cs instanceof ClustalxColourScheme)
193 else if (cs instanceof Blosum62ColourScheme)
197 else if (cs instanceof PIDColourScheme)
201 else if (cs instanceof ZappoColourScheme)
205 else if (cs instanceof TaylorColourScheme)
209 else if (cs instanceof HydrophobicColourScheme)
213 else if (cs instanceof HelixColourScheme)
217 else if (cs instanceof StrandColourScheme)
221 else if (cs instanceof TurnColourScheme)
225 else if (cs instanceof BuriedColourScheme)
229 else if (cs instanceof NucleotideColourScheme)
233 else if (cs instanceof PurinePyrimidineColourScheme)
235 index = PURINEPYRIMIDINE;
238 * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
240 else if (cs instanceof UserColourScheme)
242 if ((((UserColourScheme) cs).getName() != null)
243 && (((UserColourScheme) cs).getName().length() > 0))
245 return ((UserColourScheme) cs).getName();
247 // get default colourscheme name
248 index = USER_DEFINED;
251 return getColourName(index);
260 * @return DOCUMENT ME!
262 public static String getColourName(int index)
298 ret = "Helix Propensity";
303 ret = "Strand Propensity";
308 ret = "Turn Propensity";
313 ret = "Buried Index";
322 case PURINEPYRIMIDINE:
323 ret = "Purine/Pyrimidine";
328 * case COVARIATION: ret = "Covariation";
333 ret = "User Defined";
354 * @return DOCUMENT ME!
356 public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al,
359 return getColour(al.getSequences(), al.getWidth(), name);
363 * retrieve or create colourscheme associated with name
366 * sequences to colour
368 * range of sequences to colour
370 * colourscheme name, applet colour parameter specification, or
371 * string to parse as colour for new coloursheme
372 * @return Valid Colourscheme
374 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
377 int colindex = getColourIndexFromName(name);
378 if (colindex == UNDEFINED)
380 if (name.indexOf('=') == -1)
382 // try to build a colour from the string directly
385 return new UserColourScheme(name);
386 } catch (Exception e)
388 // System.err.println("Ignoring unknown colourscheme name");
393 // try to parse the string as a residue colourscheme
396 // fix the launchApp user defined coloursheme transfer bug
397 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
399 ucs.parseAppletParameter(name);
401 } catch (Exception e)
403 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
407 return getColour(seqs, width, getColourIndexFromName(name));
411 * Construct an instance of ColourSchemeI corresponding to the given colourscheme index
414 * sequences to be coloured by colourscheme
416 * geometry of alignment
418 * colourscheme number
420 * @return null or an instance of the colourscheme configured to colour given sequence set
422 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
425 // TODO 3.0 2.8 refactor signature to take an alignmentI like container so colourschemes based on annotation can be initialised
426 ColourSchemeI cs = null;
431 cs = new ClustalxColourScheme(seqs, width);
436 cs = new Blosum62ColourScheme();
441 cs = new PIDColourScheme();
446 cs = new ZappoColourScheme();
451 cs = new TaylorColourScheme();
455 cs = new HydrophobicColourScheme();
460 cs = new HelixColourScheme();
465 cs = new StrandColourScheme();
470 cs = new TurnColourScheme();
475 cs = new BuriedColourScheme();
480 cs = new NucleotideColourScheme();
484 case PURINEPYRIMIDINE:
485 cs = new PurinePyrimidineColourScheme();
490 // cs = new CovariationColourScheme(annotation);
495 Color[] col = new Color[24];
496 for (int i = 0; i < 24; i++)
498 col[i] = Color.white;
500 cs = new UserColourScheme(col);
510 public static Color getAWTColorFromName(String name)
513 name = name.toLowerCase();
514 if (name.equals("black"))
518 else if (name.equals("blue"))
522 else if (name.equals("cyan"))
526 else if (name.equals("darkGray"))
528 col = Color.darkGray;
530 else if (name.equals("gray"))
534 else if (name.equals("green"))
538 else if (name.equals("lightGray"))
540 col = Color.lightGray;
542 else if (name.equals("magenta"))
546 else if (name.equals("orange"))
550 else if (name.equals("pink"))
554 else if (name.equals("red"))
558 else if (name.equals("white"))
562 else if (name.equals("yellow"))