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;
24 import jalview.util.ColorUtils;
26 import java.awt.Color;
29 * ColourSchemeProperty binds names to hardwired colourschemes and tries to deal
30 * intelligently with mapping unknown names to user defined colourschemes (that
31 * exist or can be created from the string representation of the colourscheme
32 * name - either a hex RGB triplet or a named colour under java.awt.color ). The
33 * values of the colourscheme constants is important for callers of
34 * getColourName(int i), since it can be used to enumerate the set of built in
35 * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
40 public class ColourSchemeProperty
42 /** Undefined Colourscheme Index */
43 public static final int UNDEFINED = -1;
45 /** for schemes defined on the fly */
46 public static final int USER_DEFINED = 0;
48 /** No Colourscheme Index */
49 public static final int NONE = 1;
52 public static final int CLUSTAL = 2;
55 public static final int BLOSUM = 3;
58 public static final int PID = 4;
61 public static final int ZAPPO = 5;
64 public static final int TAYLOR = 6;
67 public static final int HYDROPHOBIC = 7;
70 public static final int HELIX = 8;
73 public static final int STRAND = 9;
76 public static final int TURN = 10;
79 public static final int BURIED = 11;
82 public static final int NUCLEOTIDE = 12;
87 public static final int PURINEPYRIMIDINE = 13;
89 public static final int COVARIATION = 14;
91 public static final int TCOFFEE = 15;
93 public static final int RNAHELIX = 16;
95 public static final int RNAINTERACTION = 17;
98 * index of first colourscheme (includes 'None')
100 public static final int FIRST_COLOUR = NONE;
102 public static final int LAST_COLOUR = RNAINTERACTION;
110 * @return DOCUMENT ME!
112 public static int getColourIndexFromName(String name)
116 if (name.equalsIgnoreCase("Clustal"))
120 else if (name.equalsIgnoreCase("Blosum62"))
124 else if (name.equalsIgnoreCase("% Identity"))
128 else if (name.equalsIgnoreCase("Zappo"))
132 else if (name.equalsIgnoreCase("Taylor"))
136 else if (name.equalsIgnoreCase("Hydrophobic"))
140 else if (name.equalsIgnoreCase("Helix Propensity"))
144 else if (name.equalsIgnoreCase("Strand Propensity"))
148 else if (name.equalsIgnoreCase("Turn Propensity"))
152 else if (name.equalsIgnoreCase("Buried Index"))
156 else if (name.equalsIgnoreCase("Nucleotide"))
160 else if (name.equalsIgnoreCase("T-Coffee Scores"))
165 else if (name.equalsIgnoreCase("User Defined"))
169 else if (name.equalsIgnoreCase("None"))
173 else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
175 ret = PURINEPYRIMIDINE;
177 else if (name.equalsIgnoreCase("RNA Interaction type"))
179 ret = RNAINTERACTION;
181 else if (name.equalsIgnoreCase("RNA Helices"))
185 // else if (name.equalsIgnoreCase("Covariation"))
187 // ret = COVARIATION;
199 * @return DOCUMENT ME!
201 public static String getColourName(ColourSchemeI cs)
206 if (cs instanceof ClustalxColourScheme)
210 else if (cs instanceof Blosum62ColourScheme)
214 else if (cs instanceof PIDColourScheme)
218 else if (cs instanceof ZappoColourScheme)
222 else if (cs instanceof TaylorColourScheme)
226 else if (cs instanceof HydrophobicColourScheme)
230 else if (cs instanceof HelixColourScheme)
234 else if (cs instanceof StrandColourScheme)
238 else if (cs instanceof TurnColourScheme)
242 else if (cs instanceof BuriedColourScheme)
246 else if (cs instanceof NucleotideColourScheme)
250 else if (cs instanceof PurinePyrimidineColourScheme)
252 index = PURINEPYRIMIDINE;
254 else if (cs instanceof TCoffeeColourScheme)
258 else if (cs instanceof RNAHelicesColour)
263 * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
265 else if (cs instanceof UserColourScheme)
267 if ((((UserColourScheme) cs).getName() != null)
268 && (((UserColourScheme) cs).getName().length() > 0))
270 return ((UserColourScheme) cs).getName();
272 // get default colourscheme name
273 index = USER_DEFINED;
276 return getColourName(index);
285 * @return DOCUMENT ME!
287 public static String getColourName(int index)
323 ret = "Helix Propensity";
328 ret = "Strand Propensity";
333 ret = "Turn Propensity";
338 ret = "Buried Index";
347 case PURINEPYRIMIDINE:
348 ret = "Purine/Pyrimidine";
353 ret = "T-Coffee Scores";
358 ret = "RNA Interaction type";
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 UserColourScheme ucs = new UserColourScheme("white");
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(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);
540 public static Color getAWTColorFromName(String name)
543 name = name.toLowerCase();
544 if (name.equals("black"))
548 else if (name.equals("blue"))
552 else if (name.equals("cyan"))
556 else if (name.equals("darkGray"))
558 col = Color.darkGray;
560 else if (name.equals("gray"))
564 else if (name.equals("green"))
568 else if (name.equals("lightGray"))
570 col = Color.lightGray;
572 else if (name.equals("magenta"))
576 else if (name.equals("orange"))
580 else if (name.equals("pink"))
584 else if (name.equals("red"))
588 else if (name.equals("white"))
592 else if (name.equals("yellow"))
600 public static Color rnaHelices[] = null;
602 public static void initRnaHelicesShading(int n)
605 if (rnaHelices == null)
607 rnaHelices = new Color[n + 1];
609 else if (rnaHelices != null && rnaHelices.length <= n)
611 Color[] t = new Color[n + 1];
612 System.arraycopy(rnaHelices, 0, t, 0, rnaHelices.length);
613 j = rnaHelices.length;
620 // Generate random colors and store
623 rnaHelices[j] = ColorUtils.generateRandomColor(Color.white);