a9815492748a8e1c51c541d5bcfcaddcdea299e6
[jalview.git] / src / jalview / schemes / ColourSchemeProperty.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */\r
19 \r
20 package jalview.schemes;\r
21 \r
22 public class ColourSchemeProperty\r
23 {\r
24   public static final int CLUSTAL = 0;\r
25   public static final int BLOSUM = 1;\r
26   public static final int PID = 2;\r
27   public static final int ZAPPO = 3;\r
28   public static final int HYDROPHOBIC=4;\r
29   public static final int HELIX=5;\r
30   public static final int STRAND=6;\r
31   public static final int TURN = 7;\r
32   public static final int BURIED = 8;\r
33   public static final int NUCLEOTIDE = 9;\r
34   public static final int USER_DEFINED = 10;\r
35   public static final int NONE = 11;\r
36 \r
37   public static int getColourIndexFromName(String name)\r
38   {\r
39     int ret=11;\r
40     if(name.equalsIgnoreCase("Clustal"))\r
41       ret = CLUSTAL;\r
42     else if(name.equalsIgnoreCase("Blosum62"))\r
43       ret = BLOSUM;\r
44     else if(name.equalsIgnoreCase("% Identity"))\r
45       ret = PID;\r
46     else if(name.equalsIgnoreCase("Zappo"))\r
47       ret = ZAPPO;\r
48     else if(name.equalsIgnoreCase("Hydrophobic"))\r
49       ret = HYDROPHOBIC;\r
50     else if(name.equalsIgnoreCase("Helix Propensity"))\r
51       ret = HELIX;\r
52     else if(name.equalsIgnoreCase("Strand Propensity"))\r
53       ret = STRAND;\r
54     else if(name.equalsIgnoreCase("Turn Propensity"))\r
55       ret = TURN;\r
56     else if(name.equalsIgnoreCase("Buried Index"))\r
57       ret = BURIED;\r
58     else if(name.equalsIgnoreCase("Nucleotide"))\r
59       ret = NUCLEOTIDE;\r
60     else if(name.equalsIgnoreCase("User Defined"))\r
61       ret =  USER_DEFINED;\r
62 \r
63     return ret;\r
64   }\r
65 \r
66   public static String getColourName(ColourSchemeI cs)\r
67   {\r
68     if(cs instanceof ConservationColourScheme)\r
69      cs = ((ConservationColourScheme)cs).cs;\r
70 \r
71 \r
72     int index = 11;\r
73     if(cs instanceof ClustalxColourScheme)\r
74       index = CLUSTAL;\r
75     else if(cs instanceof  Blosum62ColourScheme)\r
76       index = BLOSUM;\r
77     else if(cs instanceof  PIDColourScheme)\r
78       index = PID;\r
79     else if(cs instanceof  ZappoColourScheme)\r
80       index = ZAPPO;\r
81     else if(cs instanceof  HydrophobicColourScheme)\r
82       index = HYDROPHOBIC;\r
83     else if(cs instanceof  HelixColourScheme)\r
84       index = HELIX;\r
85     else if(cs instanceof  StrandColourScheme)\r
86       index = STRAND;\r
87     else if(cs instanceof  TurnColourScheme)\r
88       index = TURN;\r
89     else if(cs instanceof  BuriedColourScheme)\r
90       index = BURIED;\r
91     else if(cs instanceof  NucleotideColourScheme)\r
92       index = NUCLEOTIDE;\r
93     else if(cs instanceof  UserColourScheme)\r
94       index = USER_DEFINED;\r
95 \r
96     return getColourName(index);\r
97   }\r
98 \r
99   public static String getColourName(int index)\r
100   {\r
101     String ret=null;\r
102     switch(index)\r
103     {\r
104       case CLUSTAL: ret = "Clustal";    break;\r
105       case BLOSUM:  ret = "Blosum62";   break;\r
106       case PID:     ret = "% Identity"; break;\r
107       case ZAPPO:   ret = "Zappo";      break;\r
108       case HYDROPHOBIC: ret="Hydrophobic";break;\r
109       case HELIX:   ret="Helix Propensity";break;\r
110       case STRAND:  ret="Strand Propensity";break;\r
111       case TURN:    ret="Turn Propensity";break;\r
112       case BURIED:  ret="Buried Index";break;\r
113       case NUCLEOTIDE:ret="Nucleotide"; break;\r
114       case USER_DEFINED:ret="User Defined";break;\r
115       default: ret = "None"; break;\r
116     }\r
117     return ret;\r
118   }\r
119 \r
120   public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al, String name)\r
121   {\r
122     return getColour(al, getColourIndexFromName(name));\r
123   }\r
124 \r
125   public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al, int index)\r
126   {\r
127     ColourSchemeI cs = null;\r
128     switch(index)\r
129     {\r
130       case CLUSTAL: cs = new ClustalxColourScheme(al.getSequences(), al.getWidth()); break;\r
131       case BLOSUM: cs = new Blosum62ColourScheme(); break;\r
132       case PID: cs = new PIDColourScheme();  break;\r
133       case ZAPPO: cs = new ZappoColourScheme(); break;\r
134       case HYDROPHOBIC: cs = new HydrophobicColourScheme(); break;\r
135       case HELIX: cs = new HelixColourScheme(); break;\r
136       case STRAND: cs = new StrandColourScheme(); break;\r
137       case TURN: cs = new TurnColourScheme(); break;\r
138       case BURIED: cs = new BuriedColourScheme(); break;\r
139       case NUCLEOTIDE: cs = new NucleotideColourScheme(); break;\r
140       case USER_DEFINED: cs = new UserColourScheme(null);\r
141         break;\r
142 \r
143       default: break;\r
144     }\r
145 \r
146     return cs;\r
147   }\r
148 }\r