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 UserColourScheme ucs = new UserColourScheme("white");
419 ucs.parseAppletParameter(name);
421 } catch (Exception e)
423 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
427 return getColour(alignment, colindex);
431 * Construct an instance of ColourSchemeI corresponding to the given
435 * sequences to be coloured by colourscheme
437 * geometry of alignment
439 * colourscheme number
441 * @return null or an instance of the colourscheme configured to colour given
444 public static ColourSchemeI getColour(
445 jalview.datamodel.AnnotatedCollectionI coll, int index)
447 // TODO 3.0 2.8 refactor signature to take an alignmentI like container so
448 // colourschemes based on annotation can be initialised
449 ColourSchemeI cs = null;
454 cs = new ClustalxColourScheme(coll, null);
459 cs = new Blosum62ColourScheme();
464 cs = new PIDColourScheme();
469 cs = new ZappoColourScheme();
474 cs = new TaylorColourScheme();
478 cs = new HydrophobicColourScheme();
483 cs = new HelixColourScheme();
488 cs = new StrandColourScheme();
493 cs = new TurnColourScheme();
498 cs = new BuriedColourScheme();
503 cs = new NucleotideColourScheme();
507 case PURINEPYRIMIDINE:
508 cs = new PurinePyrimidineColourScheme();
513 cs = new TCoffeeColourScheme(coll);
517 cs = new RNAHelicesColour(coll);
521 // cs = new CovariationColourScheme(annotation);
525 Color[] col = new Color[24];
526 for (int i = 0; i < 24; i++)
528 col[i] = Color.white;
530 cs = new UserColourScheme(col);
541 * Returns the Color constant for a given colour name e.g. "pink", or null if
542 * the name is not recognised
547 public static Color getAWTColorFromName(String name)
554 name = name.toLowerCase();
556 // or make a static map; or use reflection on the field name
569 col = Color.darkGray;
578 col = Color.lightGray;
603 public static Color rnaHelices[] = null;
605 public static void initRnaHelicesShading(int n)
608 if (rnaHelices == null)
610 rnaHelices = new Color[n + 1];
612 else if (rnaHelices != null && rnaHelices.length <= n)
614 Color[] t = new Color[n + 1];
615 System.arraycopy(rnaHelices, 0, t, 0, rnaHelices.length);
616 j = rnaHelices.length;
623 // Generate random colors and store
626 rnaHelices[j] = jalview.util.ColorUtils
627 .generateRandomColor(Color.white);
632 * delete the existing cached RNA helces colours
634 public static void resetRnaHelicesShading()