1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.schemes; |
22 |
|
|
23 |
|
import jalview.api.AlignViewportI; |
24 |
|
import jalview.datamodel.AnnotatedCollectionI; |
25 |
|
import jalview.util.ColorUtils; |
26 |
|
import jalview.util.StringUtils; |
27 |
|
|
28 |
|
import java.awt.Color; |
29 |
|
import java.util.ArrayList; |
30 |
|
import java.util.Collections; |
31 |
|
import java.util.HashMap; |
32 |
|
import java.util.List; |
33 |
|
import java.util.Map; |
34 |
|
import java.util.Map.Entry; |
35 |
|
import java.util.StringTokenizer; |
36 |
|
|
|
|
| 83.5% |
Uncovered Elements: 27 (164) |
Complexity: 46 |
Complexity Density: 0.46 |
|
37 |
|
public class UserColourScheme extends ResidueColourScheme |
38 |
|
{ |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
Color[] lowerCaseColours; |
43 |
|
|
44 |
|
protected String schemeName; |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
5 |
public UserColourScheme()... |
47 |
|
{ |
48 |
5 |
super(ResidueProperties.aaIndex); |
49 |
|
} |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
51 |
8 |
public UserColourScheme(Color[] newColors)... |
52 |
|
{ |
53 |
8 |
super(ResidueProperties.aaIndex); |
54 |
8 |
colors = newColors; |
55 |
|
} |
56 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
0 |
@Override... |
58 |
|
public ColourSchemeI getInstance(AlignViewportI view, |
59 |
|
AnnotatedCollectionI sg) |
60 |
|
{ |
61 |
0 |
return new UserColourScheme(this); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@return |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
69 |
0 |
protected UserColourScheme(UserColourScheme from)... |
70 |
|
{ |
71 |
0 |
this(from.colors); |
72 |
0 |
schemeName = from.schemeName; |
73 |
0 |
if (from.lowerCaseColours != null) |
74 |
|
{ |
75 |
0 |
lowerCaseColours = new Color[from.lowerCaseColours.length]; |
76 |
0 |
System.arraycopy(from.lowerCaseColours, 0, lowerCaseColours, 0, |
77 |
|
from.lowerCaseColours.length); |
78 |
|
} |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
92 |
5 |
public UserColourScheme(String colour)... |
93 |
|
{ |
94 |
5 |
super(ResidueProperties.aaIndex); |
95 |
|
|
96 |
5 |
if (colour.contains("=")) |
97 |
|
{ |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
2 |
parseAppletParameter(colour); |
102 |
2 |
return; |
103 |
|
} |
104 |
|
|
105 |
3 |
Color col = ColorUtils.parseColourString(colour); |
106 |
|
|
107 |
3 |
if (col == null) |
108 |
|
{ |
109 |
1 |
System.out.println("Making colour from name: " + colour); |
110 |
1 |
col = ColorUtils.createColourFromName(colour); |
111 |
|
} |
112 |
|
|
113 |
3 |
setAll(col); |
114 |
3 |
schemeName = colour; |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
@param |
121 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
122 |
7 |
protected void setAll(Color col)... |
123 |
|
{ |
124 |
7 |
if (symbolIndex == null) |
125 |
|
{ |
126 |
0 |
return; |
127 |
|
} |
128 |
7 |
int max = 0; |
129 |
7 |
for (int index : symbolIndex) |
130 |
|
{ |
131 |
1785 |
max = Math.max(max, index); |
132 |
|
} |
133 |
7 |
colors = new Color[max + 1]; |
134 |
175 |
for (int i = 0; i <= max; i++) |
135 |
|
{ |
136 |
168 |
colors[i] = col; |
137 |
|
} |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
0 |
public Color[] getColours()... |
141 |
|
{ |
142 |
0 |
return colors; |
143 |
|
} |
144 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
145 |
0 |
public Color[] getLowerCaseColours()... |
146 |
|
{ |
147 |
0 |
return lowerCaseColours; |
148 |
|
} |
149 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
150 |
3 |
public void setName(String name)... |
151 |
|
{ |
152 |
3 |
schemeName = name; |
153 |
|
} |
154 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
155 |
0 |
public String getName()... |
156 |
|
{ |
157 |
0 |
return schemeName; |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
@param |
174 |
|
|
|
|
| 89.1% |
Uncovered Elements: 5 (46) |
Complexity: 11 |
Complexity Density: 0.39 |
|
175 |
4 |
void parseAppletParameter(String paramValue)... |
176 |
|
{ |
177 |
4 |
setAll(Color.white); |
178 |
|
|
179 |
4 |
StringTokenizer st = new StringTokenizer(paramValue, ";"); |
180 |
4 |
StringTokenizer st2; |
181 |
4 |
String token = null, colour, residues; |
182 |
4 |
try |
183 |
|
{ |
184 |
21 |
while (st.hasMoreElements()) |
185 |
|
{ |
186 |
17 |
token = st.nextToken().trim(); |
187 |
17 |
residues = token.substring(0, token.indexOf("=")); |
188 |
17 |
colour = token.substring(token.indexOf("=") + 1); |
189 |
|
|
190 |
17 |
st2 = new StringTokenizer(residues, " ,"); |
191 |
45 |
while (st2.hasMoreTokens()) |
192 |
|
{ |
193 |
28 |
String residue = st2.nextToken(); |
194 |
|
|
195 |
28 |
int colIndex = ResidueProperties.aaIndex[residue.charAt(0)]; |
196 |
28 |
if (colIndex == -1) |
197 |
|
{ |
198 |
0 |
continue; |
199 |
|
} |
200 |
|
|
201 |
28 |
if (residue.equalsIgnoreCase("lowerCase")) |
202 |
|
{ |
203 |
1 |
if (lowerCaseColours == null) |
204 |
|
{ |
205 |
0 |
lowerCaseColours = new Color[colors.length]; |
206 |
|
} |
207 |
25 |
for (int i = 0; i < lowerCaseColours.length; i++) |
208 |
|
{ |
209 |
24 |
if (lowerCaseColours[i] == null) |
210 |
|
{ |
211 |
22 |
lowerCaseColours[i] = ColorUtils.parseColourString(colour); |
212 |
|
} |
213 |
|
} |
214 |
|
|
215 |
1 |
continue; |
216 |
|
} |
217 |
|
|
218 |
27 |
if (residue.equals(residue.toLowerCase())) |
219 |
|
{ |
220 |
6 |
if (lowerCaseColours == null) |
221 |
|
{ |
222 |
4 |
lowerCaseColours = new Color[colors.length]; |
223 |
|
} |
224 |
6 |
lowerCaseColours[colIndex] = ColorUtils |
225 |
|
.parseColourString(colour); |
226 |
|
} |
227 |
|
else |
228 |
|
{ |
229 |
21 |
colors[colIndex] = ColorUtils.parseColourString(colour); |
230 |
|
} |
231 |
|
} |
232 |
|
} |
233 |
|
} catch (Exception ex) |
234 |
|
{ |
235 |
0 |
System.out.println( |
236 |
|
"Error parsing userDefinedColours:\n" + token + "\n" + ex); |
237 |
|
} |
238 |
|
|
239 |
|
} |
240 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
241 |
0 |
public void setLowerCaseColours(Color[] lcolours)... |
242 |
|
{ |
243 |
0 |
lowerCaseColours = lcolours; |
244 |
|
} |
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 5 |
Complexity Density: 1 |
|
251 |
58 |
@Override... |
252 |
|
public Color findColour(char c) |
253 |
|
{ |
254 |
58 |
if ('a' <= c && c <= 'z' && lowerCaseColours != null) |
255 |
|
{ |
256 |
14 |
Color colour = lowerCaseColours[symbolIndex[c]]; |
257 |
14 |
if (colour != null) |
258 |
|
{ |
259 |
10 |
return colour; |
260 |
|
} |
261 |
|
} |
262 |
48 |
return super.findColour(c); |
263 |
|
} |
264 |
|
|
265 |
|
|
266 |
|
|
267 |
|
|
268 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
269 |
5 |
@Override... |
270 |
|
public String getSchemeName() |
271 |
|
{ |
272 |
5 |
if (schemeName != null && schemeName.length() > 0) |
273 |
|
{ |
274 |
1 |
return schemeName; |
275 |
|
} |
276 |
4 |
return ResidueColourScheme.USER_DEFINED; |
277 |
|
} |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
@return |
283 |
|
|
|
|
| 95.6% |
Uncovered Elements: 2 (45) |
Complexity: 10 |
Complexity Density: 0.32 |
|
284 |
1 |
public String toAppletParameter()... |
285 |
|
{ |
286 |
|
|
287 |
|
|
288 |
|
|
289 |
1 |
Map<Color, List<String>> colours = new HashMap<>(); |
290 |
|
|
291 |
27 |
for (char symbol = 'A'; symbol <= 'Z'; symbol++) |
292 |
|
{ |
293 |
26 |
String residue = String.valueOf(symbol); |
294 |
26 |
int index = symbolIndex[symbol]; |
295 |
26 |
Color c = colors[index]; |
296 |
26 |
if (c != null && !c.equals(Color.white)) |
297 |
|
{ |
298 |
5 |
if (colours.get(c) == null) |
299 |
|
{ |
300 |
2 |
colours.put(c, new ArrayList<String>()); |
301 |
|
} |
302 |
5 |
colours.get(c).add(residue); |
303 |
|
} |
304 |
26 |
if (lowerCaseColours != null) |
305 |
|
{ |
306 |
26 |
c = lowerCaseColours[index]; |
307 |
26 |
if (c != null && !c.equals(Color.white)) |
308 |
|
{ |
309 |
1 |
residue = residue.toLowerCase(); |
310 |
1 |
if (colours.get(c) == null) |
311 |
|
{ |
312 |
1 |
colours.put(c, new ArrayList<String>()); |
313 |
|
} |
314 |
1 |
colours.get(c).add(residue); |
315 |
|
} |
316 |
|
} |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
1 |
List<String> residueColours = new ArrayList<>(); |
323 |
1 |
for (Entry<Color, List<String>> cols : colours.entrySet()) |
324 |
|
{ |
325 |
3 |
boolean first = true; |
326 |
3 |
StringBuilder sb = new StringBuilder(); |
327 |
3 |
for (String residue : cols.getValue()) |
328 |
|
{ |
329 |
6 |
if (!first) |
330 |
|
{ |
331 |
3 |
sb.append(","); |
332 |
|
} |
333 |
6 |
sb.append(residue); |
334 |
6 |
first = false; |
335 |
|
} |
336 |
3 |
sb.append("="); |
337 |
|
|
338 |
|
|
339 |
|
|
340 |
3 |
String hexString = Integer.toHexString(cols.getKey().getRGB()) |
341 |
|
.substring(2); |
342 |
3 |
sb.append(hexString); |
343 |
3 |
residueColours.add(sb.toString()); |
344 |
|
} |
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
1 |
Collections.sort(residueColours); |
350 |
1 |
return StringUtils.listToDelimitedString(residueColours, ";"); |
351 |
|
} |
352 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
353 |
4 |
@Override... |
354 |
|
public boolean hasGapColour() |
355 |
|
{ |
356 |
4 |
return (findColour(' ') != null); |
357 |
|
} |
358 |
|
} |