Formatted source
[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 package jalview.schemes;\r
20 \r
21 public class ColourSchemeProperty {\r
22     public static final int CLUSTAL = 0;\r
23     public static final int BLOSUM = 1;\r
24     public static final int PID = 2;\r
25     public static final int ZAPPO = 3;\r
26     public static final int HYDROPHOBIC = 4;\r
27     public static final int HELIX = 5;\r
28     public static final int STRAND = 6;\r
29     public static final int TURN = 7;\r
30     public static final int BURIED = 8;\r
31     public static final int NUCLEOTIDE = 9;\r
32     public static final int USER_DEFINED = 10;\r
33     public static final int NONE = 11;\r
34 \r
35     public static int getColourIndexFromName(String name) {\r
36         int ret = 11;\r
37 \r
38         if (name.equalsIgnoreCase("Clustal")) {\r
39             ret = CLUSTAL;\r
40         } else if (name.equalsIgnoreCase("Blosum62")) {\r
41             ret = BLOSUM;\r
42         } else if (name.equalsIgnoreCase("% Identity")) {\r
43             ret = PID;\r
44         } else if (name.equalsIgnoreCase("Zappo")) {\r
45             ret = ZAPPO;\r
46         } else if (name.equalsIgnoreCase("Hydrophobic")) {\r
47             ret = HYDROPHOBIC;\r
48         } else if (name.equalsIgnoreCase("Helix Propensity")) {\r
49             ret = HELIX;\r
50         } else if (name.equalsIgnoreCase("Strand Propensity")) {\r
51             ret = STRAND;\r
52         } else if (name.equalsIgnoreCase("Turn Propensity")) {\r
53             ret = TURN;\r
54         } else if (name.equalsIgnoreCase("Buried Index")) {\r
55             ret = BURIED;\r
56         } else if (name.equalsIgnoreCase("Nucleotide")) {\r
57             ret = NUCLEOTIDE;\r
58         } else if (name.equalsIgnoreCase("User Defined")) {\r
59             ret = USER_DEFINED;\r
60         }\r
61 \r
62         return ret;\r
63     }\r
64 \r
65     public static String getColourName(ColourSchemeI cs) {\r
66         if (cs instanceof ConservationColourScheme) {\r
67             cs = ((ConservationColourScheme) cs).cs;\r
68         }\r
69 \r
70         int index = 11;\r
71 \r
72         if (cs instanceof ClustalxColourScheme) {\r
73             index = CLUSTAL;\r
74         } else if (cs instanceof Blosum62ColourScheme) {\r
75             index = BLOSUM;\r
76         } else if (cs instanceof PIDColourScheme) {\r
77             index = PID;\r
78         } else if (cs instanceof ZappoColourScheme) {\r
79             index = ZAPPO;\r
80         } else if (cs instanceof HydrophobicColourScheme) {\r
81             index = HYDROPHOBIC;\r
82         } else if (cs instanceof HelixColourScheme) {\r
83             index = HELIX;\r
84         } else if (cs instanceof StrandColourScheme) {\r
85             index = STRAND;\r
86         } else if (cs instanceof TurnColourScheme) {\r
87             index = TURN;\r
88         } else if (cs instanceof BuriedColourScheme) {\r
89             index = BURIED;\r
90         } else if (cs instanceof NucleotideColourScheme) {\r
91             index = NUCLEOTIDE;\r
92         } else if (cs instanceof UserColourScheme) {\r
93             index = USER_DEFINED;\r
94         }\r
95 \r
96         return getColourName(index);\r
97     }\r
98 \r
99     public static String getColourName(int index) {\r
100         String ret = null;\r
101 \r
102         switch (index) {\r
103         case CLUSTAL:\r
104             ret = "Clustal";\r
105 \r
106             break;\r
107 \r
108         case BLOSUM:\r
109             ret = "Blosum62";\r
110 \r
111             break;\r
112 \r
113         case PID:\r
114             ret = "% Identity";\r
115 \r
116             break;\r
117 \r
118         case ZAPPO:\r
119             ret = "Zappo";\r
120 \r
121             break;\r
122 \r
123         case HYDROPHOBIC:\r
124             ret = "Hydrophobic";\r
125 \r
126             break;\r
127 \r
128         case HELIX:\r
129             ret = "Helix Propensity";\r
130 \r
131             break;\r
132 \r
133         case STRAND:\r
134             ret = "Strand Propensity";\r
135 \r
136             break;\r
137 \r
138         case TURN:\r
139             ret = "Turn Propensity";\r
140 \r
141             break;\r
142 \r
143         case BURIED:\r
144             ret = "Buried Index";\r
145 \r
146             break;\r
147 \r
148         case NUCLEOTIDE:\r
149             ret = "Nucleotide";\r
150 \r
151             break;\r
152 \r
153         case USER_DEFINED:\r
154             ret = "User Defined";\r
155 \r
156             break;\r
157 \r
158         default:\r
159             ret = "None";\r
160 \r
161             break;\r
162         }\r
163 \r
164         return ret;\r
165     }\r
166 \r
167     public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al,\r
168         String name) {\r
169         return getColour(al, getColourIndexFromName(name));\r
170     }\r
171 \r
172     public static ColourSchemeI getColour(jalview.datamodel.AlignmentI al,\r
173         int index) {\r
174         ColourSchemeI cs = null;\r
175 \r
176         switch (index) {\r
177         case CLUSTAL:\r
178             cs = new ClustalxColourScheme(al.getSequences(), al.getWidth());\r
179 \r
180             break;\r
181 \r
182         case BLOSUM:\r
183             cs = new Blosum62ColourScheme();\r
184 \r
185             break;\r
186 \r
187         case PID:\r
188             cs = new PIDColourScheme();\r
189 \r
190             break;\r
191 \r
192         case ZAPPO:\r
193             cs = new ZappoColourScheme();\r
194 \r
195             break;\r
196 \r
197         case HYDROPHOBIC:\r
198             cs = new HydrophobicColourScheme();\r
199 \r
200             break;\r
201 \r
202         case HELIX:\r
203             cs = new HelixColourScheme();\r
204 \r
205             break;\r
206 \r
207         case STRAND:\r
208             cs = new StrandColourScheme();\r
209 \r
210             break;\r
211 \r
212         case TURN:\r
213             cs = new TurnColourScheme();\r
214 \r
215             break;\r
216 \r
217         case BURIED:\r
218             cs = new BuriedColourScheme();\r
219 \r
220             break;\r
221 \r
222         case NUCLEOTIDE:\r
223             cs = new NucleotideColourScheme();\r
224 \r
225             break;\r
226 \r
227         case USER_DEFINED:\r
228             cs = new UserColourScheme(null);\r
229 \r
230             break;\r
231 \r
232         default:\r
233             break;\r
234         }\r
235 \r
236         return cs;\r
237     }\r
238 }\r