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