remove mentions of non-functional RNAInteraction colourscheme
[jalview.git] / src / jalview / schemes / ColourSchemeProperty.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
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.
10  *  
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.
15  * 
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  */
18 package jalview.schemes;
19
20 import jalview.datamodel.AnnotatedCollectionI;
21
22 import java.awt.Color;
23
24 /**
25  * ColourSchemeProperty binds names to hardwired colourschemes and tries to deal
26  * intelligently with mapping unknown names to user defined colourschemes (that
27  * exist or can be created from the string representation of the colourscheme
28  * name - either a hex RGB triplet or a named colour under java.awt.color ). The
29  * values of the colourscheme constants is important for callers of
30  * getColourName(int i), since it can be used to enumerate the set of built in
31  * colours. The FIRST_COLOUR and LAST_COLOUR symbols are provided for this.
32  * 
33  * @author $author$
34  * @version $Revision$
35  */
36 public class ColourSchemeProperty
37 {
38   /** Undefined Colourscheme Index */
39   public static final int UNDEFINED = -1;
40
41   /** for schemes defined on the fly */
42   public static final int USER_DEFINED = 0;
43
44   /** No Colourscheme Index */
45   public static final int NONE = 1;
46
47   /** DOCUMENT ME!! */
48   public static final int CLUSTAL = 2;
49
50   /** DOCUMENT ME!! */
51   public static final int BLOSUM = 3;
52
53   /** DOCUMENT ME!! */
54   public static final int PID = 4;
55
56   /** DOCUMENT ME!! */
57   public static final int ZAPPO = 5;
58
59   /** DOCUMENT ME!! */
60   public static final int TAYLOR = 6;
61
62   /** DOCUMENT ME!! */
63   public static final int HYDROPHOBIC = 7;
64
65   /** DOCUMENT ME!! */
66   public static final int HELIX = 8;
67
68   /** DOCUMENT ME!! */
69   public static final int STRAND = 9;
70
71   /** DOCUMENT ME!! */
72   public static final int TURN = 10;
73
74   /** DOCUMENT ME!! */
75   public static final int BURIED = 11;
76
77   /** DOCUMENT ME!! */
78   public static final int NUCLEOTIDE = 12;
79
80   /**
81    * purine/pyrimidine
82    */
83   public static final int PURINEPYRIMIDINE = 13;
84
85   public static final int COVARIATION = 14;
86
87   public static final int TCOFFEE = 15;
88
89   public static final int RNAINTERACTION = 16;
90
91   /**
92    * index of first colourscheme (includes 'None')
93    */
94   public static final int FIRST_COLOUR = NONE;
95
96   public static final int LAST_COLOUR = NUCLEOTIDE;
97
98   /**
99    * DOCUMENT ME!
100    * 
101    * @param name
102    *          DOCUMENT ME!
103    * 
104    * @return DOCUMENT ME!
105    */
106   public static int getColourIndexFromName(String name)
107   {
108     int ret = UNDEFINED;
109
110     if (name.equalsIgnoreCase("Clustal"))
111     {
112       ret = CLUSTAL;
113     }
114     else if (name.equalsIgnoreCase("Blosum62"))
115     {
116       ret = BLOSUM;
117     }
118     else if (name.equalsIgnoreCase("% Identity"))
119     {
120       ret = PID;
121     }
122     else if (name.equalsIgnoreCase("Zappo"))
123     {
124       ret = ZAPPO;
125     }
126     else if (name.equalsIgnoreCase("Taylor"))
127     {
128       ret = TAYLOR;
129     }
130     else if (name.equalsIgnoreCase("Hydrophobic"))
131     {
132       ret = HYDROPHOBIC;
133     }
134     else if (name.equalsIgnoreCase("Helix Propensity"))
135     {
136       ret = HELIX;
137     }
138     else if (name.equalsIgnoreCase("Strand Propensity"))
139     {
140       ret = STRAND;
141     }
142     else if (name.equalsIgnoreCase("Turn Propensity"))
143     {
144       ret = TURN;
145     }
146     else if (name.equalsIgnoreCase("Buried Index"))
147     {
148       ret = BURIED;
149     }
150     else if (name.equalsIgnoreCase("Nucleotide"))
151     {
152       ret = NUCLEOTIDE;
153     }
154     else if (name.equalsIgnoreCase("T-Coffee Scores"))
155     {
156       ret = TCOFFEE;
157     }
158
159     else if (name.equalsIgnoreCase("User Defined"))
160     {
161       ret = USER_DEFINED;
162     }
163     else if (name.equalsIgnoreCase("None"))
164     {
165       ret = NONE;
166     }
167     else if (name.equalsIgnoreCase("Purine/Pyrimidine"))
168     {
169       ret = PURINEPYRIMIDINE;
170     }
171     
172     else if (name.equalsIgnoreCase("RNA Interaction type"))
173     {
174       ret = RNAINTERACTION;
175     }
176     // else if (name.equalsIgnoreCase("Covariation"))
177     // {
178     // ret = COVARIATION;
179     // }
180
181     return ret;
182   }
183
184   /**
185    * DOCUMENT ME!
186    * 
187    * @param cs
188    *          DOCUMENT ME!
189    * 
190    * @return DOCUMENT ME!
191    */
192   public static String getColourName(ColourSchemeI cs)
193   {
194
195     int index = NONE;
196
197     if (cs instanceof ClustalxColourScheme)
198     {
199       index = CLUSTAL;
200     }
201     else if (cs instanceof Blosum62ColourScheme)
202     {
203       index = BLOSUM;
204     }
205     else if (cs instanceof PIDColourScheme)
206     {
207       index = PID;
208     }
209     else if (cs instanceof ZappoColourScheme)
210     {
211       index = ZAPPO;
212     }
213     else if (cs instanceof TaylorColourScheme)
214     {
215       index = TAYLOR;
216     }
217     else if (cs instanceof HydrophobicColourScheme)
218     {
219       index = HYDROPHOBIC;
220     }
221     else if (cs instanceof HelixColourScheme)
222     {
223       index = HELIX;
224     }
225     else if (cs instanceof StrandColourScheme)
226     {
227       index = STRAND;
228     }
229     else if (cs instanceof TurnColourScheme)
230     {
231       index = TURN;
232     }
233     else if (cs instanceof BuriedColourScheme)
234     {
235       index = BURIED;
236     }
237     else if (cs instanceof NucleotideColourScheme)
238     {
239       index = NUCLEOTIDE;
240     }
241     else if (cs instanceof PurinePyrimidineColourScheme)
242     {
243       index = PURINEPYRIMIDINE;
244     }
245     else if (cs instanceof TCoffeeColourScheme)
246     {
247       index = TCOFFEE;
248     }
249    
250     
251     
252     /*
253      * else if (cs instanceof CovariationColourScheme) { index = COVARIATION; }
254      */
255     else if (cs instanceof UserColourScheme)
256     {
257       if ((((UserColourScheme) cs).getName() != null)
258               && (((UserColourScheme) cs).getName().length() > 0))
259       {
260         return ((UserColourScheme) cs).getName();
261       }
262       // get default colourscheme name
263       index = USER_DEFINED;
264     }
265
266     return getColourName(index);
267   }
268
269   /**
270    * DOCUMENT ME!
271    * 
272    * @param index
273    *          DOCUMENT ME!
274    * 
275    * @return DOCUMENT ME!
276    */
277   public static String getColourName(int index)
278   {
279     String ret = null;
280
281     switch (index)
282     {
283     case CLUSTAL:
284       ret = "Clustal";
285
286       break;
287
288     case BLOSUM:
289       ret = "Blosum62";
290
291       break;
292
293     case PID:
294       ret = "% Identity";
295
296       break;
297
298     case ZAPPO:
299       ret = "Zappo";
300
301       break;
302
303     case TAYLOR:
304       ret = "Taylor";
305       break;
306
307     case HYDROPHOBIC:
308       ret = "Hydrophobic";
309
310       break;
311
312     case HELIX:
313       ret = "Helix Propensity";
314
315       break;
316
317     case STRAND:
318       ret = "Strand Propensity";
319
320       break;
321
322     case TURN:
323       ret = "Turn Propensity";
324
325       break;
326
327     case BURIED:
328       ret = "Buried Index";
329
330       break;
331
332     case NUCLEOTIDE:
333       ret = "Nucleotide";
334
335       break;
336
337     case PURINEPYRIMIDINE:
338       ret = "Purine/Pyrimidine";
339
340       break;
341
342     case TCOFFEE:
343       ret = "T-Coffee Scores";
344
345       break;
346       
347     case RNAINTERACTION:
348         ret = "RNA Interaction type";
349
350         break;
351     /*
352      * case COVARIATION: ret = "Covariation";
353      * 
354      * break;
355      */
356     case USER_DEFINED:
357       ret = "User Defined";
358
359       break;
360
361     default:
362       ret = "None";
363
364       break;
365     }
366
367     return ret;
368   }
369
370   /**
371    * retrieve or create colourscheme associated with name
372    * 
373    * @param seqs
374    *          sequences to colour
375    * @param width
376    *          range of sequences to colour
377    * @param name
378    *          colourscheme name, applet colour parameter specification, or
379    *          string to parse as colour for new coloursheme
380    * @return Valid Colourscheme
381    */
382   public static ColourSchemeI getColour(AnnotatedCollectionI alignment,
383           String name)
384   {
385     int colindex = getColourIndexFromName(name);
386     if (colindex == UNDEFINED)
387     {
388       if (name.indexOf('=') == -1)
389       {
390         // try to build a colour from the string directly
391         try
392         {
393           return new UserColourScheme(name);
394         } catch (Exception e)
395         {
396           // System.err.println("Ignoring unknown colourscheme name");
397         }
398       }
399       else
400       {
401         // try to parse the string as a residue colourscheme
402         try
403         {
404           // fix the launchApp user defined coloursheme transfer bug
405           jalview.schemes.UserColourScheme ucs = new jalview.schemes.UserColourScheme(
406                   "white");
407           ucs.parseAppletParameter(name);
408
409         } catch (Exception e)
410         {
411           // System.err.println("Ignoring exception when parsing colourscheme as applet-parameter");
412         }
413       }
414     }
415     return getColour(alignment, getColourIndexFromName(name));
416   }
417
418   /**
419    * Construct an instance of ColourSchemeI corresponding to the given
420    * colourscheme index
421    * 
422    * @param seqs
423    *          sequences to be coloured by colourscheme
424    * @param width
425    *          geometry of alignment
426    * @param index
427    *          colourscheme number
428    * 
429    * @return null or an instance of the colourscheme configured to colour given
430    *         sequence set
431    */
432   public static ColourSchemeI getColour(
433           jalview.datamodel.AnnotatedCollectionI coll, int index)
434   {
435     // TODO 3.0 2.8 refactor signature to take an alignmentI like container so
436     // colourschemes based on annotation can be initialised
437     ColourSchemeI cs = null;
438
439     switch (index)
440     {
441     case CLUSTAL:
442       cs = new ClustalxColourScheme(coll, null);
443
444       break;
445
446     case BLOSUM:
447       cs = new Blosum62ColourScheme();
448
449       break;
450
451     case PID:
452       cs = new PIDColourScheme();
453
454       break;
455
456     case ZAPPO:
457       cs = new ZappoColourScheme();
458
459       break;
460
461     case TAYLOR:
462       cs = new TaylorColourScheme();
463       break;
464
465     case HYDROPHOBIC:
466       cs = new HydrophobicColourScheme();
467
468       break;
469
470     case HELIX:
471       cs = new HelixColourScheme();
472
473       break;
474
475     case STRAND:
476       cs = new StrandColourScheme();
477
478       break;
479
480     case TURN:
481       cs = new TurnColourScheme();
482
483       break;
484
485     case BURIED:
486       cs = new BuriedColourScheme();
487
488       break;
489
490     case NUCLEOTIDE:
491       cs = new NucleotideColourScheme();
492
493       break;
494
495     case PURINEPYRIMIDINE:
496       cs = new PurinePyrimidineColourScheme();
497
498       break;
499
500     case TCOFFEE:
501       cs = new TCoffeeColourScheme(coll);
502       break;
503       
504
505       
506     // case COVARIATION:
507     // cs = new CovariationColourScheme(annotation);
508
509     // break;
510
511     case USER_DEFINED:
512       Color[] col = new Color[24];
513       for (int i = 0; i < 24; i++)
514       {
515         col[i] = Color.white;
516       }
517       cs = new UserColourScheme(col);
518       break;
519
520     default:
521       break;
522     }
523
524     return cs;
525   }
526
527   public static Color getAWTColorFromName(String name)
528   {
529     Color col = null;
530     name = name.toLowerCase();
531     if (name.equals("black"))
532     {
533       col = Color.black;
534     }
535     else if (name.equals("blue"))
536     {
537       col = Color.blue;
538     }
539     else if (name.equals("cyan"))
540     {
541       col = Color.cyan;
542     }
543     else if (name.equals("darkGray"))
544     {
545       col = Color.darkGray;
546     }
547     else if (name.equals("gray"))
548     {
549       col = Color.gray;
550     }
551     else if (name.equals("green"))
552     {
553       col = Color.green;
554     }
555     else if (name.equals("lightGray"))
556     {
557       col = Color.lightGray;
558     }
559     else if (name.equals("magenta"))
560     {
561       col = Color.magenta;
562     }
563     else if (name.equals("orange"))
564     {
565       col = Color.orange;
566     }
567     else if (name.equals("pink"))
568     {
569       col = Color.pink;
570     }
571     else if (name.equals("red"))
572     {
573       col = Color.red;
574     }
575     else if (name.equals("white"))
576     {
577       col = Color.white;
578     }
579     else if (name.equals("yellow"))
580     {
581       col = Color.yellow;
582     }
583
584     return col;
585   }
586 }