2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, 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;
89 public static final int RNAINTERACTION = 16;
92 * index of first colourscheme (includes 'None')
94 public static final int FIRST_COLOUR = NONE;
96 public static final int LAST_COLOUR = NUCLEOTIDE;
104 * @return DOCUMENT ME!
106 public static int getColourIndexFromName(String name)
110 if (name.equalsIgnoreCase("Clustal"))
114 else if (name.equalsIgnoreCase("Blosum62"))
118 else if (name.equalsIgnoreCase("% Identity"))
122 else if (name.equalsIgnoreCase("Zappo"))
126 else if (name.equalsIgnoreCase("Taylor"))
130 else if (name.equalsIgnoreCase("Hydrophobic"))
134 else if (name.equalsIgnoreCase("Helix Propensity"))
138 else if (name.equalsIgnoreCase("Strand Propensity"))
142 else if (name.equalsIgnoreCase("Turn Propensity"))
146 else if (name.equalsIgnoreCase("Buried Index"))
150 else if (name.equalsIgnoreCase("Nucleotide"))
154 else if (name.equalsIgnoreCase("T-Coffee Scores"))
159 else if (name.equalsIgnoreCase("User Defined"))
163 else if (name.equalsIgnoreCase("None"))
167 else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
169 ret = PURINEPYRIMIDINE;
172 else if (name.equalsIgnoreCase("RNA Interaction type"))
174 ret = RNAINTERACTION;
176 // else if (name.equalsIgnoreCase("Covariation"))
178 // ret = COVARIATION;
190 * @return DOCUMENT ME!
192 public static String getColourName(ColourSchemeI cs)
197 if (cs instanceof ClustalxColourScheme)
201 else if (cs instanceof Blosum62ColourScheme)
205 else if (cs instanceof PIDColourScheme)
209 else if (cs instanceof ZappoColourScheme)
213 else if (cs instanceof TaylorColourScheme)
217 else if (cs instanceof HydrophobicColourScheme)
221 else if (cs instanceof HelixColourScheme)
225 else if (cs instanceof StrandColourScheme)
229 else if (cs instanceof TurnColourScheme)
233 else if (cs instanceof BuriedColourScheme)
237 else if (cs instanceof NucleotideColourScheme)
241 else if (cs instanceof PurinePyrimidineColourScheme)
243 index = PURINEPYRIMIDINE;
245 else if (cs instanceof TCoffeeColourScheme)
249 else if (cs instanceof RNAInteractionColourScheme)
251 index = RNAINTERACTION;
256 * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
258 else if (cs instanceof UserColourScheme)
260 if ((((UserColourScheme) cs).getName() != null)
261 && (((UserColourScheme) cs).getName().length() > 0))
263 return ((UserColourScheme) cs).getName();
265 // get default colourscheme name
266 index = USER_DEFINED;
269 return getColourName(index);
278 * @return DOCUMENT ME!
280 public static String getColourName(int index)
316 ret = "Helix Propensity";
321 ret = "Strand Propensity";
326 ret = "Turn Propensity";
331 ret = "Buried Index";
340 case PURINEPYRIMIDINE:
341 ret = "Purine/Pyrimidine";
346 ret = "T-Coffee Scores";
351 ret = "RNA Interaction type";
355 * case COVARIATION: ret = "Covariation";
360 ret = "User Defined";
374 * retrieve or create colourscheme associated with name
377 * sequences to colour
379 * range of sequences to colour
381 * colourscheme name, applet colour parameter specification, or
382 * string to parse as colour for new coloursheme
383 * @return Valid Colourscheme
385 public static ColourSchemeI getColour(AnnotatedCollectionI alignment,
388 int colindex = getColourIndexFromName(name);
389 if (colindex == UNDEFINED)
391 if (name.indexOf('=') == -1)
393 // try to build a colour from the string directly
396 return new UserColourScheme(name);
397 } catch (Exception e)
399 // System.err.println("Ignoring unknown colourscheme name");
404 // try to parse the string as a residue colourscheme
407 // fix the launchApp user defined coloursheme transfer bug
408 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
410 ucs.parseAppletParameter(name);
412 } catch (Exception e)
414 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
418 return getColour(alignment, getColourIndexFromName(name));
422 * Construct an instance of ColourSchemeI corresponding to the given
426 * sequences to be coloured by colourscheme
428 * geometry of alignment
430 * colourscheme number
432 * @return null or an instance of the colourscheme configured to colour given
435 public static ColourSchemeI getColour(
436 jalview.datamodel.AnnotatedCollectionI coll, int index)
438 // TODO 3.0 2.8 refactor signature to take an alignmentI like container so
439 // colourschemes based on annotation can be initialised
440 ColourSchemeI cs = null;
445 cs = new ClustalxColourScheme(coll, null);
450 cs = new Blosum62ColourScheme();
455 cs = new PIDColourScheme();
460 cs = new ZappoColourScheme();
465 cs = new TaylorColourScheme();
469 cs = new HydrophobicColourScheme();
474 cs = new HelixColourScheme();
479 cs = new StrandColourScheme();
484 cs = new TurnColourScheme();
489 cs = new BuriedColourScheme();
494 cs = new NucleotideColourScheme();
498 case PURINEPYRIMIDINE:
499 cs = new PurinePyrimidineColourScheme();
504 cs = new TCoffeeColourScheme(coll);
508 cs = new RNAInteractionColourScheme();
512 // cs = new CovariationColourScheme(annotation);
517 Color[] col = new Color[24];
518 for (int i = 0; i < 24; i++)
520 col[i] = Color.white;
522 cs = new UserColourScheme(col);
532 public static Color getAWTColorFromName(String name)
535 name = name.toLowerCase();
536 if (name.equals("black"))
540 else if (name.equals("blue"))
544 else if (name.equals("cyan"))
548 else if (name.equals("darkGray"))
550 col = Color.darkGray;
552 else if (name.equals("gray"))
556 else if (name.equals("green"))
560 else if (name.equals("lightGray"))
562 col = Color.lightGray;
564 else if (name.equals("magenta"))
568 else if (name.equals("orange"))
572 else if (name.equals("pink"))
576 else if (name.equals("red"))
580 else if (name.equals("white"))
584 else if (name.equals("yellow"))