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;
25 import java.awt.Color;
28 * ColourSchemeProperty binds names to hardwired colourschemes and tries to deal
29 * intelligently with mapping unknown names to user defined colourschemes (that
30 * exist or can be created from the string representation of the colourscheme
31 * name - either a hex RGB triplet or a named colour under java.awt.color ). The
32 * values of the colourscheme constants is important for callers of
33 * getColourName(int i), since it can be used to enumerate the set of built in
34 * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
39 public class ColourSchemeProperty
41 /** Undefined Colourscheme Index */
42 public static final int UNDEFINED = -1;
44 /** for schemes defined on the fly */
45 public static final int USER_DEFINED = 0;
47 /** No Colourscheme Index */
48 public static final int NONE = 1;
51 public static final int CLUSTAL = 2;
54 public static final int BLOSUM = 3;
57 public static final int PID = 4;
60 public static final int ZAPPO = 5;
63 public static final int TAYLOR = 6;
66 public static final int HYDROPHOBIC = 7;
69 public static final int HELIX = 8;
72 public static final int STRAND = 9;
75 public static final int TURN = 10;
78 public static final int BURIED = 11;
81 public static final int NUCLEOTIDE = 12;
86 public static final int PURINEPYRIMIDINE = 13;
88 public static final int COVARIATION = 14;
90 public static final int TCOFFEE = 15;
92 public static final int RNAHELIX = 16;
94 public static final int RNAINTERACTION = 17;
97 * index of first colourscheme (includes 'None')
99 public static final int FIRST_COLOUR = NONE;
101 public static final int LAST_COLOUR = RNAINTERACTION;
109 * @return DOCUMENT ME!
111 public static int getColourIndexFromName(String name)
115 if (name.equalsIgnoreCase("Clustal"))
119 else if (name.equalsIgnoreCase("Blosum62"))
123 else if (name.equalsIgnoreCase("% Identity"))
127 else if (name.equalsIgnoreCase("Zappo"))
131 else if (name.equalsIgnoreCase("Taylor"))
135 else if (name.equalsIgnoreCase("Hydrophobic"))
139 else if (name.equalsIgnoreCase("Helix Propensity"))
143 else if (name.equalsIgnoreCase("Strand Propensity"))
147 else if (name.equalsIgnoreCase("Turn Propensity"))
151 else if (name.equalsIgnoreCase("Buried Index"))
155 else if (name.equalsIgnoreCase("Nucleotide"))
159 else if (name.equalsIgnoreCase("T-Coffee Scores"))
164 else if (name.equalsIgnoreCase("User Defined"))
168 else if (name.equalsIgnoreCase("None"))
172 else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
174 ret = PURINEPYRIMIDINE;
176 else if (name.equalsIgnoreCase("RNA Interaction type"))
178 ret = RNAINTERACTION;
180 else if (name.equalsIgnoreCase("RNA Helices"))
184 // else if (name.equalsIgnoreCase("Covariation"))
186 // ret = COVARIATION;
198 * @return DOCUMENT ME!
200 public static String getColourName(ColourSchemeI cs)
205 if (cs instanceof ClustalxColourScheme)
209 else if (cs instanceof Blosum62ColourScheme)
213 else if (cs instanceof PIDColourScheme)
217 else if (cs instanceof ZappoColourScheme)
221 else if (cs instanceof TaylorColourScheme)
225 else if (cs instanceof HydrophobicColourScheme)
229 else if (cs instanceof HelixColourScheme)
233 else if (cs instanceof StrandColourScheme)
237 else if (cs instanceof TurnColourScheme)
241 else if (cs instanceof BuriedColourScheme)
245 else if (cs instanceof NucleotideColourScheme)
249 else if (cs instanceof PurinePyrimidineColourScheme)
251 index = PURINEPYRIMIDINE;
253 else if (cs instanceof TCoffeeColourScheme)
257 else if (cs instanceof RNAHelicesColour)
262 * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
264 else if (cs instanceof UserColourScheme)
266 if ((((UserColourScheme) cs).getName() != null)
267 && (((UserColourScheme) cs).getName().length() > 0))
269 return ((UserColourScheme) cs).getName();
271 // get default colourscheme name
272 index = USER_DEFINED;
275 return getColourName(index);
284 * @return DOCUMENT ME!
286 public static String getColourName(int index)
322 ret = "Helix Propensity";
327 ret = "Strand Propensity";
332 ret = "Turn Propensity";
337 ret = "Buried Index";
346 case PURINEPYRIMIDINE:
347 ret = "Purine/Pyrimidine";
352 ret = "T-Coffee Scores";
357 ret = "RNA Interaction type";
365 * case COVARIATION: ret = "Covariation";
370 ret = "User Defined";
384 * retrieve or create colourscheme associated with name
387 * sequences to colour
389 * range of sequences to colour
391 * colourscheme name, applet colour parameter specification, or
392 * string to parse as colour for new coloursheme
393 * @return Valid Colourscheme
395 public static ColourSchemeI getColour(AnnotatedCollectionI alignment,
398 int colindex = getColourIndexFromName(name);
399 if (colindex == UNDEFINED)
401 if (name.indexOf('=') == -1)
403 // try to build a colour from the string directly
406 return new UserColourScheme(name);
407 } catch (Exception e)
409 // System.err.println("Ignoring unknown colourscheme name");
414 // try to parse the string as a residue colourscheme
417 // fix the launchApp user defined coloursheme transfer bug
418 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
420 ucs.parseAppletParameter(name);
422 } catch (Exception e)
424 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
428 return getColour(alignment, getColourIndexFromName(name));
432 * Construct an instance of ColourSchemeI corresponding to the given
436 * sequences to be coloured by colourscheme
438 * geometry of alignment
440 * colourscheme number
442 * @return null or an instance of the colourscheme configured to colour given
445 public static ColourSchemeI getColour(
446 jalview.datamodel.AnnotatedCollectionI coll, int index)
448 // TODO 3.0 2.8 refactor signature to take an alignmentI like container so
449 // colourschemes based on annotation can be initialised
450 ColourSchemeI cs = null;
455 cs = new ClustalxColourScheme(coll, null);
460 cs = new Blosum62ColourScheme();
465 cs = new PIDColourScheme();
470 cs = new ZappoColourScheme();
475 cs = new TaylorColourScheme();
479 cs = new HydrophobicColourScheme();
484 cs = new HelixColourScheme();
489 cs = new StrandColourScheme();
494 cs = new TurnColourScheme();
499 cs = new BuriedColourScheme();
504 cs = new NucleotideColourScheme();
508 case PURINEPYRIMIDINE:
509 cs = new PurinePyrimidineColourScheme();
514 cs = new TCoffeeColourScheme(coll);
518 cs = new RNAHelicesColour(coll);
522 // cs = new CovariationColourScheme(annotation);
526 Color[] col = new Color[24];
527 for (int i = 0; i < 24; i++)
529 col[i] = Color.white;
531 cs = new UserColourScheme(col);
541 public static Color getAWTColorFromName(String name)
544 name = name.toLowerCase();
545 if (name.equals("black"))
549 else if (name.equals("blue"))
553 else if (name.equals("cyan"))
557 else if (name.equals("darkGray"))
559 col = Color.darkGray;
561 else if (name.equals("gray"))
565 else if (name.equals("green"))
569 else if (name.equals("lightGray"))
571 col = Color.lightGray;
573 else if (name.equals("magenta"))
577 else if (name.equals("orange"))
581 else if (name.equals("pink"))
585 else if (name.equals("red"))
589 else if (name.equals("white"))
593 else if (name.equals("yellow"))
601 public static Color rnaHelices[] = null;
603 public static void initRnaHelicesShading(int n)
606 if (rnaHelices == null)
608 rnaHelices = new Color[n + 1];
610 else if (rnaHelices != null && rnaHelices.length <= n)
612 Color[] t = new Color[n + 1];
613 System.arraycopy(rnaHelices, 0, t, 0, rnaHelices.length);
614 j = rnaHelices.length;
621 // Generate random colors and store
624 rnaHelices[j] = jalview.util.ColorUtils
625 .generateRandomColor(Color.white);
630 * delete the existing cached RNA helces colours
632 public static void resetRnaHelicesShading()