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 RNAHELIX = 16;
92 public static final int RNAINTERACTION = 16;
95 * index of first colourscheme (includes 'None')
97 public static final int FIRST_COLOUR = NONE;
99 public static final int LAST_COLOUR = RNAHELIX;
107 * @return DOCUMENT ME!
109 public static int getColourIndexFromName(String name)
113 if (name.equalsIgnoreCase("Clustal"))
117 else if (name.equalsIgnoreCase("Blosum62"))
121 else if (name.equalsIgnoreCase("% Identity"))
125 else if (name.equalsIgnoreCase("Zappo"))
129 else if (name.equalsIgnoreCase("Taylor"))
133 else if (name.equalsIgnoreCase("Hydrophobic"))
137 else if (name.equalsIgnoreCase("Helix Propensity"))
141 else if (name.equalsIgnoreCase("Strand Propensity"))
145 else if (name.equalsIgnoreCase("Turn Propensity"))
149 else if (name.equalsIgnoreCase("Buried Index"))
153 else if (name.equalsIgnoreCase("Nucleotide"))
157 else if (name.equalsIgnoreCase("T-Coffee Scores"))
162 else if (name.equalsIgnoreCase("User Defined"))
166 else if (name.equalsIgnoreCase("None"))
170 else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
172 ret = PURINEPYRIMIDINE;
174 else if (name.equalsIgnoreCase("RNA Interaction type"))
176 ret = RNAINTERACTION;
178 else if (name.equalsIgnoreCase("RNA Helices"))
182 // else if (name.equalsIgnoreCase("Covariation"))
184 // ret = COVARIATION;
196 * @return DOCUMENT ME!
198 public static String getColourName(ColourSchemeI cs)
203 if (cs instanceof ClustalxColourScheme)
207 else if (cs instanceof Blosum62ColourScheme)
211 else if (cs instanceof PIDColourScheme)
215 else if (cs instanceof ZappoColourScheme)
219 else if (cs instanceof TaylorColourScheme)
223 else if (cs instanceof HydrophobicColourScheme)
227 else if (cs instanceof HelixColourScheme)
231 else if (cs instanceof StrandColourScheme)
235 else if (cs instanceof TurnColourScheme)
239 else if (cs instanceof BuriedColourScheme)
243 else if (cs instanceof NucleotideColourScheme)
247 else if (cs instanceof PurinePyrimidineColourScheme)
249 index = PURINEPYRIMIDINE;
251 else if (cs instanceof TCoffeeColourScheme)
255 else if (cs instanceof RNAHelicesColour)
260 * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
262 else if (cs instanceof UserColourScheme)
264 if ((((UserColourScheme) cs).getName() != null)
265 && (((UserColourScheme) cs).getName().length() > 0))
267 return ((UserColourScheme) cs).getName();
269 // get default colourscheme name
270 index = USER_DEFINED;
273 return getColourName(index);
282 * @return DOCUMENT ME!
284 public static String getColourName(int index)
320 ret = "Helix Propensity";
325 ret = "Strand Propensity";
330 ret = "Turn Propensity";
335 ret = "Buried Index";
344 case PURINEPYRIMIDINE:
345 ret = "Purine/Pyrimidine";
350 ret = "T-Coffee Scores";
356 ret = "RNA Interaction type";
364 >>>>>>> JAL-952_rnahelix
366 * case COVARIATION: ret = "Covariation";
371 ret = "User Defined";
385 * retrieve or create colourscheme associated with name
388 * sequences to colour
390 * range of sequences to colour
392 * colourscheme name, applet colour parameter specification, or
393 * string to parse as colour for new coloursheme
394 * @return Valid Colourscheme
396 public static ColourSchemeI getColour(AnnotatedCollectionI alignment,
399 int colindex = getColourIndexFromName(name);
400 if (colindex == UNDEFINED)
402 if (name.indexOf('=') == -1)
404 // try to build a colour from the string directly
407 return new UserColourScheme(name);
408 } catch (Exception e)
410 // System.err.println("Ignoring unknown colourscheme name");
415 // try to parse the string as a residue colourscheme
418 // fix the launchApp user defined coloursheme transfer bug
419 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
421 ucs.parseAppletParameter(name);
423 } catch (Exception e)
425 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
429 return getColour(alignment, getColourIndexFromName(name));
433 * Construct an instance of ColourSchemeI corresponding to the given
437 * sequences to be coloured by colourscheme
439 * geometry of alignment
441 * colourscheme number
443 * @return null or an instance of the colourscheme configured to colour given
446 public static ColourSchemeI getColour(
447 jalview.datamodel.AnnotatedCollectionI coll, int index)
449 // TODO 3.0 2.8 refactor signature to take an alignmentI like container so
450 // colourschemes based on annotation can be initialised
451 ColourSchemeI cs = null;
456 cs = new ClustalxColourScheme(coll, null);
461 cs = new Blosum62ColourScheme();
466 cs = new PIDColourScheme();
471 cs = new ZappoColourScheme();
476 cs = new TaylorColourScheme();
480 cs = new HydrophobicColourScheme();
485 cs = new HelixColourScheme();
490 cs = new StrandColourScheme();
495 cs = new TurnColourScheme();
500 cs = new BuriedColourScheme();
505 cs = new NucleotideColourScheme();
509 case PURINEPYRIMIDINE:
510 cs = new PurinePyrimidineColourScheme();
515 cs = new TCoffeeColourScheme(coll);
519 cs = new RNAHelicesColour(coll);
523 // cs = new CovariationColourScheme(annotation);
527 Color[] col = new Color[24];
528 for (int i = 0; i < 24; i++)
530 col[i] = Color.white;
532 cs = new UserColourScheme(col);
542 public static Color getAWTColorFromName(String name)
545 name = name.toLowerCase();
546 if (name.equals("black"))
550 else if (name.equals("blue"))
554 else if (name.equals("cyan"))
558 else if (name.equals("darkGray"))
560 col = Color.darkGray;
562 else if (name.equals("gray"))
566 else if (name.equals("green"))
570 else if (name.equals("lightGray"))
572 col = Color.lightGray;
574 else if (name.equals("magenta"))
578 else if (name.equals("orange"))
582 else if (name.equals("pink"))
586 else if (name.equals("red"))
590 else if (name.equals("white"))
594 else if (name.equals("yellow"))