1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.analysis; |
22 |
|
|
23 |
|
import jalview.datamodel.AlignmentAnnotation; |
24 |
|
import jalview.datamodel.SequenceGroup; |
25 |
|
import jalview.datamodel.SequenceI; |
26 |
|
import jalview.renderer.AnnotationRenderer; |
27 |
|
import jalview.util.Constants; |
28 |
|
|
29 |
|
import java.util.ArrayList; |
30 |
|
import java.util.Arrays; |
31 |
|
import java.util.BitSet; |
32 |
|
import java.util.Collections; |
33 |
|
import java.util.HashMap; |
34 |
|
import java.util.List; |
35 |
|
import java.util.Map; |
36 |
|
import java.util.Optional; |
37 |
|
|
|
|
| 81% |
Uncovered Elements: 22 (116) |
Complexity: 40 |
Complexity Density: 0.61 |
|
38 |
|
public class AlignmentAnnotationUtils |
39 |
|
{ |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@param |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@param |
62 |
|
|
63 |
|
@param |
64 |
|
|
65 |
|
@param |
66 |
|
|
67 |
|
|
|
|
| 94.6% |
Uncovered Elements: 4 (74) |
Complexity: 21 |
Complexity Density: 0.48 |
|
68 |
47 |
public static void getShownHiddenTypes(... |
69 |
|
Map<String, List<List<String>>> shownTypes, |
70 |
|
Map<String, List<List<String>>> hiddenTypes, |
71 |
|
List<AlignmentAnnotation> annotations, |
72 |
|
List<SequenceI> forSequences) |
73 |
|
{ |
74 |
47 |
BitSet visibleGraphGroups = AlignmentAnnotationUtils |
75 |
|
.getVisibleLineGraphGroups(annotations); |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
47 |
Map<String, Map<Integer, List<String>>> groupLabels = new HashMap<String, Map<Integer, List<String>>>(); |
82 |
|
|
83 |
|
|
84 |
47 |
List<String> addedToShown = new ArrayList<String>(); |
85 |
47 |
List<String> addedToHidden = new ArrayList<String>(); |
86 |
|
|
87 |
47 |
for (AlignmentAnnotation aa : annotations) |
88 |
|
{ |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
224 |
if (aa.annotations == null) |
94 |
|
{ |
95 |
0 |
continue; |
96 |
|
} |
97 |
224 |
if (forSequences != null && (aa.sequenceRef != null |
98 |
|
&& forSequences.contains(aa.sequenceRef))) |
99 |
|
{ |
100 |
22 |
String calcId = aa.getCalcId(); |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
22 |
final List<String> labelAsList = new ArrayList<String>(); |
106 |
22 |
final String displayLabel = aa.label; |
107 |
22 |
labelAsList.add(displayLabel); |
108 |
22 |
if (aa.graph == AlignmentAnnotation.LINE_GRAPH |
109 |
|
&& aa.graphGroup > -1) |
110 |
|
{ |
111 |
8 |
if (!groupLabels.containsKey(calcId)) |
112 |
|
{ |
113 |
2 |
groupLabels.put(calcId, new HashMap<Integer, List<String>>()); |
114 |
|
} |
115 |
8 |
Map<Integer, List<String>> groupLabelsForCalcId = groupLabels |
116 |
|
.get(calcId); |
117 |
8 |
if (groupLabelsForCalcId.containsKey(aa.graphGroup)) |
118 |
|
{ |
119 |
4 |
if (!groupLabelsForCalcId.get(aa.graphGroup) |
120 |
|
.contains(displayLabel)) |
121 |
|
{ |
122 |
4 |
groupLabelsForCalcId.get(aa.graphGroup).add(displayLabel); |
123 |
|
} |
124 |
|
} |
125 |
|
else |
126 |
|
{ |
127 |
4 |
groupLabelsForCalcId.put(aa.graphGroup, labelAsList); |
128 |
|
} |
129 |
|
} |
130 |
|
else |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
{ |
136 |
14 |
String rememberAs = calcId + "!" + displayLabel; |
137 |
14 |
if (aa.visible && !addedToShown.contains(rememberAs)) |
138 |
|
{ |
139 |
6 |
if (!shownTypes.containsKey(calcId)) |
140 |
|
{ |
141 |
4 |
shownTypes.put(calcId, new ArrayList<List<String>>()); |
142 |
|
} |
143 |
6 |
shownTypes.get(calcId).add(labelAsList); |
144 |
6 |
addedToShown.add(rememberAs); |
145 |
|
} |
146 |
|
else |
147 |
|
{ |
148 |
8 |
if (!aa.visible && !addedToHidden.contains(rememberAs)) |
149 |
|
{ |
150 |
8 |
if (!hiddenTypes.containsKey(calcId)) |
151 |
|
{ |
152 |
7 |
hiddenTypes.put(calcId, new ArrayList<List<String>>()); |
153 |
|
} |
154 |
8 |
hiddenTypes.get(calcId).add(labelAsList); |
155 |
8 |
addedToHidden.add(rememberAs); |
156 |
|
} |
157 |
|
} |
158 |
|
} |
159 |
|
} |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
47 |
for (String calcId : groupLabels.keySet()) |
168 |
|
{ |
169 |
2 |
for (int group : groupLabels.get(calcId).keySet()) |
170 |
|
{ |
171 |
4 |
final List<String> groupLabel = groupLabels.get(calcId).get(group); |
172 |
|
|
173 |
4 |
Collections.sort(groupLabel); |
174 |
4 |
if (visibleGraphGroups.get(group)) |
175 |
|
{ |
176 |
2 |
if (!shownTypes.containsKey(calcId)) |
177 |
|
{ |
178 |
1 |
shownTypes.put(calcId, new ArrayList<List<String>>()); |
179 |
|
} |
180 |
2 |
if (!shownTypes.get(calcId).contains(groupLabel)) |
181 |
|
{ |
182 |
1 |
shownTypes.get(calcId).add(groupLabel); |
183 |
|
} |
184 |
|
} |
185 |
|
else |
186 |
|
{ |
187 |
2 |
if (!hiddenTypes.containsKey(calcId)) |
188 |
|
{ |
189 |
1 |
hiddenTypes.put(calcId, new ArrayList<List<String>>()); |
190 |
|
} |
191 |
2 |
if (!hiddenTypes.get(calcId).contains(groupLabel)) |
192 |
|
{ |
193 |
1 |
hiddenTypes.get(calcId).add(groupLabel); |
194 |
|
} |
195 |
|
} |
196 |
|
} |
197 |
|
} |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
|
206 |
|
|
207 |
|
@param |
208 |
|
|
209 |
|
|
210 |
|
@param |
211 |
|
|
212 |
|
@param |
213 |
|
|
214 |
|
|
|
|
| 25% |
Uncovered Elements: 18 (24) |
Complexity: 13 |
Complexity Density: 0.93 |
|
215 |
4 |
public static void getShownHiddenSecondaryStructureProvidersForGroup(... |
216 |
|
List<String> shownTypes, List<String> hiddenTypes, |
217 |
|
List<AlignmentAnnotation> annotations, |
218 |
|
SequenceGroup selectedSequenceGroup) |
219 |
|
{ |
220 |
|
|
221 |
4 |
if (selectedSequenceGroup == null || annotations == null) |
222 |
|
{ |
223 |
0 |
return; |
224 |
|
} |
225 |
|
|
226 |
|
|
227 |
4 |
List<String> ssSourcesForSelectedGroup = selectedSequenceGroup |
228 |
|
.getSecondaryStructureSources(); |
229 |
|
|
230 |
|
|
231 |
4 |
if (ssSourcesForSelectedGroup == null |
232 |
|
|| ssSourcesForSelectedGroup.isEmpty()) |
233 |
|
{ |
234 |
4 |
return; |
235 |
|
} |
236 |
|
|
237 |
|
|
238 |
0 |
for (AlignmentAnnotation aa : annotations) |
239 |
|
{ |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
0 |
if (aa.annotations == null || aa.groupRef == null |
245 |
|
|| selectedSequenceGroup != aa.groupRef |
246 |
|
|| !aa.label.startsWith( |
247 |
|
Constants.SECONDARY_STRUCTURE_CONSENSUS_LABEL)) |
248 |
|
{ |
249 |
0 |
continue; |
250 |
|
} |
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
|
|
256 |
0 |
Optional<String> provider = ssSourcesForSelectedGroup.stream() |
257 |
|
.filter(aa.label::contains).findFirst() |
258 |
|
.map(substring -> aa.label.substring(0, |
259 |
|
aa.label.indexOf(substring) + substring.length())); |
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
0 |
provider.ifPresent(p -> { |
265 |
0 |
if (aa.visible && !shownTypes.contains(p)) |
266 |
|
{ |
267 |
0 |
shownTypes.add(p); |
268 |
|
} |
269 |
0 |
else if (!aa.visible && !shownTypes.contains(p)) |
270 |
|
{ |
271 |
0 |
hiddenTypes.add(p); |
272 |
|
} |
273 |
|
}); |
274 |
|
} |
275 |
|
} |
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
@see |
288 |
|
@param |
289 |
|
@return |
290 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
291 |
48 |
public static BitSet getVisibleLineGraphGroups(... |
292 |
|
List<AlignmentAnnotation> annotations) |
293 |
|
{ |
294 |
48 |
BitSet result = new BitSet(); |
295 |
48 |
for (AlignmentAnnotation ann : annotations) |
296 |
|
{ |
297 |
236 |
if (ann.graph == AlignmentAnnotation.LINE_GRAPH && ann.visible) |
298 |
|
{ |
299 |
6 |
int gg = ann.graphGroup; |
300 |
6 |
if (gg > -1) |
301 |
|
{ |
302 |
5 |
result.set(gg); |
303 |
|
} |
304 |
|
} |
305 |
|
} |
306 |
48 |
return result; |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
@param |
314 |
|
@return |
315 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
316 |
55 |
public static List<AlignmentAnnotation> asList(AlignmentAnnotation[] anns)... |
317 |
|
{ |
318 |
|
|
319 |
55 |
return (anns == null ? Collections.<AlignmentAnnotation> emptyList() |
320 |
|
: Arrays.asList(anns)); |
321 |
|
} |
322 |
|
} |