2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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/>.
18 package jalview.schemes;
23 * ColourSchemeProperty Binds names to hardwired colourschemes and tries to deal
24 * intelligently with mapping unknown names to user defined colourschemes (that
25 * exist or can be created from the string representation of the colourscheme
26 * name - either a hex RGB triplet or a named colour under java.awt.color ). The
27 * values of the colourscheme constants is important for callers of
28 * getColourName(int i), since it can be used to enumerate the set of built in
29 * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
34 public class ColourSchemeProperty
36 /** Undefined Colourscheme Index */
37 public static final int UNDEFINED = -1;
39 /** for schemes defined on the fly */
40 public static final int USER_DEFINED = 0;
42 /** No Colourscheme Index */
43 public static final int NONE = 1;
46 public static final int CLUSTAL = 2;
49 public static final int BLOSUM = 3;
52 public static final int PID = 4;
55 public static final int ZAPPO = 5;
58 public static final int TAYLOR = 6;
61 public static final int HYDROPHOBIC = 7;
64 public static final int HELIX = 8;
67 public static final int STRAND = 9;
70 public static final int TURN = 10;
73 public static final int BURIED = 11;
76 public static final int NUCLEOTIDE = 12;
81 public static final int PURINEPYRIMIDINE = 13;
83 public static final int COVARIATION = 14;
86 * index of first colourscheme (includes 'None')
88 public static final int FIRST_COLOUR = NONE;
90 public static final int LAST_COLOUR = NUCLEOTIDE;
98 * @return DOCUMENT ME!
100 public static int getColourIndexFromName(String name)
104 if (name.equalsIgnoreCase("Clustal"))
108 else if (name.equalsIgnoreCase("Blosum62"))
112 else if (name.equalsIgnoreCase("% Identity"))
116 else if (name.equalsIgnoreCase("Zappo"))
120 else if (name.equalsIgnoreCase("Taylor"))
124 else if (name.equalsIgnoreCase("Hydrophobic"))
128 else if (name.equalsIgnoreCase("Helix Propensity"))
132 else if (name.equalsIgnoreCase("Strand Propensity"))
136 else if (name.equalsIgnoreCase("Turn Propensity"))
140 else if (name.equalsIgnoreCase("Buried Index"))
144 else if (name.equalsIgnoreCase("Nucleotide"))
148 else if (name.equalsIgnoreCase("User Defined"))
152 else if (name.equalsIgnoreCase("None"))
156 else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
158 ret = PURINEPYRIMIDINE;
160 // else if (name.equalsIgnoreCase("Covariation"))
162 // ret = COVARIATION;
174 * @return DOCUMENT ME!
176 public static String getColourName(ColourSchemeI cs)
181 if (cs instanceof ClustalxColourScheme)
185 else if (cs instanceof Blosum62ColourScheme)
189 else if (cs instanceof PIDColourScheme)
193 else if (cs instanceof ZappoColourScheme)
197 else if (cs instanceof TaylorColourScheme)
201 else if (cs instanceof HydrophobicColourScheme)
205 else if (cs instanceof HelixColourScheme)
209 else if (cs instanceof StrandColourScheme)
213 else if (cs instanceof TurnColourScheme)
217 else if (cs instanceof BuriedColourScheme)
221 else if (cs instanceof NucleotideColourScheme)
225 else if (cs instanceof PurinePyrimidineColourScheme)
227 index = PURINEPYRIMIDINE;
230 * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
232 else if (cs instanceof UserColourScheme)
234 if ((((UserColourScheme) cs).getName() != null)
235 && (((UserColourScheme) cs).getName().length() > 0))
237 return ((UserColourScheme) cs).getName();
239 // get default colourscheme name
240 index = USER_DEFINED;
243 return getColourName(index);
252 * @return DOCUMENT ME!
254 public static String getColourName(int index)
290 ret = "Helix Propensity";
295 ret = "Strand Propensity";
300 ret = "Turn Propensity";
305 ret = "Buried Index";
314 case PURINEPYRIMIDINE:
315 ret = "Purine/Pyrimidine";
320 * case COVARIATION: ret = "Covariation";
325 ret = "User Defined";
346 * @return DOCUMENT ME!
348 public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al,
351 return getColour(al.getSequences(), al.getWidth(), name);
355 * retrieve or create colourscheme associated with name
358 * sequences to colour
360 * range of sequences to colour
362 * colourscheme name, applet colour parameter specification, or
363 * string to parse as colour for new coloursheme
364 * @return Valid Colourscheme
366 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
369 int colindex = getColourIndexFromName(name);
370 if (colindex == UNDEFINED)
372 if (name.indexOf('=') == -1)
374 // try to build a colour from the string directly
377 return new UserColourScheme(name);
378 } catch (Exception e)
380 // System.err.println("Ignoring unknown colourscheme name");
385 // try to parse the string as a residue colourscheme
388 // fix the launchApp user defined coloursheme transfer bug
389 jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
391 ucs.parseAppletParameter(name);
393 } catch (Exception e)
395 // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
399 return getColour(seqs, width, getColourIndexFromName(name));
412 * @return DOCUMENT ME!
414 public static ColourSchemeI getColour(java.util.Vector seqs, int width,
417 ColourSchemeI cs = null;
422 cs = new ClustalxColourScheme(seqs, width);
427 cs = new Blosum62ColourScheme();
432 cs = new PIDColourScheme();
437 cs = new ZappoColourScheme();
442 cs = new TaylorColourScheme();
446 cs = new HydrophobicColourScheme();
451 cs = new HelixColourScheme();
456 cs = new StrandColourScheme();
461 cs = new TurnColourScheme();
466 cs = new BuriedColourScheme();
471 cs = new NucleotideColourScheme();
475 case PURINEPYRIMIDINE:
476 cs = new PurinePyrimidineColourScheme();
481 // cs = new CovariationColourScheme(annotation);
486 Color[] col = new Color[24];
487 for (int i = 0; i < 24; i++)
489 col[i] = Color.white;
491 cs = new UserColourScheme(col);
501 public static Color getAWTColorFromName(String name)
504 name = name.toLowerCase();
505 if (name.equals("black"))
509 else if (name.equals("blue"))
513 else if (name.equals("cyan"))
517 else if (name.equals("darkGray"))
519 col = Color.darkGray;
521 else if (name.equals("gray"))
525 else if (name.equals("green"))
529 else if (name.equals("lightGray"))
531 col = Color.lightGray;
533 else if (name.equals("magenta"))
537 else if (name.equals("orange"))
541 else if (name.equals("pink"))
545 else if (name.equals("red"))
549 else if (name.equals("white"))
553 else if (name.equals("yellow"))