2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 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 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/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.schemes;
21 import jalview.datamodel.AnnotatedCollectionI;
23 import java.awt.Color;
26 * ColourSchemeProperty binds names to hardwired colourschemes and tries to deal
27 * intelligently with mapping unknown names to user defined colourschemes (that
28 * exist or can be created from the string representation of the colourscheme
29 * name - either a hex RGB triplet or a named colour under java.awt.color ). The
30 * values of the colourscheme constants is important for callers of
31 * getColourName(int i), since it can be used to enumerate the set of built in
32 * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
37 public class ColourSchemeProperty
39 /** Undefined Colourscheme Index */
40 public static final int UNDEFINED = -1;
42 /** for schemes defined on the fly */
43 public static final int USER_DEFINED = 0;
45 /** No Colourscheme Index */
46 public static final int NONE = 1;
49 public static final int CLUSTAL = 2;
52 public static final int BLOSUM = 3;
55 public static final int PID = 4;
58 public static final int ZAPPO = 5;
61 public static final int TAYLOR = 6;
64 public static final int HYDROPHOBIC = 7;
67 public static final int HELIX = 8;
70 public static final int STRAND = 9;
73 public static final int TURN = 10;
76 public static final int BURIED = 11;
79 public static final int NUCLEOTIDE = 12;
84 public static final int PURINEPYRIMIDINE = 13;
86 public static final int COVARIATION = 14;
88 public static final int TCOFFEE = 15;
90 public static final int RNAINTERACTION = 16;
93 * index of first colourscheme (includes 'None')
95 public static final int FIRST_COLOUR = NONE;
97 public static final int LAST_COLOUR = NUCLEOTIDE;
105 * @return DOCUMENT ME!
107 public static int getColourIndexFromName(String name)
111 if (name.equalsIgnoreCase("Clustal"))
115 else if (name.equalsIgnoreCase("Blosum62"))
119 else if (name.equalsIgnoreCase("% Identity"))
123 else if (name.equalsIgnoreCase("Zappo"))
127 else if (name.equalsIgnoreCase("Taylor"))
131 else if (name.equalsIgnoreCase("Hydrophobic"))
135 else if (name.equalsIgnoreCase("Helix Propensity"))
139 else if (name.equalsIgnoreCase("Strand Propensity"))
143 else if (name.equalsIgnoreCase("Turn Propensity"))
147 else if (name.equalsIgnoreCase("Buried Index"))
151 else if (name.equalsIgnoreCase("Nucleotide"))
155 else if (name.equalsIgnoreCase("T-Coffee Scores"))
160 else if (name.equalsIgnoreCase("User Defined"))
164 else if (name.equalsIgnoreCase("None"))
168 else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
170 ret = PURINEPYRIMIDINE;
173 else if (name.equalsIgnoreCase("RNA Interaction type"))
175 ret = RNAINTERACTION;
177 // else if (name.equalsIgnoreCase("Covariation"))
179 // ret = COVARIATION;
191 * @return DOCUMENT ME!
193 public static String getColourName(ColourSchemeI cs)
198 if (cs instanceof ClustalxColourScheme)
202 else if (cs instanceof Blosum62ColourScheme)
206 else if (cs instanceof PIDColourScheme)
210 else if (cs instanceof ZappoColourScheme)
214 else if (cs instanceof TaylorColourScheme)
218 else if (cs instanceof HydrophobicColourScheme)
222 else if (cs instanceof HelixColourScheme)
226 else if (cs instanceof StrandColourScheme)
230 else if (cs instanceof TurnColourScheme)
234 else if (cs instanceof BuriedColourScheme)
238 else if (cs instanceof NucleotideColourScheme)
242 else if (cs instanceof PurinePyrimidineColourScheme)
244 index = PURINEPYRIMIDINE;
246 else if (cs instanceof TCoffeeColourScheme)
254 * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
256 else if (cs instanceof UserColourScheme)
258 if ((((UserColourScheme) cs).getName() != null)
259 && (((UserColourScheme) cs).getName().length() > 0))
261 return ((UserColourScheme) cs).getName();
263 // get default colourscheme name
264 index = USER_DEFINED;
267 return getColourName(index);
276 * @return DOCUMENT ME!
278 public static String getColourName(int index)
314 ret = "Helix Propensity";
319 ret = "Strand Propensity";
324 ret = "Turn Propensity";
329 ret = "Buried Index";
338 case PURINEPYRIMIDINE:
339 ret = "Purine/Pyrimidine";
344 ret = "T-Coffee Scores";
349 ret = "RNA Interaction type";
353 * case COVARIATION: ret = "Covariation";
358 ret = "User Defined";
372 * retrieve or create colourscheme associated with name
375 * sequences to colour
377 * range of sequences to colour
379 * colourscheme name, applet colour parameter specification, or
380 * string to parse as colour for new coloursheme
381 * @return Valid Colourscheme
383 public static ColourSchemeI getColour(AnnotatedCollectionI alignment,
386 int colindex = getColourIndexFromName(name);
387 if (colindex == UNDEFINED)
389 if (name.indexOf('=') == -1)
391 // try to build a colour from the string directly
394 return new UserColourScheme(name);
395 } catch (Exception e)
397 // System.err.println("Ignoring unknown colourscheme name");
402 // try to parse the string as a residue colourscheme
405 // fix the launchApp user defined coloursheme transfer bug
406 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
408 ucs.parseAppletParameter(name);
410 } catch (Exception e)
412 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
416 return getColour(alignment, getColourIndexFromName(name));
420 * Construct an instance of ColourSchemeI corresponding to the given
424 * sequences to be coloured by colourscheme
426 * geometry of alignment
428 * colourscheme number
430 * @return null or an instance of the colourscheme configured to colour given
433 public static ColourSchemeI getColour(
434 jalview.datamodel.AnnotatedCollectionI coll, int index)
436 // TODO 3.0 2.8 refactor signature to take an alignmentI like container so
437 // colourschemes based on annotation can be initialised
438 ColourSchemeI cs = null;
443 cs = new ClustalxColourScheme(coll, null);
448 cs = new Blosum62ColourScheme();
453 cs = new PIDColourScheme();
458 cs = new ZappoColourScheme();
463 cs = new TaylorColourScheme();
467 cs = new HydrophobicColourScheme();
472 cs = new HelixColourScheme();
477 cs = new StrandColourScheme();
482 cs = new TurnColourScheme();
487 cs = new BuriedColourScheme();
492 cs = new NucleotideColourScheme();
496 case PURINEPYRIMIDINE:
497 cs = new PurinePyrimidineColourScheme();
502 cs = new TCoffeeColourScheme(coll);
508 // cs = new CovariationColourScheme(annotation);
513 Color[] col = new Color[24];
514 for (int i = 0; i < 24; i++)
516 col[i] = Color.white;
518 cs = new UserColourScheme(col);
528 public static Color getAWTColorFromName(String name)
531 name = name.toLowerCase();
532 if (name.equals("black"))
536 else if (name.equals("blue"))
540 else if (name.equals("cyan"))
544 else if (name.equals("darkGray"))
546 col = Color.darkGray;
548 else if (name.equals("gray"))
552 else if (name.equals("green"))
556 else if (name.equals("lightGray"))
558 col = Color.lightGray;
560 else if (name.equals("magenta"))
564 else if (name.equals("orange"))
568 else if (name.equals("pink"))
572 else if (name.equals("red"))
576 else if (name.equals("white"))
580 else if (name.equals("yellow"))