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 jalview.datamodel.AnnotatedCollectionI;
22 import java.awt.Color;
25 * ColourSchemeProperty Binds names to hardwired colourschemes and tries to deal
26 * intelligently with mapping unknown names to user defined colourschemes (that
27 * exist or can be created from the string representation of the colourscheme
28 * name - either a hex RGB triplet or a named colour under java.awt.color ). The
29 * values of the colourscheme constants is important for callers of
30 * getColourName(int i), since it can be used to enumerate the set of built in
31 * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
36 public class ColourSchemeProperty
38 /** Undefined Colourscheme Index */
39 public static final int UNDEFINED = -1;
41 /** for schemes defined on the fly */
42 public static final int USER_DEFINED = 0;
44 /** No Colourscheme Index */
45 public static final int NONE = 1;
48 public static final int CLUSTAL = 2;
51 public static final int BLOSUM = 3;
54 public static final int PID = 4;
57 public static final int ZAPPO = 5;
60 public static final int TAYLOR = 6;
63 public static final int HYDROPHOBIC = 7;
66 public static final int HELIX = 8;
69 public static final int STRAND = 9;
72 public static final int TURN = 10;
75 public static final int BURIED = 11;
78 public static final int NUCLEOTIDE = 12;
83 public static final int PURINEPYRIMIDINE = 13;
85 public static final int COVARIATION = 14;
87 public static final int TCOFFEE = 15;
91 * index of first colourscheme (includes 'None')
93 public static final int FIRST_COLOUR = NONE;
95 public static final int LAST_COLOUR = NUCLEOTIDE;
103 * @return DOCUMENT ME!
105 public static int getColourIndexFromName(String name)
109 if (name.equalsIgnoreCase("Clustal"))
113 else if (name.equalsIgnoreCase("Blosum62"))
117 else if (name.equalsIgnoreCase("% Identity"))
121 else if (name.equalsIgnoreCase("Zappo"))
125 else if (name.equalsIgnoreCase("Taylor"))
129 else if (name.equalsIgnoreCase("Hydrophobic"))
133 else if (name.equalsIgnoreCase("Helix Propensity"))
137 else if (name.equalsIgnoreCase("Strand Propensity"))
141 else if (name.equalsIgnoreCase("Turn Propensity"))
145 else if (name.equalsIgnoreCase("Buried Index"))
149 else if (name.equalsIgnoreCase("Nucleotide"))
153 else if (name.equalsIgnoreCase("T-Coffee scores"))
158 else if (name.equalsIgnoreCase("User Defined"))
162 else if (name.equalsIgnoreCase("None"))
166 else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
168 ret = PURINEPYRIMIDINE;
170 // else if (name.equalsIgnoreCase("Covariation"))
172 // ret = COVARIATION;
184 * @return DOCUMENT ME!
186 public static String getColourName(ColourSchemeI cs)
191 if (cs instanceof ClustalxColourScheme)
195 else if (cs instanceof Blosum62ColourScheme)
199 else if (cs instanceof PIDColourScheme)
203 else if (cs instanceof ZappoColourScheme)
207 else if (cs instanceof TaylorColourScheme)
211 else if (cs instanceof HydrophobicColourScheme)
215 else if (cs instanceof HelixColourScheme)
219 else if (cs instanceof StrandColourScheme)
223 else if (cs instanceof TurnColourScheme)
227 else if (cs instanceof BuriedColourScheme)
231 else if (cs instanceof NucleotideColourScheme)
235 else if (cs instanceof PurinePyrimidineColourScheme)
237 index = PURINEPYRIMIDINE;
240 * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
242 else if (cs instanceof UserColourScheme)
244 if ((((UserColourScheme) cs).getName() != null)
245 && (((UserColourScheme) cs).getName().length() > 0))
247 return ((UserColourScheme) cs).getName();
249 // get default colourscheme name
250 index = USER_DEFINED;
253 return getColourName(index);
262 * @return DOCUMENT ME!
264 public static String getColourName(int index)
300 ret = "Helix Propensity";
305 ret = "Strand Propensity";
310 ret = "Turn Propensity";
315 ret = "Buried Index";
324 case PURINEPYRIMIDINE:
325 ret = "Purine/Pyrimidine";
330 * case COVARIATION: ret = "Covariation";
335 ret = "User Defined";
348 * retrieve or create colourscheme associated with name
351 * sequences to colour
353 * range of sequences to colour
355 * colourscheme name, applet colour parameter specification, or
356 * string to parse as colour for new coloursheme
357 * @return Valid Colourscheme
359 public static ColourSchemeI getColour(AnnotatedCollectionI alignment,
362 int colindex = getColourIndexFromName(name);
363 if (colindex == UNDEFINED)
365 if (name.indexOf('=') == -1)
367 // try to build a colour from the string directly
370 return new UserColourScheme(name);
371 } catch (Exception e)
373 // System.err.println("Ignoring unknown colourscheme name");
378 // try to parse the string as a residue colourscheme
381 // fix the launchApp user defined coloursheme transfer bug
382 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
384 ucs.parseAppletParameter(name);
386 } catch (Exception e)
388 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
392 return getColour(alignment, getColourIndexFromName(name));
396 * Construct an instance of ColourSchemeI corresponding to the given colourscheme index
399 * sequences to be coloured by colourscheme
401 * geometry of alignment
403 * colourscheme number
405 * @return null or an instance of the colourscheme configured to colour given sequence set
407 public static ColourSchemeI getColour(jalview.datamodel.AnnotatedCollectionI coll, int index)
409 // TODO 3.0 2.8 refactor signature to take an alignmentI like container so colourschemes based on annotation can be initialised
410 ColourSchemeI cs = null;
415 cs = new ClustalxColourScheme(coll, null);
420 cs = new Blosum62ColourScheme();
425 cs = new PIDColourScheme();
430 cs = new ZappoColourScheme();
435 cs = new TaylorColourScheme();
439 cs = new HydrophobicColourScheme();
444 cs = new HelixColourScheme();
449 cs = new StrandColourScheme();
454 cs = new TurnColourScheme();
459 cs = new BuriedColourScheme();
464 cs = new NucleotideColourScheme();
468 case PURINEPYRIMIDINE:
469 cs = new PurinePyrimidineColourScheme();
474 // cs = new CovariationColourScheme(annotation);
479 Color[] col = new Color[24];
480 for (int i = 0; i < 24; i++)
482 col[i] = Color.white;
484 cs = new UserColourScheme(col);
494 public static Color getAWTColorFromName(String name)
497 name = name.toLowerCase();
498 if (name.equals("black"))
502 else if (name.equals("blue"))
506 else if (name.equals("cyan"))
510 else if (name.equals("darkGray"))
512 col = Color.darkGray;
514 else if (name.equals("gray"))
518 else if (name.equals("green"))
522 else if (name.equals("lightGray"))
524 col = Color.lightGray;
526 else if (name.equals("magenta"))
530 else if (name.equals("orange"))
534 else if (name.equals("pink"))
538 else if (name.equals("red"))
542 else if (name.equals("white"))
546 else if (name.equals("yellow"))